From b872255954a4a48d8e389ff394093791efd4ca1f Mon Sep 17 00:00:00 2001 From: Guillaume Mazoyer Date: Tue, 16 Jul 2024 10:42:31 +0200 Subject: [PATCH] Update frontend code for backend changes --- frontend/app/src/components/account-menu.tsx | 6 +++--- frontend/app/src/config/constants.tsx | 2 +- .../mutations/accounts/updateAccountPassword.ts | 2 +- .../app/src/graphql/queries/accounts/getAllAccounts.ts | 2 +- frontend/app/src/hooks/useObjectDetails.ts | 10 ++++++---- .../pages/proposed-changes/proposed-changes-items.tsx | 4 ++-- frontend/app/src/screens/branches/branch-details.tsx | 4 ++-- frontend/app/src/screens/user-profile/tab-profile.tsx | 4 ++-- frontend/app/src/screens/user-profile/user-profile.tsx | 4 ++-- 9 files changed, 20 insertions(+), 18 deletions(-) diff --git a/frontend/app/src/components/account-menu.tsx b/frontend/app/src/components/account-menu.tsx index 0dddcfe062..fc1d50ee3e 100644 --- a/frontend/app/src/components/account-menu.tsx +++ b/frontend/app/src/components/account-menu.tsx @@ -5,7 +5,7 @@ import { getProfileDetails } from "@/graphql/queries/accounts/getProfileDetails" import { useAuth } from "@/hooks/useAuth"; import { useLazyQuery } from "@/hooks/useQuery"; import { userNavigation } from "@/screens/layout/navigation-list"; -import { schemaState } from "@/state/atoms/schema.atom"; +import { genericsState } from "@/state/atoms/schema.atom"; import { classNames, parseJwt } from "@/utils/common"; import { gql } from "@apollo/client"; import { Menu, Transition } from "@headlessui/react"; @@ -20,7 +20,7 @@ export const AccountMenu = () => { const { isAuthenticated, signOut } = useAuth(); const navigate = useNavigate(); const location = useLocation(); - const [schemaList] = useAtom(schemaState); + const [schemaList] = useAtom(genericsState); const schema = schemaList.find((s) => s.kind === ACCOUNT_OBJECT); const localToken = localStorage.getItem(ACCESS_TOKEN_KEY); @@ -42,7 +42,7 @@ export const AccountMenu = () => { if (schema && accountId) { fetchProfile(); } - }, [schema, accountId]); + }, [schema?.kind, accountId]); if (loading || !schema) { return ; diff --git a/frontend/app/src/config/constants.tsx b/frontend/app/src/config/constants.tsx index 91a8d59493..8a27894e2f 100644 --- a/frontend/app/src/config/constants.tsx +++ b/frontend/app/src/config/constants.tsx @@ -14,7 +14,7 @@ export const TASK_TARGET = "CoreTaskTarget"; export const DATA_CHECK_OBJECT = "CoreDataCheck"; -export const ACCOUNT_OBJECT = "CoreAccount"; +export const ACCOUNT_OBJECT = "CoreGenericAccount"; export const ACCOUNT_TOKEN_OBJECT = "InternalAccountToken"; diff --git a/frontend/app/src/graphql/mutations/accounts/updateAccountPassword.ts b/frontend/app/src/graphql/mutations/accounts/updateAccountPassword.ts index 7da63a334a..d2e9dbadee 100644 --- a/frontend/app/src/graphql/mutations/accounts/updateAccountPassword.ts +++ b/frontend/app/src/graphql/mutations/accounts/updateAccountPassword.ts @@ -2,7 +2,7 @@ import { gql } from "@apollo/client"; export const UPDATE_ACCOUNT_PASSWORD = gql` mutation UPDATE_ACCOUNT_PASSWORD($password: String!) { - CoreAccountSelfUpdate(data: { password: $password }) { + InfrahubAccountSelfUpdate(data: { password: $password }) { ok } } diff --git a/frontend/app/src/graphql/queries/accounts/getAllAccounts.ts b/frontend/app/src/graphql/queries/accounts/getAllAccounts.ts index a70b2686ef..7f64ad89c7 100644 --- a/frontend/app/src/graphql/queries/accounts/getAllAccounts.ts +++ b/frontend/app/src/graphql/queries/accounts/getAllAccounts.ts @@ -2,7 +2,7 @@ import { gql } from "@apollo/client"; export const GET_ALL_ACCOUNTS = gql` query GetAllAccounts { - CoreAccount { + CoreGenericAccount { edges { node { id diff --git a/frontend/app/src/hooks/useObjectDetails.ts b/frontend/app/src/hooks/useObjectDetails.ts index c0604b3bd5..dc61a6422c 100644 --- a/frontend/app/src/hooks/useObjectDetails.ts +++ b/frontend/app/src/hooks/useObjectDetails.ts @@ -3,8 +3,9 @@ import { useAtomValue } from "jotai"; import useQuery from "@/hooks/useQuery"; import { genericsState, IModelSchema } from "@/state/atoms/schema.atom"; import { getObjectDetailsPaginated } from "@/graphql/queries/objects/getObjectDetails"; -import { PROFILE_KIND, TASK_OBJECT } from "@/config/constants"; +import { ACCOUNT_OBJECT, PROFILE_KIND, TASK_OBJECT } from "@/config/constants"; import { getSchemaObjectColumns, getTabs } from "@/utils/getSchemaObjectColumns"; +import { isGeneric } from "@/utils/common"; export const useObjectDetails = (schema: IModelSchema, objectId: string) => { const generics = useAtomValue(genericsState); @@ -23,9 +24,10 @@ export const useObjectDetails = (schema: IModelSchema, objectId: string) => { objectid: objectId, // Do not query profiles on profiles objects queryProfiles: - !profileGenericSchema?.used_by?.includes(schema?.kind!) && - schema?.kind !== PROFILE_KIND && - schema?.generate_profile, + !profileGenericSchema?.used_by?.includes(schema?.kind!) && + schema?.kind !== PROFILE_KIND && + !isGeneric(schema) && + schema?.generate_profile }) : // Empty query to make the gql parsing work // TODO: Find another solution for queries while loading schema diff --git a/frontend/app/src/pages/proposed-changes/proposed-changes-items.tsx b/frontend/app/src/pages/proposed-changes/proposed-changes-items.tsx index b0b8f54c20..4edcc71b1e 100644 --- a/frontend/app/src/pages/proposed-changes/proposed-changes-items.tsx +++ b/frontend/app/src/pages/proposed-changes/proposed-changes-items.tsx @@ -8,7 +8,7 @@ import { useTitle } from "@/hooks/useTitle"; import ErrorScreen from "@/screens/errors/error-screen"; import Content from "@/screens/layout/content"; import LoadingScreen from "@/screens/loading-screen/loading-screen"; -import { schemaState } from "@/state/atoms/schema.atom"; +import { genericsState } from "@/state/atoms/schema.atom"; import { constructPath } from "@/utils/fetch"; import { getObjectRelationships } from "@/utils/getSchemaObjectColumns"; import { gql } from "@apollo/client"; @@ -18,7 +18,7 @@ import { Link } from "react-router-dom"; import { ProposedChange } from "@/screens/proposed-changes/proposed-changes-item"; const ProposedChangesPage = () => { - const [schemaList] = useAtom(schemaState); + const [schemaList] = useAtom(genericsState); const permission = usePermission(); useTitle("Proposed changes list"); diff --git a/frontend/app/src/screens/branches/branch-details.tsx b/frontend/app/src/screens/branches/branch-details.tsx index 76cb72867b..ae57936bc8 100644 --- a/frontend/app/src/screens/branches/branch-details.tsx +++ b/frontend/app/src/screens/branches/branch-details.tsx @@ -18,7 +18,7 @@ import ErrorScreen from "@/screens/errors/error-screen"; import LoadingScreen from "@/screens/loading-screen/loading-screen"; import ObjectForm from "@/components/form/object-form"; import { branchesState } from "@/state/atoms/branches.atom"; -import { schemaState } from "@/state/atoms/schema.atom"; +import { genericsState } from "@/state/atoms/schema.atom"; import { datetimeAtom } from "@/state/atoms/time.atom"; import { objectToString } from "@/utils/common"; import { constructPath, getCurrentQsp } from "@/utils/fetch"; @@ -37,7 +37,7 @@ export const BranchDetails = () => { const date = useAtomValue(datetimeAtom); const auth = useAuth(); const [branches, setBranches] = useAtom(branchesState); - const [schemaList] = useAtom(schemaState); + const [schemaList] = useAtom(genericsState); const [isLoadingRequest, setIsLoadingRequest] = useState(false); const [displayModal, setDisplayModal] = useState(false); diff --git a/frontend/app/src/screens/user-profile/tab-profile.tsx b/frontend/app/src/screens/user-profile/tab-profile.tsx index dcc534b3c4..dcb0978976 100644 --- a/frontend/app/src/screens/user-profile/tab-profile.tsx +++ b/frontend/app/src/screens/user-profile/tab-profile.tsx @@ -2,7 +2,7 @@ import { ACCESS_TOKEN_KEY, ACCOUNT_OBJECT } from "@/config/constants"; import ObjectItemDetails from "@/screens/object-item-details/object-item-details-paginated"; import { parseJwt } from "@/utils/common"; import { useAtomValue } from "jotai"; -import { schemaState } from "@/state/atoms/schema.atom"; +import { genericsState } from "@/state/atoms/schema.atom"; import { useObjectDetails } from "@/hooks/useObjectDetails"; import NoDataFound from "@/screens/errors/no-data-found"; import { NetworkStatus } from "@apollo/client"; @@ -10,7 +10,7 @@ import LoadingScreen from "@/screens/loading-screen/loading-screen"; import ErrorScreen from "@/screens/errors/error-screen"; export default function TabProfile() { - const nodes = useAtomValue(schemaState); + const nodes = useAtomValue(genericsState); const schema = nodes.find(({ kind }) => kind === ACCOUNT_OBJECT); const localToken = localStorage.getItem(ACCESS_TOKEN_KEY); diff --git a/frontend/app/src/screens/user-profile/user-profile.tsx b/frontend/app/src/screens/user-profile/user-profile.tsx index 191f3623ef..5539838b4b 100644 --- a/frontend/app/src/screens/user-profile/user-profile.tsx +++ b/frontend/app/src/screens/user-profile/user-profile.tsx @@ -8,7 +8,7 @@ import { useTitle } from "@/hooks/useTitle"; import ErrorScreen from "@/screens/errors/error-screen"; import Content from "@/screens/layout/content"; import LoadingScreen from "@/screens/loading-screen/loading-screen"; -import { schemaState } from "@/state/atoms/schema.atom"; +import { genericsState } from "@/state/atoms/schema.atom"; import { parseJwt } from "@/utils/common"; import { gql } from "@apollo/client"; import { useAtom } from "jotai"; @@ -43,7 +43,7 @@ const renderContent = (tab: string | null | undefined) => { export function UserProfilePage() { const [qspTab] = useQueryParam(QSP.TAB, StringParam); - const [schemaList] = useAtom(schemaState); + const [schemaList] = useAtom(genericsState); useTitle("Profile"); const schema = schemaList.find((s) => s.kind === ACCOUNT_OBJECT);