Skip to content

Commit 5e4ece9

Browse files
feat(admin): add KeyCloak status check for SAML visibility in Admin UI (#2490)
* feat(admin): add KeyCloak status check for SAML visibility in Admin UI sidebar (#2489) * Minor improvements
1 parent 81b4d20 commit 5e4ece9

File tree

4 files changed

+48
-17
lines changed

4 files changed

+48
-17
lines changed

admin-ui/app/components/Sidebar/types.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { HealthServiceKey, HealthStatusResponse } from 'Redux/features/healthSlice'
2+
13
// Sidebar-specific type definitions
24
export interface MenuItem {
35
icon?: string
@@ -26,9 +28,10 @@ export interface ThemeContextState {
2628
}
2729
}
2830

29-
// Visibility and styling types for sidebar
30-
export interface VisibilityConditions {
31-
readonly [key: string]: string
31+
type HealthVisibilityPath = '/jans-lock' | '/fido/fidomanagement' | '/scim' | '/saml'
32+
33+
export type VisibilityConditions = {
34+
readonly [P in HealthVisibilityPath]: HealthServiceKey
3235
}
3336

3437
export interface IconStyles {
@@ -39,13 +42,6 @@ export interface MenuIconMap {
3942
readonly [key: string]: React.ReactNode
4043
}
4144

42-
// Sidebar state interface
43-
export interface SidebarState {
44-
health: Record<string, string>
45-
logoutAuditInFlight: boolean
46-
logoutAuditSucceeded: boolean | null
47-
}
48-
4945
// Root state interface for sidebar selectors
5046
export interface SidebarRootState {
5147
authReducer: {
@@ -55,7 +51,7 @@ export interface SidebarRootState {
5551
permissions?: string[]
5652
}
5753
healthReducer: {
58-
health: Record<string, string>
54+
health: HealthStatusResponse
5955
}
6056
logoutAuditReducer: {
6157
logoutAuditInFlight: boolean

admin-ui/app/redux/features/healthSlice.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
import { createSlice } from '@reduxjs/toolkit'
22
import reducerRegistry from 'Redux/reducers/ReducerRegistry'
33

4-
const initialState = {
4+
type HealthStatus = 'Running' | 'Not present'
5+
6+
export type HealthServiceKey =
7+
| 'jans-lock'
8+
| 'jans-auth'
9+
| 'jans-config-api'
10+
| 'jans-casa'
11+
| 'jans-fido2'
12+
| 'jans-scim'
13+
| 'jans-link'
14+
| 'keycloak'
15+
16+
type KnownHealthServices = Partial<Record<HealthServiceKey, HealthStatus>>
17+
18+
export type HealthStatusResponse = KnownHealthServices & {
19+
[serviceName: string]: HealthStatus
20+
}
21+
22+
export interface HealthState {
23+
serverStatus: HealthStatus | null
24+
dbStatus: HealthStatus | null
25+
health: HealthStatusResponse
26+
loading: boolean
27+
}
28+
29+
const initialState: HealthState = {
530
serverStatus: null,
631
dbStatus: null,
732
health: {},

admin-ui/app/routes/Apps/Gluu/GluuAppSidebar.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const VISIBILITY_CONDITIONS: VisibilityConditions = {
4646
'/jans-lock': 'jans-lock',
4747
'/fido/fidomanagement': 'jans-fido2',
4848
'/scim': 'jans-scim',
49+
'/saml': 'keycloak',
4950
} as const
5051

5152
const ICON_STYLES: IconStyles = {
@@ -74,7 +75,7 @@ const MENU_ICON_MAP: MenuIconMap = {
7475
// Type definitions for local state
7576
interface RootState extends SidebarRootState {}
7677

77-
const selectHealth = (state: RootState): Record<string, string> => state.healthReducer.health
78+
const selectHealth = (state: RootState) => state.healthReducer.health
7879
const selectLogoutAuditSucceeded = (state: RootState): boolean | null =>
7980
state.logoutAuditReducer.logoutAuditSucceeded
8081

@@ -156,7 +157,9 @@ function GluuAppSidebar(): JSX.Element {
156157
}
157158

158159
return menus.filter((menu: PluginMenu): boolean => {
159-
const healthKey = VISIBILITY_CONDITIONS[menu.path || '']
160+
const healthKey = menu.path
161+
? VISIBILITY_CONDITIONS[menu.path as keyof VisibilityConditions]
162+
: undefined
160163
return healthKey ? health?.[healthKey] === 'Running' : true
161164
})
162165
}, [health, fetchedServersLength])

admin-ui/app/routes/Dashboards/DashboardPage.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import CheckIcon from 'Images/svg/check.svg'
1717
import CrossIcon from 'Images/svg/cross.svg'
1818
import SetTitle from 'Utils/SetTitle'
1919
import styles from './styles'
20+
import type { HealthState } from 'Redux/features/healthSlice'
21+
2022
import { formatDate } from 'Utils/Util'
2123
import UsersIcon from '@/components/SVG/menu/Users'
2224
import Administrator from '@/components/SVG/menu/Administrator'
@@ -29,6 +31,9 @@ import customColors from '@/customColors'
2931
import { useCedarling } from '@/cedarling'
3032
import { useAppNavigation, ROUTES } from '@/helpers/navigation'
3133

34+
interface DashboardHealthRootState {
35+
healthReducer: HealthState
36+
}
3237
// Constants moved outside component for better performance
3338
const FETCHING_LICENSE_DETAILS = 'Fetch license details'
3439

@@ -54,9 +59,11 @@ function DashboardPage() {
5459
const { isUserInfoFetched } = useSelector((state: any) => state.authReducer)
5560
const totalClientsEntries = useSelector((state: any) => state.initReducer.totalClientsEntries)
5661
const license = useSelector((state: any) => state.licenseDetailsReducer.item)
57-
const serverStatus = useSelector((state: any) => state.healthReducer.serverStatus)
58-
const serverHealth = useSelector((state: any) => state.healthReducer.health)
59-
const dbStatus = useSelector((state: any) => state.healthReducer.dbStatus)
62+
const serverStatus = useSelector(
63+
(state: DashboardHealthRootState) => state.healthReducer.serverStatus,
64+
)
65+
const serverHealth = useSelector((state: DashboardHealthRootState) => state.healthReducer.health)
66+
const dbStatus = useSelector((state: DashboardHealthRootState) => state.healthReducer.dbStatus)
6067
const access_token = useSelector((state: any) => state.authReducer.token?.access_token)
6168
const permissions = useSelector((state: any) => state.authReducer.permissions)
6269

0 commit comments

Comments
 (0)