@patternfly/react-table 4.61.6 → 4.61.10

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.
Files changed (27) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/esm/components/Table/base/provider.d.ts +1 -1
  3. package/dist/esm/components/Table/base/types.d.ts +1 -1
  4. package/dist/esm/components/Table/utils/decorators/cellActions.js +1 -1
  5. package/dist/esm/components/Table/utils/decorators/cellActions.js.map +1 -1
  6. package/dist/esm/components/TableComposable/Td.d.ts +3 -1
  7. package/dist/esm/components/TableComposable/Td.d.ts.map +1 -1
  8. package/dist/esm/components/TableComposable/Td.js +2 -2
  9. package/dist/esm/components/TableComposable/Td.js.map +1 -1
  10. package/dist/js/components/Table/base/provider.d.ts +1 -1
  11. package/dist/js/components/Table/base/types.d.ts +1 -1
  12. package/dist/js/components/Table/utils/decorators/cellActions.js +1 -1
  13. package/dist/js/components/Table/utils/decorators/cellActions.js.map +1 -1
  14. package/dist/js/components/TableComposable/Td.d.ts +3 -1
  15. package/dist/js/components/TableComposable/Td.d.ts.map +1 -1
  16. package/dist/js/components/TableComposable/Td.js +2 -2
  17. package/dist/js/components/TableComposable/Td.js.map +1 -1
  18. package/dist/umd/react-table.css +227 -167
  19. package/dist/umd/react-table.js +249 -61
  20. package/dist/umd/react-table.min.css +561 -501
  21. package/dist/umd/react-table.min.js +3 -3
  22. package/package.json +6 -6
  23. package/src/components/Table/__snapshots__/Table.test.tsx.snap +0 -76
  24. package/src/components/Table/examples/LegacyTableActions.tsx +32 -43
  25. package/src/components/Table/utils/decorators/cellActions.tsx +1 -1
  26. package/src/components/TableComposable/Td.tsx +4 -0
  27. package/src/components/TableComposable/examples/ComposableTableActions.tsx +25 -20
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-console */
2
2
  import React from 'react';
