diff --git a/app/components/catalog/CatalogConfigurator.vue b/app/components/catalog/CatalogConfigurator.vue index 6f9abbe..37f610d 100644 --- a/app/components/catalog/CatalogConfigurator.vue +++ b/app/components/catalog/CatalogConfigurator.vue @@ -195,14 +195,10 @@ function sortParamValues(values: ParamValue[]) { }); } -function getFieldOptions(group: ProductGroup, state: GroupState, field: ParamFieldKey) { +function getAllFieldOptions(group: ProductGroup, field: ParamFieldKey) { const values = new Set(); for (const product of group.products) { - if (!matchesState(product, state, field)) { - continue; - } - const value = product[field]; if (value !== null) { values.add(value); @@ -213,6 +209,7 @@ function getFieldOptions(group: ProductGroup, state: GroupState, field: ParamFie } function createGroupState(group: ProductGroup): GroupState { + void group; const state: GroupState = { widthMm: null, lengthM: null, @@ -222,29 +219,9 @@ function createGroupState(group: ProductGroup): GroupState { isExpanded: false, }; - for (const key of PARAM_KEYS) { - const options = getFieldOptions(group, state, key); - state[key] = (options[0] as GroupState[typeof key] | undefined) ?? null; - } - return state; } -function normalizeState(group: ProductGroup, state: GroupState) { - for (const key of PARAM_KEYS) { - const options = getFieldOptions(group, state, key); - if (options.length === 0) { - state[key] = null; - continue; - } - - const current = state[key]; - if (current === null || !options.some((option) => option === current)) { - state[key] = (options[0] as GroupState[typeof key] | undefined) ?? null; - } - } -} - watch( productGroups, (groups) => { @@ -260,7 +237,6 @@ watch( if (!groupStates[group.key]) { groupStates[group.key] = createGroupState(group); } - normalizeState(group, groupStates[group.key]); } }, { immediate: true }, @@ -280,11 +256,13 @@ function getGroupState(group: ProductGroup): GroupState { function updateField(group: ProductGroup, field: ParamFieldKey, value: ParamValue) { const state = getGroupState(group); state[field] = value as GroupState[typeof field]; - normalizeState(group, state); } function selectedProduct(group: ProductGroup) { const state = getGroupState(group); + if (PARAM_KEYS.some((key) => state[key] === null)) { + return null; + } return group.products.find((product) => matchesState(product, state)) ?? null; } @@ -311,7 +289,7 @@ function formatOptionLabel(field: ParamFieldKey, value: ParamValue) { function selectedFieldValue(group: ProductGroup, field: ParamFieldKey) { const value = getGroupState(group)[field]; if (value === null) { - return '—'; + return 'не выбрано'; } return formatOptionLabel(field, value); } @@ -436,7 +414,7 @@ function decrementSelected(group: ProductGroup) {

{{ field.label }}