-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(DHIS2-17668): sanitise HTML in table instead of showing it as text
- Loading branch information
Showing
6 changed files
with
294 additions
and
65 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { | ||
DataTable, | ||
TableHead, | ||
DataTableRow, | ||
DataTableColumnHeader, | ||
TableBody, | ||
DataTableCell, | ||
} from '@dhis2/ui' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import ReactHtmlParser from 'react-html-parser' | ||
import styles from './table.module.css' | ||
|
||
// Needs to have the same width as the table, so can't use the one from | ||
// @dhis2/ui | ||
const DataTableToolbar = ({ children, columns }) => ( | ||
<tr> | ||
<th className={styles.titleCell} colSpan={columns.toString()}> | ||
{children} | ||
</th> | ||
</tr> | ||
) | ||
|
||
DataTableToolbar.propTypes = { | ||
children: PropTypes.any.isRequired, | ||
columns: PropTypes.number.isRequired, | ||
} | ||
|
||
const TableCustomDataSet = ({ title, columns, rows }) => ( | ||
<> | ||
<DataTable className={styles.dataTable} width="auto"> | ||
<TableHead> | ||
<DataTableToolbar columns={columns.length}> | ||
{ReactHtmlParser(title)} | ||
</DataTableToolbar> | ||
<DataTableRow> | ||
<DataTableColumnHeader className={styles.cell}> | ||
<span className={styles.labelCellContent}> | ||
{ReactHtmlParser(columns[0])} | ||
</span> | ||
</DataTableColumnHeader> | ||
|
||
{columns.slice(1).map((column) => { | ||
return ( | ||
<DataTableColumnHeader | ||
key={column} | ||
className={styles.cell} | ||
> | ||
{ReactHtmlParser(column)} | ||
</DataTableColumnHeader> | ||
) | ||
})} | ||
</DataTableRow> | ||
</TableHead> | ||
<TableBody> | ||
{rows.map((row, index) => { | ||
const [firstCell, ...cells] = row | ||
|
||
return ( | ||
<DataTableRow key={index}> | ||
<DataTableCell className={styles.cell}> | ||
<span className={styles.labelCellContent}> | ||
{ReactHtmlParser(firstCell)} | ||
</span> | ||
</DataTableCell> | ||
|
||
{cells.map((value, index) => ( | ||
<DataTableCell | ||
key={index} | ||
className={styles.cell} | ||
> | ||
{ReactHtmlParser(value)} | ||
</DataTableCell> | ||
))} | ||
</DataTableRow> | ||
) | ||
})} | ||
</TableBody> | ||
</DataTable> | ||
</> | ||
) | ||
|
||
TableCustomDataSet.propTypes = { | ||
columns: PropTypes.array.isRequired, | ||
rows: PropTypes.array.isRequired, | ||
title: PropTypes.string.isRequired, | ||
} | ||
|
||
export { TableCustomDataSet } |
Oops, something went wrong.