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

All/selected row switch #284

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

radekkaluzik
Copy link
Collaborator

@radekkaluzik radekkaluzik commented Jan 29, 2025

All/selected rows switch

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

all-selected.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 +174


## 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"

```
Copy link
Collaborator

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

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

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

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?

@fhlavac
Copy link
Collaborator

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
Collaborator

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

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.

3 participants