Skip to content

Commit d1b68d6

Browse files
fix: set themeView correctly (#694)
* fix: only load dashboard query if teamId is there * fix: add some debug logs * feat: add ThemeViewInitializer to manage theme view based on user role * fix: remove logs --------- Co-authored-by: Ferruh Cihan <[email protected]>
1 parent df45a47 commit d1b68d6

File tree

5 files changed

+48
-15
lines changed

5 files changed

+48
-15
lines changed

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import TeamsOverviewPage from 'pages/teams/overview/TeamsOverviewPage'
5252
import WorkloadsCreateEditPage from 'pages/workloads/create-edit/WorkloadsCreateEditPage'
5353
import WorkloadsOverviewPage from 'pages/workloads/overview/WorkloadsOverviewPage'
5454
import WorkloadCatalogsPage from 'pages/workloads/catalog/WorkloadCatalogsPage'
55+
import ThemeViewInitializer from 'components/ThemeViewInitializer'
5556
import { HttpErrorBadRequest } from './utils/error'
5657
import { NotistackProvider, SnackbarUtilsConfigurator } from './utils/snack'
5758

@@ -84,6 +85,7 @@ function App() {
8485
<SnackbarUtilsConfigurator />
8586
<CssBaseline />
8687
<Helmet titleTemplate='%s | App Platform' defaultTitle='Akamai App Platform' />
88+
<ThemeViewInitializer />
8789
<Switch>
8890
<Route path='/' component={Dashboard} exact />
8991
<PrivateRoute

src/components/Dashboard.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function IFramesCard({ classes, title, iframeSources, iframeClass, themeMode, sh
207207
export default function Dashboard({ team, inventory }: Props): React.ReactElement {
208208
const theme = useTheme()
209209
const { classes } = useStyles()
210-
const { themeView, onChangeView } = useSettings()
210+
const { themeView } = useSettings()
211211
const { oboTeamId, appsEnabled, user, versions } = useSession()
212212
const hostname = window.location.hostname
213213
const domain = getDomain(hostname)
@@ -220,11 +220,6 @@ export default function Dashboard({ team, inventory }: Props): React.ReactElemen
220220
React.useEffect(() => {
221221
setCookiesLoaded(false)
222222
}, [themeView])
223-
// reset themeView to team if user is not admin
224-
React.useEffect(() => {
225-
const { isPlatformAdmin } = user
226-
if (!isPlatformAdmin) onChangeView({ target: { value: 'team' } } as React.ChangeEvent<HTMLInputElement>)
227-
}, [])
228223

229224
// platform view base iframe urls
230225
const clusterResourceUtilization = `https://grafana.${domain}/d-solo/efa86fd1d0c121a26444b636a3f509a8/kubernetes-compute-resources-cluster?orgId=1&refresh=30s&theme=${theme.palette.mode}&panelId=`
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React, { useEffect } from 'react'
2+
import { useSession } from 'providers/Session'
3+
import useSettings from 'hooks/useSettings'
4+
5+
/**
6+
* Initializes theme view based on user role.
7+
* Non-platform admin users are automatically set to 'team' view.
8+
*/
9+
export default function ThemeViewInitializer() {
10+
const { user } = useSession()
11+
const { onChangeView } = useSettings()
12+
13+
useEffect(() => {
14+
const { isPlatformAdmin } = user
15+
if (!isPlatformAdmin) onChangeView({ target: { value: 'team' } } as React.ChangeEvent<HTMLInputElement>)
16+
}, [])
17+
18+
return null
19+
}

src/pages/Dashboard.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ export default function (): React.ReactElement {
2828
const { data: teamData } = useGetTeamQuery({ teamId: oboTeamId }, { skip: !oboTeamId || isPlatformAdmin })
2929

3030
const teamId = isPlatformView ? undefined : oboTeamId
31+
3132
const {
3233
data: dashboard,
3334
isFetching: isFetchingDashboard,
3435
refetch: refetchDashboard,
35-
} = useGetDashboardQuery({ teamId })
36+
} = useGetDashboardQuery({ teamId }, { skip: !isPlatformAdmin && !teamId })
3637

3738
const isDirty = useAppSelector(({ global: { isDirty } }) => isDirty)
3839
useEffect(() => {

src/redux/otomiApi.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5238,7 +5238,9 @@ export type GetDockerConfigApiArg = {
52385238
}
52395239
export type GetSessionApiResponse = /** status 200 Get the session for the logged in user */ {
52405240
ca?: string
5241-
core?: object
5241+
core?: {
5242+
[key: string]: any
5243+
}
52425244
corrupt?: boolean
52435245
editor?: string
52445246
inactivityTimeout?: number
@@ -5277,7 +5279,9 @@ export type GetSessionApiResponse = /** status 200 Get the session for the logge
52775279
console?: string
52785280
values?: string
52795281
}
5280-
valuesSchema?: object
5282+
valuesSchema?: {
5283+
[key: string]: any
5284+
}
52815285
}
52825286
export type GetSessionApiArg = void
52835287
export type GetApiDocApiResponse = /** status 200 The requested apiDoc. */ object
@@ -5868,8 +5872,12 @@ export type EditSettingsApiArg = {
58685872
export type GetAppsApiResponse = /** status 200 The request is successful. */ {
58695873
enabled?: boolean
58705874
id: string
5871-
rawValues?: object
5872-
values?: object
5875+
rawValues?: {
5876+
[key: string]: any
5877+
}
5878+
values?: {
5879+
[key: string]: any
5880+
}
58735881
}[]
58745882
export type GetAppsApiArg = {
58755883
teamId: string
@@ -5885,8 +5893,12 @@ export type ToggleAppsApiArg = {
58855893
export type GetTeamAppApiResponse = /** status 200 The request is successful. */ {
58865894
enabled?: boolean
58875895
id: string
5888-
rawValues?: object
5889-
values?: object
5896+
rawValues?: {
5897+
[key: string]: any
5898+
}
5899+
values?: {
5900+
[key: string]: any
5901+
}
58905902
}
58915903
export type GetTeamAppApiArg = {
58925904
teamId: string
@@ -5900,8 +5912,12 @@ export type EditAppApiArg = {
59005912
body: {
59015913
enabled?: boolean
59025914
id: string
5903-
rawValues?: object
5904-
values?: object
5915+
rawValues?: {
5916+
[key: string]: any
5917+
}
5918+
values?: {
5919+
[key: string]: any
5920+
}
59055921
}
59065922
}
59075923
export type GetAiModelsApiResponse = /** status 200 Successfully obtained shared AI models */ ({

0 commit comments

Comments
 (0)