Skip to content

Commit e293afa

Browse files
WIP - Complete raw record access into AutoTable bulk action callback
1 parent c8da7f4 commit e293afa

2 files changed

Lines changed: 72 additions & 3 deletions

File tree

packages/react/spec/auto/storybook/table/AutoTableActions.stories.jsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,37 @@ export const NoTriggerableActions = {
6161
},
6262
};
6363

64+
export const CustomCellRenderersWithCustomActions = {
65+
args: {
66+
model: api.autoTableTest,
67+
select: {
68+
id: true, // TODO - AutoInclude this
69+
str: true,
70+
num: true,
71+
email: true,
72+
},
73+
columns: [
74+
"id",
75+
"str",
76+
{
77+
header: "custom cell renderer",
78+
render: ({ record }) => <p>{JSON.stringify(record)}</p>,
79+
},
80+
],
81+
actions: [
82+
{
83+
label: "Window alert all records",
84+
promoted: true,
85+
// action: (records) => windowAlert(`Sum of record "num" values: ${sumRecordNumValues(records)}`),
86+
action: (records) => {
87+
console.log("records :", records);
88+
windowAlert(`records : ${JSON.stringify(records, null, 2)}`);
89+
},
90+
},
91+
],
92+
},
93+
};
94+
6495
const windowAlert = (message) => {
6596
// eslint-disable-next-line no-undef
6697
window.alert(message);

packages/react/src/auto/polaris/PolarisAutoTable.tsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,30 @@ const PolarisAutoTableComponent = <
169169
const selectedRows = (rows ?? []).filter((row) => selection.recordIds.includes(row.id as string));
170170

171171
const promotedBulkActions = useMemo(
172-
() => bulkActionOptions.filter((option) => option.promoted).map(bulkActionOptionMapper(selectedRows, selection.clearAll)),
172+
() =>
173+
bulkActionOptions
174+
.filter((option) => option.promoted)
175+
.map(
176+
bulkActionOptionMapper({
177+
rawRecords,
178+
selectedRows,
179+
clearSelection: selection.clearAll,
180+
})
181+
),
173182
[bulkActionOptions, selectedRows]
174183
);
175184

176185
const bulkActions = useMemo(
177-
() => bulkActionOptions.filter((option) => !option.promoted).map(bulkActionOptionMapper(selectedRows, selection.clearAll)),
186+
() =>
187+
bulkActionOptions
188+
.filter((option) => !option.promoted)
189+
.map(
190+
bulkActionOptionMapper({
191+
rawRecords,
192+
selectedRows,
193+
clearSelection: selection.clearAll,
194+
})
195+
),
178196
[bulkActionOptions, selectedRows]
179197
);
180198

@@ -303,7 +321,27 @@ const disablePaginatedSelectAllButton = {
303321
paginatedSelectAllActionText: "", // Empty string to hide the select all button. We only allow selections on the current page.
304322
};
305323

306-
const bulkActionOptionMapper = (selectedRows: TableRow[], clearSelection: () => void) => {
324+
const bulkActionOptionMapper = (props: {
325+
rawRecords: GadgetRecord<any>[] | null;
326+
selectedRows: TableRow[];
327+
clearSelection: () => void;
328+
}) => {
329+
const { rawRecords, selectedRows, clearSelection } = props;
330+
331+
// TODO - Get the rawRecords into the selected rows
332+
// TODO - Get the rawRecords into the selected rows
333+
// TODO - Get the rawRecords into the selected rows
334+
// TODO - Get the rawRecords into the selected rows
335+
// TODO - Get the rawRecords into the selected rows
336+
// TODO - Get the rawRecords into the selected rows
337+
// TODO - Get the rawRecords into the selected rows
338+
// TODO - Get the rawRecords into the selected rows
339+
// TODO - Get the rawRecords into the selected rows
340+
// TODO - Get the rawRecords into the selected rows
341+
// TODO - Get the rawRecords into the selected rows
342+
// TODO - Get the rawRecords into the selected rows
343+
// TODO - Get the rawRecords into the selected rows
344+
307345
return (option: BulkActionOption) => ({
308346
id: option.humanizedName,
309347
destructive: "isDeleter" in option ? option.isDeleter : false,

0 commit comments

Comments
 (0)