Skip to content

Commit e88e670

Browse files
authored
Merge pull request #1019 from layer5io/visibility-chip
add visibility change functionlity in workspae tables
2 parents 08b124b + f2026d9 commit e88e670

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, TableRightActionHeader } 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';
@@ -41,6 +42,8 @@ interface ViewsTableProps {
4142
handleShowDetails: (viewId: string, viewName: string, filterType: string) => void;
4243
handleOpenInOperator?: (designId: string, viewName: string, filterType: string) => void;
4344
showPlaygroundActions?: boolean;
45+
handleVisibilityChange?: (id: string, visibility: VIEW_VISIBILITY) => void;
46+
currentUserId?: string;
4447
}
4548

4649
const colViews: ColView[] = [
@@ -77,7 +80,9 @@ const WorkspaceViewsTable: React.FC<ViewsTableProps> = ({
7780
useUnassignViewFromWorkspaceMutation,
7881
useAssignViewToWorkspaceMutation,
7982
isAssignAllowed,
80-
handleShowDetails
83+
handleShowDetails,
84+
handleVisibilityChange,
85+
currentUserId
8186
}) => {
8287
const theme = useTheme();
8388

@@ -86,7 +91,7 @@ const WorkspaceViewsTable: React.FC<ViewsTableProps> = ({
8691
const [page, setPage] = useState<number>(0);
8792
const [pageSize, setPageSize] = useState<number>(10);
8893
const [sortOrder, setSortOrder] = useState<string>('updated_at desc');
89-
const { data: viewsOfWorkspace } = useGetViewsOfWorkspaceQuery(
94+
const { data: viewsOfWorkspace, refetch } = useGetViewsOfWorkspaceQuery(
9095
{
9196
workspaceId,
9297
page: page,
@@ -215,8 +220,29 @@ const WorkspaceViewsTable: React.FC<ViewsTableProps> = ({
215220
filter: false,
216221
sort: false,
217222
searchable: true,
218-
customBodyRender: (value: VIEW_VISIBILITY) => {
219-
return <VisibilityChipMenu value={value} enabled={false} />;
223+
customBodyRender: (value: VIEW_VISIBILITY, tableMeta) => {
224+
const rowIndex = tableMeta.rowIndex;
225+
const viewId = tableMeta.tableData[rowIndex]?.id;
226+
const viewVisibility = tableMeta.tableData[rowIndex]?.visibility;
227+
const ownerId = tableMeta.tableData[rowIndex]?.user_id;
228+
const isOwner = ownerId === currentUserId;
229+
const isEnabled = viewVisibility !== VIEW_VISIBILITY.PUBLISHED && isOwner;
230+
return (
231+
<VisibilityChipMenu
232+
value={value as VIEW_VISIBILITY}
233+
onChange={(value) => {
234+
if (handleVisibilityChange) {
235+
handleVisibilityChange(viewId, value as VIEW_VISIBILITY);
236+
refetch();
237+
}
238+
}}
239+
enabled={isEnabled}
240+
options={[
241+
[VIEW_VISIBILITY.PUBLIC, Public],
242+
[VIEW_VISIBILITY.PRIVATE, Lock]
243+
]}
244+
/>
245+
);
220246
}
221247
}
222248
},

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)