WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 42e0295

Browse files
authored
Merge pull request #799 from amitamrutiya/aimt/design-table
Create cloud catalog design table into sistent component
2 parents ec65297 + b41d01f commit 42e0295

File tree

18 files changed

+862
-48
lines changed

18 files changed

+862
-48
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import _ from 'lodash';
3+
import { useEffect, useRef, useState } from 'react';
4+
import { PublishIcon } from '../../icons';
5+
import { CHARCOAL, useTheme } from '../../theme';
6+
import { Pattern } from '../CustomCatalog/CustomCard';
7+
import { useWindowDimensions } from '../Helpers/Dimension';
8+
import PromptComponent from '../Prompt';
9+
import { PromptRef } from '../Prompt/promt-component';
10+
import ResponsiveDataTable from '../ResponsiveDataTable';
11+
import UnpublishTooltipIcon from './UnpublishTooltipIcon';
12+
13+
interface CatalogDesignsTableProps {
14+
patterns: Pattern[];
15+
filter: any;
16+
columns: Array<any>;
17+
totalCount: number;
18+
sortOrder: string;
19+
setSortOrder: (order: string) => void;
20+
pageSize: number;
21+
setPageSize: (size: number) => void;
22+
page: number;
23+
setPage: (page: number) => void;
24+
columnVisibility: Record<string, boolean>;
25+
colViews: Record<string, boolean> | undefined;
26+
handleBulkDeleteModal: (patterns: Pattern[], modalRef: React.RefObject<PromptRef>) => void;
27+
handleBulkpatternsDataUnpublishModal: (
28+
selected: any,
29+
patterns: Pattern[],
30+
modalRef: React.RefObject<PromptRef>
31+
) => void;
32+
}
33+
34+
export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
35+
patterns,
36+
filter,
37+
columns = [],
38+
totalCount = 0,
39+
sortOrder = '',
40+
setSortOrder,
41+
pageSize = 10,
42+
setPageSize,
43+
page = 0,
44+
setPage,
45+
columnVisibility = {},
46+
colViews = {},
47+
handleBulkDeleteModal,
48+
handleBulkpatternsDataUnpublishModal
49+
}) => {
50+
const [tableCols, updateCols] = useState<Array<any>>([]);
51+
const { width } = useWindowDimensions();
52+
const smallScreen = width <= 360;
53+
const theme = useTheme();
54+
const modalRef = useRef<PromptRef>(null);
55+
56+
useEffect(() => {
57+
if (Array.isArray(columns) && columns.length > 0) {
58+
updateCols(columns);
59+
}
60+
}, [columns]);
61+
62+
const options: any = {
63+
selectableRows: _.isNil(filter) ? 'none' : 'multiple',
64+
serverSide: true,
65+
filterType: 'multiselect',
66+
responsive: smallScreen ? 'vertical' : 'standard',
67+
count: totalCount,
68+
rowsPerPage: pageSize,
69+
page,
70+
elevation: 0,
71+
onTableChange: (action: string, tableState: any) => {
72+
const sortInfo = tableState.announceText ? tableState.announceText.split(' : ') : [];
73+
let order = '';
74+
if (tableState.activeColumn) {
75+
order = `${columns[tableState.activeColumn].name} desc`;
76+
}
77+
switch (action) {
78+
case 'changePage':
79+
setPage(tableState.page);
80+
break;
81+
case 'changeRowsPerPage':
82+
setPageSize(tableState.rowsPerPage);
83+
break;
84+
case 'sort':
85+
if (
86+
sortInfo.length === 2 &&
87+
tableState.activeColumn !== undefined &&
88+
Array.isArray(columns)
89+
) {
90+
if (sortInfo[1] === 'ascending') {
91+
order = `${columns[tableState.activeColumn].name} asc`;
92+
} else {
93+
order = `${columns[tableState.activeColumn].name} desc`;
94+
}
95+
}
96+
if (order !== sortOrder) {
97+
setSortOrder(order);
98+
}
99+
break;
100+
}
101+
}
102+
};
103+
104+
if (_.isNil(filter)) {
105+
options.customToolbarSelect = (selected: any) => (
106+
<UnpublishTooltipIcon
107+
title="Unpublish"
108+
onClick={() => handleBulkpatternsDataUnpublishModal(selected, patterns, modalRef)}
109+
iconType="publish"
110+
id={'unpublish-button'}
111+
>
112+
<PublishIcon width={28.8} height={28.8} fill={CHARCOAL} />
113+
</UnpublishTooltipIcon>
114+
);
115+
} else {
116+
options.onRowsDelete = (rowsDeleted: any) => {
117+
const selectedPatterns = rowsDeleted.data.map(({ dataIndex }: any) => patterns[dataIndex]);
118+
handleBulkDeleteModal(selectedPatterns, modalRef);
119+
return false;
120+
};
121+
}
122+
123+
if (!Array.isArray(tableCols) || tableCols.length === 0) {
124+
return null;
125+
}
126+
127+
return (
128+
<>
129+
<PromptComponent ref={modalRef} />
130+
<ResponsiveDataTable
131+
columns={columns}
132+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
133+
//@ts-ignore
134+
data={patterns || []}
135+
options={options}
136+
colViews={colViews}
137+
tableCols={tableCols}
138+
updateCols={updateCols}
139+
columnVisibility={columnVisibility}
140+
backgroundColor={
141+
theme.palette.mode === 'light'
142+
? theme.palette.background.default
143+
: theme.palette.background.secondary
144+
}
145+
/>
146+
</>
147+
);
148+
};
149+
150+
export default CatalogDesignsTable;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React, { Dispatch, SetStateAction } from 'react';
2+
import { CustomColumnVisibilityControl } from '../CustomColumnVisibilityControl';
3+
import { CustomColumn } from '../CustomColumnVisibilityControl/CustomColumnVisibilityControl';
4+
import { ViewSwitch } from './ViewSwitch';
5+
6+
type TypeView = 'grid' | 'table';
7+
8+
interface TableVisibilityControlProps {
9+
viewType: TypeView;
10+
setViewType: (view: TypeView) => void;
11+
filteredColumns: CustomColumn[];
12+
columnVisibility: Record<string, boolean>;
13+
setColumnVisibility: Dispatch<SetStateAction<Record<string, boolean>>>;
14+
viewSwitchDisabled?: boolean;
15+
}
16+
17+
export const TableVisibilityControl: React.FC<TableVisibilityControlProps> = ({
18+
viewType,
19+
setViewType,
20+
filteredColumns,
21+
columnVisibility,
22+
setColumnVisibility,
23+
viewSwitchDisabled = false
24+
}) => {
25+
return (
26+
<div style={{ display: 'flex', alignItems: 'center' }}>
27+
{viewType !== 'grid' && (
28+
<CustomColumnVisibilityControl
29+
columns={filteredColumns}
30+
customToolsProps={{
31+
columnVisibility,
32+
setColumnVisibility
33+
}}
34+
id={'catalog-table'}
35+
style={{ zIndex: 9999 }}
36+
/>
37+
)}
38+
<ViewSwitch view={viewType} changeView={setViewType} disabled={viewSwitchDisabled} />
39+
</div>
40+
);
41+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { ReactNode } from 'react';
2+
import { IconButton } from '../../base';
3+
import { useTheme } from '../../theme';
4+
import { HOVER_DELETE } from '../../theme/colors/colors';
5+
import { CustomTooltip } from '../CustomTooltip';
6+
import { IconWrapper } from '../ResponsiveDataTable';
7+
8+
interface UnpublishTooltipIconProps {
9+
children: ReactNode;
10+
onClick: () => void;
11+
title: string;
12+
iconType: 'delete' | 'publish';
13+
id: string;
14+
style?: object;
15+
placement?: 'bottom' | 'top' | 'left' | 'right';
16+
disabled?: boolean;
17+
}
18+
19+
function UnpublishTooltipIcon({
20+
children,
21+
onClick,
22+
title,
23+
iconType,
24+
id,
25+
style,
26+
placement,
27+
disabled = false
28+
}: UnpublishTooltipIconProps) {
29+
const theme = useTheme();
30+
return (
31+
<CustomTooltip key={id} title={title} placement={placement}>
32+
<IconWrapper disabled={disabled}>
33+
<IconButton
34+
disabled={disabled}
35+
onClick={onClick}
36+
sx={{
37+
'&:hover': {
38+
'& svg': {
39+
fill: iconType === 'delete' ? HOVER_DELETE : theme.palette.primary.brand?.default
40+
}
41+
},
42+
...style
43+
}}
44+
disableRipple
45+
>
46+
{children}
47+
</IconButton>
48+
</IconWrapper>
49+
</CustomTooltip>
50+
);
51+
}
52+
53+
export default UnpublishTooltipIcon;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* Renders a switch component for toggling between grid and table view.
3+
*
4+
* @typedef {("grid" | "table")} TypeView
5+
* @typedef {object} Props
6+
* @prop {TypeView} props.view - The current view type ("grid" or "table").
7+
* @prop {Function} props.changeView - The function to change the view type.
8+
*/
9+
10+
import { IconButton } from '@mui/material';
11+
import { GridViewIcon, TableViewIcon } from '../../icons';
12+
import { useTheme } from '../../theme';
13+
import { CustomTooltip } from '../CustomTooltip';
14+
15+
type TypeView = 'grid' | 'table';
16+
17+
interface ViewSwitchProps {
18+
view: TypeView;
19+
changeView: (view: TypeView) => void;
20+
height?: string;
21+
style?: React.CSSProperties;
22+
disabled?: boolean;
23+
}
24+
25+
export const ViewSwitch: React.FC<ViewSwitchProps> = ({
26+
view,
27+
changeView,
28+
height = '3rem',
29+
style = {},
30+
disabled = false
31+
}) => {
32+
const handleClick = () => {
33+
changeView(view === 'grid' ? 'table' : 'grid');
34+
};
35+
36+
const Icon = view === 'grid' ? TableViewIcon : GridViewIcon;
37+
const label = view === 'grid' ? 'Table View' : 'Grid View';
38+
const theme = useTheme();
39+
40+
return (
41+
<CustomTooltip title={label} arrow>
42+
<span>
43+
<IconButton
44+
disabled={disabled}
45+
onClick={handleClick}
46+
aria-label="Switch View"
47+
sx={{
48+
height: { height },
49+
borderRadius: '50%',
50+
padding: '0.625rem',
51+
'&:hover': {
52+
'& svg': {
53+
fill: theme.palette.primary.brand?.default
54+
},
55+
borderRadius: '4px'
56+
},
57+
...style
58+
}}
59+
disableRipple
60+
>
61+
<Icon fill={theme.palette.icon.default} opacity={disabled ? 0.5 : 1} />
62+
</IconButton>
63+
</span>
64+
</CustomTooltip>
65+
);
66+
};

0 commit comments

Comments
 (0)