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

FIO-8650 -- returning empty array for empty edit grids #116

Merged
merged 1 commit into from
Jul 10, 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
24 changes: 24 additions & 0 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,29 @@ describe('Process Tests', () => {
components: [nestedForm],
},
];
it('should return empty array when no data is provided', async () => {
const submission = {
data: {
editGrid: [],
},
};
const context = {
form: { components },
submission,
data: submission.data,
components,
processors: ProcessTargets.submission,
scope: {},
config: {
server: true,
},
};
processSync(context);
context.processors = ProcessTargets.evaluator;
processSync(context);
expect(context.data).to.deep.equal({ editGrid: [] });

})
it('Should validate required component when it is filled out', async () => {
const submission = {
data: {
Expand Down Expand Up @@ -2924,6 +2947,7 @@ describe('Process Tests', () => {
processSync(context);
expect((context.scope as ValidationScope).errors).to.have.length(1);
});

});
});
/*
Expand Down
13 changes: 8 additions & 5 deletions src/process/filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,18 @@ export const filterPostProcess: ProcessorFnSync<FilterScope> = (
context: FilterContext
) => {
const { scope, component, submission } = context;
let filtered = {};
let filtered: Record<string, object> = {};
for (const path in scope.filter) {
let value = get(submission?.data, path) as any;
const pathFilter = scope.filter[path];

if (pathFilter.compModelType === 'array') {
// special case for array, if it's empty, set it to empty array
if(value.length === 0) {
filtered[path] = []
}
continue;
}
if (pathFilter) {
let value = get(submission?.data, path) as any;

} else if (pathFilter) {
// when it's a dataModel Object, don't set values directly on the data object, let child fields do that.
// it can have extra data on updates, so pass all other values except data
// standard lodash set function will mutate original value, using the functional version so it doesn't
Expand Down
Loading