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

feat(table): add custom input to header columns #3767

Open
wants to merge 2 commits into
base: 2.x.x
Choose a base branch
from

Conversation

EKong-IBM
Copy link
Collaborator

GRAPHITE-58370

Summary

  • Adding property to allow custom column inputs for Table. This will also allow for extended filters to be added.

Change List (commits, features, bugs, etc)

  • FilterHeaderRow and testing file. Added property to TableHead.

Acceptance Test (how to verify the PR)

  • When creating a table, set customInput to an element and it should display that element instead of the current multiselect, combobox, or textinput.

Things to look for during review

  • Make sure all references to iot or bx class prefix is using the prefix variable
  • (React) All major areas have a data-testid attribute. New test ids should have test written to ensure they are not changed or removed.
  • UI should be checked in RTL mode to ensure the proper handling of layout and text.
  • All strings should be translatable.
  • The code should pass a11y scans (The storybook a11y knob should show no violations). New components should have a11y test written.
  • Unit test should be written and should have a coverage of 90% or higher in all areas.
  • All components should be passing visual regression test. For new styles or components either a visual regression test should be written for all permutations or the base image updated.
  • Changes or new components should either write new or update existing documentation.
  • PR should link and close out an existing issue

@netlify
Copy link

netlify bot commented Apr 6, 2023

Deploy Preview for carbon-addons-iot-react ready!

Name Link
🔨 Latest commit 0d6c89f
🔍 Latest deploy log https://app.netlify.com/sites/carbon-addons-iot-react/deploys/6446cd273079e80008b2b0b5
😎 Deploy Preview https://deploy-preview-3767--carbon-addons-iot-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Collaborator

@davidicus davidicus left a 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

@EKong-IBM EKong-IBM requested a review from sls-ca as a code owner April 24, 2023 18:40
@@ -669,6 +669,7 @@ const TableHead = ({
isFilterable: !isNil(column.filter),
isMultiselect: column.filter?.isMultiselect,
width: column.width,
customInput: column?.customInput,
Copy link
Collaborator

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,

Copy link
Collaborator Author

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>,
Copy link
Collaborator

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.

Copy link
Collaborator

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.

@EKong-IBM
Copy link
Collaborator Author

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
customInput: column?.customInput, -> customInput: column.filter?.customInput,

packages/react/src/components/Table/Table.story.helpers.jsx
customInput: <div>customInput</div>, -> filter: { customInput: <div>customInput</div> },

Copy link
Collaborator

@davidicus davidicus left a 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>,
Copy link
Collaborator

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,
Copy link
Collaborator

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.

Suggested change
customInput: PropTypes.element,
customInput: PropTypes. elementType,

Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do change this to be an elementType you can render like so:
image
Where you define a local variable like const CustomInput = column.customInput

@@ -1034,4 +1034,16 @@ describe('FilterHeaderRow', () => {
expect(screen.getByTestId('filter-row-icon')).toBeVisible();
});
});

it('should display custom input when not undefined', () => {
Copy link
Collaborator

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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
customInput: column?.customInput,
customInput: column.filter?.customInput,

Copy link
Collaborator

@sls-ca sls-ca left a 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?

@erzhan-temir-mamyrov
Copy link
Collaborator

@sls-ca I am not sure. I can follow up with Graphite ticket and resolve merge conflicts.

@erzhan-temir-mamyrov erzhan-temir-mamyrov self-assigned this May 30, 2023
@JordanWSmith15
Copy link
Collaborator

@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.

@herleraja herleraja changed the base branch from next to 2.x.x January 7, 2025 12:38
@herleraja herleraja self-requested a review as a code owner January 7, 2025 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants