Skip to content

Commit 4d30c96

Browse files
authored
Merge branch 'master' into leecalcote/sharingmodel/docs-link
2 parents 041143d + 93c7854 commit 4d30c96

File tree

6 files changed

+96
-42
lines changed

6 files changed

+96
-42
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"@emotion/react": "^11.11.3",
100100
"@emotion/styled": "^11.11.0",
101101
"@layer5/meshery-design-embed": "^0.4.0",
102-
"@layer5/schemas": "^0.0.6-13",
102+
"@layer5/schemas": "^0.0.6-14",
103103
"@mui/material": "^5.15.11",
104104
"@types/mui-datatables": "*",
105105
"billboard.js": "^3.14.3",

src/custom/CatalogDesignTable/DesignTableColumnConfig.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Lock, Public } from '@mui/icons-material';
12
import RemoveCircleIcon from '@mui/icons-material/RemoveCircle';
23
import { Theme } from '@mui/material';
34
import { MUIDataTableColumn, MUIDataTableMeta } from 'mui-datatables';
@@ -42,6 +43,8 @@ interface ColumnConfigProps {
4243
isRemoveAllowed?: boolean;
4344
theme?: Theme;
4445
showPlaygroundActions: boolean;
46+
handleVisibilityChange?: (id: string, visibility: VIEW_VISIBILITY) => void;
47+
currentUserId?: string;
4548
}
4649

4750
export const colViews: ColView[] = [
@@ -73,7 +76,9 @@ export const createDesignsColumnsConfig = ({
7376
theme,
7477
handleOpenInDesigner,
7578
showPlaygroundActions = true,
76-
isFromWorkspaceTable = false
79+
isFromWorkspaceTable = false,
80+
currentUserId,
81+
handleVisibilityChange
7782
}: ColumnConfigProps): MUIDataTableColumn[] => {
7883
return [
7984
{
@@ -154,8 +159,26 @@ export const createDesignsColumnsConfig = ({
154159
filter: false,
155160
sort: false,
156161
searchable: true,
157-
customBodyRender: (value: VIEW_VISIBILITY) => {
158-
return <VisibilityChipMenu value={value} enabled={false} />;
162+
customBodyRender: (value: VIEW_VISIBILITY, tableMeta) => {
163+
const rowIndex = (tableMeta as TableMeta).rowIndex;
164+
const designId = (tableMeta as TableMeta).tableData[rowIndex]?.id;
165+
const designVisibility = (tableMeta as TableMeta).tableData[rowIndex]?.visibility;
166+
const ownerId = (tableMeta as TableMeta).tableData[rowIndex]?.user_id;
167+
const isOwner = ownerId === currentUserId;
168+
const isEnabled = designVisibility !== VIEW_VISIBILITY.PUBLISHED && isOwner;
169+
return (
170+
<VisibilityChipMenu
171+
value={value as VIEW_VISIBILITY}
172+
onChange={(value) =>
173+
handleVisibilityChange && handleVisibilityChange(designId, value as VIEW_VISIBILITY)
174+
}
175+
enabled={isEnabled}
176+
options={[
177+
[VIEW_VISIBILITY.PUBLIC, Public],
178+
[VIEW_VISIBILITY.PRIVATE, Lock]
179+
]}
180+
/>
181+
);
159182
}
160183
}
161184
},

src/custom/Workspaces/DesignTable.tsx

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import _ from 'lodash';
33
import React, { useEffect, useRef, useState } from 'react';
4-
import { Box, Typography } from '../../base';
4+
import { Box } from '../../base';
55
import { DesignIcon } from '../../icons';
66
import { publishCatalogItemSchema } from '../../schemas';
77
import { useTheme } from '../../theme';
@@ -16,9 +16,10 @@ import { useWindowDimensions } from '../Helpers/Dimension';
1616
import { updateVisibleColumns } from '../Helpers/ResponsiveColumns/responsive-coulmns.tsx/responsive-column';
1717
import PromptComponent from '../Prompt';
1818
import SearchBar from '../SearchBar';
19+
import { VIEW_VISIBILITY } from '../VisibilityChipMenu/VisibilityChipMenu';
1920
import AssignmentModal from './AssignmentModal';
2021
import useDesignAssignment from './hooks/useDesignAssignment';
21-
import { L5EditIcon, TableHeader, TableRightActionHeader } from './styles';
22+
import { L5EditIcon, TableHeader } from './styles';
2223
export interface DesignTableProps {
2324
workspaceId: string;
2425
isKanvasEnabled: boolean;
@@ -59,6 +60,8 @@ export interface DesignTableProps {
5960
setDesignSearch: (value: string) => void;
6061
handleOpenInDesigner?: (designId: string, designName: string) => void;
6162
showPlaygroundActions?: boolean;
63+
handleVisibilityChange?: (id: string, visibility: VIEW_VISIBILITY) => void;
64+
currentUserId?: string;
6265
}
6366

6467
export interface PublishModalState {
@@ -101,7 +104,9 @@ const DesignTable: React.FC<DesignTableProps> = ({
101104
useGetWorkspaceDesignsQuery,
102105
setDesignSearch,
103106
handleOpenInDesigner,
104-
showPlaygroundActions = true
107+
showPlaygroundActions = true,
108+
handleVisibilityChange,
109+
currentUserId
105110
}) => {
106111
const [publishModal, setPublishModal] = useState<PublishModalState>({
107112
open: false,
@@ -139,7 +144,9 @@ const DesignTable: React.FC<DesignTableProps> = ({
139144
isRemoveAllowed,
140145
theme,
141146
handleOpenInDesigner,
142-
showPlaygroundActions
147+
showPlaygroundActions,
148+
handleVisibilityChange,
149+
currentUserId
143150
});
144151

145152
const [publishSchema, setPublishSchema] = useState<{
@@ -188,13 +195,15 @@ const DesignTable: React.FC<DesignTableProps> = ({
188195

189196
const tableHeaderContent = (
190197
<TableHeader style={{ padding: '1rem' }}>
191-
<Box display={'flex'} alignItems="center" gap={1} width="100%">
192-
<DesignIcon height="1.5rem" width="1.5rem" />
193-
<Typography variant="body1" fontWeight={'bold'}>
194-
Assigned Designs
195-
</Typography>
196-
</Box>
197-
<TableRightActionHeader style={{ marginRight: '0rem' }}>
198+
<Box
199+
style={{
200+
marginRight: '0rem',
201+
width: '100%',
202+
justifyContent: 'end',
203+
display: 'flex',
204+
alignItems: 'center'
205+
}}
206+
>
198207
<SearchBar
199208
onSearch={(value) => {
200209
setDesignSearch(value);
@@ -219,7 +228,7 @@ const DesignTable: React.FC<DesignTableProps> = ({
219228
disabled={!isAssignAllowed}
220229
title="Assign Designs"
221230
/>
222-
</TableRightActionHeader>
231+
</Box>
223232
</TableHeader>
224233
);
225234

src/custom/Workspaces/WorkspaceViewsTable.tsx

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import { Lock, Public } from '@mui/icons-material';
23
import RemoveCircleIcon from '@mui/icons-material/RemoveCircle';
34
import { MUIDataTableColumn, MUIDataTableMeta } from 'mui-datatables';
45
import React, { useState } from 'react';
5-
import { Box, Typography } from '../../base';
6-
import { EnvironmentIcon, ViewIcon } from '../../icons';
6+
import { Box } from '../../base';
7+
import { EnvironmentIcon } from '../../icons';
78
import { useTheme } from '../../theme';
89
import { NameDiv } from '../CatalogDesignTable/style';
910
import { RESOURCE_TYPES } from '../CatalogDetail/types';
@@ -22,13 +23,7 @@ import { UserTableAvatarInfo } from '../UsersTable';
2223
import VisibilityChipMenu, { VIEW_VISIBILITY } from '../VisibilityChipMenu/VisibilityChipMenu';
2324
import AssignmentModal from './AssignmentModal';
2425
import useViewAssignment from './hooks/useViewsAssignment';
25-
import {
26-
CellStyle,
27-
CustomBodyRenderStyle,
28-
L5EditIcon,
29-
TableHeader,
30-
TableRightActionHeader
31-
} from './styles';
26+
import { CellStyle, CustomBodyRenderStyle, L5EditIcon, TableHeader } from './styles';
3227

3328
interface ViewsTableProps {
3429
workspaceId: string;
@@ -41,6 +36,8 @@ interface ViewsTableProps {
4136
handleShowDetails: (viewId: string, viewName: string, filterType: string) => void;
4237
handleOpenInOperator?: (designId: string, viewName: string, filterType: string) => void;
4338
showPlaygroundActions?: boolean;
39+
handleVisibilityChange?: (id: string, visibility: VIEW_VISIBILITY) => void;
40+
currentUserId?: string;
4441
}
4542

4643
const colViews: ColView[] = [
@@ -77,7 +74,9 @@ const WorkspaceViewsTable: React.FC<ViewsTableProps> = ({
7774
useUnassignViewFromWorkspaceMutation,
7875
useAssignViewToWorkspaceMutation,
7976
isAssignAllowed,
80-
handleShowDetails
77+
handleShowDetails,
78+
handleVisibilityChange,
79+
currentUserId
8180
}) => {
8281
const theme = useTheme();
8382

@@ -86,7 +85,7 @@ const WorkspaceViewsTable: React.FC<ViewsTableProps> = ({
8685
const [page, setPage] = useState<number>(0);
8786
const [pageSize, setPageSize] = useState<number>(10);
8887
const [sortOrder, setSortOrder] = useState<string>('updated_at desc');
89-
const { data: viewsOfWorkspace } = useGetViewsOfWorkspaceQuery(
88+
const { data: viewsOfWorkspace, refetch } = useGetViewsOfWorkspaceQuery(
9089
{
9190
workspaceId,
9291
page: page,
@@ -215,8 +214,29 @@ const WorkspaceViewsTable: React.FC<ViewsTableProps> = ({
215214
filter: false,
216215
sort: false,
217216
searchable: true,
218-
customBodyRender: (value: VIEW_VISIBILITY) => {
219-
return <VisibilityChipMenu value={value} enabled={false} />;
217+
customBodyRender: (value: VIEW_VISIBILITY, tableMeta) => {
218+
const rowIndex = tableMeta.rowIndex;
219+
const viewId = tableMeta.tableData[rowIndex]?.id;
220+
const viewVisibility = tableMeta.tableData[rowIndex]?.visibility;
221+
const ownerId = tableMeta.tableData[rowIndex]?.user_id;
222+
const isOwner = ownerId === currentUserId;
223+
const isEnabled = viewVisibility !== VIEW_VISIBILITY.PUBLISHED && isOwner;
224+
return (
225+
<VisibilityChipMenu
226+
value={value as VIEW_VISIBILITY}
227+
onChange={(value) => {
228+
if (handleVisibilityChange) {
229+
handleVisibilityChange(viewId, value as VIEW_VISIBILITY);
230+
refetch();
231+
}
232+
}}
233+
enabled={isEnabled}
234+
options={[
235+
[VIEW_VISIBILITY.PUBLIC, Public],
236+
[VIEW_VISIBILITY.PRIVATE, Lock]
237+
]}
238+
/>
239+
);
220240
}
221241
}
222242
},
@@ -311,13 +331,15 @@ const WorkspaceViewsTable: React.FC<ViewsTableProps> = ({
311331
return (
312332
<>
313333
<TableHeader style={{ padding: '1rem' }}>
314-
<Box display={'flex'} alignItems="center" gap={1} width="100%">
315-
<ViewIcon height="1.5rem" width="1.5rem" fill={theme.palette.icon.brand} />
316-
<Typography variant="body1" fontWeight={'bold'}>
317-
Assigned Views
318-
</Typography>
319-
</Box>
320-
<TableRightActionHeader style={{ marginRight: '0rem' }}>
334+
<Box
335+
style={{
336+
marginRight: '0rem',
337+
width: '100%',
338+
justifyContent: 'end',
339+
display: 'flex',
340+
alignItems: 'center'
341+
}}
342+
>
321343
<SearchBar
322344
onSearch={(value) => {
323345
setSearch(value);
@@ -342,7 +364,7 @@ const WorkspaceViewsTable: React.FC<ViewsTableProps> = ({
342364
disabled={!isAssignAllowed}
343365
title="Assign Views"
344366
/>
345-
</TableRightActionHeader>
367+
</Box>
346368
</TableHeader>
347369

348370
<ResponsiveDataTable

src/schemas/createAndEditWorkspace/schema.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const createAndEditWorkspace = {
2929
}
3030
},
3131
type: 'object',
32-
required: workspaceSchema.workspacePayload.required
32+
required: ['name', 'organization']
3333
};
3434

3535
export default createAndEditWorkspace;

0 commit comments

Comments
 (0)