From 4264c810705012553d4f22e6f142e50570545785 Mon Sep 17 00:00:00 2001 From: joostdecock Date: Sat, 17 Feb 2024 15:57:40 +0100 Subject: [PATCH 1/8] feat[plugin-bust]: Move conditionality to preSetDraft lifecycle hook This plugin is used to draft designs for high bust rather than full chest circumference. To facilitate that, we provide(d) a named export called `withCondition` that checks whether the plugin is wanted, and if so loads it. Problem with that is that the conditional loading of a plugin applied to the entire pattern. And since we support drafting patterns for multiple sets (and use this to sample) this means that all of these sets would either get the plugin effect or not, based on the first set. So, to fix that, we have changed the lifecycle hook used by this plugin to `preSetDraft` (from `preDraft`) and changed the `withCondition` method to always return true. This means that the plugin will always be loaded, and we have moved the check that used to be in `withCondition` to the lifecycle hook. In other words, this plugin will now always be loaded and will check for each set whether it needs to do something. This allows the conditionality to apply to each set in the pattern, rather than to the entire pattern. Note that conditionally loading plugins pattern-wide is still a valid use-case. It just so happens that for this plugin, it was the wrong approach. --- config/changelog.yaml | 15 +++++++++++++++ plugins/plugin-bust/src/index.mjs | 22 +++++++++++++--------- plugins/plugin-bust/tests/plugin.test.mjs | 9 ++++----- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/config/changelog.yaml b/config/changelog.yaml index b8526a3a742..02622ff36b3 100644 --- a/config/changelog.yaml +++ b/config/changelog.yaml @@ -1,3 +1,18 @@ +Unreleased: + Changed: + plugin-bust: + - This plugin now uses the `preSetDraft` rather than `preDraft` lifecycle hook + - Conditionality has been moved to the `preSetDraft` lifecycle hook, rather than exposing a `withCondition` named export + - The plugin will now always be loaded, but will check for each drafted set whether it should make any changes. + + Deprecated: + plugin-bust: + - The `withCondition` named export is deprecated and will always return true. + + Fixed: + hugo: + - Add missing dimension id attributes + 3.2.0: date: 2024-02-11 diff --git a/plugins/plugin-bust/src/index.mjs b/plugins/plugin-bust/src/index.mjs index 0e6cd5ac18f..3962540323c 100644 --- a/plugins/plugin-bust/src/index.mjs +++ b/plugins/plugin-bust/src/index.mjs @@ -4,13 +4,12 @@ export const plugin = { name, version, hooks: { - preDraft: function ({ settings }) { - for (const i in settings) { - if (settings[i].measurements) { - if (typeof settings[i].measurements.bust === 'undefined') { - settings[i].measurements.bust = settings[i].measurements.chest - settings[i].measurements.chest = settings[i].measurements.highBust - } + preSetDraft: function ({ settings, activeSet }) { + const set = settings[Number(activeSet)] + if (set.measurements && set.options?.draftForHighBust && set.measurements?.highBust) { + if (typeof set.measurements.bust === 'undefined') { + set.measurements.bust = set.measurements.chest + set.measurements.chest = set.measurements.highBust } } }, @@ -24,6 +23,11 @@ export const pluginBust = plugin // Helper method to conditionally load this plugin export const withCondition = { plugin, - condition: (settings = false) => - settings?.options?.draftForHighBust && settings?.measurements?.highBust ? true : false, + condition: (settings = false) => { + console.log( + "WARNING: The 'withCondition' named export in @freesewing/plugin-bust is deprecated. Conditionality has moved to the preSetDraft lifecycle hook" + ) + + return true + }, } diff --git a/plugins/plugin-bust/tests/plugin.test.mjs b/plugins/plugin-bust/tests/plugin.test.mjs index 9cf75f48616..abc23940363 100644 --- a/plugins/plugin-bust/tests/plugin.test.mjs +++ b/plugins/plugin-bust/tests/plugin.test.mjs @@ -6,9 +6,10 @@ const measurements = { chest: 100, highBust: 90, } +const options = { draftForHighBust: true } const Pattern = new Design() -const pattern = new Pattern({ measurements }).use(plugin) +const pattern = new Pattern({ measurements, options }).use(plugin) pattern.draft() describe('Bust plugin Tests', () => { @@ -18,9 +19,7 @@ describe('Bust plugin Tests', () => { }) it('Should copy measurement from chest to bust and from highBust to chest', function () { - const testPattern = new Design({ - measurements: [], - }) + const testPattern = new Design({ measurements: [], options }) const pattern = new testPattern().use(plugin) const userMeasurements = { chest: 50, highBust: 60 } pattern.settings[0].measurements = userMeasurements @@ -30,7 +29,7 @@ describe('Bust plugin Tests', () => { }) it('Should not overwrite existing bust measurements', function () { - let config = { measurements: [] } + let config = { measurements: [], options } const testPattern = new Design(config, plugin) let pattern = new testPattern() let userMeasurements = { chest: 50, highBust: 60, bust: 55 } From 786a5d06cbba8586e9fdd05814c5a9de8fba9c1f Mon Sep 17 00:00:00 2001 From: joostdecock Date: Sat, 17 Feb 2024 16:06:32 +0100 Subject: [PATCH 2/8] chore(brian): Always load plugin-bust The plugin changed how it handles conditionality, so we are always loading it. --- config/changelog.yaml | 2 ++ designs/brian/src/base.mjs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/config/changelog.yaml b/config/changelog.yaml index 02622ff36b3..bfd8d51b2b2 100644 --- a/config/changelog.yaml +++ b/config/changelog.yaml @@ -1,5 +1,7 @@ Unreleased: Changed: + brian: + - Always load plugin-bust due to its changes in how it handle conditionality. plugin-bust: - This plugin now uses the `preSetDraft` rather than `preDraft` lifecycle hook - Conditionality has been moved to the `preSetDraft` lifecycle hook, rather than exposing a `withCondition` named export diff --git a/designs/brian/src/base.mjs b/designs/brian/src/base.mjs index 3e64ad3f6be..3883fb07b42 100644 --- a/designs/brian/src/base.mjs +++ b/designs/brian/src/base.mjs @@ -1,4 +1,4 @@ -import { withCondition as bustPlugin } from '@freesewing/plugin-bust' +import { bustPlugin } from '@freesewing/plugin-bust' export const base = { name: 'brian.base', From 3b7615f03a2ad19664b640b5972ac7925e949450 Mon Sep 17 00:00:00 2001 From: joostdecock Date: Sat, 17 Feb 2024 16:14:14 +0100 Subject: [PATCH 3/8] feat(markdown): Added notes to lifecycle hooks docs --- markdown/dev/reference/hooks/predraft/en.md | 5 ++++- markdown/dev/reference/hooks/presetdraft/en.md | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/markdown/dev/reference/hooks/predraft/en.md b/markdown/dev/reference/hooks/predraft/en.md index 471c5af6f3c..bc31d7e0aab 100644 --- a/markdown/dev/reference/hooks/predraft/en.md +++ b/markdown/dev/reference/hooks/predraft/en.md @@ -20,4 +20,7 @@ pattern.on('preDraft', pattern => { ## Notes -The `preDraft` hook is rarely used, but it's there if you need it. +The `preDraft` hook fires once for all the sets in the pattern. +While typically, there is only one set, there might be more. +In that case, the [`preSetDraft` lifecycle hook](/reference/hooks/presetdraft) is +the per-set equivalent of this hook. diff --git a/markdown/dev/reference/hooks/presetdraft/en.md b/markdown/dev/reference/hooks/presetdraft/en.md index 0c805941c06..ffb7dee9c84 100644 --- a/markdown/dev/reference/hooks/presetdraft/en.md +++ b/markdown/dev/reference/hooks/presetdraft/en.md @@ -21,4 +21,15 @@ pattern.on('preSetDraft', pattern => { ## Notes -The `preSetDraft` hook is rarely used, but it's there if you need it. +The `preSetDraft` fires once for each set in the pattern. + +The pattern tracks the active set on the `activeSet` property. +So if you are using this hook and would like to get access to teh active set, you can do so like this: + +```js +pattern.on('preSetDraft', ({ settings, activeSet }) => { + const set = settings[Number(activeSet)] + + // Now set holds the active set of settings +} +``` From c3ea6bc5c29c3fe5ccdc33c9e94ac8ddaff35320 Mon Sep 17 00:00:00 2001 From: joostdecock Date: Sat, 17 Feb 2024 16:24:39 +0100 Subject: [PATCH 4/8] chore(plugin-bust): Removed unused variable --- plugins/plugin-bust/src/index.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/plugin-bust/src/index.mjs b/plugins/plugin-bust/src/index.mjs index 3962540323c..c25a25081fe 100644 --- a/plugins/plugin-bust/src/index.mjs +++ b/plugins/plugin-bust/src/index.mjs @@ -23,7 +23,7 @@ export const pluginBust = plugin // Helper method to conditionally load this plugin export const withCondition = { plugin, - condition: (settings = false) => { + condition: () => { console.log( "WARNING: The 'withCondition' named export in @freesewing/plugin-bust is deprecated. Conditionality has moved to the preSetDraft lifecycle hook" ) From 5dc84c0eb881ffeec47bd69f428187bcf7671ba3 Mon Sep 17 00:00:00 2001 From: joostdecock Date: Sat, 17 Feb 2024 16:44:46 +0100 Subject: [PATCH 5/8] feat(shared): Add name to curated sets This replaces #6077 and closes #5898 but does so with proper CSS. --- sites/shared/components/curated-sets.mjs | 27 +++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/sites/shared/components/curated-sets.mjs b/sites/shared/components/curated-sets.mjs index 0bc421fa2ad..1e67ecae7ca 100644 --- a/sites/shared/components/curated-sets.mjs +++ b/sites/shared/components/curated-sets.mjs @@ -50,7 +50,14 @@ import { export const ns = ['account', 'patterns', 'status', 'measurements', 'sets', inputNs] -const SetLineup = ({ sets = [], href = false, onClick = false }) => ( +const SetNameWrapper = ({ name, children }) => ( +
+ {children} + {name} +
+) + +const SetLineup = ({ sets = [], lang, href = false, onClick = false }) => (
1 ? 'justify-start px-8' : 'justify-center' @@ -76,9 +83,10 @@ const SetLineup = ({ sets = [], href = false, onClick = false }) => ( if (onClick) props.onClick = () => onClick(set) else if (typeof href === 'function') props.href = href(set.id) - if (onClick) return - else if (href) return - else return
+ let img =
+ if (onClick) img = + else if (href) img = + return {img} })}
) @@ -95,7 +103,7 @@ const ShowCuratedSet = ({ cset }) => { <>

{cset[`name${capitalize(lang)}`]}

- +
@@ -206,6 +214,8 @@ export const CuratedSets = ({ href = false, clickHandler = false, published = tr // Hooks const backend = useBackend() const { setLoadingStatus } = useContext(LoadingStatusContext) + const { i18n } = useTranslation(ns) + const lang = i18n.language // State const [sets, setSets] = useState([]) @@ -236,7 +246,7 @@ export const CuratedSets = ({ href = false, clickHandler = false, published = tr return (
- + {selected && }
) @@ -245,7 +255,8 @@ export const CuratedSets = ({ href = false, clickHandler = false, published = tr // Component for the maintaining the list of curated-sets export const CuratedSetsList = ({ href = false }) => { // Hooks - const { t } = useTranslation(ns) + const { t, i18n } = useTranslation(ns) + const lang = i18n.language const backend = useBackend() const { setLoadingStatus, LoadingProgress } = useContext(LoadingStatusContext) const [refresh, setRefresh] = useState(0) @@ -371,7 +382,7 @@ export const CuratedSetsList = ({ href = false }) => { ))} - +
) } From 9cdf064b46faf50fbbe6f2d7e182ae78eabb8856 Mon Sep 17 00:00:00 2001 From: joostdecock Date: Sat, 17 Feb 2024 16:48:18 +0100 Subject: [PATCH 6/8] fix(shared): Add key prop to iterator --- sites/shared/components/curated-sets.mjs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sites/shared/components/curated-sets.mjs b/sites/shared/components/curated-sets.mjs index 1e67ecae7ca..921441cc6a7 100644 --- a/sites/shared/components/curated-sets.mjs +++ b/sites/shared/components/curated-sets.mjs @@ -86,7 +86,11 @@ const SetLineup = ({ sets = [], lang, href = false, onClick = false }) => ( let img =
if (onClick) img = else if (href) img = - return {img} + return ( + + {img} + + ) })} ) From 147433e16893360e5212773638b1303bf3720c35 Mon Sep 17 00:00:00 2001 From: joostdecock Date: Sat, 17 Feb 2024 16:50:22 +0100 Subject: [PATCH 7/8] Revert "fix(shared): Add key prop to iterator" This reverts commit 9cdf064b46faf50fbbe6f2d7e182ae78eabb8856. Need to keep this out of the PR --- sites/shared/components/curated-sets.mjs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sites/shared/components/curated-sets.mjs b/sites/shared/components/curated-sets.mjs index 921441cc6a7..1e67ecae7ca 100644 --- a/sites/shared/components/curated-sets.mjs +++ b/sites/shared/components/curated-sets.mjs @@ -86,11 +86,7 @@ const SetLineup = ({ sets = [], lang, href = false, onClick = false }) => ( let img =
if (onClick) img = else if (href) img = - return ( - - {img} - - ) + return {img} })} ) From 43c069719c83bc34b3fff3bc3e38614315e6acf2 Mon Sep 17 00:00:00 2001 From: joostdecock Date: Sat, 17 Feb 2024 16:50:47 +0100 Subject: [PATCH 8/8] Revert "feat(shared): Add name to curated sets" This reverts commit 5dc84c0eb881ffeec47bd69f428187bcf7671ba3. Need to keep this out of the PR --- sites/shared/components/curated-sets.mjs | 27 +++++++----------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/sites/shared/components/curated-sets.mjs b/sites/shared/components/curated-sets.mjs index 1e67ecae7ca..0bc421fa2ad 100644 --- a/sites/shared/components/curated-sets.mjs +++ b/sites/shared/components/curated-sets.mjs @@ -50,14 +50,7 @@ import { export const ns = ['account', 'patterns', 'status', 'measurements', 'sets', inputNs] -const SetNameWrapper = ({ name, children }) => ( -
- {children} - {name} -
-) - -const SetLineup = ({ sets = [], lang, href = false, onClick = false }) => ( +const SetLineup = ({ sets = [], href = false, onClick = false }) => (
1 ? 'justify-start px-8' : 'justify-center' @@ -83,10 +76,9 @@ const SetLineup = ({ sets = [], lang, href = false, onClick = false }) => ( if (onClick) props.onClick = () => onClick(set) else if (typeof href === 'function') props.href = href(set.id) - let img =
- if (onClick) img = - else if (href) img = - return {img} + if (onClick) return + else if (href) return + else return
})}
) @@ -103,7 +95,7 @@ const ShowCuratedSet = ({ cset }) => { <>

{cset[`name${capitalize(lang)}`]}

- +
@@ -214,8 +206,6 @@ export const CuratedSets = ({ href = false, clickHandler = false, published = tr // Hooks const backend = useBackend() const { setLoadingStatus } = useContext(LoadingStatusContext) - const { i18n } = useTranslation(ns) - const lang = i18n.language // State const [sets, setSets] = useState([]) @@ -246,7 +236,7 @@ export const CuratedSets = ({ href = false, clickHandler = false, published = tr return (
- + {selected && }
) @@ -255,8 +245,7 @@ export const CuratedSets = ({ href = false, clickHandler = false, published = tr // Component for the maintaining the list of curated-sets export const CuratedSetsList = ({ href = false }) => { // Hooks - const { t, i18n } = useTranslation(ns) - const lang = i18n.language + const { t } = useTranslation(ns) const backend = useBackend() const { setLoadingStatus, LoadingProgress } = useContext(LoadingStatusContext) const [refresh, setRefresh] = useState(0) @@ -382,7 +371,7 @@ export const CuratedSetsList = ({ href = false }) => { ))} - +
) }