From 6067bbfb4636bb34c6ecda6cc42dc6d950304e89 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Tue, 23 Feb 2021 14:23:14 +0100 Subject: [PATCH] Reduce API calls --- frontend/src/panels/admin.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/src/panels/admin.tsx b/frontend/src/panels/admin.tsx index 7f9c9f3fc..36ab53ec0 100644 --- a/frontend/src/panels/admin.tsx +++ b/frontend/src/panels/admin.tsx @@ -82,15 +82,19 @@ export function canCustomize(user: LoggedUser): boolean { return canCustomizeDuration(user) || canCustomizePoolAffinity(user); } -export function SessionCreationDialog({ client, conf, sessions, user, users, template, templates, show, onCreate, onHide, allowUserSelection = false }: { client: Client, conf: Configuration, sessions?: Record, user: LoggedUser, users?: Record | null, template?: string, templates: Record | null, show: boolean, onCreate: (conf: SessionConfiguration, id?: string, ) => void, onHide: () => void , allowUserSelection?: boolean}): JSX.Element { +export function SessionCreationDialog({ client, conf, sessions, user, template, templates, show, onCreate, onHide, allowUserSelection = false }: { client: Client, conf: Configuration, sessions?: Record, user: LoggedUser, template?: string, templates: Record | null, show: boolean, onCreate: (conf: SessionConfiguration, id?: string, ) => void, onHide: () => void , allowUserSelection?: boolean}): JSX.Element { const [selectedUser, setUser] = React.useState(user.id); const [selectedTemplate, setTemplate] = React.useState(null); const [duration, setDuration] = React.useState(conf.sessionDefaults.duration); const [poolAffinity, setPoolAffinity] = React.useState(conf.sessionDefaults.poolAffinity); const [pools, setPools] = useState | null>(null); + const [users, setUsers] = useState | null>(null); useInterval(async () => { setPools(await client.listPools()); + if (allowUserSelection) { + setUsers(await client.listUsers()); + } }, 5000); const handleUserChange = (_event: any, newValue: string | null) => setUser(newValue); @@ -241,13 +245,11 @@ function Sessions({ client, conf, user }: { client: Client, conf: Configuration, setSelected(name); } }; - const [users, setUsers] = useState | null>(null); const [templates, setTemplates] = useState | null>(null); useInterval(async () => { const { templates } = await client.get(); setTemplates(templates); - setUsers(await client.listUsers()); }, 5000); function sessionMock(conf: SessionConfiguration): Session { @@ -367,7 +369,7 @@ function Sessions({ client, conf, user }: { client: Client, conf: Configuration, {errorMessage && setErrorMessage(null)} />} {showCreationDialog && - onCreate(conf, id, setSessions)} onHide={() => setShowCreationDialog(false)} />} + onCreate(conf, id, setSessions)} onHide={() => setShowCreationDialog(false)} />} {(selected && showUpdateDialog) && onUpdate(id, conf, setSessions)} onHide={() => setShowUpdateDialog(false)} />}