Skip to content

Commit

Permalink
Merge pull request #1693 from vivid-planet/merge-main-into-next
Browse files Browse the repository at this point in the history
Merge main into next
  • Loading branch information
johnnyomair authored Feb 13, 2024
2 parents ec4ef75 + 8f7129a commit 0ba88ac
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 49 deletions.
5 changes: 5 additions & 0 deletions .changeset/atlantic-scallop-fisherman
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/cms-api": patch
---

API Generator: Disable input generation if `create` and `update` are set to `false` in the decorator
5 changes: 5 additions & 0 deletions .changeset/neat-rivers-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/cms-admin": patch
---

Use `useCurrentUser` hook where possible
29 changes: 5 additions & 24 deletions packages/admin/cms-admin/src/common/header/UserHeaderItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from "react";
import { FormattedMessage } from "react-intl";

import { AboutModal } from "./about/AboutModal";
import { GQLCurrentUserQuery, GQLSignOutMutation } from "./UserHeaderItem.generated";
import { GQLSignOutMutation } from "./UserHeaderItem.generated";

const DropdownContent = styled(Box)`
width: 250px;
Expand All @@ -24,21 +24,9 @@ const Separator = styled(Box)`
margin-bottom: 20px;
`;

const LoadingWrapper = styled("div")`
width: 60px;
height: 100%;
border-left: 1px solid rgba(255, 255, 255, 0.2);
`;
import { gql, useMutation } from "@apollo/client";

import { gql, useMutation, useQuery } from "@apollo/client";

const currentUserQuery = gql`
query CurrentUser {
currentUser {
name
}
}
`;
import { useCurrentUser } from "../../userPermissions/hooks/currentUser";

const signOutMutation = gql`
mutation SignOut {
Expand All @@ -53,19 +41,12 @@ interface UserHeaderItemProps {
export function UserHeaderItem(props: UserHeaderItemProps): React.ReactElement {
const { aboutModalLogo } = props;

const user = useCurrentUser();
const [showAboutModal, setShowAboutModal] = React.useState(false);
const { loading, data } = useQuery<GQLCurrentUserQuery>(currentUserQuery);
const [signOut, { loading: isSigningOut }] = useMutation<GQLSignOutMutation>(signOutMutation);

if (loading || !data)
return (
<LoadingWrapper>
<Loading behavior="fillParent" sx={{ fontSize: 20 }} color="inherit" />
</LoadingWrapper>
);

return (
<AppHeaderDropdown buttonChildren={data.currentUser.name} startIcon={<Account />}>
<AppHeaderDropdown buttonChildren={user.name} startIcon={<Account />}>
<DropdownContent padding={4}>
<Button
fullWidth={true}
Expand Down
20 changes: 3 additions & 17 deletions packages/admin/cms-admin/src/dashboard/DefaultGreeting.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import { gql, useQuery } from "@apollo/client";
import React from "react";
import { FormattedMessage } from "react-intl";

import { GQLDashboardCurrentUserNameQuery } from "./DefaultGreeting.generated";

const CURRENT_USER_NAME_QUERY = gql`
query DashboardCurrentUserName {
currentUser {
name
}
}
`;
import { useCurrentUser } from "../userPermissions/hooks/currentUser";

export const DefaultGreeting = () => {
const { data } = useQuery<GQLDashboardCurrentUserNameQuery>(CURRENT_USER_NAME_QUERY);

if (data) {
return <FormattedMessage id="dashboard.userGreeting" defaultMessage="Hello {givenName}!" values={{ givenName: data.currentUser.name }} />;
}

return <FormattedMessage id="dashboard.greeting" defaultMessage="Hello!" />;
const user = useCurrentUser();
return <FormattedMessage id="dashboard.userGreeting" defaultMessage="Hello {givenName}!" values={{ givenName: user.name }} />;
};
8 changes: 1 addition & 7 deletions packages/api/cms-api/src/generator/generate-crud-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ import {
findInputClassImportPath,
morphTsProperty,
} from "./utils/ts-morph-helper";
import { GeneratedFile, writeGeneratedFiles } from "./utils/write-generated-files";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export async function writeCrudInput(generatorOptions: { targetDirectory: string }, metadata: EntityMetadata<any>): Promise<void> {
const files = await generateCrudInput(generatorOptions, metadata);
await writeGeneratedFiles(files, generatorOptions);
}
import { GeneratedFile } from "./utils/write-generated-files";

function tsCodeRecordToString(object: Record<string, string | undefined>) {
const filteredEntries = Object.entries(object).filter(([key, value]) => value !== undefined);
Expand Down
5 changes: 4 additions & 1 deletion packages/api/cms-api/src/generator/generate-crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -982,5 +982,8 @@ export async function generateCrud(generatorOptionsParam: CrudGeneratorOptions,
return generatedFiles;
}

return [...(await generateCrudInput(generatorOptions, metadata)), ...(await generateCrudResolver())];
const crudInput = await generateCrudInput(generatorOptions, metadata);
const crudResolver = await generateCrudResolver();

return generatorOptions.create || generatorOptions.update ? [...crudInput, ...crudResolver] : [...crudResolver];
}

0 comments on commit 0ba88ac

Please sign in to comment.