From 92d6076df295aeda17576625482280758b84636d Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Thu, 25 Jan 2024 10:57:20 +0000 Subject: [PATCH] fix: projects list navigation (#3328) --- .../web/components/ProjectManageWidget.tsx | 293 +++++++++--------- 1 file changed, 153 insertions(+), 140 deletions(-) diff --git a/frontend/web/components/ProjectManageWidget.tsx b/frontend/web/components/ProjectManageWidget.tsx index f6fc57d759c6..a86dd15e0113 100644 --- a/frontend/web/components/ProjectManageWidget.tsx +++ b/frontend/web/components/ProjectManageWidget.tsx @@ -8,7 +8,7 @@ import AccountStore from 'common/stores/account-store' import { useHasPermission } from 'common/providers/Permission' import ConfigProvider from 'common/providers/ConfigProvider' import { useGetOrganisationsQuery } from 'common/services/useOrganisation' -import { useGetProjectsQuery } from 'common/services/useProject' +import OrganisationProvider from 'common/providers/OrganisationProvider' import { Project } from 'common/types/responses' import Button from './base/forms/Button' import PanelSearch from './PanelSearch' @@ -28,10 +28,6 @@ const ProjectManageWidget: FC = ({ const isAdmin = AccountStore.isAdmin() const { data: organisations } = useGetOrganisationsQuery({}) - const { data: projects, isLoading: projectsLoading } = useGetProjectsQuery( - { organisationId: organisationId as string }, - { skip: !organisationId }, - ) const organisation = useMemo( () => organisations?.results?.find((v) => `${v.id}` === organisationId), [organisations, organisationId], @@ -71,155 +67,172 @@ const ProjectManageWidget: FC = ({ }, [handleCreateProjectClick, router.route.location]) return ( -
-
- {(projects && projects.length) || projectsLoading ? ( -
- ) : isAdmin ? ( -
-
- Great! Now you can create your first project. -
-

- When you create a project we'll also generate a{' '} - development and production{' '} - environment for you. -

-

- You can create features for your project, then enable and - configure them per environment. -

-
- ) : ( -
-

- You do not have access to any projects within this Organisation. - If this is unexpected please contact a member of the Project who - has Administrator privileges. Users can be added to Projects from - the Project settings menu. -

-
- )} - {(projectsLoading || !projects) && ( -
- -
- )} - {!projectsLoading && ( + + {({ + isLoading, + projects, + }: { + isLoading: boolean + projects: Project[] + }) => ( +
- - { - return ( - <> - {i === 0 && ( -
- {Utils.renderWithPermission( - canCreateProject, - Constants.organisationPermissions( - Utils.getCreateProjectPermissionDescription( - AccountStore.getOrganisation(), - ), + {(projects && projects.length) || isLoading ? ( +
+ ) : isAdmin ? ( +
+
+ Great! Now you can create your first project. +
+

+ When you create a project we'll also generate a{' '} + development and production{' '} + environment for you. +

+

+ You can create features for your project, then enable and + configure them per environment. +

+
+ ) : ( +
+

+ You do not have access to any projects within this + Organisation. If this is unexpected please contact a member of + the Project who has Administrator privileges. Users can be + added to Projects from the Project settings menu. +

+
+ )} + {(isLoading || !projects) && ( +
+ +
+ )} + {!isLoading && ( +
+ + { + return ( + <> + {i === 0 && ( +
+ {Utils.renderWithPermission( + canCreateProject, + Constants.organisationPermissions( + Utils.getCreateProjectPermissionDescription( + AccountStore.getOrganisation(), + ), + ), + , + )} +
+ )} + + + + + ) + }} + renderNoResults={ +
+ {Utils.renderWithPermission( + canCreateProject, + Constants.organisationPermissions( + Utils.getCreateProjectPermissionDescription( + organisation, ), + ), +
, - )} -
- )} - - - - - ) - }} - renderNoResults={ -
- {Utils.renderWithPermission( - canCreateProject, - Constants.organisationPermissions( - Utils.getCreateProjectPermissionDescription( - organisation, - ), - ), -
- -
, - )} -
- } - filterRow={(item: Project, search: string) => - item.name.toLowerCase().indexOf(search) > -1 - } - sorting={[ - { - default: true, - label: 'Name', - order: 'asc', - value: 'name', - }, - ]} - /> - + +
, + )} +
+ } + filterRow={(item: Project, search: string) => + item.name.toLowerCase().indexOf(search) > -1 + } + sorting={[ + { + default: true, + label: 'Name', + order: 'asc', + value: 'name', + }, + ]} + /> + +
+ )}
- )} -
-
+
+ )} + ) }