-
Notifications
You must be signed in to change notification settings - Fork 78
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
feat(table): add custom input to header columns #3767
base: 2.x.x
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for carbon-addons-iot-react ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are almost there. Just a few more tweaks and then the addition to the Table story to showcase this new feature as well as adding it to the docs
packages/react/src/components/Table/TableHead/FilterHeaderRow/FilterHeaderRow.jsx
Outdated
Show resolved
Hide resolved
packages/react/src/components/Table/TableHead/FilterHeaderRow/FilterHeaderRow.test.jsx
Outdated
Show resolved
Hide resolved
@@ -669,6 +669,7 @@ const TableHead = ({ | |||
isFilterable: !isNil(column.filter), | |||
isMultiselect: column.filter?.isMultiselect, | |||
width: column.width, | |||
customInput: column?.customInput, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would imagine we would want this to be part of the filter object. Like above on line 670,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok that seems to have worked. Thanks 👍
{ | ||
id: 'customInput', | ||
name: 'Custom Input', | ||
customInput: <div>customInput</div>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not render without the filter property present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we need to change the proptype of this new property. We should pass in an elementType
so we can render the component in the FilterhaderRow and pass a ref. This will resolve the issue with the test on StatefulTable
. You can also look into the stateful table's code to see where it using the ref and put a condition in there to avoid test failure.
Either that or we need to clone the Element we bring in and add a ref.
I wasn't quite able to resolve the unit test issues, but I had followed David's review and the display seemed to work properly. packages/react/src/components/Table/TableHead/TableHead.jsx packages/react/src/components/Table/Table.story.helpers.jsx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more comments on clarity and how you are able to fix that test issue. I did test that the failure comes from not having a ref on the filter. So changing to elementType will resolve it and render the custom input that we want. We just need to find out if that works for the needed use case in Graphite. Otherwise, you can try to clone the element and see if that works.
{ | ||
id: 'customInput', | ||
name: 'Custom Input', | ||
customInput: <div>customInput</div>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we need to change the proptype of this new property. We should pass in an elementType
so we can render the component in the FilterhaderRow and pass a ref. This will resolve the issue with the test on StatefulTable
. You can also look into the stateful table's code to see where it using the ref and put a condition in there to avoid test failure.
Either that or we need to clone the Element we bring in and add a ref.
@@ -60,6 +60,7 @@ class FilterHeaderRow extends Component { | |||
), | |||
/** if isMultiselect and isFilterable are true, the table is filtered based on a multiselect */ | |||
isMultiselect: PropTypes.bool, | |||
customInput: PropTypes.element, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect we need this to be an elementType
so we can pass in a ref.
customInput: PropTypes.element, | |
customInput: PropTypes. elementType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may need to define an onChange handler in the filter object.
OR,
If we keep as an element
we can clone the component and add the ref that way. That may be preferable.
@@ -361,6 +362,8 @@ class FilterHeaderRow extends Component { | |||
const headerContent = | |||
column.isFilterable !== undefined && !column.isFilterable ? ( | |||
<div /> | |||
) : column.customInput !== undefined ? ( | |||
column.customInput |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1034,4 +1034,16 @@ describe('FilterHeaderRow', () => { | |||
expect(screen.getByTestId('filter-row-icon')).toBeVisible(); | |||
}); | |||
}); | |||
|
|||
it('should display custom input when not undefined', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a test where we use the custom input to ensure that we are able to filter data in the table.
@@ -669,6 +669,7 @@ const TableHead = ({ | |||
isFilterable: !isNil(column.filter), | |||
isMultiselect: column.filter?.isMultiselect, | |||
width: column.width, | |||
customInput: column?.customInput, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
customInput: column?.customInput, | |
customInput: column.filter?.customInput, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@erzhan-temir-mamyrov @JordanWSmith15 Is this PR still valid?
@sls-ca I am not sure. I can follow up with Graphite ticket and resolve merge conflicts. |
@sls-ca it is needed still, it just isn't high priority any more. Let's let it sit for a while, and some other dev will pick it up and finish it. |
GRAPHITE-58370
Summary
Change List (commits, features, bugs, etc)
Acceptance Test (how to verify the PR)
Things to look for during review
iot
orbx
class prefix is using the prefix variabledata-testid
attribute. New test ids should have test written to ensure they are not changed or removed.