Skip to content

Commit ac9d570

Browse files
authored
Merge pull request #815 from amitamrutiya/update-cell
feat: add AuthorCell component and integrate it into CatalogDesignTable
2 parents e88d5f1 + b0b842b commit ac9d570

File tree

4 files changed

+80
-51
lines changed

4 files changed

+80
-51
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import React from 'react';
2+
import { Avatar, Box, Grid, Typography } from '../../base';
3+
import { CLOUD_URL } from '../../constants/constants';
4+
import { PersonIcon } from '../../icons';
5+
import { CustomTooltip } from '../CustomTooltip';
6+
7+
interface AuthorCellProps {
8+
firstName: string;
9+
lastName: string;
10+
avatarUrl: string;
11+
userId: string;
12+
maxWidth?: boolean;
13+
}
14+
15+
const AuthorCell: React.FC<AuthorCellProps> = ({
16+
firstName,
17+
lastName,
18+
avatarUrl,
19+
userId,
20+
maxWidth = true
21+
}) => {
22+
const displayName =
23+
firstName && lastName
24+
? `${firstName} ${lastName}`
25+
: firstName
26+
? firstName
27+
: lastName
28+
? lastName
29+
: '';
30+
31+
return (
32+
<Box sx={{ '& > img': { mr: 2, flexShrink: 0 } }}>
33+
<Grid
34+
container
35+
alignItems="center"
36+
style={maxWidth ? { width: 'max-content' } : { width: '' }}
37+
>
38+
<Grid item>
39+
<Box sx={{ color: 'text.secondary', mr: 1 }}>
40+
<CustomTooltip title={`View ${displayName}'s Profile`}>
41+
<div>
42+
<Avatar
43+
style={{ cursor: 'pointer' }}
44+
alt={displayName}
45+
src={avatarUrl}
46+
onClick={() => {
47+
window.open(`${CLOUD_URL}/user/${userId}`, '_blank');
48+
}}
49+
>
50+
{!avatarUrl && <PersonIcon />}
51+
</Avatar>
52+
</div>
53+
</CustomTooltip>
54+
</Box>
55+
</Grid>
56+
{maxWidth && (
57+
<Grid item>
58+
<Typography variant="body2">{displayName}</Typography>
59+
</Grid>
60+
)}
61+
</Grid>
62+
</Box>
63+
);
64+
};
65+
66+
export default AuthorCell;

src/custom/CatalogDesignTable/CatalogDesignTable.tsx

+4-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useCallback, useMemo, useRef } from 'react';
44
import { PublishIcon } from '../../icons';
55
import { CHARCOAL, useTheme } from '../../theme';
66
import { Pattern } from '../CustomCatalog/CustomCard';
7-
import { useWindowDimensions } from '../Helpers/Dimension';
7+
import { ErrorBoundary } from '../ErrorBoundary';
88
import PromptComponent from '../Prompt';
99
import { PromptRef } from '../Prompt/promt-component';
1010
import ResponsiveDataTable from '../ResponsiveDataTable';
@@ -47,8 +47,6 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
4747
handleBulkDeleteModal,
4848
handleBulkpatternsDataUnpublishModal
4949
}) => {
50-
const { width } = useWindowDimensions();
51-
const smallScreen = width <= 360;
5250
const theme = useTheme();
5351
const modalRef = useRef<PromptRef>(null);
5452

@@ -133,7 +131,7 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
133131
selectableRows: _.isNil(filter) ? 'none' : 'multiple',
134132
serverSide: true,
135133
filterType: 'multiselect',
136-
responsive: smallScreen ? 'vertical' : 'standard',
134+
responsive: 'standard',
137135
count: totalCount,
138136
rowsPerPage: pageSize,
139137
page,
@@ -163,7 +161,6 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
163161
}),
164162
[
165163
filter,
166-
smallScreen,
167164
totalCount,
168165
pageSize,
169166
page,
@@ -179,7 +176,7 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
179176
}
180177

