Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cat-combo-table): prevent filter from unmounting data-elements #186

Merged
merged 3 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TableBody, TableRow, TableCell } from '@dhis2/ui'
import cx from 'classnames'
import PropTypes from 'prop-types'
import React, { useCallback } from 'react'
import { useMetadata, selectors } from '../../shared/index.js'
Expand Down Expand Up @@ -43,16 +44,19 @@ export const CategoryComboTableBody = React.memo(
? new Array(maxColumnsInSection - sortedCOCs.length).fill(0)
: []

const filteredDataElements = dataElements.filter((de) => {
const filteredDeIds = new Set()
// filter out elements that do not match filterText
dataElements.forEach((de) => {
const name = de.displayFormName.toLowerCase()
return (
(!filterText || name.includes(filterText.toLowerCase())) &&
(!globalFilterText ||
name.includes(globalFilterText.toLowerCase()))
)
if (
(filterText && !name.includes(filterText.toLowerCase())) ||
(globalFilterText &&
!name.includes(globalFilterText.toLowerCase()))
) {
filteredDeIds.add(de.id)
}
})
const hiddenItemsCount =
dataElements.length - filteredDataElements.length
const hiddenItemsCount = filteredDeIds.size

return (
<TableBody>
Expand All @@ -63,9 +67,14 @@ export const CategoryComboTableBody = React.memo(
paddingCells={paddingCells}
checkTableActive={checkTableActive}
/>
{filteredDataElements.map((de, i) => {
{dataElements.map((de, i) => {
return (
<TableRow key={de.id}>
<TableRow
key={de.id}
className={cx({
[styles.hidden]: filteredDeIds.has(de.id),
})}
>
<DataElementCell dataElement={de} />
{sortedCOCs.map((coc) => (
<DataEntryCell key={coc.id}>
Expand Down
4 changes: 4 additions & 0 deletions src/data-workspace/table-body.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@
composes: totalCell;
font-weight: initial;
}

.hidden {
display: none;
}