Skip to content

Commit

Permalink
chore: add defense code
Browse files Browse the repository at this point in the history
Signed-off-by: samuel.park <[email protected]>
  • Loading branch information
piggggggggy committed Dec 17, 2024
1 parent a5a2531 commit 44abf21
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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],
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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 = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
}
});

Expand Down

0 comments on commit 44abf21

Please sign in to comment.