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' ;
5- import { Box , Typography } from '../../base' ;
6- import { EnvironmentIcon , ViewIcon } from '../../icons' ;
6+ import { Box } from '../../base' ;
7+ import { EnvironmentIcon } from '../../icons' ;
78import { useTheme } from '../../theme' ;
89import { NameDiv } from '../CatalogDesignTable/style' ;
910import { RESOURCE_TYPES } from '../CatalogDetail/types' ;
@@ -22,13 +23,7 @@ import { UserTableAvatarInfo } from '../UsersTable';
2223import VisibilityChipMenu , { VIEW_VISIBILITY } from '../VisibilityChipMenu/VisibilityChipMenu' ;
2324import AssignmentModal from './AssignmentModal' ;
2425import 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
3328interface 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
4643const 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
0 commit comments