Skip to content

Commit 72326bc

Browse files
committed
feat: enhance CatalogDesignTable with search functionality and improved column permissions
Signed-off-by: Amit Amrutiya <amitamrutiya2210@gmail.com>
1 parent 7d13fcf commit 72326bc

6 files changed

Lines changed: 44 additions & 26 deletions

File tree

src/custom/CatalogDesignTable/CatalogDesignTable.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ interface CatalogDesignsTableProps {
2525
columnVisibility: Record<string, boolean>;
2626
colViews: ColView[];
2727
handleBulkDeleteModal: (patterns: Pattern[], modalRef: React.RefObject<PromptRef>) => void;
28+
setSearch?: (search: string) => void;
2829
handleBulkpatternsDataUnpublishModal: (
2930
selected: any,
3031
patterns: Pattern[],
@@ -46,6 +47,7 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
4647
columnVisibility = {},
4748
colViews = [],
4849
handleBulkDeleteModal,
50+
setSearch,
4951
handleBulkpatternsDataUnpublishModal
5052
}) => {
5153
const theme = useTheme();
@@ -106,6 +108,9 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
106108
case 'changeRowsPerPage':
107109
setPageSize(tableState.rowsPerPage);
108110
break;
111+
case 'search':
112+
setSearch && setSearch(tableState.searchText !== null ? tableState.searchText : '');
113+
break;
109114
case 'sort':
110115
if (
111116
sortInfo.length === 2 &&
@@ -124,7 +129,7 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
124129
break;
125130
}
126131
},
127-
[columns, setPage, setPageSize, setSortOrder, sortOrder]
132+
[columns, setPage, setSearch, setPageSize, setSortOrder, sortOrder]
128133
);
129134

