Skip to content

Commit

Permalink
refactor: apply code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kabaros committed Mar 5, 2024
1 parent 14b1b94 commit a939679
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ export const PivotedCategoryComboTableBody = React.memo(
colSpan={fieldInRow.colSpan}
rowSpan={fieldInRow.rowSpan}
>
{fieldInRow.displayFormName !==
'default' &&
{fieldInRow.name !== 'default' &&
fieldInRow.displayFormName}
</TableCellHead>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2409,108 +2409,126 @@ Array [
"displayFormName": "Location Fixed/Outreach",
"id": "fMZEcRHuamy",
"metadataType": "category",
"name": "Location Fixed/Outreach",
"type": "columnHeader",
},
Object {
"displayFormName": "EPI/nutrition age",
"id": "YNZyaJHiHYq",
"metadataType": "category",
"name": "EPI/nutrition age",
"type": "columnHeader",
},
Object {
"displayFormName": "Children getting therapeutic feeding",
"id": "qw2sIef52Fu",
"metadataType": "dataElement",
"name": "Children getting therapeutic feeding",
"type": "columnHeader",
},
Object {
"displayFormName": "Children supplied with food supplemements",
"id": "Y53Jcc9LBYh",
"metadataType": "dataElement",
"name": "Children supplied with food supplemements",
"type": "columnHeader",
},
Object {
"displayFormName": "Mebendazole/Albendazole (for children 12-59 months)",
"id": "d5xTg3WR3DP",
"metadataType": "dataElement",
"name": "Mebendazole/Albendazole (for children 12-59 months)",
"type": "columnHeader",
},
Object {
"displayFormName": "Newborn protected at birth against tetanus (TT2+)",
"id": "DUSpd8Jq3M7",
"metadataType": "dataElement",
"name": "Newborn protected at birth against tetanus (TT2+)",
"type": "columnHeader",
},
Object {
"displayFormName": "Q_Early breastfeeding (within 1 hr after delivery) at BCG",
"id": "dU0GquGkGQr",
"metadataType": "dataElement",
"name": "Q_Early breastfeeding (within 1 hr after delivery) at BCG",
"type": "columnHeader",
},
Object {
"displayFormName": "Q_Exclusive breastfeeding at time of Penta 3",
"id": "pEOVd4Z3TAS",
"metadataType": "dataElement",
"name": "Q_Exclusive breastfeeding at time of Penta 3",
"type": "columnHeader",
},
Object {
"displayFormName": "Q_LLITN given at time of 2nd Vit A dose",
"id": "Rmixc9wJl0G",
"metadataType": "dataElement",
"name": "Q_LLITN given at time of 2nd Vit A dose",
"type": "columnHeader",
},
Object {
"displayFormName": "Q_Slept under LLIN last night Measles",
"id": "GCGfEY82Wz6",
"metadataType": "dataElement",
"name": "Q_Slept under LLIN last night Measles",
"type": "columnHeader",
},
Object {
"displayFormName": "Q_Vitamin A received 4-6 months ago at 12-59 dose",
"id": "ca8lfO062zg",
"metadataType": "dataElement",
"name": "Q_Vitamin A received 4-6 months ago at 12-59 dose",
"type": "columnHeader",
},
Object {
"displayFormName": "Vitamin A given to < 5y",
"id": "tU7GixyHhsv",
"metadataType": "dataElement",
"name": "Vitamin A given to < 5y",
"type": "columnHeader",
},
Object {
"displayFormName": "Weight for age below lower line (red)",
"id": "bTcRDVjC66S",
"metadataType": "dataElement",
"name": "Weight for age below lower line (red)",
"type": "columnHeader",
},
Object {
"displayFormName": "Weight for age between middle and lower line (yellow)",
"id": "ldGXl6SEdqf",
"metadataType": "dataElement",
"name": "Weight for age between middle and lower line (yellow)",
"type": "columnHeader",
},
Object {
"displayFormName": "Weight for age on or above middle line (green)",
"id": "NLnXLV5YpZF",
"metadataType": "dataElement",
"name": "Weight for age on or above middle line (green)",
"type": "columnHeader",
},
Object {
"displayFormName": "Weight for height 70-79 percent",
"id": "pnL2VG8Bn7N",
"metadataType": "dataElement",
"name": "Weight for height 70-79 percent",
"type": "columnHeader",
},
Object {
"displayFormName": "Weight for height 80 percent and above",
"id": "qPVDd87kS9Z",
"metadataType": "dataElement",
"name": "Weight for height 80 percent and above",
"type": "columnHeader",
},
Object {
"displayFormName": "Weight for height below 70 percent",
"id": "lVsbKXoF0zX",
"metadataType": "dataElement",
"name": "Weight for height below 70 percent",
"type": "columnHeader",
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import i18n from '@dhis2/d2-i18n'
import { selectors } from '../../../shared/index.js'

export const generateMatrixTransposed = (options) => {
Expand All @@ -16,6 +17,7 @@ export const generateMatrixTransposed = (options) => {
...columnHeaderFields.map((header) => {
return {
id: header?.id,
name: header.name,
displayFormName: header?.displayFormName,
type: 'columnHeader',
metadataType: header.valueType ? 'dataElement' : 'category',
Expand Down Expand Up @@ -43,11 +45,16 @@ export const generateMatrixTransposed = (options) => {
if (!alreadyAdded[categoryOption.id] || lastCateogry) {
dataEntryRow.push({
id: categoryOption?.id,
displayFormName: categoryOption?.displayName,
displayFormName:
categoryOption?.name === 'default'
? i18n.t('Value')
: categoryOption?.displayName,
rowSpan:
sortedCOCs.length /
categories.length /
(categoryIndex + 1),
categories.length === 1
? 1
: sortedCOCs.length /
categories.length /
(categoryIndex + 1),
type: 'rowHeader',
})
alreadyAdded[categoryOption.id] = true
Expand Down
22 changes: 1 addition & 21 deletions src/data-workspace/section-form/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import classNames from 'classnames'
import PropTypes from 'prop-types'
import React, { useMemo, useState } from 'react'
import { useMetadata, selectors, useFeature } from '../../shared/index.js'
import { useMetadata, selectors } from '../../shared/index.js'
import { CategoryComboTableBody } from '../category-combo-table-body/index.js'
import {
PivotedCategoryComboTableBody,
Expand Down Expand Up @@ -69,26 +69,6 @@ export function SectionFormSection({ section, dataSetId, globalFilterText }) {
const { displayOptions: displayOptionString } = section
const displayOptions = JSON.parse(displayOptionString)

// feature toggle to enable testing this feature without maintenance app
// format of toggle is: &features=pivot_fMZEcRHuamy
// (to add to the query parameter)
const featureTogglePivotOptions = useFeature('pivot')

console.debug('[feature toggle: pivotOptions]', featureTogglePivotOptions)
if (featureTogglePivotOptions) {
displayOptions.pivotMode = 'pivot'

if (featureTogglePivotOptions.length) {
const [pivotedCategory] = featureTogglePivotOptions

if (pivotedCategory) {
displayOptions.pivotMode = 'move_categories'
displayOptions.pivotedCategory = pivotedCategory
}
console.debug('[feature: final displayOptions]', displayOptions)
}
}

const isPivotMode =
displayOptions.pivotMode === 'move_categories' ||
displayOptions.pivotMode === 'pivot'
Expand Down
14 changes: 0 additions & 14 deletions src/shared/use-context-selection/use-context-selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@ export function usePeriodId() {
return useQueryParam('periodId', PARAMS_SCHEMA.periodId)
}

export function useFeature(feature) {
const [allFeatures] = useQueryParam('features', StringParam)
const features = allFeatures?.split(',')

const featureWithOptions = features?.find((feat) =>
feat.includes(`${feature}_`)
)

if (featureWithOptions) {
return featureWithOptions.replace(`${feature}_`, '')?.split(',')
}
return features?.includes(feature)
}

/**
*
* @returns the selected attribute-options in the shape of
Expand Down

0 comments on commit a939679

Please sign in to comment.