From 7226ad3df187267090962e4bd5cb85607712800e Mon Sep 17 00:00:00 2001 From: Mahmoud Mabrouk Date: Fri, 21 Nov 2025 18:13:21 +0100 Subject: [PATCH] refactor: simplify project filtering logic in dropdown and workspace redirection Updated the logic for filtering projects and organizations to remove unnecessary checks for demo projects. This change enhances the clarity and efficiency of the code in the dropdown items and workspace redirection components. --- .../Sidebar/hooks/useDropdownItems/index.tsx | 2 +- .../src/components/pages/WorkspaceRedirect/index.tsx | 5 ++--- web/oss/src/state/project/selectors/project.ts | 11 ++--------- web/oss/src/state/url/postLoginRedirect.ts | 6 +----- 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/web/oss/src/components/Sidebar/hooks/useDropdownItems/index.tsx b/web/oss/src/components/Sidebar/hooks/useDropdownItems/index.tsx index c3eb972101..75158012bc 100644 --- a/web/oss/src/components/Sidebar/hooks/useDropdownItems/index.tsx +++ b/web/oss/src/components/Sidebar/hooks/useDropdownItems/index.tsx @@ -24,7 +24,7 @@ export const useDropdownItems = ({ const filteredOrgs = useMemo(() => { return projects.flatMap((project) => - orgs.filter((org) => org.id === project.organization_id && !project.is_demo), + orgs.filter((org) => org.id === project.organization_id), ) }, [projects, orgs]) diff --git a/web/oss/src/components/pages/WorkspaceRedirect/index.tsx b/web/oss/src/components/pages/WorkspaceRedirect/index.tsx index bc847c58a9..f5ad22aac4 100644 --- a/web/oss/src/components/pages/WorkspaceRedirect/index.tsx +++ b/web/oss/src/components/pages/WorkspaceRedirect/index.tsx @@ -1,8 +1,8 @@ import {useEffect, useMemo} from "react" import {Spin} from "antd" -import {useRouter} from "next/router" import {useAtomValue} from "jotai" +import {useRouter} from "next/router" import useURL from "@/oss/hooks/useURL" import {projectsAtom} from "@/oss/state/project" @@ -20,8 +20,7 @@ const WorkspaceRedirect = () => { return workspaceMatch || orgMatch }) if (!belonging.length) return null - const nonDemo = belonging.find((project) => !project.is_demo) - return (nonDemo ?? belonging[0])?.project_id ?? null + return belonging[0]?.project_id ?? null }, [projects, workspaceId]) const targetPath = useMemo(() => { diff --git a/web/oss/src/state/project/selectors/project.ts b/web/oss/src/state/project/selectors/project.ts index fe6a848fca..cd7d7f5a31 100644 --- a/web/oss/src/state/project/selectors/project.ts +++ b/web/oss/src/state/project/selectors/project.ts @@ -61,20 +61,13 @@ const projectMatchesWorkspace = (project: ProjectsResponse, workspaceId: string) const pickPreferredProject = (projects: ProjectsResponse[], workspaceId: string | null) => { if (!projects.length) return null - const nonDemo = projects.filter((project) => !project.is_demo) if (workspaceId) { - const workspaceMatch = projects.find( - (project) => projectMatchesWorkspace(project, workspaceId) && !project.is_demo, - ) - if (workspaceMatch) return workspaceMatch - - const workspaceAny = projects.find((project) => + const workspaceMatch = projects.find((project) => projectMatchesWorkspace(project, workspaceId), ) - if (workspaceAny) return workspaceAny + if (workspaceMatch) return workspaceMatch } - if (nonDemo.length) return nonDemo[0] return projects[0] } diff --git a/web/oss/src/state/url/postLoginRedirect.ts b/web/oss/src/state/url/postLoginRedirect.ts index e753d0f7e2..8792cfa315 100644 --- a/web/oss/src/state/url/postLoginRedirect.ts +++ b/web/oss/src/state/url/postLoginRedirect.ts @@ -31,13 +31,9 @@ const pickPreferredProject = ( ? projects.filter((project) => projectMatchesWorkspace(project, workspaceId)) : projects - const nonDemoScoped = scoped.find((project) => !project.is_demo) - if (nonDemoScoped) return nonDemoScoped - if (scoped.length > 0) return scoped[0] - const nonDemoAny = projects.find((project) => !project.is_demo) - return nonDemoAny ?? projects[0] + return projects[0] } export interface WorkspaceContext {