Skip to content

Commit

Permalink
Revert "change filter processor to be more verbose and have compModel…
Browse files Browse the repository at this point in the history
…Type in scope"

This reverts commit 6d6c278.
  • Loading branch information
lane-formio committed Apr 12, 2024
1 parent d1763b9 commit be37bee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/process/filter/__tests__/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ it('Should not filter empty array value for dataGrid component', async () => {
};
const context: any = generateProcessorContext(dataGridComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'dataGrid': {'compModelType': 'array', 'include': true}});
expect(context.scope.filter).to.deep.equal({'dataGrid': true});
});

it('Should not filter empty array value for editGrid component', async () => {
Expand All @@ -46,7 +46,7 @@ it('Should not filter empty array value for editGrid component', async () => {
};
const context: any = generateProcessorContext(editGridComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'editGrid': {'compModelType': 'array', 'include': true}});
expect(context.scope.filter).to.deep.equal({'editGrid': true});
});

it('Should not filter empty array value for datTable component', async () => {
Expand All @@ -69,5 +69,5 @@ it('Should not filter empty array value for datTable component', async () => {
};
const context: any = generateProcessorContext(dataTableComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'dataTable': {'compModelType': 'array', 'include': true}});
expect(context.scope.filter).to.deep.equal({'dataTable': true});
});
29 changes: 8 additions & 21 deletions src/process/filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,18 @@ export const filterProcessSync: ProcessorFnSync<FilterScope> = (context: FilterC
const modelType = Utils.getModelType(component);
switch (modelType) {
case 'dataObject':
scope.filter[absolutePath] = {
compModelType: modelType,
include: true,
value: {data: {}}
};
scope.filter[absolutePath] = {data: {}};
break;
case 'array':
scope.filter[absolutePath] = {
compModelType: modelType,
include: true,
};
scope.filter[absolutePath] = true;
break;
case 'object':
if (component.type !== 'container') {
scope.filter[absolutePath] = {
compModelType: modelType,
include: true,
};
scope.filter[absolutePath] = true;
}
break;
default:
scope.filter[absolutePath] = {
compModelType: modelType,
include: true,
};
scope.filter[absolutePath] = true;
break;
}
}
Expand All @@ -50,13 +37,13 @@ export const filterPostProcess: ProcessorFnSync<FilterScope> = (context: FilterC
const { scope, submission } = context;
const filtered = {};
for (const path in scope.filter) {
if (scope.filter[path].include) {
if (scope.filter[path]) {
let value = get(submission?.data, path);
if (isObject(value) && isObject(scope.filter[path])) {
if (scope.filter[path].compModelType === 'dataObject') {
value = {...value, ...scope.filter[path].value, data: (value as any)?.data}
if ((value as any).data) {
value = {...value, ...scope.filter[path], data: (value as any)?.data}
} else {
value = {...value, ...scope.filter[path].value}
value = {...value, ...scope.filter[path]}
}
}
set(filtered, path, value);
Expand Down
8 changes: 2 additions & 6 deletions src/types/process/filter/FilterScope.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { ProcessorScope } from "..";
export type FilterScope = {
filter: Record<string, {
compModelType: string;
include: boolean;
value?: any;
}>;
} & ProcessorScope;
filter: Record<string, any>;
} & ProcessorScope;

0 comments on commit be37bee

Please sign in to comment.