Skip to content

Commit c552754

Browse files
authored
Merge pull request #807 from amitamrutiya/open-table
add 'Open in Playground' action button conditionally in action …
2 parents fea308e + 6880be0 commit c552754

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

src/custom/CatalogDesignTable/columnConfig.tsx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ interface ColumnConfigProps {
5353
type?: string;
5454
theme?: any;
5555
showUnpublish?: boolean;
56+
showOpenPlayground?: boolean;
5657
currentUserId?: string;
5758
isCloneDisabled?: boolean;
5859
isUnpublishDisabled?: boolean;
@@ -80,7 +81,8 @@ export const createDesignColumns = ({
8081
showUnpublish,
8182
currentUserId,
8283
isCloneDisabled,
83-
isUnpublishDisabled
84+
isUnpublishDisabled,
85+
showOpenPlayground
8486
}: ColumnConfigProps): MUIDataTableColumn[] => {
8587
const cleanedType = type?.replace('my-', '').replace(/s$/, '');
8688
const getColumnValue = (tableMeta: MUIDataTableMeta, targetColumn: string): any => {
@@ -342,27 +344,27 @@ export const createDesignColumns = ({
342344
</FacebookShareButton>
343345
</div>
344346
)
345-
},
346-
{
347-
title: 'Open in playground',
348-
onClick: () => handleOpenPlayground(rowData.id, rowData.name),
349-
icon: <KanvasIcon width={24} height={24} primaryFill={theme.palette.text.primary} />
350347
}
351348
];
349+
// Conditionally add playground and unpublish buttons
350+
const actionsList = [...baseActions];
352351

353-
const actionsList = showUnpublish
354-
? [
355-
...baseActions.slice(0, 2),
356-
{
357-
title: 'Unpublish',
358-
onClick: () => handleUnpublish(rowData),
359-
disabled: isUnpublishDisabled,
360-
icon: <PublishIcon width={24} height={24} fill={theme.palette.text.primary} />
361-
},
362-
...baseActions.slice(2)
363-
]
364-
: baseActions;
352+
if (showUnpublish) {
353+
actionsList.splice(2, 0, {
354+
title: 'Unpublish',
355+
onClick: () => handleUnpublish(rowData),
356+
disabled: isUnpublishDisabled,
357+
icon: <PublishIcon width={24} height={24} fill={theme.palette.text.primary} />
358+
});
359+
}
365360

361+
if (showOpenPlayground) {
362+
actionsList.splice(2, 0, {
363+
title: 'Open in playground',
364+
onClick: () => handleOpenPlayground(rowData.id, rowData.name),
365+
icon: <KanvasIcon width={24} height={24} primaryFill={theme.palette.text.primary} />
366+
});
367+
}
366368
//@ts-ignore
367369
return <DataTableEllipsisMenu actionsList={actionsList} theme={theme} />;
368370
}

0 commit comments

Comments
 (0)