181178
return (
182-
<>
179+
<ErrorBoundary>
183180
<PromptComponent ref={modalRef} />
184181
<ResponsiveDataTable
185182
columns={processedColumns}
@@ -196,7 +193,7 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
196193
: theme.palette.background.secondary
197194
}
198195
/>
199-
</>
196+
</ErrorBoundary>
200197
);
201198
};
202199

src/custom/CatalogDesignTable/columnConfig.tsx

+8-43
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
/* eslint-disable @typescript-eslint/no-explicit-any */
33
import { MUIDataTableColumn, MUIDataTableMeta } from 'mui-datatables';
44
import { FacebookShareButton, LinkedinShareButton, TwitterShareButton } from 'react-share';
5-
import { Avatar, Box, Grid, Typography } from '../../base';
6-
import { CLOUD_URL } from '../../constants/constants';
75
import { iconMedium } from '../../constants/iconsSizes';
86
import {
97
ChainIcon,
@@ -12,16 +10,15 @@ import {
1210
FacebookIcon,
1311
KanvasIcon,
1412
LinkedinIcon,
15-
PersonIcon,
1613
PublishIcon,
1714
TwitterIcon
1815
} from '../../icons';
1916
import { downloadFilter, downloadYaml } from '../CatalogDetail/helper';
2017
import { RESOURCE_TYPES } from '../CatalogDetail/types';
2118
import { Pattern } from '../CustomCatalog/CustomCard';
22-
import { CustomTooltip } from '../CustomTooltip';
2319
import { ConditionalTooltip } from '../Helpers/CondtionalTooltip';
2420
import { DataTableEllipsisMenu } from '../ResponsiveDataTable';
21+
import AuthorCell from './AuthorCell';
2522
import { NameDiv } from './style';
2623

2724
export type ColView = [string, 'na' | 'xs' | 'l'];
@@ -141,47 +138,15 @@ export const createDesignColumns = ({
141138
const lastName = getColumnValue(tableMeta, 'last_name');
142139
const avatar_url = getColumnValue(tableMeta, 'avatar_url');
143140
const user_id = getColumnValue(tableMeta, 'user_id');
144-
const displayName =
145-
firstName && lastName
146-
? `${firstName} ${lastName}`
147-
: firstName
148-
? firstName
149-
: lastName
150-
? lastName
151-
: '';
152141

153142
return (
154-
<Box sx={{ '& > img': { mr: 2, flexShrink: 0 } }}>
155-
<Grid
156-
container
157-
alignItems="center"
158-
style={maxWidth ? { width: 'max-content' } : { width: '' }}
159-
>
160-
<Grid item>
161-
<Box sx={{ color: 'text.secondary', mr: 1 }}>
162-
<CustomTooltip title={`View ${displayName}'s Profile`}>
163-
<div>
164-
<Avatar
165-
style={{ cursor: 'pointer' }}
166-
alt={displayName}
167-
src={avatar_url}
168-
onClick={() => {
169-
window.open(`${CLOUD_URL}/user/${user_id}`, '_blank');
170-
}}
171-
>
172-
{!avatar_url && <PersonIcon />}
173-
</Avatar>
174-
</div>
175-
</CustomTooltip>
176-
</Box>
177-
</Grid>
178-
{maxWidth && (
179-
<Grid item>
180-
<Typography variant="body2">{displayName}</Typography>
181-
</Grid>
182-
)}
183-
</Grid>
184-
</Box>
143+
<AuthorCell
144+
firstName={firstName}
145+
lastName={lastName}
146+
avatarUrl={avatar_url}
147+
userId={user_id}
148+
maxWidth={maxWidth}
149+
/>
185150
);
186151
}
187152
}
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import AuthorCell from './AuthorCell';
12
import CatalogDesignsTable from './CatalogDesignTable';
23
import { colViews, createDesignColumns } from './columnConfig';
34
export { TableVisibilityControl } from './TableVisibilityControl';
45
export { ViewSwitch } from './ViewSwitch';
5-
export { CatalogDesignsTable, colViews, createDesignColumns };
6+
export { AuthorCell, CatalogDesignsTable, colViews, createDesignColumns };

0 commit comments

Comments
 (0)