Skip to content

Commit e797073

Browse files
authored
Merge pull request #113 from fhlavac/fixes
2 parents 3b2ac8b + 3ad2ae4 commit e797073

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

packages/module/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsContext.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Table, Tbody, Th, Thead, Tr, Td } from '@patternfly/react-table';
1818
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
1919
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
2020
import { useDataViewEventsContext, DataViewEventsContext, DataViewEventsProvider, EventTypes } from '@patternfly/react-data-view/dist/dynamic/DataViewEventsContext';
21+
import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
2122
import { Drawer, DrawerContent, DrawerContentBody } from '@patternfly/react-core';
2223

2324
The **data view events context** provides a way of listening to the data view events from the outside of the component.

packages/module/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsExample.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Drawer, DrawerActions, DrawerCloseButton, DrawerContent, DrawerContentB
33
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
44
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
55
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';
68

79
interface Repository {
810
name: string;
@@ -64,25 +66,45 @@ interface RepositoriesTableProps {
6466
selectedRepo?: Repository;
6567
}
6668

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+
6787
const RepositoriesTable: React.FunctionComponent<RepositoriesTableProps> = ({ selectedRepo = undefined }) => {
88+
const selection = useDataViewSelection({ matchOption: (a, b) => a.row[0] === b.row[0] });
6889
const { trigger } = useDataViewEventsContext();
6990
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);
7294
};
7395

7496
return repositories.map(repo => ({
75-
row: Object.values(repo),
97+
row: [ ...Object.values(repo), { cell: <ActionsColumn items={rowActions}/>, props: { isActionCell: true } } ],
7698
props: {
7799
isClickable: true,
78-
onRowClick: () => handleRowClick(selectedRepo?.name === repo.name ? undefined : repo),
100+
onRowClick: (event) => handleRowClick(event, selectedRepo?.name === repo.name ? undefined : repo),
79101
isRowSelected: selectedRepo?.name === repo.name
80102
}
81103
}));
82104
}, [ selectedRepo?.name, trigger ]);
83105

84106
return (
85-
<DataView>
107+
<DataView selection={selection}>
86108
<DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} />
87109
</DataView>
88110
);

packages/module/patternfly-docs/generated/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ module.exports = {
4949
'/extensions/data-view/components/react': {
5050
id: "Components",
5151
title: "Components",
52-
toc: [{"text":"Data view toolbar"},[{"text":"Basic toolbar example"}],{"text":"Data view table"},[{"text":"Rows and columns customization"},{"text":"Tree table example"},{"text":"Empty state example"}]],
53-
examples: ["Basic toolbar example","Rows and columns customization","Tree table example","Empty state example"],
52+
toc: [{"text":"Data view toolbar"},[{"text":"Basic toolbar example"},{"text":"Actions configuration"},{"text":"Actions example"}],{"text":"Data view table"},[{"text":"Rows and columns customization"},{"text":"Tree table example"},{"text":"Empty state example"},{"text":"Error state example"},{"text":"Loading state example"}]],
53+
examples: ["Basic toolbar example","Actions example","Rows and columns customization","Tree table example","Empty state example","Error state example","Loading state example"],
5454
section: "extensions",
5555
subsection: "Data view",
5656
source: "react",

packages/module/src/DataView/DataView.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Stack, StackItem } from '@patternfly/react-core';
2+
import { Stack, StackItem, StackProps } from '@patternfly/react-core';
33
import { DataViewSelection, InternalContextProvider } from '../InternalContext';
44

55
export const DataViewState = {
@@ -10,7 +10,8 @@ export const DataViewState = {
1010

1111
export type DataViewState = typeof DataViewState[keyof typeof DataViewState];
1212

13-
export interface DataViewProps {
13+
/** extends StackProps */
14+
export interface DataViewProps extends StackProps {
1415
/** Content rendered inside the data view */
1516
children: React.ReactNode;
1617
/** Custom OUIA ID */

0 commit comments

Comments
 (0)