From 6880be0e04c714beaf71f2cf16033aafc68e64fc Mon Sep 17 00:00:00 2001 From: Amit Amrutiya Date: Tue, 12 Nov 2024 20:26:53 +0530 Subject: [PATCH] feat: add 'Open in Playground' action button conditionally in action menu Signed-off-by: Amit Amrutiya --- .../CatalogDesignTable/columnConfig.tsx | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/custom/CatalogDesignTable/columnConfig.tsx b/src/custom/CatalogDesignTable/columnConfig.tsx index ed7260c7..b56e37f2 100644 --- a/src/custom/CatalogDesignTable/columnConfig.tsx +++ b/src/custom/CatalogDesignTable/columnConfig.tsx @@ -53,6 +53,7 @@ interface ColumnConfigProps { type?: string; theme?: any; showUnpublish?: boolean; + showOpenPlayground?: boolean; currentUserId?: string; isCloneDisabled?: boolean; isUnpublishDisabled?: boolean; @@ -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 => { @@ -342,27 +344,27 @@ export const createDesignColumns = ({ ) - }, - { - title: 'Open in playground', - onClick: () => handleOpenPlayground(rowData.id, rowData.name), - icon: } ]; + // Conditionally add playground and unpublish buttons + const actionsList = [...baseActions]; - const actionsList = showUnpublish - ? [ - ...baseActions.slice(0, 2), - { - title: 'Unpublish', - onClick: () => handleUnpublish(rowData), - disabled: isUnpublishDisabled, - icon: - }, - ...baseActions.slice(2) - ] - : baseActions; + if (showUnpublish) { + actionsList.splice(2, 0, { + title: 'Unpublish', + onClick: () => handleUnpublish(rowData), + disabled: isUnpublishDisabled, + icon: + }); + } + if (showOpenPlayground) { + actionsList.splice(2, 0, { + title: 'Open in playground', + onClick: () => handleOpenPlayground(rowData.id, rowData.name), + icon: + }); + } //@ts-ignore return ; }