Skip to content

All/selected row switch#284

Merged
karelhala merged 1 commit intopatternfly:mainfrom
radekkaluzik:RHCLOUD-34812
Feb 25, 2025
Merged

All/selected row switch#284
karelhala merged 1 commit intopatternfly:mainfrom
radekkaluzik:RHCLOUD-34812

Conversation

@radekkaluzik
Copy link
Collaborator

@radekkaluzik radekkaluzik commented Jan 29, 2025

All/selected rows switch

https://issues.redhat.com/browse/RHCLOUD-34812

Zaznam.obrazovky.2025-02-25.v.10.46.55.mov

@radekkaluzik radekkaluzik requested a review from fhlavac January 29, 2025 14:05
@patternfly-build
Copy link

patternfly-build commented Jan 29, 2025

Comment on lines 144 to 154


## All/selected data switch
To allow users to filter data records in the data view, add filtering support that displays the applied filter chips.

The data view toolbar can include a set of filters by passing a React node to the `filters` property. You can use the predefined components `<DataViewFilters>`, `<DataViewTextFilter>`, and `<DataViewCheckboxFilter>` to customize and handle filtering directly in the toolbar. The `<DataViewFilters>` component is a wrapper that allows conditional filtering using multiple attributes. If you need just a single filter, you can use `<DataViewTextFilter>`, `<DataViewCheckboxFilter>`, or a different filter component alone. Props of these filter components are listed in the [props section of this page](#props).

You can either pass a `value` and `onChange` event to every filter separately, or you can pass `values` and `onChange` to the `<DataViewFilters>` wrapper, which makes them available to its children. Props directly passed to child filters have a higher priority than the "inherited" ones.

### Filters state

The `useDataViewFilters` hook manages the filter state of the data view. It allows you to define default filter values, synchronize filter state with URL parameters, and handle filter changes efficiently.

**Initial values:**
- `initialFilters` object with default filter values (if the filter param allows multiple values, pass an array).
- Optional `searchParams` object for managing URL-based filter state.
- Optional `setSearchParams` function to update the URL when filters are modified.

The `useDataViewFilters` hook works well with the [React Router](https://reactrouter.com/) library to support URL-based filtering. Alternatively, you can manage the filter state in the URL using `URLSearchParams` and `window.history.pushState` APIs, or other routing libraries. If no URL parameters are provided, the filter state is managed internally.

**Return values:**
- `filters` object representing the current filter values.
- `onSetFilters` function to update the filter state.
- `clearAllFilters` function to reset all filters to their initial values.

### All/selected example
This example demonstrates the setup and usage of filters within the data view. It includes text filters for different attributes, the ability to clear all filters, and persistence of filter state in the URL.

```js file="./AllSelectedExample.tsx"

``` No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

The content seems to be just copied from the filters section, we should describe, what is happening in the new example

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Replaced by the actual component description.

onSelect={handleBulkSelect}
/>
}
toggleGroup={<ToggleGroup aria-label="Default with single selectable">
Copy link
Contributor

Choose a reason for hiding this comment

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

we could come up with some better aria label

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

how about introducing constants for all/selected strings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Implemented.

@fhlavac
Copy link
Contributor

fhlavac commented Jan 30, 2025

It would be nice to add some cypress test coverage - it can be just an e2e test checking that appropriate rows are displayed

@fhlavac
Copy link
Contributor

fhlavac commented Jan 30, 2025

@radekkaluzik did you have a chance to talk with UX about what to do with the toggle buttons if no rows are selected or become unselected? --If we want to hide the toggle group or just disable buttons/switch to appropriate? This should be probably figured out before we merge the example

@karelhala karelhala merged commit 2a07782 into patternfly:main Feb 25, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants