11// Copyright (C) 2022-2025 Intel Corporation
22// LIMITED EDGE SOFTWARE DISTRIBUTION LICENSE
33
4- import { Key } from 'react' ;
5-
64import { useFeatureFlags } from '@geti/core/src/feature-flags/hooks/use-feature-flags.hook' ;
75import { useActiveUser } from '@geti/core/src/users/hook/use-users.hook' ;
86import { isOrganizationAdmin } from '@geti/core/src/users/user-role-utils' ;
97import { RESOURCE_TYPE } from '@geti/core/src/users/users.interface' ;
108import { useWorkspacesApi } from '@geti/core/src/workspaces/hooks/use-workspaces.hook' ;
119import { WorkspaceEntity } from '@geti/core/src/workspaces/services/workspaces.interface' ;
12- import { ActionButton , Flex , Item , Loading , TabList , Tabs , Tooltip , TooltipTrigger } from '@geti/ui' ;
13- import { Add } from '@geti/ui/icons' ;
10+ import { Flex } from '@geti/ui' ;
1411import { useOverlayTriggerState } from 'react-stately' ;
1512
1613import { useOrganizationIdentifier } from '../../../hooks/use-organization-identifier/use-organization-identifier.hook' ;
1714import { CustomTabItem } from '../../../shared/components/custom-tab-item/custom-tab-item.component' ;
1815import { EditNameDialog } from '../../../shared/components/edit-name-dialog/edit-name-dialog.component' ;
1916import { HasPermission } from '../../../shared/components/has-permission/has-permission.component' ;
2017import { OPERATION } from '../../../shared/components/has-permission/has-permission.interface' ;
18+ import { ManagedTabs } from '../../../shared/components/managed-tabs/managed-tabs.component' ;
2119import { WorkspaceDeleteDialog } from '../../landing-page/workspaces-tabs/components/workspace-delete-dialog.component' ;
2220import { CustomTabItemWithMenu } from '../../landing-page/workspaces-tabs/custom-tab-item-with-menu.component' ;
2321import { useWorkspaceActions } from '../../landing-page/workspaces-tabs/hooks/use-workspace-actions.hook' ;
2422import { CreateWorkspaceDialog } from './create-workspace-dialog/create-workspace-dialog.component' ;
2523
26- import classes from '../../../shared/components/custom-tab-item/custom-tab-item.module.scss' ;
27-
2824interface WorkspaceUsersToolbarProps {
2925 workspaces : WorkspaceEntity [ ] ;
3026 selectedWorkspaceId : string | undefined ;
@@ -48,71 +44,53 @@ export const WorkspaceUsersToolbar = ({
4844
4945 const { deleteDialog, editDialog } = useWorkspaceActions ( workspaces . length , selectedWorkspaceId ) ;
5046
51- const tabItems = workspaces . map ( ( workspace ) => ( { key : workspace . id , name : workspace . name } ) ) ;
5247 const workspacesNames = workspaces . map ( ( workspace ) => workspace . name ) ;
5348
54- const handleSelection = ( key : Key ) => {
55- onSelectWorkspace ( key . toString ( ) ) ;
56- } ;
57-
5849 return (
59- < Flex direction = { 'column' } gap = { 'size-150' } UNSAFE_className = { classes . componentWrapper } >
60- < Tabs
61- selectedKey = { selectedWorkspaceId }
62- onSelectionChange = { handleSelection }
63- aria-label = { 'Workspace tabs' }
64- items = { tabItems }
65- orientation = 'vertical'
66- >
67- < Flex alignItems = { 'center' } gap = { 'size-200' } UNSAFE_className = { classes . tabWrapper } >
68- < div className = { classes . tabListScrollContainer } >
69- < TabList UNSAFE_className = { classes . tabList } >
70- { ( item : { key : string ; name : string } ) => {
71- return (
72- < Item key = { item . key } textValue = { item . name } >
73- { item . key === selectedWorkspaceId && FEATURE_FLAG_WORKSPACE_ACTIONS ? (
74- < HasPermission
75- operations = { [ OPERATION . WORKSPACE_MANAGEMENT ] }
76- resources = { [ { type : RESOURCE_TYPE . WORKSPACE , id : item . key } ] }
77- specialCondition = {
78- activeUser !== undefined &&
79- isOrganizationAdmin ( activeUser , organizationId )
80- }
81- Fallback = { < CustomTabItem name = { item . name } isMoreIconVisible = { false } /> }
82- >
83- < CustomTabItemWithMenu
84- workspace = { selectedWorkspace as WorkspaceEntity }
85- isMoreIconVisible = { item . key === selectedWorkspaceId }
86- workspaces = { workspaces }
87- selectWorkspace = { ( id : string ) => handleSelection ( id ) }
88- />
89- </ HasPermission >
90- ) : (
91- < CustomTabItem isMoreIconVisible = { false } name = { item . name } />
92- ) }
93- </ Item >
94- ) ;
95- } }
96- </ TabList >
97- </ div >
98- { FEATURE_FLAG_WORKSPACE_ACTIONS && (
99- < HasPermission operations = { [ OPERATION . WORKSPACE_CREATION ] } >
100- < TooltipTrigger placement = { 'bottom' } >
101- < ActionButton
102- isQuiet
103- aria-label = { 'Create workspace' }
104- id = { 'create-workspace-toolbar-btn' }
105- onPress = { createWorkspaceDialogState . open }
106- isDisabled = { createWorkspace . isPending }
107- >
108- { createWorkspace . isPending ? < Loading mode = 'inline' size = { 'S' } /> : < Add /> }
109- </ ActionButton >
110- < Tooltip > Create workspace</ Tooltip >
111- </ TooltipTrigger >
112- </ HasPermission >
113- ) }
114- </ Flex >
115- </ Tabs >
50+ < Flex direction = { 'column' } gap = { 'size-150' } >
51+ < ManagedTabs < WorkspaceEntity >
52+ items = { workspaces }
53+ selectedKey = { selectedWorkspaceId || '' }
54+ onSelectionChange = { ( key ) => onSelectWorkspace ( String ( key ) ) }
55+ renderTabItem = { ( workspace ) => {
56+ const isSelected = workspace . id === selectedWorkspaceId ;
57+
58+ if ( isSelected && FEATURE_FLAG_WORKSPACE_ACTIONS ) {
59+ return (
60+ < HasPermission
61+ operations = { [ OPERATION . WORKSPACE_MANAGEMENT ] }
62+ resources = { [ { type : RESOURCE_TYPE . WORKSPACE , id : workspace . id } ] }
63+ specialCondition = {
64+ activeUser !== undefined && isOrganizationAdmin ( activeUser , organizationId )
65+ }
66+ Fallback = { < CustomTabItem name = { workspace . name } isMoreIconVisible = { false } /> }
67+ >
68+ < CustomTabItemWithMenu
69+ workspace = { workspace }
70+ isMoreIconVisible = { true }
71+ workspaces = { workspaces }
72+ selectWorkspace = { onSelectWorkspace }
73+ />
74+ </ HasPermission >
75+ ) ;
76+ }
77+
78+ return < CustomTabItem isMoreIconVisible = { false } name = { workspace . name } /> ;
79+ } }
80+ renderTabPanel = { ( ) => < > </ > }
81+ addButton = {
82+ FEATURE_FLAG_WORKSPACE_ACTIONS
83+ ? {
84+ id : 'create-workspace-toolbar-btn' ,
85+ ariaLabel : 'Create workspace' ,
86+ tooltipText : 'Create workspace' ,
87+ onPress : createWorkspaceDialogState . open ,
88+ isLoading : createWorkspace . isPending ,
89+ }
90+ : undefined
91+ }
92+ ariaLabel = 'Workspace tabs'
93+ />
11694 { selectedWorkspace && deleteDialog . deleteWorkspaceDialogState . isOpen && (
11795 < WorkspaceDeleteDialog
11896 name = { selectedWorkspace . name }
0 commit comments