fix(ct): снятый выбор победителя не возвращается после F5 (#7)
Выбор победителя жил только в состоянии таблицы и попадал в данные формы лишь по «Сохранить». После F5 сессия не знала, что выбор сняли, и форма подставляла победителя из шапки СТ. Теперь выбор и снятие сразу пишутся в данные формы, как статус и исключение поставщика, а победитель из шапки СТ берётся только когда сессии нет (СТ открыта в другом браузере). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -191,8 +191,9 @@ const CtCreateForm: React.FC<ICtCreateFormProps> = ({ context, userDisplayName,
|
|||||||
noOfferFromSp,
|
noOfferFromSp,
|
||||||
);
|
);
|
||||||
// Победитель обязателен для «Сохранить» на Шаге 3: без сессии берём его из шапки СТ, иначе
|
// Победитель обязателен для «Сохранить» на Шаге 3: без сессии берём его из шапки СТ, иначе
|
||||||
// в другом браузере пришлось бы выбирать заново.
|
// в другом браузере пришлось бы выбирать заново. Только когда сессии нет (колонки из SP):
|
||||||
const winnerColumnId = formData.recommendedSupplierId === undefined
|
// в сессии «не выбран» может быть осознанно снятым выбором — его SP не перебивает.
|
||||||
|
const winnerColumnId = formData.suppliers.length === 0
|
||||||
? findWinnerColumnId(suppliers, ct.winSupplierSpId)
|
? findWinnerColumnId(suppliers, ct.winSupplierSpId)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -95,9 +95,15 @@ export function useStep3Matrix(args: UseStep3MatrixArgs) {
|
|||||||
return map;
|
return map;
|
||||||
});
|
});
|
||||||
|
|
||||||
const [selectedSupplierId, setSelectedSupplierId] = useState<string | undefined>(
|
const [selectedSupplierId, setSelectedSupplierIdState] = useState<string | undefined>(
|
||||||
formData.recommendedSupplierId
|
formData.recommendedSupplierId
|
||||||
);
|
);
|
||||||
|
// Выбор победителя сразу пишем в formData, как статус и исключение поставщика: иначе снятый
|
||||||
|
// выбор жил только на экране, а после F5 возвращался из сессии или из шапки СТ.
|
||||||
|
const setSelectedSupplierId = useCallback((id: string | undefined): void => {
|
||||||
|
setSelectedSupplierIdState(id);
|
||||||
|
onSave({ recommendedSupplierId: id });
|
||||||
|
}, [onSave]);
|
||||||
const [isSaving, setIsSaving] = useState(false);
|
const [isSaving, setIsSaving] = useState(false);
|
||||||
const [saveError, setSaveError] = useState<string | undefined>(undefined);
|
const [saveError, setSaveError] = useState<string | undefined>(undefined);
|
||||||
// Тумблер «Перевести в ед. изм. заявки»: переводит кол-во и цену поставщика в ед. заявки.
|
// Тумблер «Перевести в ед. изм. заявки»: переводит кол-во и цену поставщика в ед. заявки.
|
||||||
@@ -488,7 +494,7 @@ export function useStep3Matrix(args: UseStep3MatrixArgs) {
|
|||||||
}
|
}
|
||||||
// Исключённый не может остаться выбранным — иначе он уйдёт победителем в шапку СТ.
|
// Исключённый не может остаться выбранным — иначе он уйдёт победителем в шапку СТ.
|
||||||
if (exclusion && selectedSupplierId === supplierId) setSelectedSupplierId(undefined);
|
if (exclusion && selectedSupplierId === supplierId) setSelectedSupplierId(undefined);
|
||||||
}, [isReadOnly, suppliers, extraSuppliers, selectedSupplierId, onSave]);
|
}, [isReadOnly, suppliers, extraSuppliers, selectedSupplierId, setSelectedSupplierId, onSave]);
|
||||||
|
|
||||||
const handleExcludeSupplier = useCallback((supplierId: string, reason: string): void => {
|
const handleExcludeSupplier = useCallback((supplierId: string, reason: string): void => {
|
||||||
if (!reason.trim()) return;
|
if (!reason.trim()) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user