Skip to content

Commit

Permalink
fix: hasResponse for table
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentC35 committed Nov 8, 2023
1 parent 3ad7b05 commit 673df7a
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions queen-v2/src/utils/components/deduceState.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ import {
COMP_TYPE_TEXTAREA,
} from 'utils/constants';

export const extractComponentFromTableLine = line => {
if (Array.isArray(line))
return line.reduce((result, cell) => {
if (typeof cell === 'object' && 'componentType' in cell) return [...result, cell];
return result;
}, []);
return [];
};

export const extractComponentFromTable = component => {
const { componentType } = component;
if (COMP_TYPE_TABLE !== componentType) return [component];
const { body } = component;
if (Array.isArray(body)) {
return body.reduce((result, line) => {
return [...result, ...extractComponentFromTableLine(line)];
}, []);
}
return [];
};

export const componentHasResponse = component => {
if (component === undefined) return false;

Expand All @@ -17,9 +38,12 @@ export const componentHasResponse = component => {

const { componentType } = component;
switch (componentType) {
case COMP_TYPE_CHECK_BOX_GROUP:
case COMP_TYPE_TABLE:
return Object.values(component.value).some(val => val !== null);
const tableComponents = extractComponentFromTable(component);
return tableComponents.reduce((result, comp) => {
return componentHasResponse(comp) || result;
}, false);
case COMP_TYPE_CHECK_BOX_GROUP:
case COMP_TYPE_INPUT_NUMBER:
case COMP_TYPE_CHECK_BOX_BOOLEAN:
case COMP_TYPE_TEXTAREA:
Expand Down

0 comments on commit 673df7a

Please sign in to comment.