Skip to content

Commit

Permalink
fix(color-coded-heatmap): apply missing validation planning
Browse files Browse the repository at this point in the history
Signed-off-by: samuel.park <samuel.park@megazone.com>
  • Loading branch information
piggggggggy committed Jan 6, 2025
1 parent 307c620 commit 69ccd0b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,22 @@ export const widgetValidatorRegistry: WidgetValidatorRegistry = {
}
return !!fieldValue.data;
},
formatRules: (fieldValue: FormatRulesValue, widgetConfig) => {
formatRules: (fieldValue: FormatRulesValue, widgetConfig, allValueMap) => {
const _fieldsSchema = integrateFieldsSchema(widgetConfig.requiredFieldsSchema, widgetConfig.optionalFieldsSchema);
const formatRulesOptions = (_fieldsSchema.formatRules?.options ?? {}) as FormatRulesOptions;
const type = formatRulesOptions.formatRulesType;

if (formatRulesOptions.useField) {
if (formatRulesOptions.dependentField) {
const dependentValue: string|string[]|undefined = allValueMap?.[formatRulesOptions.dependentField]?.value?.data;
if (!dependentValue) return !!fieldValue.field;
if (Array.isArray(dependentValue)) {
return !dependentValue.includes(fieldValue.field);
}
return dependentValue !== fieldValue.field;
}
return !!fieldValue.field;
}
if (type === FORMAT_RULE_TYPE.textThreshold) {
return fieldValue.rules.every((d) => !!d.text && !!d.color);
}
Expand All @@ -64,9 +75,6 @@ export const widgetValidatorRegistry: WidgetValidatorRegistry = {
if (type === FORMAT_RULE_TYPE.textNumberThreshold) {
return fieldValue.rules.every((d) => !!d.text && !!d.number && !!d.color);
}
if (formatRulesOptions.useField) {
return !!fieldValue.field;
}
return true;
},
categoryBy: (fieldValue: CategoryByValue, widgetConfig) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export default class WidgetFieldValueManager {
dataTable: PublicDataTableModel|PrivateDataTableModel,
originData: WidgetFieldValueMap,
) {
console.debug('WidgetFieldValueManager.constructor()', widgetConfig, dataTable, originData);
this.widgetConfig = widgetConfig;
this.dataTable = dataTable;
this.widgetInvalid = !dataTable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ const state = reactive({
fieldValue: computed<FormatRulesValue>(() => props.fieldManager.data[FIELD_KEY].value),
type: computed<FormatRulesType>(() => props.widgetFieldSchema?.options?.formatRulesType as FormatRulesType),
invalid: computed(() => !validator(state.fieldValue, props.widgetConfig)),
fieldInvalid: computed(() => {
if (!props.widgetFieldSchema?.options?.useField) return false;
if (state.fieldValue.field === undefined) return true;
const dependentField = props.widgetFieldSchema?.options?.dependentField;
const dependentValue: string|string[]|undefined = props.fieldManager.data[dependentField]?.value?.data;
if (dependentField && dependentValue) {
if (Array.isArray(dependentValue)) {
return dependentValue.includes(state.fieldValue.field);
}
return dependentValue === state.fieldValue.field;
}
return false;
}),
selectedField: computed<string|undefined>(() => {
if (props.widgetFieldSchema?.options?.useField) {
return state.fieldValue.field;
Expand Down Expand Up @@ -98,7 +111,7 @@ const handleUpdateField = (val: string) => {
<p-select-dropdown :menu="state.menuItems"
:selected="state.selectedField"
use-fixed-menu-style
:invalid="state.selectedField === undefined"
:invalid="state.fieldInvalid"
block
@update:selected="handleUpdateField"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface FormatRulesValue {
export interface FormatRulesOptions {
useField?: boolean;
dataTarget?: FieldDataTargetType;
dependentField?: string; // groupBy field, xAxis field, yAxis field.. etc.
formatRulesType: FormatRulesType;
description?: string;
baseColor?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const colorCodedHeatmap: WidgetConfig = {
options: {
dataTarget: 'labels_info',
useField: true,
dependentField: 'groupBy',
formatRulesType: FORMAT_RULE_TYPE.textThreshold,
description: 'COMMON.WIDGETS.ADVANCED_FORMAT_RULES.COLOR_CODED_HEATMAP_DESC',
},
Expand Down

0 comments on commit 69ccd0b

Please sign in to comment.