130135
const options = useMemo(
@@ -137,6 +142,11 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
137142
rowsPerPage: pageSize,
138143
page,
139144
elevation: 0,
145+
sortOrder: {
146+
name: 'updated_at At',
147+
direction: 'desc'
148+
},
149+
140150
onTableChange: handleTableChange,
141151
customToolbarSelect: _.isNil(filter)
142152
? (selected: any) => (

src/custom/CatalogDesignTable/DesignTableColumnConfig.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ interface ColumnConfigProps {
2525
handleCopyUrl: (type: string, name: string, id: string) => void;
2626
handleClone: (name: string, id: string) => void;
2727
handleShowDetails: (designId: string, designName: string) => void;
28-
isDownloadDisabled: boolean;
29-
isCopyLinkDisabled: boolean;
30-
isDeleteDisabled: boolean;
31-
isPublishDisabled: boolean;
32-
isUnpublishDisabled: boolean;
28+
isDownloadAllowed: boolean;
29+
isCopyLinkAllowed: boolean;
30+
isDeleteAllowed: boolean;
31+
isPublishAllowed: boolean;
32+
isUnpublishAllowed: boolean;
33+
// for workspace designs table page only
34+
isFromWorkspaceTable?: boolean;
35+
isRemoveAllowed?: boolean;
3336
}
3437

3538
export const colViews: ColView[] = [
@@ -49,11 +52,13 @@ export const createDesignsColumnsConfig = ({
4952
handleCopyUrl,
5053
handleClone,
5154
handleShowDetails,
52-
isUnpublishDisabled,
53-
isCopyLinkDisabled,
54-
isDeleteDisabled,
55-
isPublishDisabled,
56-
isDownloadDisabled
55+
isUnpublishAllowed,
56+
isCopyLinkAllowed,
57+
isDeleteAllowed,
58+
isPublishAllowed,
59+
isDownloadAllowed,
60+
isRemoveAllowed,
61+
isFromWorkspaceTable = false
5762
}: ColumnConfigProps): MUIDataTableColumn[] => {
5863
return [
5964
{
@@ -153,12 +158,12 @@ export const createDesignsColumnsConfig = ({
153158
{
154159
title: 'Download',
155160
onClick: () => downloadYaml(rowData?.pattern_file, rowData?.name),
156-
disabled: isDownloadDisabled,
161+
disabled: !isDownloadAllowed,
157162
icon: <Download width={24} height={24} fill={CHARCOAL} />
158163
},
159164
{
160165
title: 'Copy Link',
161-
disabled: rowData.visibility === 'private' || isCopyLinkDisabled,
166+
disabled: rowData.visibility === 'private' || !isCopyLinkAllowed,
162167
onClick: () => {
163168
handleCopyUrl(RESOURCE_TYPES.DESIGNS, rowData?.name, rowData?.id);
164169
},
@@ -179,24 +184,24 @@ export const createDesignsColumnsConfig = ({
179184
icon: <KanvasIcon width={24} height={24} primaryFill={CHARCOAL} />
180185
},
181186
{
182-
title: 'Delete',
183-
disabled: isDeleteDisabled,
187+
title: isFromWorkspaceTable ? 'Remove Design' : 'Delete',
188+
disabled: isFromWorkspaceTable ? !isRemoveAllowed : !isDeleteAllowed,
184189
onClick: () => handleDeleteModal(rowData)(),
185190
icon: <L5DeleteIcon />
186191
}
187192
];
188193

189194
const publishAction = {
190195
title: 'Publish',
191-
disabled: isPublishDisabled,
196+
disabled: !isPublishAllowed,
192197
onClick: () => handlePublishModal(rowData),
193198
icon: <PublishIcon width={24} height={24} fill={CHARCOAL} />
194199
};
195200

196201
const unpublishAction = {
197202
title: 'Unpublish',
198203
onClick: () => handleUnpublishModal(rowData)(),
199-
disabled: isUnpublishDisabled,
204+
disabled: !isUnpublishAllowed,
200205
icon: <PublishIcon width={24} height={24} fill={CHARCOAL} />
201206
};
202207

src/custom/CustomColumnVisibilityControl/CustomColumnVisibilityControl.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { FormControlLabel } from '../../base/FormControlLabel';
88
import { ColumnIcon } from '../../icons';
99
import { useTheme } from '../../theme';
1010
import PopperListener from '../PopperListener';
11-
import TooltipIcon from '../TooltipIcon';
11+
import { TooltipIcon } from '../TooltipIconButton';
1212

1313
export interface CustomColumnVisibilityControlProps {
1414
columns: MUIDataTableColumn[];

src/custom/ResponsiveDataTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Checkbox, Collapse, ListItemIcon, ListItemText, Menu, MenuItem } from '
55
import { ShareIcon } from '../icons';
66
import { EllipsisIcon } from '../icons/Ellipsis';
77
import { ColView } from './Helpers/ResponsiveColumns/responsive-coulmns.tsx';
8-
import TooltipIcon from './TooltipIcon';
8+
import { TooltipIcon } from './TooltipIconButton';
99

1010
export const IconWrapper = styled('div')<{ disabled?: boolean }>(({ disabled = false }) => ({
1111
cursor: disabled ? 'not-allowed' : 'pointer',

src/custom/SearchBar.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ClickAwayListener } from '../base/ClickAwayListener';
77
import { TextField } from '../base/TextField';
88
import { CloseIcon, SearchIcon } from '../icons';
99
import { useTheme } from '../theme';
10-
import TooltipIcon from './TooltipIcon';
10+
import { TooltipIcon } from './TooltipIconButton';
1111

1212
const customTheme = (theme: Theme) =>
1313
createTheme({
@@ -92,7 +92,8 @@ function SearchBar({
9292
debouncedOnSearch(value);
9393
};
9494

95-
const handleClearIconClick = (): void => {
95+
const handleClearIconClick = (e: React.MouseEvent): void => {
96+
e.stopPropagation();
9697
debouncedOnSearch('');
9798
setSearchText('');
9899
setExpanded(false);
@@ -101,7 +102,8 @@ function SearchBar({
101102
}
102103
};
103104

104-
const handleSearchIconClick = (): void => {
105+
const handleSearchIconClick = (e: React.MouseEvent): void => {
106+
e.stopPropagation();
105107
if (expanded) {
106108
debouncedOnSearch('');
107109
setSearchText('');
@@ -119,17 +121,18 @@ function SearchBar({
119121
return (
120122
<ClickAwayListener
121123
onClickAway={(event) => {
124+
event.stopPropagation();
122125
const isTable = (event.target as HTMLElement)?.closest('#ref');
123126

124127
if (searchText !== '') {
125128
return;
126129
}
127130
if (isTable) {
128-
handleClearIconClick(); // Close the search bar as needed
131+
handleClearIconClick(event as unknown as React.MouseEvent);
129132
}
130133
}}
131134
>
132-
<div>
135+
<>
133136
<ThemeProvider theme={customTheme(theme)}>
134137
<TextField
135138
variant="standard"
@@ -159,7 +162,7 @@ function SearchBar({
159162
arrow
160163
/>
161164
)}
162-
</div>
165+
</>
163166
</ClickAwayListener>
164167
);
165168
}

src/custom/UniversalFilter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Select } from '../base/Select';
99
import { FilterIcon } from '../icons';
1010
import { useTheme } from '../theme';
1111
import PopperListener from './PopperListener';
12-
import TooltipIcon from './TooltipIcon';
12+
import { TooltipIcon } from './TooltipIconButton';
1313

1414
export interface FilterColumn {
1515
name: string;

0 commit comments

Comments
 (0)