2023-08-27 17:01:58 +02:00
|
|
|
import { Fragment } from 'react'
|
2023-08-27 16:24:18 +02:00
|
|
|
import { ns as optionsNs } from './options.mjs'
|
|
|
|
import { ns as measieNs } from './measurements.mjs'
|
|
|
|
import { Accordion } from 'shared/components/accordion.mjs'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
import { nsMerge } from 'shared/utils.mjs'
|
2023-09-28 15:58:50 +02:00
|
|
|
import { OptionsIcon, MeasieIcon } from 'shared/components/icons.mjs'
|
2023-08-27 16:24:18 +02:00
|
|
|
import { ListInput } from 'shared/components/inputs.mjs'
|
|
|
|
import { optionsMenuStructure } from 'shared/utils.mjs'
|
|
|
|
|
|
|
|
export const ns = nsMerge('workbench', optionsNs, measieNs)
|
|
|
|
|
|
|
|
const flattenOptions = (options, list = false, path = []) => {
|
|
|
|
if (list === false) return flattenOptions(optionsMenuStructure(options), new Set())
|
|
|
|
|
|
|
|
for (const [key, option] of Object.entries(options)) {
|
|
|
|
if (key !== 'isGroup') {
|
|
|
|
if (!option.isGroup) list.add({ key, option, path })
|
|
|
|
else list = flattenOptions(option, list, [...path, key])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
|
|
|
const spacer = <span className="px-2 opacity-50">/</span>
|
2023-06-06 13:18:44 -05:00
|
|
|
|
|
|
|
export const TestMenu = ({
|
|
|
|
design,
|
|
|
|
patternConfig,
|
|
|
|
settings,
|
|
|
|
update,
|
2023-08-27 17:01:58 +02:00
|
|
|
//language,
|
|
|
|
//account,
|
|
|
|
//DynamicDocs,
|
2023-06-06 13:18:44 -05:00
|
|
|
}) => {
|
2023-08-27 16:24:18 +02:00
|
|
|
const { t } = useTranslation(ns)
|
|
|
|
|
|
|
|
const allOptions = flattenOptions(patternConfig.options)
|
2023-06-06 13:18:44 -05:00
|
|
|
|
|
|
|
return (
|
2023-08-27 16:24:18 +02:00
|
|
|
<Accordion
|
|
|
|
items={[
|
|
|
|
[
|
2023-08-27 17:06:01 +02:00
|
|
|
<Fragment key={1}>
|
2023-08-27 16:24:18 +02:00
|
|
|
<h5 className="flex flex-row gap-2 items-center justify-between w-full">
|
|
|
|
<span>{t('workbench:testOptions')}</span>
|
|
|
|
<OptionsIcon className="w-8 h-8" />
|
|
|
|
</h5>
|
|
|
|
<p>{t('workbench:testOptionsDesc')}</p>
|
2023-08-27 17:06:01 +02:00
|
|
|
</Fragment>,
|
2023-08-27 16:24:18 +02:00
|
|
|
<ListInput
|
2023-08-27 17:06:01 +02:00
|
|
|
key={2}
|
2023-08-27 17:01:58 +02:00
|
|
|
list={[...allOptions].map((option, i) => ({
|
|
|
|
key: i,
|
2023-08-27 16:24:18 +02:00
|
|
|
label: [
|
|
|
|
...option.path.map((p) => (
|
|
|
|
<>
|
|
|
|
<span>{t(`${p}.t`)}</span>
|
|
|
|
{spacer}
|
|
|
|
</>
|
|
|
|
)),
|
2023-08-27 17:01:58 +02:00
|
|
|
<span key={1}>{t(`${design}:${option.key}.t`)}</span>,
|
2023-08-27 16:24:18 +02:00
|
|
|
],
|
|
|
|
val: option.key,
|
|
|
|
}))}
|
|
|
|
update={(value) => {
|
|
|
|
if (value) update.settings(['sample'], { type: 'option', option: value })
|
|
|
|
else update.settings(['sample'])
|
|
|
|
}}
|
2023-08-28 15:00:59 +02:00
|
|
|
current={settings?.sample?.option}
|
2023-08-27 16:24:18 +02:00
|
|
|
/>,
|
|
|
|
],
|
|
|
|
[
|
2023-08-27 17:01:58 +02:00
|
|
|
<Fragment key="a">
|
2023-08-27 16:24:18 +02:00
|
|
|
<h5 className="flex flex-row gap-2 items-center justify-between w-full">
|
|
|
|
<span>{t('workbench:testMeasurements')}</span>
|
|
|
|
<MeasieIcon className="w-8 h-8" />
|
|
|
|
</h5>
|
2023-09-26 15:40:32 +02:00
|
|
|
<p className="text-left">{t('workbench:testMeasurementsDesc')}</p>
|
2023-08-27 17:01:58 +02:00
|
|
|
</Fragment>,
|
2023-08-27 16:24:18 +02:00
|
|
|
<ListInput
|
2023-08-27 17:01:58 +02:00
|
|
|
key="b"
|
2023-08-27 16:24:18 +02:00
|
|
|
list={patternConfig.measurements.map((m) => ({
|
|
|
|
label: t(m),
|
|
|
|
val: m,
|
|
|
|
}))}
|
|
|
|
update={(value) => {
|
|
|
|
if (value) update.settings(['sample'], { type: 'measurement', measurement: value })
|
|
|
|
else update.settings(['sample'])
|
|
|
|
}}
|
2023-08-28 15:00:59 +02:00
|
|
|
current={settings?.sample?.measurement}
|
2023-08-27 16:24:18 +02:00
|
|
|
/>,
|
|
|
|
],
|
2023-09-26 15:40:32 +02:00
|
|
|
// FIXME: Implement this once v3 is ready
|
|
|
|
//[
|
|
|
|
// <Fragment key="a">
|
|
|
|
// <h5 className="flex flex-row gap-2 items-center justify-between w-full">
|
|
|
|
// <span>{t('workbench:testSets')}</span>
|
|
|
|
// <CommunityIcon className="w-8 h-8" />
|
|
|
|
// </h5>
|
|
|
|
// <p>{t('workbench:testSetsDesc')}</p>
|
|
|
|
// </Fragment>,
|
|
|
|
// <V3Wip key="b" />,
|
|
|
|
//],
|
2023-08-27 16:24:18 +02:00
|
|
|
]}
|
|
|
|
/>
|
2023-06-06 13:18:44 -05:00
|
|
|
)
|
|
|
|
}
|