1
0
Fork 0

fix(shared): Apply control limits to draft header. Fixes #5059

This commit is contained in:
joostdecock 2023-10-01 16:15:14 +02:00
parent 5f27133b5e
commit 9382585c07
3 changed files with 87 additions and 56 deletions

View file

@ -11,6 +11,7 @@ import {
MarginIcon, MarginIcon,
ExpandIcon, ExpandIcon,
} from 'shared/components/icons.mjs' } from 'shared/components/icons.mjs'
import { freeSewingConfig as config } from 'shared/config/freesewing.config.mjs'
export const defaultSamm = (units, inMm = true) => { export const defaultSamm = (units, inMm = true) => {
const dflt = units === 'imperial' ? 0.5 : 1 const dflt = units === 'imperial' ? 0.5 : 1
@ -24,7 +25,7 @@ export const loadSettingsConfig = ({
parts = [], parts = [],
}) => ({ }) => ({
sabool: { sabool: {
control: 2, // Show when control > 1 control: config.coreSettingsControl.sa,
list: [0, 1], list: [0, 1],
choiceTitles: { choiceTitles: {
0: 'saNo', 0: 'saNo',
@ -39,7 +40,7 @@ export const loadSettingsConfig = ({
}, },
samm: sabool samm: sabool
? { ? {
control: 2, // Show when control > 1 control: config.coreSettingsControl.sa,
min: 0, min: 0,
max: units === 'imperial' ? 2 : 2.5, max: units === 'imperial' ? 2 : 2.5,
dflt: defaultSamm(units), dflt: defaultSamm(units),
@ -47,7 +48,7 @@ export const loadSettingsConfig = ({
} }
: false, : false,
paperless: { paperless: {
control: 2, // Show when control > 1 control: config.coreSettingsControl.paperless,
list: [0, 1], list: [0, 1],
choiceTitles: { choiceTitles: {
0: 'paperlessNo', 0: 'paperlessNo',
@ -61,7 +62,7 @@ export const loadSettingsConfig = ({
icon: PaperlessIcon, icon: PaperlessIcon,
}, },
locale: { locale: {
control: 3, // Show when control > 2 control: config.coreSettingsControl.locale,
list: ['de', 'en', 'es', 'fr', 'nl'], list: ['de', 'en', 'es', 'fr', 'nl'],
dflt: language, dflt: language,
choiceTitles: { choiceTitles: {
@ -81,7 +82,7 @@ export const loadSettingsConfig = ({
icon: I18nIcon, icon: I18nIcon,
}, },
units: { units: {
control: 1, // Show when control > 2 control: config.coreSettingsControl.units,
list: ['metric', 'imperial'], list: ['metric', 'imperial'],
dflt: 'metric', dflt: 'metric',
choiceTitles: { choiceTitles: {
@ -95,7 +96,7 @@ export const loadSettingsConfig = ({
icon: UnitsIcon, icon: UnitsIcon,
}, },
complete: { complete: {
control: 4, // Show when control > 3 control: config.coreSettingsControl.complete,
list: [1, 0], list: [1, 0],
dflt: 1, dflt: 1,
choiceTitles: { choiceTitles: {
@ -109,7 +110,7 @@ export const loadSettingsConfig = ({
icon: DetailIcon, icon: DetailIcon,
}, },
expand: { expand: {
control: 4, // Show when control > 3 control: config.coreSettingsControl.expand,
list: [1, 0], list: [1, 0],
dflt: 1, dflt: 1,
choiceTitles: { choiceTitles: {
@ -123,14 +124,14 @@ export const loadSettingsConfig = ({
icon: ExpandIcon, icon: ExpandIcon,
}, },
only: { only: {
control: 4, // Show when control > 3 control: config.coreSettingsControl.only,
dflt: false, dflt: false,
list: parts, list: parts,
parts, parts,
icon: IncludeIcon, icon: IncludeIcon,
}, },
scale: { scale: {
control: 4, // Show when control > 3 control: config.coreSettingsControl.scale,
min: 0.1, min: 0.1,
max: 5, max: 5,
dflt: 1, dflt: 1,
@ -138,7 +139,7 @@ export const loadSettingsConfig = ({
icon: ScaleIcon, icon: ScaleIcon,
}, },
margin: { margin: {
control: 4, // Show when control > 3 control: config.coreSettingsControl.margin,
min: 0, min: 0,
max: 2.5, max: 2.5,
dflt: measurementAsMm(units === 'imperial' ? 0.125 : 0.2, units), dflt: measurementAsMm(units === 'imperial' ? 0.125 : 0.2, units),

View file

@ -1,6 +1,7 @@
// __SDEFILE__ - This file is a dependency for the stand-alone environment // __SDEFILE__ - This file is a dependency for the stand-alone environment
// Dependencies // Dependencies
import { capitalize, shortDate } from 'shared/utils.mjs' import { capitalize, shortDate } from 'shared/utils.mjs'
import { controlLevels } from 'shared/config/freesewing.config.mjs'
// Hooks // Hooks
import { useContext, useMemo } from 'react' import { useContext, useMemo } from 'react'
import { useMobileAction } from 'shared/context/mobile-menubar-context.mjs' import { useMobileAction } from 'shared/context/mobile-menubar-context.mjs'
@ -145,52 +146,62 @@ export const DraftHeader = ({
{headerZoomButtons} {headerZoomButtons}
<Spacer /> <Spacer />
<div className="flex flex-row items-center gap-4"> <div className="flex flex-row items-center gap-4">
<IconButton {control < controlLevels.core.sa ? null : (
Icon={SaIcon} <IconButton
dflt={settings.sabool ? false : true} Icon={SaIcon}
onClick={() => update.toggleSa()} dflt={settings.sabool ? false : true}
title={t('core-settings:sabool.t')} onClick={() => update.toggleSa()}
/> title={t('core-settings:sabool.t')}
<IconButton />
Icon={PaperlessIcon} )}
dflt={settings.paperless ? false : true} {control < controlLevels.core.paperless ? null : (
onClick={() => update.settings(['paperless'], !settings.paperless)} <IconButton
title={t('core-settings:paperless.t')} Icon={PaperlessIcon}
/> dflt={settings.paperless ? false : true}
<IconButton onClick={() => update.settings(['paperless'], !settings.paperless)}
Icon={DetailIcon} title={t('core-settings:paperless.t')}
dflt={settings.complete} />
onClick={() => )}
update.settings( {control < controlLevels.core.complete ? null : (
['complete'], <IconButton
typeof settings.complete === 'undefined' ? 0 : settings.complete ? 0 : 1 Icon={DetailIcon}
) dflt={settings.complete}
} onClick={() =>
title={t('core-settings:complete.t')} update.settings(
/> ['complete'],
<IconButton typeof settings.complete === 'undefined' ? 0 : settings.complete ? 0 : 1
Icon={ExpandIcon} )
dflt={settings.expand || typeof settings.expand === 'undefined' ? true : false} }
onClick={() => title={t('core-settings:complete.t')}
update.settings( />
['expand'], )}
typeof settings.expand === 'undefined' ? 1 : settings.expand ? 0 : 1 {control < controlLevels.core.expand ? null : (
) <IconButton
} Icon={ExpandIcon}
title={t('core-settings:expand.t')} dflt={settings.expand || typeof settings.expand === 'undefined' ? true : false}
/> onClick={() =>
<IconButton update.settings(
Icon={ ['expand'],
settings.units !== 'imperial' typeof settings.expand === 'undefined' ? 1 : settings.expand ? 0 : 1
? UnitsIcon )
: ({ className }) => <UnitsIcon className={`${className} rotate-180 w-6 h-6`} /> }
} title={t('core-settings:expand.t')}
dflt={settings.units !== 'imperial'} />
onClick={() => )}
update.settings(['units'], settings.units === 'imperial' ? 'metric' : 'imperial') {control < controlLevels.core.units ? null : (
} <IconButton
title={t('core-settings:units.t')} Icon={
/> settings.units !== 'imperial'
? UnitsIcon
: ({ className }) => <UnitsIcon className={`${className} rotate-180 w-6 h-6`} />
}
dflt={settings.units !== 'imperial'}
onClick={() =>
update.settings(['units'], settings.units === 'imperial' ? 'metric' : 'imperial')
}
title={t('core-settings:units.t')}
/>
)}
</div> </div>
<Spacer /> <Spacer />
<div <div

View file

@ -69,6 +69,23 @@ export const freeSewingConfig = {
id: 4, id: 4,
}, },
}, },
control: {
core: {
sa: 2,
paperless: 2,
locale: 3,
units: 1,
complete: 4,
expand: 4,
only: 4,
scale: 4,
margin: 4,
},
ui: {
renderer: 4,
kiosk: 2,
},
},
social, social,
statuses: { statuses: {
0: { 0: {
@ -98,4 +115,6 @@ export const controlLevels = {
...freeSewingConfig.account.fields.identities, ...freeSewingConfig.account.fields.identities,
sets: freeSewingConfig.account.sets, sets: freeSewingConfig.account.sets,
patterns: freeSewingConfig.account.patterns, patterns: freeSewingConfig.account.patterns,
core: freeSewingConfig.control.core,
ui: freeSewingConfig.control.ui,
} }