-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(key-management-service): add services loader in sidebar (#13040)
ref: MANAGER-14636 Signed-off-by: David Arsène <[email protected]>
- Loading branch information
1 parent
0156c6e
commit 7b79460
Showing
4 changed files
with
87 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 42 additions & 18 deletions
60
...s/manager/apps/container/src/container/legacy/server-sidebar/universe/useServiceLoader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,64 @@ | ||
import { useReket } from '@ovh-ux/ovh-reket'; | ||
import { useShell } from '@/context'; | ||
import { apiClient } from '@ovh-ux/manager-core-api'; | ||
import { AxiosResponse } from 'axios'; | ||
import { SidebarMenuItem } from '../sidebarMenu'; | ||
|
||
type TService = { | ||
displayName: string; | ||
serviceName: string; | ||
url?: string; | ||
baseUrl?: string; | ||
extraParams?: Record<string, string>; | ||
stateParams?: (number | string)[]; | ||
parentName?: string; | ||
searchParams?: string[]; | ||
}; | ||
|
||
const fetchServices = ( | ||
path: string, | ||
subType: string, | ||
): Promise<AxiosResponse<TService[]>> => | ||
apiClient.aapi.get('/service', { | ||
params: { | ||
type: path, | ||
subType, | ||
external: false, | ||
}, | ||
}); | ||
|
||
export default function useServiceLoader(appId: string) { | ||
const reketInstance = useReket(); | ||
const shell = useShell(); | ||
const navigation = shell.getPlugin('navigation'); | ||
|
||
return { | ||
async loadServices( | ||
path: string, | ||
subType?: string, | ||
applicationId = appId | ||
applicationId = appId, | ||
): Promise<SidebarMenuItem[]> { | ||
const services = await reketInstance.get('/service', { | ||
requestType: 'aapi', | ||
params: { | ||
type: path, | ||
subType, | ||
external: false, | ||
}, | ||
}); | ||
return services | ||
.map((service: any) => ({ | ||
const { data: services } = await fetchServices(path, subType); | ||
|
||
const menuItems: SidebarMenuItem[] = services.map((service: TService) => { | ||
const item: SidebarMenuItem = { | ||
id: `service-${path}-${service.serviceName}`, | ||
label: service.displayName, | ||
extraParams: service.extraParams, | ||
stateParams: service.stateParams || [], | ||
searchParams: service.searchParams || [], | ||
href: navigation.getURL(applicationId, service.url || service.baseUrl || ''), | ||
href: navigation.getURL( | ||
applicationId, | ||
service.url || service.baseUrl || '', | ||
), | ||
parentName: service.parentName, | ||
serviceName: service.serviceName, | ||
})) | ||
.sort((a: SidebarMenuItem, b: SidebarMenuItem) => { | ||
return a.label?.localeCompare(b.label); | ||
}); | ||
}; | ||
|
||
return item; | ||
}); | ||
|
||
return menuItems.sort((a: SidebarMenuItem, b: SidebarMenuItem) => | ||
a.label?.localeCompare(b.label), | ||
); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters