-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy pathWorkspaceCard.tsx
More file actions
423 lines (407 loc) · 13.2 KB
/
WorkspaceCard.tsx
File metadata and controls
423 lines (407 loc) · 13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
import { Grid2, useTheme } from '@mui/material';
import { Backdrop, CircularProgress } from '../../base';
import { getRelativeTime } from '../../utils';
import { FlipCard } from '../FlipCard';
import { RecordRow, RedirectButton, TransferButton } from './WorkspaceTransferButton';
import {
AllocationColumnGrid,
AllocationWorkspace,
BulkSelectCheckbox,
CardBackActionsGrid,
CardBackTitleGrid,
CardBackTopGrid,
CardBackWrapper,
CardFrontWrapper,
CardTitle,
DateColumnGrid,
DateGrid,
DateLabel,
DescriptionLabel,
EmptyDescription,
L5DeleteIcon,
L5EditIcon,
RecentActivityGrid,
RecentActivityTitle,
WorkspaceCardGrid
} from './styles';
interface WorkspaceDetails {
id: number;
name: string;
description: string;
deleted_at: { Valid: boolean };
updated_at: string;
created_at: string;
}
type Activity = {
description: string;
first_name: string;
created_at: string;
};
interface CardFrontProps {
onFlip: () => void;
name: string;
description: string;
environmentsCount: number;
onAssignEnvironment: () => void;
teamsCount: number;
onAssignTeam: () => void;
designAndViewOfWorkspaceCount: number;
onAssignDesign: () => void;
isEnvironmentAllowed: boolean;
isTeamAllowed: boolean;
isDesignAllowed: boolean;
isViewAllowed: boolean;
isViewsVisible: boolean;
isDesignsVisible: boolean;
isTeamsVisible: boolean;
isEnvironmentsVisible: boolean;
}
interface CardBackProps {
onFlipBack: () => void;
onSelect: () => void;
name: string;
onEdit: () => void;
onDelete: () => void;
selectedWorkspaces: number[];
workspaceId: number;
loadingEvents: boolean;
recentActivities: Activity[];
updatedDate: string;
createdDate: string;
deleted: boolean;
isDeleteWorkspaceAllowed: boolean;
isEditWorkspaceAllowed: boolean;
}
interface WorkspaceCardProps {
workspaceDetails: WorkspaceDetails;
onDelete: () => void;
onEdit: () => void;
onSelect: () => void;
selectedWorkspaces: number[];
onAssignTeam: () => void;
onAssignEnvironment: () => void;
onAssignDesign: () => void;
recentActivities: Activity[];
onFlip: () => void;
onFlipBack: () => void;
loadingEvents: boolean;
teamsOfWorkspaceCount: number;
environmentsOfWorkspaceCount: number;
designAndViewOfWorkspaceCount: number;
isEnvironmentAllowed: boolean;
isTeamAllowed: boolean;
isDesignAllowed: boolean;
isViewAllowed: boolean;
isDeleteWorkspaceAllowed: boolean;
isEditWorkspaceAllowed: boolean;
isViewsVisible: boolean;
isDesignsVisible: boolean;
isTeamsVisible: boolean;
isEnvironmentsVisible: boolean;
}
/**
* Renders a Workspace card component.
*
* @param {Object} props - The component props.
* @param {Object} props.environmentDetails - The details of the workspace.
* @param {string} props.environmentDetails.name - The name of the workspace.
* @param {string} props.environmentDetails.description - The description of the workspace.
* @param {Function} props.onDelete - Function to delete the workspace.
* @param {Function} props.onEdit - Function to edit the workspace.
* @param {Function} props.onSelect - Function to select workspace for bulk actions.
* @param {Array} props.selectedWorkspaces - Selected workspace list for delete.
* @param {Function} props.onAssignTeam - Function to open team assignment modal open.
* @param {Function} props.onAssignDesign - Function to open design assignment modal open.
* @param {Array} props.latestActivity - List of latest activity.
* @param {Function} props.onFlip - Click event to trigger when card flip.
* @param {Function} props.onFlipBack - Click event to trigger when card flip back.
* @param {Boolean} props.loadingEvents - Loading state of the events.
* @param {Number} props.teamsOfWorkspaceCount - Count of teams assigned to the workspace.
* @param {Number} props.environmentsOfWorkspaceCount - Count of environments assigned to the workspace.
* @param {Number} props.designAndViewOfWorkspaceCount - Count of designs/views assigned to the workspace.
* @param {Boolean} props.isEnvironmentAllowed - Flag to check if environment assignment is allowed.
* @param {Boolean} props.isTeamAllowed - Flag to check if team assignment is allowed.
* @param {Boolean} props.isDesignAndViewAllowed - Flag to check if design assignment is allowed.
* @param {Boolean} props.isDeleteWorkspaceAllowed - Flag to check if workspace deletion is allowed.
* @param {Boolean} props.isEditWorkspaceAllowed - Flag to check if workspace edit is allowed.
* @returns {React.ReactElement} The Workspace card component.
*
*/
const WorkspaceCard = ({
workspaceDetails,
onDelete,
onEdit,
onSelect,
selectedWorkspaces,
onAssignTeam,
onAssignEnvironment,
onAssignDesign,
recentActivities,
onFlip,
onFlipBack,
loadingEvents,
teamsOfWorkspaceCount,
environmentsOfWorkspaceCount,
designAndViewOfWorkspaceCount,
isEnvironmentAllowed,
isTeamAllowed,
isDesignAllowed,
isViewAllowed,
isDeleteWorkspaceAllowed,
isEditWorkspaceAllowed,
isViewsVisible,
isDesignsVisible,
isEnvironmentsVisible,
isTeamsVisible
}: WorkspaceCardProps) => {
const deleted = workspaceDetails.deleted_at.Valid;
return (
<FlipCard
disableFlip={selectedWorkspaces.includes(workspaceDetails.id) ? true : false}
padding={'0'}
>
<CardFront
onFlip={onFlip}
name={workspaceDetails?.name}
description={workspaceDetails?.description}
environmentsCount={environmentsOfWorkspaceCount}
onAssignEnvironment={onAssignEnvironment}
teamsCount={teamsOfWorkspaceCount}
onAssignTeam={onAssignTeam}
designAndViewOfWorkspaceCount={designAndViewOfWorkspaceCount}
onAssignDesign={onAssignDesign}
isEnvironmentAllowed={isEnvironmentAllowed}
isTeamAllowed={isTeamAllowed}
isDesignAllowed={isDesignAllowed}
isViewAllowed={isViewAllowed}
isViewsVisible={isViewsVisible}
isDesignsVisible={isDesignsVisible}
isEnvironmentsVisible={isEnvironmentsVisible}
isTeamsVisible={isTeamsVisible}
/>
<CardBack
onFlipBack={onFlipBack}
onSelect={onSelect}
name={workspaceDetails?.name}
onEdit={onEdit}
onDelete={onDelete}
selectedWorkspaces={selectedWorkspaces}
workspaceId={workspaceDetails?.id}
loadingEvents={loadingEvents}
recentActivities={recentActivities}
updatedDate={workspaceDetails?.updated_at}
createdDate={workspaceDetails?.created_at}
deleted={deleted}
isDeleteWorkspaceAllowed={isDeleteWorkspaceAllowed}
isEditWorkspaceAllowed={isEditWorkspaceAllowed}
/>
</FlipCard>
);
};
export default WorkspaceCard;
const CardFront = ({
onFlip,
name,
description,
environmentsCount,
onAssignEnvironment,
teamsCount,
onAssignTeam,
designAndViewOfWorkspaceCount,
onAssignDesign,
isEnvironmentAllowed,
isTeamAllowed,
isDesignAllowed,
isViewAllowed,
isViewsVisible,
isDesignsVisible,
isEnvironmentsVisible,
isTeamsVisible
}: CardFrontProps) => {
return (
<CardFrontWrapper elevation={2} onClick={onFlip}>
<WorkspaceCardGrid>
<CardTitle variant="body2" onClick={(e) => e.stopPropagation()}>
{name}
</CardTitle>
</WorkspaceCardGrid>
<Grid2>
{description ? (
<DescriptionLabel onClick={(e) => e.stopPropagation()} sx={{ maxHeight: '105px' }}>
{description}
</DescriptionLabel>
) : (
<EmptyDescription onClick={(e) => e.stopPropagation()}>No description</EmptyDescription>
)}
</Grid2>
<Grid2
sx={{
display: 'flex',
flexDirection: { xs: 'column', sm: 'row' },
pt: { xs: 1, md: 2 },
gap: 1
}}
>
{isEnvironmentsVisible && (
<AllocationColumnGrid>
<AllocationWorkspace onClick={(e) => e.stopPropagation()}>
{isEnvironmentAllowed ? (
<TransferButton
title="Environments"
count={environmentsCount}
onAssign={onAssignEnvironment}
disabled={!isEnvironmentAllowed}
/>
) : (
<RedirectButton title="Environment" count={environmentsCount} />
)}
<RedirectButton title="Connections" count={0} />
</AllocationWorkspace>
</AllocationColumnGrid>
)}
{isTeamsVisible && (
<AllocationColumnGrid>
<AllocationWorkspace onClick={(e) => e.stopPropagation()}>
{isTeamAllowed ? (
<TransferButton
title="Teams"
count={teamsCount}
onAssign={onAssignTeam}
disabled={!isTeamAllowed}
/>
) : (
<RedirectButton title="Teams" count={teamsCount} />
)}
<RedirectButton title="Users" count={0} />
</AllocationWorkspace>
</AllocationColumnGrid>
)}
{isDesignsVisible && !isViewsVisible && (
<AllocationColumnGrid>
<AllocationWorkspace onClick={(e) => e.stopPropagation()}>
{isDesignAllowed ? (
<TransferButton
title="Designs"
count={designAndViewOfWorkspaceCount}
onAssign={onAssignDesign}
disabled={!isDesignAllowed}
/>
) : (
<RedirectButton title="Designs" count={designAndViewOfWorkspaceCount} />
)}
<RedirectButton title="Deploys" count={0} />
</AllocationWorkspace>
</AllocationColumnGrid>
)}
{isDesignsVisible && isViewsVisible && (
<AllocationColumnGrid>
<AllocationWorkspace onClick={(e) => e.stopPropagation()}>
{isDesignAllowed && isViewAllowed ? (
<TransferButton
title="Designs/Views"
count={designAndViewOfWorkspaceCount}
onAssign={onAssignDesign}
disabled={!(isDesignAllowed && isViewAllowed)}
/>
) : (
<RedirectButton title="Designs/Views" count={designAndViewOfWorkspaceCount} />
)}
<RedirectButton title="Deploys" count={0} />
</AllocationWorkspace>
</AllocationColumnGrid>
)}
</Grid2>
</CardFrontWrapper>
);
};
const CardBack = ({
onFlipBack,
onSelect,
name,
onEdit,
onDelete,
selectedWorkspaces,
workspaceId,
loadingEvents,
recentActivities,
updatedDate,
createdDate,
deleted,
isDeleteWorkspaceAllowed,
isEditWorkspaceAllowed
}: CardBackProps) => {
const isWorkspaceSelected = selectedWorkspaces?.includes(workspaceId);
const isEditButtonDisabled = isWorkspaceSelected ? true : !isEditWorkspaceAllowed;
const isDeleteButtonDisabled = isWorkspaceSelected ? true : !isDeleteWorkspaceAllowed;
const theme = useTheme();
return (
<CardBackWrapper elevation={2} onClick={onFlipBack}>
<CardBackTopGrid size={12}>
<CardBackTitleGrid size={6}>
<BulkSelectCheckbox
onClick={(e) => e.stopPropagation()}
onChange={onSelect}
disabled={deleted ? true : !isDeleteWorkspaceAllowed}
/>
<CardTitle
sx={{ color: theme.palette.background.constant?.white }}
variant="body2"
onClick={(e) => e.stopPropagation()}
>
{name}
</CardTitle>
</CardBackTitleGrid>
<CardBackActionsGrid size={6}>
<L5EditIcon
onClick={onEdit}
disabled={isEditButtonDisabled}
style={{ fill: theme.palette.background.constant?.white }}
bulk={true}
/>
<L5DeleteIcon
onClick={onDelete}
style={{ fill: theme.palette.background.constant?.white }}
disabled={isDeleteButtonDisabled}
bulk={true}
/>
</CardBackActionsGrid>
</CardBackTopGrid>
<Grid2 sx={{ display: 'flex', alignItems: 'center', flexDirection: 'row' }}>
<RecentActivityTitle variant="body2">Recent Activity</RecentActivityTitle>
</Grid2>
<RecentActivityGrid>
{loadingEvents ? (
<Backdrop sx={{ zIndex: '2010' }} open={loadingEvents}>
<CircularProgress
color="inherit"
style={{ color: theme.palette.background.constant?.white }}
/>
</Backdrop>
) : (
recentActivities?.map((activity, index) => {
return (
<RecordRow
key={index}
title={activity?.description}
name={activity?.first_name}
date={activity?.created_at}
/>
);
})
)}
</RecentActivityGrid>
<DateGrid size={12}>
<DateColumnGrid size={6}>
<DateLabel onClick={(e) => e.stopPropagation()}>
Updated At: {getRelativeTime(updatedDate)}
</DateLabel>
</DateColumnGrid>
<DateColumnGrid size={6}>
<DateLabel onClick={(e) => e.stopPropagation()}>
Created At: {getRelativeTime(createdDate)}
</DateLabel>
</DateColumnGrid>
</DateGrid>
</CardBackWrapper>
);
};