Skip to content

Commit

Permalink
feat(DHIS2-16132): transpose section forms
Browse files Browse the repository at this point in the history
  • Loading branch information
kabaros committed Feb 20, 2024
1 parent 94fbaa6 commit 4ae88d1
Show file tree
Hide file tree
Showing 15 changed files with 21,881 additions and 565 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ The category model can be fairly confusing, so we've created a few diagrams to h
[Models used in form](./docs/category-combo-diagram.png)

[Attribute category combo diagram](./docs/attribute-category-combo-diagram.png)

Entry-Form
|- Section-Form
|--- Section
|------ CategoryComboTableBody
10 changes: 8 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2023-08-10T08:31:47.096Z\n"
"PO-Revision-Date: 2023-08-10T08:31:47.096Z\n"
"POT-Creation-Date: 2024-01-15T14:35:08.966Z\n"
"PO-Revision-Date: 2024-01-15T14:35:08.966Z\n"

msgid "Not authorized"
msgstr "Not authorized"
Expand Down Expand Up @@ -210,6 +210,9 @@ msgstr "Data item has a comment"
msgid "Invalid value, not saved"
msgstr "Invalid value, not saved"

msgid "Warning, saved"
msgstr "Warning, saved"

msgid "Locked, not editable"
msgstr "Locked, not editable"

Expand Down Expand Up @@ -588,3 +591,6 @@ msgstr "{{title}} (disabled)"

msgid "Close details sidebar"
msgstr "Close details sidebar"

msgid "Integer numbers have to be in the range from -2147483648 to 2147483647"
msgstr "Integer numbers have to be in the range from -2147483648 to 2147483647"
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"devDependencies": {
"@badeball/cypress-cucumber-preprocessor": "^16.0.0",
"@cypress/webpack-preprocessor": "^5.17.0",
"@dhis2/cli-app-scripts": "^10.2.3",
"@dhis2/cli-app-scripts": "^10.4.0",
"@dhis2/cli-style": "10.5.1",
"@dhis2/cypress-commands": "^10.0.1",
"@dhis2/cypress-plugins": "^10.0.1",
Expand All @@ -45,12 +45,13 @@
"enzyme-adapter-react-16": "1.15.7",
"eslint-plugin-cypress": "2.12.1",
"fake-indexeddb": "4.0.1",
"jest-extended": "^4.0.2",
"start-server-and-test": "1.15.4"
},
"dependencies": {
"@dhis2/app-runtime": "^3.8.0",
"@dhis2/multi-calendar-dates": "^1.0.0-alpha.22",
"@dhis2/ui": "^8.12.0",
"@dhis2/app-runtime": "^3.10.2",
"@dhis2/multi-calendar-dates": "^1.1.0",
"@dhis2/ui": "^9.2.0",
"@dhis2/ui-forms": "7.16.3",
"@tanstack/react-query": "4.24.10",
"@tanstack/react-query-devtools": "4.24.14",
Expand All @@ -77,5 +78,10 @@
},
"engines": {
"node": ">=14.0.0"
},
"resolutions": {
"@dhis2/multi-calendar-dates": "^1.1.0",
"@dhis2/ui": "^9.2.0",
"@dhis2/app-runtime": "^3.10.2"
}
}
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,

Check failure on line 23 in src/data-workspace/category-combo-table-body-pivoted/category-combo-table-body-pivoted.js

View workflow job for this annotation

GitHub Actions / lint

'renderRowTotals' is defined but never used
renderColumnTotals,

Check failure on line 24 in src/data-workspace/category-combo-table-body-pivoted/category-combo-table-body-pivoted.js

View workflow job for this annotation

GitHub Actions / lint

'renderColumnTotals' is defined but never used
grouped
}) {
const { data: metadata } = useMetadata()

const categories = selectors.getCategoriesByCategoryComboId(
metadata,
categoryCombo.id
)

const sortedCOCs = selectors.getSortedCoCsByCatComboId(
metadata,
categoryCombo.id
)

const checkTableActive = useCallback(

Check failure on line 39 in src/data-workspace/category-combo-table-body-pivoted/category-combo-table-body-pivoted.js

View workflow job for this annotation

GitHub Actions / lint

'checkTableActive' is assigned a value but never used
(activeDeId) => dataElements.some(({ id }) => id === activeDeId),
[dataElements]
)

const paddingCells =

Check failure on line 44 in src/data-workspace/category-combo-table-body-pivoted/category-combo-table-body-pivoted.js

View workflow job for this annotation

GitHub Actions / lint

'paddingCells' is assigned a value but never used
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

Check failure on line 61 in src/data-workspace/category-combo-table-body-pivoted/category-combo-table-body-pivoted.js

View workflow job for this annotation

GitHub Actions / lint

'hiddenItemsCount' is assigned a value but never used

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 */) => {

Check failure on line 85 in src/data-workspace/category-combo-table-body-pivoted/category-combo-table-body-pivoted.js

View workflow job for this annotation

GitHub Actions / lint

'id' is defined but never used
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>

Check failure on line 215 in src/data-workspace/category-combo-table-body-pivoted/category-combo-table-body-pivoted.js

View workflow job for this annotation

GitHub Actions / lint

'PaddingCell' is assigned a value but never used
Loading

0 comments on commit 4ae88d1

Please sign in to comment.