Skip to content

Commit

Permalink
feat: add 'Open in Playground' action button conditionally in action …
Browse files Browse the repository at this point in the history
…menu

Signed-off-by: Amit Amrutiya <[email protected]>
  • Loading branch information
amitamrutiya committed Nov 12, 2024
1 parent fea308e commit 6880be0
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/custom/CatalogDesignTable/columnConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ interface ColumnConfigProps {
type?: string;
theme?: any;
showUnpublish?: boolean;
showOpenPlayground?: boolean;
currentUserId?: string;
isCloneDisabled?: boolean;
isUnpublishDisabled?: boolean;
Expand Down Expand Up @@ -80,7 +81,8 @@ export const createDesignColumns = ({
showUnpublish,
currentUserId,
isCloneDisabled,
isUnpublishDisabled
isUnpublishDisabled,
showOpenPlayground
}: ColumnConfigProps): MUIDataTableColumn[] => {
const cleanedType = type?.replace('my-', '').replace(/s$/, '');
const getColumnValue = (tableMeta: MUIDataTableMeta, targetColumn: string): any => {
Expand Down Expand Up @@ -342,27 +344,27 @@ export const createDesignColumns = ({
</FacebookShareButton>
</div>
)
},
{
title: 'Open in playground',
onClick: () => handleOpenPlayground(rowData.id, rowData.name),
icon: <KanvasIcon width={24} height={24} primaryFill={theme.palette.text.primary} />
}
];
// Conditionally add playground and unpublish buttons
const actionsList = [...baseActions];

const actionsList = showUnpublish
? [
...baseActions.slice(0, 2),
{
title: 'Unpublish',
onClick: () => handleUnpublish(rowData),
disabled: isUnpublishDisabled,
icon: <PublishIcon width={24} height={24} fill={theme.palette.text.primary} />
},
...baseActions.slice(2)
]
: baseActions;
if (showUnpublish) {
actionsList.splice(2, 0, {
title: 'Unpublish',
onClick: () => handleUnpublish(rowData),
disabled: isUnpublishDisabled,
icon: <PublishIcon width={24} height={24} fill={theme.palette.text.primary} />
});
}

if (showOpenPlayground) {
actionsList.splice(2, 0, {
title: 'Open in playground',
onClick: () => handleOpenPlayground(rowData.id, rowData.name),
icon: <KanvasIcon width={24} height={24} primaryFill={theme.palette.text.primary} />
});
}
//@ts-ignore
return <DataTableEllipsisMenu actionsList={actionsList} theme={theme} />;
}
Expand Down

0 comments on commit 6880be0

Please sign in to comment.