From 4634ced281c069fedb6e2d7db4f773db9824c253 Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Sat, 29 Jan 2022 18:24:36 +0100 Subject: [PATCH] chore(lab): Refactoring workbench menu --- .../menu/core-settings/core-setting-bool.js | 50 ++----- .../menu/core-settings/core-setting-list.js | 8 +- .../core-settings/core-setting-sa-bool.js | 49 ++----- .../workbench/menu/core-settings/index.js | 40 ++---- .../workbench/menu/core-settings/setting.js | 126 ++++++------------ .../workbench/menu/design-options/index.js | 27 ++-- .../menu/design-options/option-group.js | 49 +++---- .../menu/design-options/option-sub-group.js | 49 ++----- .../workbench/menu/design-options/option.js | 96 ++++--------- .../components/workbench/menu/index.js | 64 +++++++++ .../components/workbench/menu/xray/disable.js | 39 ++---- .../components/workbench/menu/xray/index.js | 21 +-- .../components/workbench/menu/xray/list.js | 60 ++++----- .../components/workbench/menu/xray/path.js | 5 + .../components/workbench/menu/xray/reset.js | 42 ++---- 15 files changed, 270 insertions(+), 455 deletions(-) create mode 100644 packages/freesewing.shared/components/workbench/menu/xray/path.js diff --git a/packages/freesewing.shared/components/workbench/menu/core-settings/core-setting-bool.js b/packages/freesewing.shared/components/workbench/menu/core-settings/core-setting-bool.js index e5aa79caaae..fbb2be48d1f 100644 --- a/packages/freesewing.shared/components/workbench/menu/core-settings/core-setting-bool.js +++ b/packages/freesewing.shared/components/workbench/menu/core-settings/core-setting-bool.js @@ -1,11 +1,9 @@ import { useState } from 'react' -import { linkClasses } from 'shared/components/navigation/primary.js' +import { SecText, SumButton, Li, SumDiv, Deg } from 'shared/components/workbench/menu/index.js' const CoreSettingBool = props => { - const val = props.gist[props.setting] - const dflt = props.dflt - const [value, setValue] = useState(val) + const [value, setValue] = useState(props.gist[props.setting]) const toggle = (evt) => { props.updateGist([props.setting], !value) @@ -13,41 +11,15 @@ const CoreSettingBool = props => { } return ( -
  • - -
  • +
  • + + + + { props.app.t(`settings.${props.setting}.title`) } + + {props.app.t('app.'+ (value ? 'yes' : 'no'))} + +
  • ) } diff --git a/packages/freesewing.shared/components/workbench/menu/core-settings/core-setting-list.js b/packages/freesewing.shared/components/workbench/menu/core-settings/core-setting-list.js index bc4c85d6d4e..761c57e0890 100644 --- a/packages/freesewing.shared/components/workbench/menu/core-settings/core-setting-list.js +++ b/packages/freesewing.shared/components/workbench/menu/core-settings/core-setting-list.js @@ -1,4 +1,5 @@ import { useState } from 'react' +import { Deg } from 'shared/components/workbench/menu/index.js' const CoreSettingList = props => { const { dflt, list } = props @@ -35,12 +36,7 @@ const CoreSettingList = props => { ${entry.key === value && 'font-bold text-secondary'} `} > - - <>° - + {entry.title} ))} diff --git a/packages/freesewing.shared/components/workbench/menu/core-settings/core-setting-sa-bool.js b/packages/freesewing.shared/components/workbench/menu/core-settings/core-setting-sa-bool.js index 9cb1a87a969..6766e1fc1ba 100644 --- a/packages/freesewing.shared/components/workbench/menu/core-settings/core-setting-sa-bool.js +++ b/packages/freesewing.shared/components/workbench/menu/core-settings/core-setting-sa-bool.js @@ -1,10 +1,9 @@ import { useState } from 'react' -import { linkClasses } from 'shared/components/navigation/primary.js' +import { SecText, SumButton, Li, SumDiv, Deg } from 'shared/components/workbench/menu/index.js' const CoreSettingSaBool = props => { - const val = props.gist.saBool || false - const [value, setValue] = useState(val) + const [value, setValue] = useState(props.gist.saBool || false) const toggle = () => { props.setGist({ @@ -16,45 +15,19 @@ const CoreSettingSaBool = props => { } return ( -
  • - -
  • + + {props.app.t('app.'+ (value ? 'yes' : 'no'))} + + ) } diff --git a/packages/freesewing.shared/components/workbench/menu/core-settings/index.js b/packages/freesewing.shared/components/workbench/menu/core-settings/index.js index d91bdd5f367..81c622ab939 100644 --- a/packages/freesewing.shared/components/workbench/menu/core-settings/index.js +++ b/packages/freesewing.shared/components/workbench/menu/core-settings/index.js @@ -1,6 +1,7 @@ import SettingsIcon from 'shared/components/icons/settings.js' import { linkClasses, Chevron } from 'shared/components/navigation/primary.js' import Setting from './setting.js' +import { Ul, Details, TopSummary, TopSumTitle } from '../index.js' const settings = { paperless: { @@ -46,31 +47,18 @@ const settings = { }, } -const CoreSettings = props => { - - return ( -
    - - - - {props.app.t('app.settings')} - - - -
      - {Object.keys(settings).map(setting => ( - - ))} -
    -
    - ) -} +const CoreSettings = props => ( +
    + }> + {props.app.t('app.settings')} + + +
      + {Object.keys(settings).map(setting => ( + + ))} +
    +
    +) export default CoreSettings diff --git a/packages/freesewing.shared/components/workbench/menu/core-settings/setting.js b/packages/freesewing.shared/components/workbench/menu/core-settings/setting.js index d28d0e9e109..eef31c32db1 100644 --- a/packages/freesewing.shared/components/workbench/menu/core-settings/setting.js +++ b/packages/freesewing.shared/components/workbench/menu/core-settings/setting.js @@ -1,4 +1,4 @@ -import { linkClasses, Chevron } from 'shared/components/navigation/primary.js' +import { Chevron } from 'shared/components/navigation/primary.js' import PctDegOption from 'shared/components/workbench/inputs/design-option-pct-deg' import CountOption from 'shared/components/workbench/inputs/design-option-count' import ListSetting from './core-setting-list' @@ -9,67 +9,46 @@ import BoolSetting from './core-setting-bool.js' import SaBoolSetting from './core-setting-sa-bool.js' import SaMmSetting from './core-setting-sa-mm.js' import { formatMm, formatPercentage, optionType } from 'shared/utils.js' +import { SecText, Li, Details, Summary, SumDiv, Deg } from 'shared/components/workbench/menu/index.js' const settings = { - paperless: props => { - return ( - - {props.app.t(`app.${props.gist.paperless ? 'yes' : 'no'}`)} - - ) - }, - complete: props => { - return ( - - {props.app.t(`app.${props.gist.complete ? 'yes' : 'no'}`)} - - ) - }, - debug: props => { - return ( - - {props.app.t(`app.${props.gist.debug ? 'yes' : 'no'}`)} - - ) - }, - locale: props => { - return ( - - {props.app.t(`i18n.${props.gist.locale}`)} - - ) - }, - units: props => { - return ( - - {props.app.t(`app.${props.gist.units}Units`)} - - ) - }, - margin: props => { - return ( - - ) - }, + paperless: props => ( + + {props.app.t(`app.${props.gist.paperless ? 'yes' : 'no'}`)} + + ), + complete: props => ( + + {props.app.t(`app.${props.gist.complete ? 'yes' : 'no'}`)} + + ), + debug: props => ( + + {props.app.t(`app.${props.gist.debug ? 'yes' : 'no'}`)} + + ), + locale: props => ( + + {props.app.t(`i18n.${props.gist.locale}`)} + + ), + units: props => ( + + {props.app.t(`app.${props.gist.units}Units`)} + + ), + margin: props => , scale: props => props.gist.scale === 1 - ? {props.gist.scale} + ? {props.gist.scale} : {props.gist.scale}, - saMm: props => { - return ( - - ) - }, + saMm: props => , renderer: props => ( - + {props.config.titles[props.gist.renderer]} - + ), only: props => (props.gist?.only && props.gist.only.length > 0) - ? {props.gist.only.length} + ? {props.gist.only.length} : {props.app.t('app.default')} } @@ -112,30 +91,11 @@ const Setting = props => { const Value = settings[props.setting] return ( -
  • -
    - -
    - - <>° - +
  • +
    + + + {props.setting === 'saMm' ? ( <> @@ -145,13 +105,13 @@ const Setting = props => { ) : {props.app.t(`settings.${props.setting}.title`)} } -
  • + - -
    + + -
    -
  • + + ) } diff --git a/packages/freesewing.shared/components/workbench/menu/design-options/index.js b/packages/freesewing.shared/components/workbench/menu/design-options/index.js index 34d27542653..321dad6a005 100644 --- a/packages/freesewing.shared/components/workbench/menu/design-options/index.js +++ b/packages/freesewing.shared/components/workbench/menu/design-options/index.js @@ -1,31 +1,22 @@ import OptionsIcon from 'shared/components/icons/options.js' -import { linkClasses, Chevron } from 'shared/components/navigation/primary.js' +import { Chevron } from 'shared/components/navigation/primary.js' import OptionGroup from './option-group' +import { Ul, Details, TopSummary, TopSumTitle } from 'shared/components/workbench/menu' const DesignOptions = props => { return ( -
    - - - - {props.app.t('app.designOptions')} - +
    + }> + {props.app.t('app.designOptions')} -
    -
      + +
        {Object.keys(props.pattern.config.optionGroups).map(group => ( ))} -
      -
    + + ) } diff --git a/packages/freesewing.shared/components/workbench/menu/design-options/option-group.js b/packages/freesewing.shared/components/workbench/menu/design-options/option-group.js index 0dae9cdd78a..39d132344b5 100644 --- a/packages/freesewing.shared/components/workbench/menu/design-options/option-group.js +++ b/packages/freesewing.shared/components/workbench/menu/design-options/option-group.js @@ -1,49 +1,30 @@ -import { linkClasses, Chevron } from 'shared/components/navigation/primary.js' +import { Chevron } from 'shared/components/navigation/primary.js' import Option from './option' import OptionSubGroup from './option-sub-group' +import { Li, Ul, Details, Summary, SumDiv, Deg } from 'shared/components/workbench/menu' const OptionGroup = props => { const config = props.config || props.pattern.config.optionGroups[props.group] return ( -
  • -
    - -
    - - <>° - - +
  • +
    + + + + { props.app.t(`optiongroups.${props.group}`) } -
  • - -
    -
      + + + +
        {config.map(option => typeof option === 'string' ?
      -
    -
  • + + + ) } diff --git a/packages/freesewing.shared/components/workbench/menu/design-options/option-sub-group.js b/packages/freesewing.shared/components/workbench/menu/design-options/option-sub-group.js index c5eb0eca145..ccc52c7c09b 100644 --- a/packages/freesewing.shared/components/workbench/menu/design-options/option-sub-group.js +++ b/packages/freesewing.shared/components/workbench/menu/design-options/option-sub-group.js @@ -1,47 +1,26 @@ import { linkClasses, Chevron } from 'shared/components/navigation/primary.js' import Option from './option' +import { Li, Ul, Details, Summary, SumButton, SumDiv, Deg } from 'shared/components/workbench/menu' const OptionSubGroup = props => { return Object.keys(props.sub).map(name => ( -
  • -
    - -
    - - <>° - - - { props.app.t(`optiongroups.${name}`) } - -
    - -
    -
      +
    • +
      + + + + { props.app.t(`optiongroups.${name}`) } + + + +
        {props.sub[name].map(option => typeof option === 'string' ?
      -
      -
    • +
    +
    +
  • )) } diff --git a/packages/freesewing.shared/components/workbench/menu/design-options/option.js b/packages/freesewing.shared/components/workbench/menu/design-options/option.js index 44098c0522c..5394e8ce202 100644 --- a/packages/freesewing.shared/components/workbench/menu/design-options/option.js +++ b/packages/freesewing.shared/components/workbench/menu/design-options/option.js @@ -1,8 +1,9 @@ -import { linkClasses, Chevron } from 'shared/components/navigation/primary.js' +import { Chevron } from 'shared/components/navigation/primary.js' import PctDegOption from 'shared/components/workbench/inputs/design-option-pct-deg' import CountOption from 'shared/components/workbench/inputs/design-option-count' import ListOption from 'shared/components/workbench/inputs/design-option-list' import { formatMm, formatPercentage, optionType } from 'shared/utils.js' +import { Li, Ul, Details, Summary, SumButton, SumDiv, Deg } from 'shared/components/workbench/menu' const values = { pct: props => { @@ -94,77 +95,36 @@ const Option = props => { else props.unsetGist(['options', props.option]) } - if (type === 'bool') return ( -
  • - -
  • - - ) - - return ( -
  • -
    - -
    - - <>° - + return (type === 'bool') + ? ( +
  • + + + { props.app.t(`options.${props.pattern.config.name}.${props.option}.title`) } -
  • + - -
    - -
    -
  • - ) + + + ) : ( +
  • +
    + + + + + { props.app.t(`options.${props.pattern.config.name}.${props.option}.title`) } + + + + + + +
    +
  • + ) } export default Option diff --git a/packages/freesewing.shared/components/workbench/menu/index.js b/packages/freesewing.shared/components/workbench/menu/index.js index 8cccf4cb41d..93e6dde5d2b 100644 --- a/packages/freesewing.shared/components/workbench/menu/index.js +++ b/packages/freesewing.shared/components/workbench/menu/index.js @@ -1,8 +1,72 @@ +import { linkClasses, Chevron } from 'shared/components/navigation/primary.js' import ModesMenu from './modes.js' import DesignOptions from './design-options' import CoreSettings from './core-settings' import Xray from './xray' +export const Ul = props =>
      {props.children}
    +export const Li = props =>
  • {props.children}
  • +export const Details = props => ( +
    + {props.children} +
    +) +export const Deg = props => ° +export const SumDiv = props => ( +
    {props.children}
    +) +export const Summary = props => ( + {props.children} +) +export const TopSummary = props => ( + + {props.icon || null} + {props.children} + +) +export const SumButton = props => ( + +) +export const TopSumTitle = props => ( + + {props.children} + +) +export const SecText = props => props.raw + ? + : {props.children} + const WorkbenchMenu = props => { return (