diff --git a/src/entitiy/element/model/implementations/VerificationConditionsElement/VerificationConditionsRender.tsx b/src/entitiy/element/model/implementations/VerificationConditionsElement/VerificationConditionsRender.tsx index bcb2858..4aa4063 100644 --- a/src/entitiy/element/model/implementations/VerificationConditionsElement/VerificationConditionsRender.tsx +++ b/src/entitiy/element/model/implementations/VerificationConditionsElement/VerificationConditionsRender.tsx @@ -29,8 +29,28 @@ import { VerificationConditionsValue, } from './types' +// Утилиты для работы с localStorage +const getLocalStorageKey = (type: string, id: string) => `${type}_${id}` + +const saveToLocalStorage = (key: string, value: string) => { + try { + localStorage.setItem(key, value) + } catch (error) { + console.warn('Failed to save to localStorage:', error) + } +} + +const getFromLocalStorage = (key: string): string => { + try { + return localStorage.getItem(key) || '' + } catch (error) { + console.warn('Failed to get from localStorage:', error) + return '' + } +} + interface VerificationConditionsRenderProps { - config: VerificationConditionsConfig + config: VerificationConditionsConfig & { id?: string } value?: VerificationConditionsValue onChange?: (value: VerificationConditionsValue) => void onSave?: (value: VerificationConditionsValue) => Promise @@ -42,9 +62,22 @@ export function VerificationConditionsRender({ onChange, onSave, }: VerificationConditionsRenderProps) { - const [selectedDate, setSelectedDate] = useState( - value?.date || config.selectedDate || new Date().toISOString().split('T')[0] - ) + // Инициализация даты с учетом localStorage + const getInitialDate = () => { + if (value?.date) return value.date + if (config.selectedDate) return config.selectedDate + + // Попытка загрузить из localStorage + if (config.id) { + const key = getLocalStorageKey('verification_conditions_date', config.id) + const savedDate = getFromLocalStorage(key) + if (savedDate) return savedDate + } + + return new Date().toISOString().split('T')[0] + } + + const [selectedDate, setSelectedDate] = useState(getInitialDate) const [editDialogOpen, setEditDialogOpen] = useState(false) const [editingConditions, setEditingConditions] = useState< Record @@ -101,6 +134,12 @@ export function VerificationConditionsRender({ const newDate = event.target.value setSelectedDate(newDate) + // Сохранение в localStorage + if (config.id) { + const key = getLocalStorageKey('verification_conditions_date', config.id) + saveToLocalStorage(key, newDate) + } + // Обновляем значение даты в value if (onChange) { onChange({ diff --git a/src/entitiy/element/model/implementations/VerificationConditionsElement/definition.tsx b/src/entitiy/element/model/implementations/VerificationConditionsElement/definition.tsx index 03c11fd..a3d513f 100644 --- a/src/entitiy/element/model/implementations/VerificationConditionsElement/definition.tsx +++ b/src/entitiy/element/model/implementations/VerificationConditionsElement/definition.tsx @@ -58,6 +58,7 @@ export const verificationConditionsElementDefinition: ElementDefinition< conditionMappings: [], showUnits: true, targetCells: [], + id: '', }, // Компоненты @@ -65,10 +66,26 @@ export const verificationConditionsElementDefinition: ElementDefinition< Preview: VerificationConditionsPreview, Render: VerificationConditionsRender, - // Получение начальных значений из конфигурации + // Получение начальных значений из конфигурации с учетом localStorage getInitialValue: config => { + let initialDate = + config.selectedDate || new Date().toISOString().split('T')[0] + + // Попытка загрузить дату из localStorage + if (config.id) { + try { + const key = `verification_conditions_date_${config.id}` + const savedDate = localStorage.getItem(key) + if (savedDate) { + initialDate = savedDate + } + } catch (error) { + console.warn('Failed to get date from localStorage:', error) + } + } + return { - date: config.selectedDate || new Date().toISOString().split('T')[0], + date: initialDate, conditions: {}, } }, diff --git a/src/entitiy/element/model/implementations/VerificationConditionsElement/types.ts b/src/entitiy/element/model/implementations/VerificationConditionsElement/types.ts index efc3559..f2fb8cf 100644 --- a/src/entitiy/element/model/implementations/VerificationConditionsElement/types.ts +++ b/src/entitiy/element/model/implementations/VerificationConditionsElement/types.ts @@ -19,6 +19,8 @@ export interface VerificationConditionsConfig { showUnits?: boolean // Целевые ячейки targetCells?: any[] + // Идентификатор для совместимости с TemplateElement + id?: string } // Значение элемента