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' ;
@@ -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
4043const 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 } ,
0 commit comments