Skip to content

Commit

Permalink
feat: generate grid layout for non-admin crud
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Jan 21, 2024
1 parent 01b1315 commit 02f0de2
Show file tree
Hide file tree
Showing 26 changed files with 441 additions and 82 deletions.
2 changes: 1 addition & 1 deletion api-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ type User {
id: String!
identities: [Identity!]
name: String
profileUrl: String
profileUrl: String!
role: UserRole
status: UserStatus
updatedAt: DateTime
Expand Down
4 changes: 2 additions & 2 deletions libs/api/user/feature/src/lib/api-user.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export class ApiUserResolver {
return user.avatarUrl?.length ? user.avatarUrl : null
}

@ResolveField(() => String, { nullable: true })
@ResolveField(() => String)
profileUrl(@Parent() user: User) {
return ['/profile', user.username].join('/')
return ['/u', user.username].join('/')
}

@ResolveField(() => [Identity], { nullable: true })
Expand Down
26 changes: 13 additions & 13 deletions libs/sdk/src/generated/graphql-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export type User = {
id: Scalars['String']['output']
identities?: Maybe<Array<Identity>>
name?: Maybe<Scalars['String']['output']>
profileUrl?: Maybe<Scalars['String']['output']>
profileUrl: Scalars['String']['output']
role?: Maybe<UserRole>
status?: Maybe<UserStatus>
updatedAt?: Maybe<Scalars['DateTime']['output']>
Expand Down Expand Up @@ -319,7 +319,7 @@ export type LoginMutation = {
developer?: boolean | null
id: string
name?: string | null
profileUrl?: string | null
profileUrl: string
role?: UserRole | null
status?: UserStatus | null
updatedAt?: Date | null
Expand All @@ -344,7 +344,7 @@ export type RegisterMutation = {
developer?: boolean | null
id: string
name?: string | null
profileUrl?: string | null
profileUrl: string
role?: UserRole | null
status?: UserStatus | null
updatedAt?: Date | null
Expand All @@ -363,7 +363,7 @@ export type MeQuery = {
developer?: boolean | null
id: string
name?: string | null
profileUrl?: string | null
profileUrl: string
role?: UserRole | null
status?: UserStatus | null
updatedAt?: Date | null
Expand Down Expand Up @@ -479,7 +479,7 @@ export type AdminFindManyIdentityQuery = {
developer?: boolean | null
id: string
name?: string | null
profileUrl?: string | null
profileUrl: string
role?: UserRole | null
status?: UserStatus | null
updatedAt?: Date | null
Expand Down Expand Up @@ -654,7 +654,7 @@ export type UserDetailsFragment = {
developer?: boolean | null
id: string
name?: string | null
profileUrl?: string | null
profileUrl: string
role?: UserRole | null
status?: UserStatus | null
updatedAt?: Date | null
Expand All @@ -674,7 +674,7 @@ export type AdminCreateUserMutation = {
developer?: boolean | null
id: string
name?: string | null
profileUrl?: string | null
profileUrl: string
role?: UserRole | null
status?: UserStatus | null
updatedAt?: Date | null
Expand Down Expand Up @@ -703,7 +703,7 @@ export type AdminFindManyUserQuery = {
developer?: boolean | null
id: string
name?: string | null
profileUrl?: string | null
profileUrl: string
role?: UserRole | null
status?: UserStatus | null
updatedAt?: Date | null
Expand Down Expand Up @@ -748,7 +748,7 @@ export type AdminFindOneUserQuery = {
developer?: boolean | null
id: string
name?: string | null
profileUrl?: string | null
profileUrl: string
role?: UserRole | null
status?: UserStatus | null
updatedAt?: Date | null
Expand All @@ -770,7 +770,7 @@ export type AdminUpdateUserMutation = {
developer?: boolean | null
id: string
name?: string | null
profileUrl?: string | null
profileUrl: string
role?: UserRole | null
status?: UserStatus | null
updatedAt?: Date | null
Expand All @@ -793,7 +793,7 @@ export type UserFindManyUserQuery = {
developer?: boolean | null
id: string
name?: string | null
profileUrl?: string | null
profileUrl: string
role?: UserRole | null
status?: UserStatus | null
updatedAt?: Date | null
Expand Down Expand Up @@ -825,7 +825,7 @@ export type UserFindOneUserQuery = {
developer?: boolean | null
id: string
name?: string | null
profileUrl?: string | null
profileUrl: string
role?: UserRole | null
status?: UserStatus | null
updatedAt?: Date | null
Expand All @@ -846,7 +846,7 @@ export type UserUpdateUserMutation = {
developer?: boolean | null
id: string
name?: string | null
profileUrl?: string | null
profileUrl: string
role?: UserRole | null
status?: UserStatus | null
updatedAt?: Date | null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ exports[`web-feature generator should run successfully with crud 20`] = `
"import { Button, Group } from '@mantine/core';
import { UiPageLimit, UiSearchField } from '@proj/web-ui-core';
import { useUserFindManyTest } from '@proj/web-test-data-access';
import { UserTestUiTable } from '@proj/web-test-ui';
import { TestUiGrid } from '@proj/web-test-ui';
import {
UiBack,
UiDebugModal,
Expand Down Expand Up @@ -620,16 +620,14 @@ export function UserTestListFeature() {
{query.isLoading ? (
<UiLoader />
) : items?.length ? (
<UserTestUiTable
deleteTest={(test) => {
if (!window.confirm('Are you sure?')) return;
return deleteTest(test.id);
}}
<TestUiGrid
tests={items}
page={pagination.page}
totalRecords={pagination.total}
recordsPerPage={pagination.limit}
onPageChange={(page) => void pagination.setPage(page)}
onPageChange={pagination.setPage}
limit={pagination.limit}
setLimit={pagination.setLimit}
setPage={pagination.setPage}
/>
) : (
<UiInfo message="No tests found" />
Expand Down Expand Up @@ -663,6 +661,10 @@ exports[`web-feature generator should run successfully with crud 22`] = `
"export * from './lib/admin-test-ui-create-form';
export * from './lib/admin-test-ui-table';
export * from './lib/admin-test-ui-update-form';
export * from './lib/test-ui-avatar';
export * from './lib/test-ui-grid';
export * from './lib/test-ui-grid-item';
export * from './lib/test-ui-item';
export * from './lib/user-test-ui-create-form';
export * from './lib/user-test-ui-table';
export * from './lib/user-test-ui-update-form';
Expand Down Expand Up @@ -818,6 +820,138 @@ export function AdminTestUiUpdateForm({
`;
exports[`web-feature generator should run successfully with crud 26`] = `
"import { User } from '@pubkey-stack/sdk';
import { UiAvatar, UiAvatarProps } from '@pubkey-stack/web-ui-core';
export type UserUiAvatarProps = UiAvatarProps & {
test?: User;
};
export function UserUiAvatar({ test, ...props }: UserUiAvatarProps) {
return <UiAvatar avatarUrl={test?.avatarUrl} name={test?.name} {...props} />;
}
"
`;
exports[`web-feature generator should run successfully with crud 27`] = `
"import { Paper } from '@mantine/core';
import type { User } from '@pubkey-stack/sdk';
import { UiDebugModal, UiGroup } from '@pubkey-ui/core';
import { UserUiItem } from './test-ui-item';
export function UserUiGridItem({ test, to }: { test: User; to?: string }) {
return (
<Paper withBorder p="md">
<UiGroup>
<UserUiItem test={test} to={to} />
<UiDebugModal data={test} />
</UiGroup>
</Paper>
);
}
"
`;
exports[`web-feature generator should run successfully with crud 28`] = `
"import { Group, Pagination, SimpleGrid } from '@mantine/core';
import type { User } from '@pubkey-stack/sdk';
import { gridLimits, UiPageLimit } from '@pubkey-stack/web-ui-core';
import { UiDebugModal, UiGroup, UiStack } from '@pubkey-ui/core';
import { DataTableProps } from 'mantine-datatable';
import { UserUiGridItem } from './test-ui-grid-item';
export function UserUiGrid({
tests = [],
onPageChange,
page,
totalRecords,
limit,
setLimit,
setPage,
}: {
tests: User[];
page: DataTableProps['page'];
totalRecords: number;
onPageChange: (page: number) => void;
limit: number;
setLimit: (limit: number) => void;
setPage: (page: number) => void;
}) {
const totalPages = totalRecords / limit + 1;
return (
<UiStack>
<SimpleGrid cols={{ base: 1, sm: 2, md: 3 }} spacing="md">
{tests.map((test) => (
<UserUiGridItem key={test.id} to={test.profileUrl} test={test} />
))}
</SimpleGrid>
<UiGroup>
<Pagination
disabled={totalPages < 2}
total={totalPages}
value={page}
onChange={onPageChange}
/>
<Group>
<UiDebugModal data={tests} />
<UiPageLimit
data={gridLimits}
limit={limit}
setLimit={setLimit}
setPage={setPage}
/>
</Group>
</UiGroup>
</UiStack>
);
}
"
`;
exports[`web-feature generator should run successfully with crud 29`] = `
"import {
AvatarProps,
Group,
type GroupProps,
Stack,
Text,
} from '@mantine/core';
import { User } from '@pubkey-stack/sdk';
import { UiAnchor, type UiAnchorProps } from '@pubkey-ui/core';
import { UserUiAvatar } from './test-ui-avatar';
export function UserUiItem({
anchorProps,
avatarProps,
groupProps,
test,
to,
}: {
anchorProps?: UiAnchorProps;
avatarProps?: Omit<AvatarProps, 'src'>;
groupProps?: GroupProps;
test?: User;
to?: string | null;
}) {
if (!test) return null;
return (
<UiAnchor to={to ?? undefined} underline="never" {...anchorProps}>
<Group gap="sm" {...groupProps}>
<UserUiAvatar test={test} {...avatarProps} />
<Stack gap={1}>
<Text size="sm" fw={500}>
{test?.name}
</Text>
</Stack>
</Group>
</UiAnchor>
);
}
"
`;
exports[`web-feature generator should run successfully with crud 30`] = `
"import { Button, Group } from '@mantine/core';
import { UserCreateTestInput } from '@proj/sdk';
import { formFieldText, UiForm, UiFormField } from '@pubkey-ui/core';
Expand Down Expand Up @@ -850,7 +984,7 @@ export function UserTestUiCreateForm({
"
`;
exports[`web-feature generator should run successfully with crud 27`] = `
exports[`web-feature generator should run successfully with crud 31`] = `
"import { ActionIcon, Anchor, Group, ScrollArea } from '@mantine/core';
import { Test } from '@proj/sdk';
import { IconPencil, IconTrash } from '@tabler/icons-react';
Expand Down Expand Up @@ -931,7 +1065,7 @@ export function UserTestUiTable({
"
`;
exports[`web-feature generator should run successfully with crud 28`] = `
exports[`web-feature generator should run successfully with crud 32`] = `
"import { Button, Group } from '@mantine/core';
import { UserUpdateTestInput, Test } from '@proj/sdk';
import { formFieldText, UiForm, UiFormField } from '@pubkey-ui/core';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ describe('web-feature generator', () => {
"libs/web/test/ui/src/lib/admin-test-ui-create-form.tsx",
"libs/web/test/ui/src/lib/admin-test-ui-table.tsx",
"libs/web/test/ui/src/lib/admin-test-ui-update-form.tsx",
"libs/web/test/ui/src/lib/test-ui-avatar.tsx",
"libs/web/test/ui/src/lib/test-ui-grid-item.tsx",
"libs/web/test/ui/src/lib/test-ui-grid.tsx",
"libs/web/test/ui/src/lib/test-ui-item.tsx",
"libs/web/test/ui/src/lib/user-test-ui-create-form.tsx",
"libs/web/test/ui/src/lib/user-test-ui-table.tsx",
"libs/web/test/ui/src/lib/user-test-ui-update-form.tsx",
Expand Down
Loading

0 comments on commit 02f0de2

Please sign in to comment.