-
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.
feat(DHIS2-16132): transpose section forms
- Loading branch information
Showing
15 changed files
with
21,881 additions
and
565 deletions.
There are no files selected for viewing
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
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
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
215 changes: 215 additions & 0 deletions
215
src/data-workspace/category-combo-table-body-pivoted/category-combo-table-body-pivoted.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,215 @@ | ||
import { | ||
TableRow, | ||
TableCell, | ||
TableCellHead, | ||
} from '@dhis2/ui' | ||
import classNames from 'classnames' | ||
import PropTypes from 'prop-types' | ||
import React, { useCallback } from 'react' | ||
import { useMetadata, selectors } from '../../shared/index.js' | ||
import { DataEntryCell, DataEntryField } from '../data-entry-cell/index.js' | ||
import { getFieldId } from '../get-field-id.js' | ||
import styles from '../table-body.module.css' | ||
import { generateFormMatrix } from './generate-form-matrix.js' | ||
|
||
export const PivotedCategoryComboTableBody = React.memo( | ||
function PivotedCategoryComboTableBody({ | ||
categoryCombo, | ||
dataElements, | ||
filterText, | ||
globalFilterText, | ||
greyedFields, | ||
maxColumnsInSection, | ||
renderRowTotals, | ||
renderColumnTotals, | ||
grouped | ||
}) { | ||
const { data: metadata } = useMetadata() | ||
|
||
const categories = selectors.getCategoriesByCategoryComboId( | ||
metadata, | ||
categoryCombo.id | ||
) | ||
|
||
const sortedCOCs = selectors.getSortedCoCsByCatComboId( | ||
metadata, | ||
categoryCombo.id | ||
) | ||
|
||
const checkTableActive = useCallback( | ||
(activeDeId) => dataElements.some(({ id }) => id === activeDeId), | ||
[dataElements] | ||
) | ||
|
||
const paddingCells = | ||
maxColumnsInSection > 0 | ||
? new Array(maxColumnsInSection - sortedCOCs.length).fill(0) | ||
: [] | ||
|
||
const filteredDeIds = new Set() | ||
// filter out elements that do not match filterText | ||
dataElements.forEach((de) => { | ||
const name = de.displayFormName.toLowerCase() | ||
if ( | ||
(filterText && !name.includes(filterText.toLowerCase())) || | ||
(globalFilterText && | ||
!name.includes(globalFilterText.toLowerCase())) | ||
) { | ||
filteredDeIds.add(de.id) | ||
} | ||
}) | ||
const hiddenItemsCount = filteredDeIds.size | ||
|
||
const categoryOptionsDetails = categories | ||
.map((c) => { | ||
const headerOptions = selectors.getCategoryOptionsByCategoryId( | ||
metadata, | ||
c.id | ||
) | ||
return [...headerOptions] | ||
}) | ||
.flat() | ||
|
||
const options = { | ||
metadata, | ||
categoryOptionsDetails, | ||
sortedCOCs, | ||
categories, | ||
dataElements, | ||
} | ||
|
||
const rowsMatrix = generateFormMatrix(options, grouped) | ||
|
||
return ( | ||
<> | ||
{rowsMatrix.map((row, id /** todo: find suitable id */) => { | ||
return ( | ||
<TableRow key={row.id}> | ||
{row.map((fieldInRow) => { | ||
if (fieldInRow.type === 'columnHeader') { | ||
return ( | ||
<TableCellHead | ||
key={fieldInRow.id} | ||
className={classNames([ | ||
styles.categoryNameHeader, | ||
styles.noWrap, | ||
// styles.centered | ||
], { | ||
[styles.centered]: fieldInRow.colSpan > 1 | ||
})} | ||
colSpan={fieldInRow.colSpan} | ||
rowSpan={fieldInRow.rowSpan} | ||
> | ||
{fieldInRow.displayFormName !== | ||
'default' && | ||
fieldInRow.displayFormName} | ||
</TableCellHead> | ||
) | ||
} | ||
|
||
if (fieldInRow.type === 'group') { | ||
return ( | ||
<TableCellHead | ||
key={fieldInRow.id} | ||
className={[ | ||
styles.groupHeader, | ||
styles.noWrap, | ||
]} | ||
colSpan={fieldInRow.colSpan} | ||
> | ||
{fieldInRow.displayName} | ||
</TableCellHead> | ||
) | ||
} | ||
|
||
if (fieldInRow.type === 'empty') { | ||
return ( | ||
<TableCell | ||
className={[ | ||
styles.categoryNameHeader, | ||
styles.noWrap, | ||
]} | ||
key={fieldInRow.id} | ||
colSpan={fieldInRow.colSpan} | ||
/> | ||
) | ||
} | ||
|
||
if ( | ||
fieldInRow.rowSpan > 1 && | ||
fieldInRow.notFirstInstance | ||
) { | ||
return null | ||
} | ||
if (fieldInRow.type === 'de') { | ||
return ( | ||
<DataEntryCell key={fieldInRow.id}> | ||
<DataEntryField | ||
dataElement={ | ||
fieldInRow.dataElement | ||
} | ||
categoryOptionCombo={ | ||
fieldInRow.coc | ||
} | ||
disabled={greyedFields?.has( | ||
getFieldId( | ||
fieldInRow.dataElement | ||
.id, | ||
fieldInRow.coc.id | ||
) | ||
)} | ||
/> | ||
</DataEntryCell> | ||
|
||
// <TableCell | ||
// key={r.id} | ||
// rowSpan={r.rowSpan} | ||
// > | ||
// {r.displayName} | ||
// </TableCell> | ||
) | ||
} | ||
// console.log('rRRR', r) | ||
return ( | ||
<TableCell | ||
key={fieldInRow.id} | ||
rowSpan={fieldInRow.rowSpan} | ||
className={styles.cellBase} | ||
> | ||
{fieldInRow.displayName} | ||
</TableCell> | ||
) | ||
})} | ||
</TableRow> | ||
) | ||
})} | ||
</> | ||
) | ||
} | ||
) | ||
|
||
PivotedCategoryComboTableBody.propTypes = { | ||
categoryCombo: PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
}), | ||
dataElements: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
displayFormName: PropTypes.string, | ||
headerCombo: PropTypes.shape({ | ||
id: PropTypes.string, | ||
}), | ||
valueType: PropTypes.string, | ||
}) | ||
), | ||
filterText: PropTypes.string, | ||
globalFilterText: PropTypes.string, | ||
/** Greyed fields is a Set where .has(fieldId) is true if that field is greyed/disabled */ | ||
greyedFields: PropTypes.instanceOf(Set), | ||
grouped: PropTypes.bool, | ||
maxColumnsInSection: PropTypes.number, | ||
renderColumnTotals: PropTypes.bool, | ||
renderRowTotals: PropTypes.bool, | ||
} | ||
|
||
const PaddingCell = () => <TableCell className={styles.paddingCell}></TableCell> | ||
Oops, something went wrong.