Skip to content

Commit 7782b18

Browse files
fix: enhance error handling for showIf conditions in resource validation
1 parent 384fa20 commit 7782b18

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

adminforth/modules/configValidator.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -807,17 +807,23 @@ export default class ConfigValidator implements IConfigValidator {
807807
if (typeof condition !== 'object') {
808808
return;
809809
}
810+
const relatedColumn = res.columns.find((c) => c.name === field);
811+
if (!relatedColumn) {
812+
const similar = suggestIfTypo(res.columns.map((c) => c.name), field);
813+
errors.push(`Resource "${res.resourceId}" column "${column.name}" has showIf on unknown column "${field}". ${similar ? `Did you mean "${similar}"?` : ''}`);
814+
return;
815+
}
810816
if ("$in" in condition && !Array.isArray(condition.$in)) {
811817
errors.push(`Resource "${res.resourceId}" column "${column.name}" has showIf with $in that is not an array`);
812818
}
813819
if ("$nin" in condition && !Array.isArray(condition.$nin)) {
814820
errors.push(`Resource "${res.resourceId}" column "${column.name}" has showIf with $nin that is not an array`);
815821
}
816-
if ("$includes" in condition && !column.isArray) {
817-
errors.push(`Resource "${res.resourceId}" has showIf with $includes on non-array column "${column.name}"`);
822+
if ("$includes" in condition && !relatedColumn.isArray?.enabled) {
823+
errors.push(`Resource "${res.resourceId}" has showIf with $includes on non-array column "${relatedColumn.name}"`);
818824
}
819-
if ("$nincludes" in condition && !column.isArray) {
820-
errors.push(`Resource "${res.resourceId}" has showIf with $nincludes on non-array column "${column.name}"`);
825+
if ("$nincludes" in condition && !relatedColumn.isArray?.enabled) {
826+
errors.push(`Resource "${res.resourceId}" has showIf with $nincludes on non-array column "${relatedColumn.name}"`);
821827
}
822828
});
823829
}

0 commit comments

Comments
 (0)