3
3
  import {
4
- ButtonVariant,
4
+ Button,
5
5
  Checkbox,
6
6
  DropdownToggle,
7
7
  ToggleGroup,
@@ -13,14 +13,15 @@ import {
13
13
  } from '@patternfly/react-core';
14
14
  import {
15
15
  CustomActionsToggleProps,
16
+ fitContent,
16
17
  headerCol,
17
18
  TableProps,
18
- IAction,
19
19
  IActions,
20
20
  IActionsResolver,
21
21
  Table,
22
22
  TableBody,
23
- TableHeader
23
+ TableHeader,
24
+ TableText
24
25
  } from '@patternfly/react-table';
25
26
 
26
27
  interface Repository {
@@ -29,6 +30,7 @@ interface Repository {
29
30
  prs: string;
30
31
  workspaces: string;
31
32
  lastCommit: string;
33
+ singleAction: string;
32
34
  }
33
35
 
34
36
  type ExampleType = 'actions' | 'actionResolver';
@@ -36,11 +38,18 @@ type ExampleType = 'actions' | 'actionResolver';
36
38
  export const LegacyTableActions: React.FunctionComponent = () => {
37
39
  // In real usage, this data would come from some external source like an API via props.
38
40
  const repositories: Repository[] = [
39
- { name: 'a', branches: 'two', prs: '1', workspaces: 'four', lastCommit: 'five' },
40
- { name: 'disable actions', branches: 'two', prs: '3', workspaces: 'four', lastCommit: 'five' },
41
- { name: 'green actions', branches: 'two', prs: '4', workspaces: 'four', lastCommit: 'five' },
42
- { name: 'extra action props', branches: 'two', prs: '5', workspaces: 'four', lastCommit: 'five' },
43
- { name: 'blue actions', branches: 'two', prs: '6', workspaces: 'four', lastCommit: 'five' }
41
+ { name: 'a', branches: 'two', prs: '1', workspaces: 'four', lastCommit: 'five', singleAction: 'Start' },
42
+ { name: 'disable actions', branches: 'two', prs: '3', workspaces: 'four', lastCommit: 'five', singleAction: '' },
43
+ { name: 'green actions', branches: 'two', prs: '4', workspaces: 'four', lastCommit: 'five', singleAction: 'Start' },
44
+ {
45
+ name: 'extra action props',
46
+ branches: 'two',
47
+ prs: '5',
48
+ workspaces: 'four',
49
+ lastCommit: 'five',
50
+ singleAction: 'Start'
51
+ },
52
+ { name: 'blue actions', branches: 'two', prs: '6', workspaces: 'four', lastCommit: 'five', singleAction: 'Start' }
44
53
  ];
45
54
 
46
55
  // This state is just for the ToggleGroup in this example and isn't necessary for Table usage.
@@ -51,7 +60,6 @@ export const LegacyTableActions: React.FunctionComponent = () => {
51
60
  };
52
61
 
53
62
  const [useCustomToggle, setUseCustomToggle] = React.useState(false);
54
- const [useExtraAction, setUseExtraAction] = React.useState(false);
55
63
 
56
64
  const customActionsToggle = (props: CustomActionsToggleProps) => (
57
65
  <DropdownToggle onToggle={props.onToggle} isDisabled={props.isDisabled}>
@@ -64,10 +72,22 @@ export const LegacyTableActions: React.FunctionComponent = () => {
64
72
  'Branches',
65
73
  'Pull requests',
66
74
  'Workspaces',
67
- 'Last commit'
75
+ 'Last commit',
76
+ { title: '', dataLabel: 'Action', cellTransforms: [fitContent] }
68
77
  ];
78
+
69
79
  const rows: TableProps['rows'] = repositories.map(repo => {
70
- const cells = [repo.name, repo.branches, repo.prs, repo.workspaces, repo.lastCommit];
80
+ let singleActionButton = null;
81
+ if (repo.singleAction !== '') {
82
+ singleActionButton = (
83
+ <TableText>
84
+ <Button variant="secondary">{repo.singleAction}</Button>
85
+ </TableText>
86
+ );
87
+ }
88
+
89
+ const cells = [repo.name, repo.branches, repo.prs, repo.workspaces, repo.lastCommit, singleActionButton];
90
+
71
91
  // These rows have arbitrary differences for this example, but these could be based on some other conditions
72
92
  if (repo.name === 'disable actions') {
73
93
  return { cells, disableActions: true };
@@ -84,15 +104,6 @@ export const LegacyTableActions: React.FunctionComponent = () => {
84
104
  return { cells };
85
105
  });
86
106
 
87
- /**
88
- * Use actions or actionResolver, not both
89
- */
90
- const extraAction: IAction = {
91
- title: 'Start',
92
- variant: ButtonVariant.secondary,
93
- onClick: (_event, rowId, rowData, extra) => console.log('clicked on extra action on row: ', rowId, rowData, extra),
94
- isOutsideDropdown: true
95
- };
96
107
  const actions: IActions = [
97
108
  {
98
109
  title: 'Some action',
@@ -108,8 +119,7 @@ export const LegacyTableActions: React.FunctionComponent = () => {
108
119
  title: 'Third action',
109
120
  onClick: (_event, rowId, rowData, extra) =>
110
121
  console.log('clicked on Third action, on row: ', rowId, rowData, extra)
111
- },
112
- ...(useExtraAction ? [extraAction] : [])
122
+ }
113
123
  ];
114
124
 
115
125
  /**
@@ -120,16 +130,6 @@ export const LegacyTableActions: React.FunctionComponent = () => {
120
130
  return [];
121
131
  }
122
132
 
123
- const extraAction: IActions = [
124
- {
125
- title: 'Start',
126
- variant: ButtonVariant.secondary,
127
- onClick: (_event, rowId, rowData, extra) =>
128
- console.log('clicked on extra action on row: ', rowId, rowData, extra),
129
- isOutsideDropdown: true
130
- }
131
- ];
132
-
133
133
  const thirdAction: IActions = [
134
134
  {
135
135
  isSeparator: true
@@ -142,7 +142,6 @@ export const LegacyTableActions: React.FunctionComponent = () => {
142
142
  ];
143
143
 
144
144
  return [
145
- ...(useExtraAction ? extraAction : []),
146
145
  {
147
146
  title: 'actionResolver action',
148
147
  onClick: (_event, rowId, rowData, extra) =>
@@ -187,16 +186,6 @@ export const LegacyTableActions: React.FunctionComponent = () => {
187
186
  name="toggle-custom-actions-toggle"
188
187
  />
189
188
  </ToolbarItem>
190
- <ToolbarItem>
191
- <Checkbox
192
- label="Add extra actions"
193
- isChecked={useExtraAction}
194
- onChange={setUseExtraAction}
195
- aria-label="toggle extra actions"
196
- id="toggle-extra-action"
197
- name="toggle-extra-action"
198
- />
199
- </ToolbarItem>
200
189
  </ToolbarContent>
201
190
  </Toolbar>
202
191
  <Table
@@ -73,7 +73,7 @@ export const cellActions = (
73
73
 
74
74
  return {
75
75
  className: css(styles.tableAction),
76
- style: { width: 'auto', paddingRight: 0 },
76
+ style: { paddingRight: 0 },
77
77
  isVisible: true,
78
78
  ...renderProps
79
79
  };
@@ -45,11 +45,14 @@ export interface TdProps extends BaseCellProps, Omit<React.HTMLProps<HTMLTableDa
45
45
  draggableRow?: TdDraggableType;
46
46
  /** True to remove padding */
47
47
  noPadding?: boolean;
48
+ /** Applies pf-c-table__action to td */
49
+ isActionCell?: boolean;
48
50
  }
49
51
 
50
52
  const TdBase: React.FunctionComponent<TdProps> = ({
51
53
  children,
52
54
  className,
55
+ isActionCell = false,
53
56
  component = 'td',
54
57
  dataLabel,
55
58
  textCenter = false,
@@ -205,6 +208,7 @@ const TdBase: React.FunctionComponent<TdProps> = ({
205
208
  {...(!treeTableTitleCell && { 'data-label': dataLabel })}
206
209
  className={css(
207
210
  className,
211
+ isActionCell && styles.tableAction,
208
212
  textCenter && styles.modifiers.center,
209
213
  noPadding && styles.modifiers.noPadding,
210
214
  styles.modifiers[modifier as 'breakWord' | 'fitContent' | 'nowrap' | 'truncate' | 'wrap' | undefined],
@@ -1,14 +1,9 @@
1
1
  /* eslint-disable no-console */
2
2
  import React from 'react';
3
- import {
4
- ButtonVariant,
5
- DropdownToggle,
6
- ToggleGroup,
7
- ToggleGroupItem,
8
- ToggleGroupItemProps
9
- } from '@patternfly/react-core';
3
+ import { Button, DropdownToggle, ToggleGroup, ToggleGroupItem, ToggleGroupItemProps } from '@patternfly/react-core';
10
4
  import {
11
5
  TableComposable,
6
+ TableText,
12
7
  Thead,
13
8
  Tr,
14
9
  Th,
@@ -25,6 +20,7 @@ interface Repository {
25
20
  prs: string;
26
21
  workspaces: string;
27
22
  lastCommit: string;
23
+ singleAction: string;
28
24
  }
29
25
 
30
26
  type ExampleType = 'defaultToggle' | 'customToggle';
@@ -32,11 +28,11 @@ type ExampleType = 'defaultToggle' | 'customToggle';
32
28
  export const ComposableTableActions: React.FunctionComponent = () => {
33
29
  // In real usage, this data would come from some external source like an API via props.
34
30
  const repositories: Repository[] = [
35
- { name: 'one', branches: 'two', prs: 'a', workspaces: 'four', lastCommit: 'five' },
36
- { name: 'a', branches: 'two', prs: 'k', workspaces: 'four', lastCommit: 'five' },
37
- { name: 'p', branches: 'two', prs: 'b', workspaces: 'four', lastCommit: 'five' },
38
- { name: '4', branches: '2', prs: 'b', workspaces: 'four', lastCommit: 'five' },
39
- { name: '5', branches: '2', prs: 'b', workspaces: 'four', lastCommit: 'five' }
31
+ { name: 'one', branches: 'two', prs: 'a', workspaces: 'four', lastCommit: 'five', singleAction: 'Start' },
32
+ { name: 'a', branches: 'two', prs: 'k', workspaces: 'four', lastCommit: 'five', singleAction: '' },
33
+ { name: 'p', branches: 'two', prs: 'b', workspaces: 'four', lastCommit: 'five', singleAction: 'Start' },
34
+ { name: '4', branches: '2', prs: 'b', workspaces: 'four', lastCommit: 'five', singleAction: 'Start' },
35
+ { name: '5', branches: '2', prs: 'b', workspaces: 'four', lastCommit: 'five', singleAction: 'Start' }
40
36
  ];
41
37
 
42
38
  const columnNames = {
@@ -44,7 +40,8 @@ export const ComposableTableActions: React.FunctionComponent = () => {
44
40
  branches: 'Branches',
45
41
  prs: 'Pull requests',
46
42
  workspaces: 'Workspaces',
47
- lastCommit: 'Last commit'
43
+ lastCommit: 'Last commit',
44
+ singleAction: 'Single action'
48
45
  };
49
46
 
50
47
  // This state is just for the ToggleGroup in this example and isn't necessary for TableComposable usage.
@@ -74,12 +71,6 @@ export const ComposableTableActions: React.FunctionComponent = () => {
74
71
  {
75
72
  title: 'Third action',
76
73
  onClick: () => console.log(`clicked on Third action, on row ${repo.name}`)
77
- },
78
- {
79
- title: 'Start',
80
- variant: ButtonVariant.secondary,
81
- onClick: () => console.log(`clicked on extra action, on row ${repo.name}`),
82
- isOutsideDropdown: true
83
74
  }
84
75
  ];
85
76
 
@@ -125,6 +116,8 @@ export const ComposableTableActions: React.FunctionComponent = () => {
125
116
  <Th>{columnNames.prs}</Th>
126
117
  <Th>{columnNames.workspaces}</Th>
127
118
  <Th>{columnNames.lastCommit}</Th>
119
+ <Td></Td>
120
+ <Td></Td>
128
121
  </Tr>
129
122
  </Thead>
130
123
  <Tbody>
@@ -137,6 +130,15 @@ export const ComposableTableActions: React.FunctionComponent = () => {
137
130
  if (repo.name === '5') {
138
131
  rowActions = lastRowActions(repo);
139
132
  }
133
+ let singleActionButton = null;
134
+ if (repo.singleAction !== '') {
135
+ singleActionButton = (
136
+ <TableText>
137
+ <Button variant="secondary">{repo.singleAction}</Button>
138
+ </TableText>
139
+ );
140
+ }
141
+
140
142
  return (
141
143
  <Tr key={repo.name}>
142
144
  <Td dataLabel={columnNames.name}>{repo.name}</Td>
@@ -144,7 +146,10 @@ export const ComposableTableActions: React.FunctionComponent = () => {
144
146
  <Td dataLabel={columnNames.prs}>{repo.prs}</Td>
145
147
  <Td dataLabel={columnNames.workspaces}>{repo.workspaces}</Td>
146
148
  <Td dataLabel={columnNames.lastCommit}>{repo.lastCommit}</Td>
147
- <Td>
149
+ <Td dataLabel={columnNames.singleAction} modifier="fitContent">
150
+ {singleActionButton}
151
+ </Td>
152
+ <Td isActionCell>
148
153
  {rowActions ? (
149
154
  <ActionsColumn
150
155
  items={rowActions}