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

Fixed DataFilters to show all filter options #6943

Merged
merged 2 commits into from Sep 13, 2023

Conversation

halocline
Copy link
Collaborator

@halocline halocline commented Sep 11, 2023

What does this PR do?

Closes #6940.

Uses unfilteredData instead of data as source to build up default filter options. Previously, the logic was built up from data, however if data reached a length of zero, then no object was available to build up the options.

Where should the reviewer start?

  • review issue
  • DataFilters.js

What testing has been done on this PR?

  • Storybook
  • Added unit tests

How should this be manually tested?

Use the following stories:

For each:

  1. Use a combination of filters to get zero results.
  2. Re-open filters, all filter properties should be options.

Story w/out properties prop:

 <Data
    data={[
      {
        name: 'aa',
        enabled: true,
        rating: 2.3,
        sub: { note: 'ZZ' },
        tags: ['qa', 'staging', 'prod'],
      },
      {
        name: 'bb',
        enabled: false,
        rating: 4.3,
        sub: { note: 'YY' },
        tags: ['qa', 'staging'],
      },
      { name: 'cc', sub: {}, tags: ['qa'] },
      { name: 'dd' },
    ]}
    toolbar
  >
    <DataTable
      columns={[
        { property: 'name', header: 'Name' },
        { property: 'sub.note', header: 'Note' },
        {
          property: 'tags',
          header: 'Tags',
          render: ({ tags }) => (tags ? tags.join(', ') : null),
        },
      ]}
    />
  </Data>

Story with properties prop:

 <Data
    data={[
      {
        name: 'aa',
        enabled: true,
        rating: 2.3,
        sub: { note: 'ZZ' },
        tags: ['qa', 'staging', 'prod'],
      },
      {
        name: 'bb',
        enabled: false,
        rating: 4.3,
        sub: { note: 'YY' },
        tags: ['qa', 'staging'],
      },
      { name: 'cc', sub: {}, tags: ['qa'] },
      { name: 'dd' },
    ]}
    toolbar
    properties={{
      name: { label: 'Name' },
      'sub.note': { label: 'Note' },
      tags: {
        label: 'Tags',
        options: [
          { label: '01 - Development', value: 'dev' },
          { label: '02 - QA', value: 'qa' },
          { label: '03 - Staging', value: 'staging' },
          { label: '04 - Production', value: 'prod' },
        ],
      },
    }}
  >
    <DataTable
      columns={[
        { property: 'name', header: 'Name' },
        { property: 'sub.note', header: 'Note' },
        {
          property: 'tags',
          header: 'Tags',
          render: ({ tags }) => (tags ? tags.join(', ') : null),
        },
      ]}
    />
  </Data>

Do Jest tests follow these best practices?

  • screen is used for querying.
  • The correct query is used. (Refer to this list of queries)
  • userEvent is used in place of fireEvent.
  • asFragment() is used for snapshot testing.

Any background context you want to provide?

What are the relevant issues?

#6940

Screenshots (if appropriate)

Do the grommet docs need to be updated?

No.

Should this PR be mentioned in the release notes?

Yes.

Is this change backwards compatible or is it a breaking change?

Backwards compatible.

@halocline halocline added the Data and friends For data components in grommet label Sep 11, 2023
// build from a piece of data, ignore object values
filtersFor = Object.keys(data[0]).filter(
(k) => typeof data[0][k] !== 'object',
filtersFor = Object.keys(unfilteredData[0]).filter(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is it reasonable for us to only be looking at the first object to build up the default options? This assumes the first object is representative of all objects in the data set and has all properties. What if other objects have properties not represented?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's reasonable given they can specify properties if they have sparse objects for some reason

// build from a piece of data, ignore object values
filtersFor = Object.keys(data[0]).filter(
(k) => typeof data[0][k] !== 'object',
filtersFor = Object.keys(unfilteredData[0]).filter(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's reasonable given they can specify properties if they have sparse objects for some reason

Copy link
Collaborator

@jcfilben jcfilben left a comment

Choose a reason for hiding this comment

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

Looks good!

@jcfilben jcfilben merged commit 0daec2f into master Sep 13, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Data and friends For data components in grommet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataFilters do not show an filterable properties when result set is zero
4 participants