Skip to content

Commit

Permalink
returning empty array for empty edit grids
Browse files Browse the repository at this point in the history
  • Loading branch information
John Teague committed Jul 10, 2024
1 parent 48e4e28 commit 4f48b9b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
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

0 comments on commit 4f48b9b

Please sign in to comment.