-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into Add-track-columnst-prop
- Loading branch information
Showing
5 changed files
with
139 additions
and
2 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
14 changes: 14 additions & 0 deletions
14
src/QueryBuilder/ResultViewer/DynamicTable/DynamicTable.css
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,14 @@ | ||
.DynamicTable { | ||
width: calc(100% + calc(2 * var(--gutter-static-two-thirds))); | ||
margin: calc(-1 * var(--gutter-static-one-third)) calc(-1 * var(--gutter-static-two-thirds)); | ||
border-collapse: collapse; | ||
} | ||
|
||
.DynamicTable td { | ||
vertical-align: top; | ||
} | ||
|
||
|
||
.DynamicTable th, .DynamicTable td { | ||
padding: var(--gutter-static-one-third) var(--gutter-static-two-thirds); | ||
} |
36 changes: 36 additions & 0 deletions
36
src/QueryBuilder/ResultViewer/DynamicTable/DynamicTable.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,36 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import css from './DynamicTable.css'; | ||
|
||
export const DynamicTable = ({ properties, values }) => { | ||
const tableBodyRows = JSON.parse(values); | ||
|
||
if (!tableBodyRows.length) return null; | ||
|
||
return ( | ||
<table className={css.DynamicTable}> | ||
<thead> | ||
<tr>{properties?.map((cell) => ( | ||
<th key={cell.property} style={{ width: `${100 / properties.length}%` }}>{cell.labelAlias}</th> | ||
))} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{tableBodyRows.map((row, index) => ( | ||
<tr key={index}> | ||
{properties?.map((cell) => ( | ||
<td key={cell.property}> | ||
{row[cell.property]} | ||
</td> | ||
))} | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
); | ||
}; | ||
|
||
DynamicTable.propTypes = { | ||
properties: PropTypes.arrayOf(PropTypes.object), | ||
values: PropTypes.string, | ||
}; |
82 changes: 82 additions & 0 deletions
82
src/QueryBuilder/ResultViewer/DynamicTable/DynamicTable.test.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,82 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { DynamicTable } from './DynamicTable'; | ||
|
||
describe('DynamicTable component', () => { | ||
const properties = [ | ||
{ | ||
'name': 'code', | ||
'dataType': { | ||
'dataType': 'stringType', | ||
}, | ||
'labelAlias': 'Code', | ||
'property': 'code', | ||
}, | ||
{ | ||
'name': 'distribution_type', | ||
'dataType': { | ||
'dataType': 'stringType', | ||
}, | ||
'labelAlias': 'Distribution type', | ||
'property': 'distributionType', | ||
}, | ||
{ | ||
'name': 'encumbrance', | ||
'dataType': { | ||
'dataType': 'rangedUUIDType', | ||
}, | ||
'labelAlias': 'Encumbrance', | ||
'property': 'encumbrance', | ||
}, | ||
{ | ||
'name': 'fund_id', | ||
'dataType': { | ||
'dataType': 'rangedUUIDType', | ||
}, | ||
'labelAlias': 'Fund ID', | ||
'property': 'fundId', | ||
}, | ||
{ | ||
'name': 'value', | ||
'dataType': { | ||
'dataType': 'numberType', | ||
}, | ||
'labelAlias': 'Value', | ||
'property': 'value', | ||
}, | ||
]; | ||
|
||
const values = '[{"code": "STATE-MONOSER", "value": 100.0, "fundId": "bbd4a5e1-c9f3-44b9-bfdf-d184e04f0ba0", "encumbrance": "eb506834-6c70-4239-8d1a-6414a5b08010", "distributionType": "percentage"}]'; | ||
|
||
it('render null value if there are no rows', () => { | ||
const { container } = render(<DynamicTable properties={properties} values="[]" />); | ||
|
||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
|
||
it('renders table with correct properties and values', () => { | ||
const { getByText } = render(<DynamicTable properties={properties} values={values} />); | ||
|
||
properties.forEach(property => { | ||
const label = getByText(property.labelAlias); | ||
|
||
expect(label).toBeInTheDocument(); | ||
}); | ||
|
||
const codeValue = getByText('STATE-MONOSER'); | ||
|
||
expect(codeValue).toBeInTheDocument(); | ||
|
||
const encumbranceValue = getByText('eb506834-6c70-4239-8d1a-6414a5b08010'); | ||
|
||
expect(encumbranceValue).toBeInTheDocument(); | ||
|
||
const fundIdValue = getByText('bbd4a5e1-c9f3-44b9-bfdf-d184e04f0ba0'); | ||
|
||
expect(fundIdValue).toBeInTheDocument(); | ||
|
||
const numberValue = getByText('100'); | ||
|
||
expect(numberValue).toBeInTheDocument(); | ||
}); | ||
}); |
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