From 0dd09062e340199067584627d7261b6279928e25 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Thu, 2 Jan 2025 08:33:04 -0800 Subject: [PATCH] Sort workspaces, envs, jars --- src-web/hooks/useCookieJars.ts | 6 +++++- src-web/hooks/useEnvironments.ts | 6 +++++- src-web/hooks/useWorkspaces.ts | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src-web/hooks/useCookieJars.ts b/src-web/hooks/useCookieJars.ts index 612e8c0f..fb307dd7 100644 --- a/src-web/hooks/useCookieJars.ts +++ b/src-web/hooks/useCookieJars.ts @@ -3,6 +3,10 @@ import { atom, useAtomValue } from 'jotai'; export const cookieJarsAtom = atom(); +export const sortedCookieJars = atom((get) => + get(cookieJarsAtom)?.sort((a, b) => a.name.localeCompare(b.name)), +); + export function useCookieJars() { - return useAtomValue(cookieJarsAtom); + return useAtomValue(sortedCookieJars); } diff --git a/src-web/hooks/useEnvironments.ts b/src-web/hooks/useEnvironments.ts index 395288e6..2c732e94 100644 --- a/src-web/hooks/useEnvironments.ts +++ b/src-web/hooks/useEnvironments.ts @@ -4,12 +4,16 @@ import { atom } from 'jotai/index'; export const environmentsAtom = atom([]); +export const sortedEnvironmentsAtom = atom((get) => + get(environmentsAtom).sort((a, b) => a.name.localeCompare(b.name)), +); + export const environmentsBreakdownAtom = atom<{ baseEnvironment: Environment | null; allEnvironments: Environment[]; subEnvironments: Environment[]; }>((get) => { - const allEnvironments = get(environmentsAtom); + const allEnvironments = get(sortedEnvironmentsAtom); const baseEnvironment = allEnvironments.find((e) => e.environmentId == null) ?? null; const subEnvironments = allEnvironments.filter((e) => e.environmentId === (baseEnvironment?.id ?? 'n/a')) ?? []; diff --git a/src-web/hooks/useWorkspaces.ts b/src-web/hooks/useWorkspaces.ts index 38a0fda9..22359654 100644 --- a/src-web/hooks/useWorkspaces.ts +++ b/src-web/hooks/useWorkspaces.ts @@ -5,6 +5,10 @@ import { listWorkspaces } from '../lib/store'; const workspaces = await listWorkspaces(); export const workspacesAtom = atom(workspaces); +export const sortedWorkspacesAtom = atom((get) => + get(workspacesAtom).sort((a, b) => a.name.localeCompare(b.name)), +); + export function useWorkspaces() { - return useAtomValue(workspacesAtom); + return useAtomValue(sortedWorkspacesAtom); }