@patternfly/react-data-view 5.4.0 → 5.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { StackProps } from '@patternfly/react-core';
2
3
  import { DataViewSelection } from '../InternalContext';
3
4
  export declare const DataViewState: {
4
5
  readonly empty: "empty";
@@ -6,7 +7,8 @@ export declare const DataViewState: {
6
7
  readonly error: "error";
7
8
  };
8
9
  export type DataViewState = typeof DataViewState[keyof typeof DataViewState];
9
- export interface DataViewProps {
10
+ /** extends StackProps */
11
+ export interface DataViewProps extends StackProps {
10
12
  /** Content rendered inside the data view */
11
13
  children: React.ReactNode;
12
14
  /** Custom OUIA ID */
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { StackProps } from '@patternfly/react-core';
2
3
  import { DataViewSelection } from '../InternalContext';
3
4
  export declare const DataViewState: {
4
5
  readonly empty: "empty";
@@ -6,7 +7,8 @@ export declare const DataViewState: {
6
7
  readonly error: "error";
7
8
  };
8
9
  export type DataViewState = typeof DataViewState[keyof typeof DataViewState];
9
- export interface DataViewProps {
10
+ /** extends StackProps */
11
+ export interface DataViewProps extends StackProps {
10
12
  /** Content rendered inside the data view */
11
13
  children: React.ReactNode;
12
14
  /** Custom OUIA ID */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-data-view",
3
- "version": "5.4.0",
3
+ "version": "5.4.1",
4
4
  "description": "Data view used for Red Hat projects.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -72,13 +72,15 @@ The `DataViewTable` component accepts the following props:
72
72
 
73
73
  - optional `props` (`TableProps`) that are passed down to the `<Table>` component, except for `onSelect`, which is managed internally.
74
74
 
75
+ It is also possible to disable row selection using the `isSelectDisabled` function passed to the wrapping data view component through `selection`.
76
+
75
77
  ### Tree table example
76
78
  This example shows the tree table variant with expandable rows, custom icons for leaf and parent nodes. Tree table is turned on by passing `isTreeTable` flag to the `DataViewTable` component. You can pass `collapsedIcon`, `expandedIcon` or `leafIcon` to be displayen rows with given status. The tree table rows have to be defined in a format of object with following keys:
77
79
  - `row` (`DataViewTd[]`) defining the content for each cell in the row.
78
80
  - `id` (`string`) for the row (used to match items in selection end expand the rows).
79
81
  - optional `children` (`DataViewTrTree[]`) defining the children rows.
80
82
 
81
- It is also possible to disable row selection using the `isSelectDisabled` function passed to the wrapping data view component.
83
+ It is also possible to disable row selection using the `isSelectDisabled` function passed to the wrapping data view component through `selection`.
82
84
 
83
85
  ```js file="./DataViewTableTreeExample.tsx"
84
86
 
@@ -18,6 +18,7 @@ import { Table, Tbody, Th, Thead, Tr, Td } from '@patternfly/react-table';
18
18
  import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
19
19
  import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
20
20
  import { useDataViewEventsContext, DataViewEventsContext, DataViewEventsProvider, EventTypes } from '@patternfly/react-data-view/dist/dynamic/DataViewEventsContext';
21
+ import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
21
22
  import { Drawer, DrawerContent, DrawerContentBody } from '@patternfly/react-core';
22
23
 
23
24
  The **data view events context** provides a way of listening to the data view events from the outside of the component.
@@ -3,6 +3,8 @@ import { Drawer, DrawerActions, DrawerCloseButton, DrawerContent, DrawerContentB
3
3
  import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
4
4
  import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
5
5
  import { DataViewEventsProvider, EventTypes, useDataViewEventsContext } from '@patternfly/react-data-view/dist/dynamic/DataViewEventsContext';
6
+ import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
7
+ import { ActionsColumn } from '@patternfly/react-table';
6
8
 
7
9
  interface Repository {
8
10
  name: string;
@@ -64,25 +66,45 @@ interface RepositoriesTableProps {
64
66
  selectedRepo?: Repository;
65
67
  }
66
68
 
69
+ const rowActions = [
70
+ {
71
+ title: 'Some action',
72
+ onClick: () => console.log('clicked on Some action') // eslint-disable-line no-console
73
+ },
74
+ {
75
+ title: <div>Another action</div>,
76
+ onClick: () => console.log('clicked on Another action') // eslint-disable-line no-console
77
+ },
78
+ {
79
+ isSeparator: true
80
+ },
81
+ {
82
+ title: 'Third action',
83
+ onClick: () => console.log('clicked on Third action') // eslint-disable-line no-console
84
+ }
85
+ ];
86
+
67
87
  const RepositoriesTable: React.FunctionComponent<RepositoriesTableProps> = ({ selectedRepo = undefined }) => {
88
+ const selection = useDataViewSelection({ matchOption: (a, b) => a.row[0] === b.row[0] });
68
89
  const { trigger } = useDataViewEventsContext();
69
90
  const rows = useMemo(() => {
70
- const handleRowClick = (repo: Repository | undefined) => {
71
- trigger(EventTypes.rowClick, repo);
91
+ const handleRowClick = (event, repo: Repository | undefined) => {
92
+ // prevents drawer toggle on actions or checkbox click
93
+ (event.target.matches('td') || event.target.matches('tr')) && trigger(EventTypes.rowClick, repo);
72
94
  };
73
95
 
74
96
  return repositories.map(repo => ({
75
- row: Object.values(repo),
97
+ row: [ ...Object.values(repo), { cell: <ActionsColumn items={rowActions}/>, props: { isActionCell: true } } ],
76
98
  props: {
77
99
  isClickable: true,
78
- onRowClick: () => handleRowClick(selectedRepo?.name === repo.name ? undefined : repo),
100
+ onRowClick: (event) => handleRowClick(event, selectedRepo?.name === repo.name ? undefined : repo),
79
101
  isRowSelected: selectedRepo?.name === repo.name
80
102
  }
81
103
  }));
82
104
  }, [ selectedRepo?.name, trigger ]);
83
105
 
84
106
  return (
85
- <DataView>
107
+ <DataView selection={selection}>
86
108
  <DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} />
87
109
  </DataView>
88
110
  );
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { Stack, StackItem } from '@patternfly/react-core';
2
+ import { Stack, StackItem, StackProps } from '@patternfly/react-core';
3
3
  import { DataViewSelection, InternalContextProvider } from '../InternalContext';
4
4
 
5
5
  export const DataViewState = {
@@ -10,7 +10,8 @@ export const DataViewState = {
10
10
 
11
11
  export type DataViewState = typeof DataViewState[keyof typeof DataViewState];
12
12
 
13
- export interface DataViewProps {
13
+ /** extends StackProps */
14
+ export interface DataViewProps extends StackProps {
14
15
  /** Content rendered inside the data view */
15
16
  children: React.ReactNode;
16
17
  /** Custom OUIA ID */