diff --git a/apps/web/src/common/modules/widgets/_widget-field-value-manager/constant/default-value-registry.ts b/apps/web/src/common/modules/widgets/_widget-field-value-manager/constant/default-value-registry.ts index b0afa5af51..067718850f 100644 --- a/apps/web/src/common/modules/widgets/_widget-field-value-manager/constant/default-value-registry.ts +++ b/apps/web/src/common/modules/widgets/_widget-field-value-manager/constant/default-value-registry.ts @@ -134,7 +134,7 @@ export const widgetFieldDefaultValueSetterRegistry: WidgetFieldDefaultValueSette const result = widgetFieldDefaultValueMap.dataField; - const fieldKeys = sortWidgetTableFields(Object.keys(dataTable.data_info ?? {})); + const fieldKeys = sortWidgetTableFields(Object.keys(dataTable?.data_info ?? {})); result.data = dataFieldOptions.multiSelectable ? [fieldKeys?.[0]] : fieldKeys?.[0]; @@ -154,7 +154,7 @@ export const widgetFieldDefaultValueSetterRegistry: WidgetFieldDefaultValueSette }; } if (formatRulesOptions.useField && formatRulesOptions.dataTarget) { - const fieldKeys = sortWidgetTableFields(Object.keys(dataTable[formatRulesOptions.dataTarget])); + const fieldKeys = sortWidgetTableFields(Object.keys(dataTable?.[formatRulesOptions.dataTarget] ?? {})); result = { ...result, field: fieldKeys?.[0], @@ -168,7 +168,7 @@ export const widgetFieldDefaultValueSetterRegistry: WidgetFieldDefaultValueSette const result = widgetFieldDefaultValueMap.categoryBy; - const fieldKeys = sortWidgetTableFields(Object.keys(dataTable[categoryByOptions.dataTarget])); + const fieldKeys = sortWidgetTableFields(Object.keys(dataTable?.[categoryByOptions.dataTarget] ?? {})); return { ...result, @@ -182,7 +182,7 @@ export const widgetFieldDefaultValueSetterRegistry: WidgetFieldDefaultValueSette const result = widgetFieldDefaultValueMap.categoryBy; - const fieldKeys = sortWidgetTableFields(Object.keys(dataTable[stackByOptions.dataTarget])); + const fieldKeys = sortWidgetTableFields(Object.keys(dataTable?.[stackByOptions.dataTarget] ?? {})); return { ...result, @@ -196,7 +196,7 @@ export const widgetFieldDefaultValueSetterRegistry: WidgetFieldDefaultValueSette const result = widgetFieldDefaultValueMap.categoryBy; - const fieldKeys = sortWidgetTableFields(Object.keys(dataTable[xAxisOptions.dataTarget])); + const fieldKeys = sortWidgetTableFields(Object.keys(dataTable?.[xAxisOptions.dataTarget] ?? {})); return { ...result, @@ -210,7 +210,7 @@ export const widgetFieldDefaultValueSetterRegistry: WidgetFieldDefaultValueSette const result = widgetFieldDefaultValueMap.categoryBy; - const fieldKeys = sortWidgetTableFields(Object.keys(dataTable[yAxisOptions.dataTarget])); + const fieldKeys = sortWidgetTableFields(Object.keys(dataTable?.[yAxisOptions.dataTarget] ?? {})); return { ...result, @@ -267,7 +267,7 @@ export const widgetFieldDefaultValueSetterRegistry: WidgetFieldDefaultValueSette const result = widgetFieldDefaultValueMap.categoryBy; - const fieldKeys = sortWidgetTableFields(Object.keys(dataTable[groupByOptions.dataTarget])); + const fieldKeys = sortWidgetTableFields(Object.keys(dataTable?.[groupByOptions.dataTarget] ?? {})); result.data = groupByOptions.multiSelectable ? [fieldKeys?.[0]] : fieldKeys?.[0]; @@ -347,7 +347,7 @@ export const widgetFieldDefaultValueSetterRegistry: WidgetFieldDefaultValueSette const _fieldsSchema = integrateFieldsSchema(widgetConfig.requiredFieldsSchema, widgetConfig.optionalFieldsSchema); const numberFormatOptions = (_fieldsSchema.numberFormat?.options ?? {}) as NumberFormatOptions; - const dataKeys = Object.keys(dataTable.data_info ?? {}) as string[]; + const dataKeys = Object.keys(dataTable?.data_info ?? {}) as string[]; if (numberFormatOptions.default) { const result: NumberFormatValue = {}; diff --git a/apps/web/src/common/modules/widgets/_widget-field-value-manager/index.ts b/apps/web/src/common/modules/widgets/_widget-field-value-manager/index.ts index a99f8d18f0..42eaf42095 100644 --- a/apps/web/src/common/modules/widgets/_widget-field-value-manager/index.ts +++ b/apps/web/src/common/modules/widgets/_widget-field-value-manager/index.ts @@ -26,15 +26,15 @@ export default class WidgetFieldValueManager { static applyDefaultValue( originData: WidgetFieldValueMap, widgetConfig: WidgetConfig, - dataTable: PublicDataTableModel|PrivateDataTableModel, + dataTable?: PublicDataTableModel|PrivateDataTableModel, ): WidgetFieldValueMap { const result: WidgetFieldValueMap = { ...originData }; const integratedFieldSchema = integrateFieldsSchema(widgetConfig.requiredFieldsSchema, widgetConfig.optionalFieldsSchema); const widgetFieldKeys = ['header', ...Object.keys(integratedFieldSchema)]; - Object.entries(widgetFieldDefaultValueSetterRegistry).forEach(([key, setter]) => { + Object.entries(widgetFieldDefaultValueSetterRegistry).forEach(([key, defaultValueSetter]) => { if (widgetFieldKeys.includes(key) && !result[key]) { - result[key] = { value: setter(widgetConfig, dataTable) }; + result[key] = { value: defaultValueSetter(widgetConfig, dataTable) }; } });