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,18 +146,23 @@ 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">
{control < controlLevels.core.sa ? null : (
<IconButton <IconButton
Icon={SaIcon} Icon={SaIcon}
dflt={settings.sabool ? false : true} dflt={settings.sabool ? false : true}
onClick={() => update.toggleSa()} onClick={() => update.toggleSa()}
title={t('core-settings:sabool.t')} title={t('core-settings:sabool.t')}
/> />
)}
{control < controlLevels.core.paperless ? null : (
<IconButton <IconButton
Icon={PaperlessIcon} Icon={PaperlessIcon}
dflt={settings.paperless ? false : true} dflt={settings.paperless ? false : true}
onClick={() => update.settings(['paperless'], !settings.paperless)} onClick={() => update.settings(['paperless'], !settings.paperless)}
title={t('core-settings:paperless.t')} title={t('core-settings:paperless.t')}
/> />
)}
{control < controlLevels.core.complete ? null : (
<IconButton <IconButton
Icon={DetailIcon} Icon={DetailIcon}
dflt={settings.complete} dflt={settings.complete}
@ -168,6 +174,8 @@ export const DraftHeader = ({
} }
title={t('core-settings:complete.t')} title={t('core-settings:complete.t')}
/> />
)}
{control < controlLevels.core.expand ? null : (
<IconButton <IconButton
Icon={ExpandIcon} Icon={ExpandIcon}
dflt={settings.expand || typeof settings.expand === 'undefined' ? true : false} dflt={settings.expand || typeof settings.expand === 'undefined' ? true : false}
@ -179,6 +187,8 @@ export const DraftHeader = ({
} }
title={t('core-settings:expand.t')} title={t('core-settings:expand.t')}
/> />
)}
{control < controlLevels.core.units ? null : (
<IconButton <IconButton
Icon={ Icon={
settings.units !== 'imperial' settings.units !== 'imperial'
@ -191,6 +201,7 @@ export const DraftHeader = ({
} }
title={t('core-settings:units.t')} 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,
} }