Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change filter processor to be more verbose and have compModelType in … #79

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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': true});
expect(context.scope.filter).to.deep.equal({'dataGrid': {'compModelType': 'array', 'include': 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': true});
expect(context.scope.filter).to.deep.equal({'editGrid': {'compModelType': 'array', 'include': 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': true});
expect(context.scope.filter).to.deep.equal({'dataTable': {'compModelType': 'array', 'include': true}});
});
29 changes: 21 additions & 8 deletions src/process/filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,31 @@ export const filterProcessSync: ProcessorFnSync<FilterScope> = (context: FilterC
const modelType = Utils.getModelType(component);
switch (modelType) {
case 'dataObject':
scope.filter[absolutePath] = {data: {}};
scope.filter[absolutePath] = {
compModelType: modelType,
include: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"include" is really not needed. By this having a "scope.filter" for that path, it is included. Are you maybe adding the ability for some other processor to NOT include it?

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;
}
}
Expand All @@ -37,13 +50,13 @@ export const filterPostProcess: ProcessorFnSync<FilterScope> = (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);
Expand Down
8 changes: 6 additions & 2 deletions src/types/process/filter/FilterScope.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ProcessorScope } from "..";
export type FilterScope = {
filter: Record<string, any>;
} & ProcessorScope;
filter: Record<string, {
compModelType: string;
include: boolean;
value?: any;
}>;
} & ProcessorScope;
Loading