diff --git a/src/process/filter/__tests__/filter.test.ts b/src/process/filter/__tests__/filter.test.ts index 65b0b017..a6cea9f3 100644 --- a/src/process/filter/__tests__/filter.test.ts +++ b/src/process/filter/__tests__/filter.test.ts @@ -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': true}); + expect(context.scope.filter).to.deep.equal({'dataGrid': {'compModelType': 'array', 'include': true}}); }); it('Should not filter empty array value for editGrid component', async () => { @@ -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': true}); + expect(context.scope.filter).to.deep.equal({'editGrid': {'compModelType': 'array', 'include': true}}); }); it('Should not filter empty array value for datTable component', async () => { @@ -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': true}); + expect(context.scope.filter).to.deep.equal({'dataTable': {'compModelType': 'array', 'include': true}}); }); diff --git a/src/process/filter/index.ts b/src/process/filter/index.ts index e8e489cf..9efeebe3 100644 --- a/src/process/filter/index.ts +++ b/src/process/filter/index.ts @@ -12,18 +12,31 @@ export const filterProcessSync: ProcessorFnSync = (context: FilterC const modelType = Utils.getModelType(component); switch (modelType) { case 'dataObject': - scope.filter[absolutePath] = {data: {}}; + scope.filter[absolutePath] = { + compModelType: modelType, + include: true, + value: {data: {}} + }; break; case 'array': - scope.filter[absolutePath] = true; + scope.filter[absolutePath] = { + compModelType: modelType, + include: true, + }; break; case 'object': if (component.type !== 'container') { - scope.filter[absolutePath] = true; + scope.filter[absolutePath] = { + compModelType: modelType, + include: true, + }; } break; default: - scope.filter[absolutePath] = true; + scope.filter[absolutePath] = { + compModelType: modelType, + include: true, + }; break; } } @@ -37,13 +50,13 @@ export const filterPostProcess: ProcessorFnSync = (context: FilterC const { scope, submission } = context; const filtered = {}; for (const path in scope.filter) { - if (scope.filter[path]) { + if (scope.filter[path].include) { let value = get(submission?.data, path); if (isObject(value) && isObject(scope.filter[path])) { - if ((value as any).data) { - value = {...value, ...scope.filter[path], data: (value as any)?.data} + if (scope.filter[path].compModelType === 'dataObject') { + value = {...value, ...scope.filter[path].value, data: (value as any)?.data} } else { - value = {...value, ...scope.filter[path]} + value = {...value, ...scope.filter[path].value} } } set(filtered, path, value); diff --git a/src/types/process/filter/FilterScope.ts b/src/types/process/filter/FilterScope.ts index fdd3724d..e81db652 100644 --- a/src/types/process/filter/FilterScope.ts +++ b/src/types/process/filter/FilterScope.ts @@ -1,4 +1,8 @@ import { ProcessorScope } from ".."; export type FilterScope = { - filter: Record; -} & ProcessorScope; \ No newline at end of file + filter: Record; +} & ProcessorScope;