diff --git a/src/component/BasicElements/SelectElement.tsx b/src/component/BasicElements/SelectElement.tsx index fd38661..d22a470 100644 --- a/src/component/BasicElements/SelectElement.tsx +++ b/src/component/BasicElements/SelectElement.tsx @@ -111,11 +111,13 @@ export const selectDefinition: ElementDefinition = { - {config.options.map((option, index) => ( - - {option.label} - - ))} + {config.options + .filter(option => option.value.trim() !== '') + .map((option, index) => ( + + {option.label} + + ))} @@ -127,11 +129,13 @@ export const selectDefinition: ElementDefinition = { - {config.options.map((option, index) => ( - - {option.label} - - ))} + {config.options + .filter(option => option.value.trim() !== '') + .map((option, index) => ( + + {option.label} + + ))} diff --git a/src/component/VerificationConditionsElement/VerificationConditionsRender.tsx b/src/component/VerificationConditionsElement/VerificationConditionsRender.tsx index f2aa78a..311da0c 100644 --- a/src/component/VerificationConditionsElement/VerificationConditionsRender.tsx +++ b/src/component/VerificationConditionsElement/VerificationConditionsRender.tsx @@ -1,5 +1,4 @@ import { Button } from '@/component/ui/button' -import { Calendar } from '@/component/ui/calendar' import { Card, CardContent, CardHeader, CardTitle } from '@/component/ui/card' import { Dialog, @@ -10,7 +9,6 @@ import { } from '@/component/ui/dialog' import { Input } from '@/component/ui/input' import { Label } from '@/component/ui/label' -import { Popover, PopoverContent, PopoverTrigger } from '@/component/ui/popover' import { AlertCircle, Building2, @@ -47,7 +45,6 @@ export function VerificationConditionsRender({ config.selectedDate || new Date().toISOString().split('T')[0] ) const [editDialogOpen, setEditDialogOpen] = useState(false) - const [calendarOpen, setCalendarOpen] = useState(false) const [editingConditions, setEditingConditions] = useState< Record >({}) @@ -67,26 +64,23 @@ export function VerificationConditionsRender({ const hasConditions = dailyCondition && Object.keys(dailyCondition.conditions).length > 0 - // Автоматическая инициализация onChange при загрузке данных + // Инициализация данных при загрузке из БД, только если данные еще не заполнены useEffect(() => { - if (dailyCondition && onChange && hasConditions) { + if ( + dailyCondition && + hasConditions && + onChange && + (!value?.conditions || Object.keys(value.conditions).length === 0) + ) { onChange({ date: selectedDate, conditions: dailyCondition.conditions, }) } - }, [dailyCondition, onChange, selectedDate, hasConditions]) + }, [dailyCondition, hasConditions, onChange, selectedDate, value?.conditions]) - const handleDateChange = (date: string) => { - setSelectedDate(date) - } - - const handleCalendarSelect = (date: Date | undefined) => { - if (date) { - const dateString = date.toISOString().split('T')[0] - setSelectedDate(dateString) - setCalendarOpen(false) - } + const handleDateChange = (event: React.ChangeEvent) => { + setSelectedDate(event.target.value) } const handleOpenEditDialog = (isCreating = false) => { @@ -167,25 +161,13 @@ export function VerificationConditionsRender({ {/* Выбор даты */}
- - - - - - - - +
{/* Статус и данные */} diff --git a/src/component/VerificationConditionsElement/definition.tsx b/src/component/VerificationConditionsElement/definition.tsx index 0b994b1..bd78d5a 100644 --- a/src/component/VerificationConditionsElement/definition.tsx +++ b/src/component/VerificationConditionsElement/definition.tsx @@ -31,6 +31,14 @@ export const verificationConditionsElementDefinition: ElementDefinition< Preview: VerificationConditionsPreview, Render: VerificationConditionsRender, + // Получение начальных значений из конфигурации + getInitialValue: config => { + return { + date: config.selectedDate || new Date().toISOString().split('T')[0], + conditions: {}, + } + }, + // Получение ячеек для записи данных на основе маппинга условий mapToCells: (config): CellTarget[] => { // Возвращаем только те targetCells, которые замаплены к условиям diff --git a/src/entitiy/element/model/implementations/StandardsElement/definition.tsx b/src/entitiy/element/model/implementations/StandardsElement/definition.tsx index 8a5c513..a20badd 100644 --- a/src/entitiy/element/model/implementations/StandardsElement/definition.tsx +++ b/src/entitiy/element/model/implementations/StandardsElement/definition.tsx @@ -39,6 +39,15 @@ export const standardsDefinition: ElementDefinition< }, Editor: StandardsEditor, Preview: StandardsPreview, + + // Получение начальных значений из конфигурации + getInitialValue: config => { + return { + standardIds: config.selectedStandards || [], + standardNames: [], // Будет заполнено при рендере компонента + } + }, + Render: ({ config, value, onChange }) => { const [isStandardsDialogOpen, setIsStandardsDialogOpen] = useState(false) const [selectedStandardIds, setSelectedStandardIds] = useState( @@ -60,9 +69,14 @@ export const standardsDefinition: ElementDefinition< .map(id => standards.find(s => s.id === id)) .filter(Boolean) - // Автоматическая инициализация onChange при загрузке данных эталонов + // Обновляем standardNames при получении данных из API, если они еще не заполнены useEffect(() => { - if (standards.length > 0 && selectedStandardIds.length > 0) { + if ( + standards.length > 0 && + selectedStandardIds.length > 0 && + (!value?.standardNames || value.standardNames.length === 0) && + onChange + ) { const standardNames = selectedStandardIds .map((id, index) => { const standard = standards.find(s => s.id === id) @@ -72,12 +86,14 @@ export const standardsDefinition: ElementDefinition< }) .filter(Boolean) - onChange?.({ - standardIds: selectedStandardIds, - standardNames, - }) + if (standardNames.length > 0) { + onChange({ + standardIds: selectedStandardIds, + standardNames, + }) + } } - }, [selectedStandardIds, standards, onChange]) + }, [standards, selectedStandardIds, value?.standardNames, onChange]) return (
diff --git a/src/entitiy/element/model/interface.ts b/src/entitiy/element/model/interface.ts index 698edce..65b2459 100644 --- a/src/entitiy/element/model/interface.ts +++ b/src/entitiy/element/model/interface.ts @@ -20,6 +20,7 @@ export interface ElementDefinition { /* бизнес-логика */ defaultConfig: Config + getInitialValue?(config: Config): Value // получение начальных значений из конфигурации mapToCells(config: Config): CellTarget[] // куда пишем данные (для отображения) mapToCellValues( config: Config, diff --git a/src/page/ProtocolCreation/Page.tsx b/src/page/ProtocolCreation/Page.tsx index fe6f37c..390313b 100644 --- a/src/page/ProtocolCreation/Page.tsx +++ b/src/page/ProtocolCreation/Page.tsx @@ -74,10 +74,36 @@ const FormElement: FC = ({ element, value, onChange }) => { const ProtocolForm: FC = ({ template, onSave, onBack }) => { const [formData, setFormData] = useState>({}) const [showSpreadsheet, setShowSpreadsheet] = useState(false) + const [isInitialized, setIsInitialized] = useState(false) const engineRef = useRef(null) const toast = useToast() const navigate = useNavigate() + // Инициализация значений для специальных элементов + useEffect(() => { + if (!isInitialized && template.elements.length > 0) { + const initialData: Record = {} + + template.elements.forEach(element => { + // Получаем определение элемента + const elementDefinition = getElementDefinition(element.type) + if (elementDefinition?.getInitialValue) { + // Используем метод getInitialValue для получения начального значения + const initialValue = elementDefinition.getInitialValue(element as any) + if (initialValue !== undefined) { + initialData[element.id] = initialValue + } + } + }) + + if (Object.keys(initialData).length > 0) { + setFormData(initialData) + } + + setIsInitialized(true) + } + }, [template.elements, isInitialized]) + const handleFieldChange = (elementId: string, value: any) => { setFormData(prev => ({ ...prev,