Skip to content

Commit

Permalink
Update frontend code for backend changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazoyer committed Jul 16, 2024
1 parent 8840235 commit b872255
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 18 deletions.
6 changes: 3 additions & 3 deletions frontend/app/src/components/account-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
Expand All @@ -42,7 +42,7 @@ export const AccountMenu = () => {
if (schema && accountId) {
fetchProfile();
}
}, [schema, accountId]);
}, [schema?.kind, accountId]);

if (loading || !schema) {
return <Avatar isLoading />;
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/config/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { gql } from "@apollo/client";

export const GET_ALL_ACCOUNTS = gql`
query GetAllAccounts {
CoreAccount {
CoreGenericAccount {
edges {
node {
id
Expand Down
10 changes: 6 additions & 4 deletions frontend/app/src/hooks/useObjectDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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");

Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/screens/branches/branch-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/screens/user-profile/tab-profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ 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";
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);
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/screens/user-profile/user-profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b872255

Please sign in to comment.