11/* eslint-disable @typescript-eslint/no-explicit-any */
2+ import { Lock , Public } from '@mui/icons-material' ;
23import RemoveCircleIcon from '@mui/icons-material/RemoveCircle' ;
34import { MUIDataTableColumn , MUIDataTableMeta } from 'mui-datatables' ;
45import 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
4649const 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 } ,
0 commit comments