фикс багов
This commit is contained in:
@@ -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<string[]>(
|
||||
@@ -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 (
|
||||
<div className="space-y-2">
|
||||
|
||||
@@ -20,6 +20,7 @@ export interface ElementDefinition<Config = any, Value = any> {
|
||||
|
||||
/* бизнес-логика */
|
||||
defaultConfig: Config
|
||||
getInitialValue?(config: Config): Value // получение начальных значений из конфигурации
|
||||
mapToCells(config: Config): CellTarget[] // куда пишем данные (для отображения)
|
||||
mapToCellValues(
|
||||
config: Config,
|
||||
|
||||
Reference in New Issue
Block a user