Skip to content

Commit fb59a25

Browse files
authored
Merge branch 'master' into update-toolbar
2 parents 38b2291 + e88e670 commit fb59a25

File tree

6 files changed

+71
-15
lines changed

6 files changed

+71
-15
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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ 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';
2122
import { L5EditIcon, TableHeader } from './styles';
@@ -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<{

src/custom/Workspaces/WorkspaceViewsTable.tsx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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';
@@ -35,6 +36,8 @@ interface ViewsTableProps {
3536
handleShowDetails: (viewId: string, viewName: string, filterType: string) => void;
3637
handleOpenInOperator?: (designId: string, viewName: string, filterType: string) => void;
3738
showPlaygroundActions?: boolean;
39+
handleVisibilityChange?: (id: string, visibility: VIEW_VISIBILITY) => void;
40+
currentUserId?: string;
3841
}
3942

4043
const colViews: ColView[] = [
@@ -71,7 +74,9 @@ const WorkspaceViewsTable: React.FC<ViewsTableProps> = ({
7174
useUnassignViewFromWorkspaceMutation,
7275
useAssignViewToWorkspaceMutation,
7376
isAssignAllowed,
74-
handleShowDetails
77+
handleShowDetails,
78+
handleVisibilityChange,
79+
currentUserId
7580
}) => {
7681
const theme = useTheme();
7782

@@ -80,7 +85,7 @@ const WorkspaceViewsTable: React.FC<ViewsTableProps> = ({
8085
const [page, setPage] = useState<number>(0);
8186
const [pageSize, setPageSize] = useState<number>(10);
8287
const [sortOrder, setSortOrder] = useState<string>('updated_at desc');
83-
const { data: viewsOfWorkspace } = useGetViewsOfWorkspaceQuery(
88+
const { data: viewsOfWorkspace, refetch } = useGetViewsOfWorkspaceQuery(
8489
{
8590
workspaceId,
8691
page: page,
@@ -209,8 +214,29 @@ const WorkspaceViewsTable: React.FC<ViewsTableProps> = ({
209214
filter: false,
210215
sort: false,
211216
searchable: true,
212-
customBodyRender: (value: VIEW_VISIBILITY) => {
213-
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+
);
214240
}
215241
}
216242
},

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)