-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
5,405 additions
and
232 deletions.
There are no files selected for viewing
5,071 changes: 5,071 additions & 0 deletions
5,071
...rkspace/category-combo-table-body-pivoted/__snapshots__/generate-form-matrix.test.js.snap
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 0 additions & 189 deletions
189
src/data-workspace/category-combo-table-body-pivoted/generate-form-matrix.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...rkspace/category-combo-table-body-pivoted/generate-form-matrix/generate-column-headers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
export const generateColumnHeaders = (options, groupedBy) => { | ||
const { | ||
metadata, | ||
categoryOptionsDetails, | ||
sortedCOCs, | ||
categories, | ||
dataElements, | ||
} = options | ||
|
||
const transposedOnly = groupedBy?.length === 0 | ||
|
||
const headerFields = transposedOnly | ||
? [...categories, ...dataElements] | ||
: [...categories.filter((cat) => !groupedBy.includes(cat.id))] | ||
|
||
const transposedCategories = categories.filter((cat) => | ||
groupedBy.includes(cat.id) | ||
) | ||
|
||
if (transposedOnly) { | ||
return [ | ||
[ | ||
...headerFields.map((header) => { | ||
return { | ||
id: header?.id, | ||
displayFormName: header?.displayFormName, | ||
type: 'columnHeader', | ||
metadataType: header.valueType ? 'dataElement': 'category', | ||
} | ||
}), | ||
], | ||
] | ||
} | ||
|
||
const columnsHeader = [ | ||
{ | ||
id: -1 /** todo: unique id */, | ||
type: 'empty', | ||
colSpan: (categories.length - headerFields.length) * 2, // 1 for data element | ||
}, | ||
...headerFields.map((header) => { | ||
const isCategory = !!header.categoryOptions // todo: cleaner way to distinguish categories from data elements in header | ||
|
||
return { | ||
id: header?.id, | ||
displayFormName: header?.displayFormName, | ||
type: 'columnHeader', | ||
metadataType: isCategory ? 'category' : 'dataElement', | ||
colSpan: header.categoryOptions?.length ?? '', | ||
} | ||
}), | ||
] | ||
|
||
const columnsSubHeader = [ | ||
{ | ||
id: -1 /** todo: unique id */, | ||
type: 'empty', | ||
colSpan: | ||
(categories.length - headerFields.length) * 2 - | ||
transposedCategories.length, // 1 for data element | ||
}, | ||
...transposedCategories.map((category) => { | ||
return { | ||
id: category.id, | ||
displayFormName: category?.displayFormName, | ||
type: 'columnHeader', | ||
metadataType: 'category', | ||
} | ||
}), | ||
...headerFields | ||
.map((header) => { | ||
return header.categoryOptions?.map((co) => { | ||
const optionMatch = categoryOptionsDetails.find( | ||
(cod) => cod.id === co | ||
) | ||
|
||
return { | ||
id: optionMatch?.id, | ||
displayFormName: optionMatch?.displayFormName, | ||
type: 'columnHeader', | ||
metadataType: 'categoryOption', | ||
} | ||
}) | ||
}) | ||
.flat(), | ||
] | ||
|
||
|
||
return [[...columnsHeader], [...columnsSubHeader]] | ||
} |
Oops, something went wrong.