From 5ff586d1272d3c01b840febf14b0583fa228be7b Mon Sep 17 00:00:00 2001 From: Francesco Sardo Date: Sun, 30 May 2021 20:20:51 +0100 Subject: [PATCH 1/3] Fix #2407 --- packages/generator/templates/page/index.tsx | 13 ++++++++++--- .../route-import-manifest/route-import-manifest.ts | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/generator/templates/page/index.tsx b/packages/generator/templates/page/index.tsx index 91debda6e2..28aa319fba 100644 --- a/packages/generator/templates/page/index.tsx +++ b/packages/generator/templates/page/index.tsx @@ -61,9 +61,16 @@ export const __ModelNames__List = () => { diff --git a/packages/server/src/stages/route-import-manifest/route-import-manifest.ts b/packages/server/src/stages/route-import-manifest/route-import-manifest.ts index 95ae3c528a..456693574d 100644 --- a/packages/server/src/stages/route-import-manifest/route-import-manifest.ts +++ b/packages/server/src/stages/route-import-manifest/route-import-manifest.ts @@ -67,10 +67,10 @@ export function generateManifest( return `${name}(query: { ${[ ...parameters.map( - (param) => param.name + (param.optional ? "?" : "") + ": string | number", + (param) => param.name + (param.optional ? "?" : "") + ": string | number | undefined", ), ...multipleParameters.map( - (param) => param.name + (param.optional ? "?" : "") + ": (string | number)[]", + (param) => param.name + (param.optional ? "?" : "") + ": (string | number | undefined)[]", ), ].join("; ")} } & ParsedUrlQueryInput): RouteUrlObject` }, From 13156407bc446688925078fd1b544521359f32c5 Mon Sep 17 00:00:00 2001 From: Francesco Sardo Date: Sun, 6 Jun 2021 12:53:56 +0100 Subject: [PATCH 2/3] Enforce non null __parentModelId__ --- packages/generator/templates/page/__modelIdParam__.tsx | 4 ++-- packages/generator/templates/page/__modelIdParam__/edit.tsx | 4 ++-- packages/generator/templates/page/index.tsx | 4 ++-- packages/generator/templates/page/new.tsx | 2 +- .../src/stages/route-import-manifest/route-import-manifest.ts | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/generator/templates/page/__modelIdParam__.tsx b/packages/generator/templates/page/__modelIdParam__.tsx index 8465d98497..35105bfc41 100644 --- a/packages/generator/templates/page/__modelIdParam__.tsx +++ b/packages/generator/templates/page/__modelIdParam__.tsx @@ -8,7 +8,7 @@ export const __ModelName__ = () => { const router = useRouter() const __modelId__ = useParam("__modelId__", "number") if (process.env.parentModel) { - const __parentModelId__ = useParam("__parentModelId__", "number") + const __parentModelId__ = useParam("__parentModelId__", "number")! } const [delete__ModelName__Mutation] = useMutation(delete__ModelName__) const [__modelName__] = useQuery(get__ModelName__, {id: __modelId__} ) @@ -59,7 +59,7 @@ export const __ModelName__ = () => { const Show__ModelName__Page: BlitzPage = () => { if (process.env.parentModel) { - const __parentModelId__ = useParam("__parentModelId__", "number") + const __parentModelId__ = useParam("__parentModelId__", "number")! } return ( diff --git a/packages/generator/templates/page/__modelIdParam__/edit.tsx b/packages/generator/templates/page/__modelIdParam__/edit.tsx index 754f716e45..9f60ef0851 100644 --- a/packages/generator/templates/page/__modelIdParam__/edit.tsx +++ b/packages/generator/templates/page/__modelIdParam__/edit.tsx @@ -9,7 +9,7 @@ export const Edit__ModelName__ = () => { const router = useRouter() const __modelId__ = useParam("__modelId__", "number") if (process.env.parentModel) { - const __parentModelId__ = useParam("__parentModelId__", "number") + const __parentModelId__ = useParam("__parentModelId__", "number")! } const [__modelName__, {setQueryData}] = useQuery(get__ModelName__, {id: __modelId__}) const [update__ModelName__Mutation] = useMutation(update__ModelName__) @@ -58,7 +58,7 @@ export const Edit__ModelName__ = () => { const Edit__ModelName__Page: BlitzPage = () => { if (process.env.parentModel) { - const __parentModelId__ = useParam("__parentModelId__", "number") + const __parentModelId__ = useParam("__parentModelId__", "number")! } return ( diff --git a/packages/generator/templates/page/index.tsx b/packages/generator/templates/page/index.tsx index 28aa319fba..cd47940011 100644 --- a/packages/generator/templates/page/index.tsx +++ b/packages/generator/templates/page/index.tsx @@ -13,7 +13,7 @@ export const __ModelNames__List = () => { const router = useRouter() const page = Number(router.query.page) || 0 if (process.env.parentModel) { - const __parentModelId__ = useParam("__parentModelId__", "number") + const __parentModelId__ = useParam("__parentModelId__", "number")! const [{__modelNames__, hasMore}] = usePaginatedQuery(get__ModelNames__, { where: {__parentModel__: {id: __parentModelId__}}, orderBy: {id: "asc"}, @@ -88,7 +88,7 @@ export const __ModelNames__List = () => { const __ModelNames__Page: BlitzPage = () => { if (process.env.parentModel) { - const __parentModelId__ = useParam("__parentModelId__", "number") + const __parentModelId__ = useParam("__parentModelId__", "number")! } return ( diff --git a/packages/generator/templates/page/new.tsx b/packages/generator/templates/page/new.tsx index 92ba34a0d9..2e0a5361d1 100644 --- a/packages/generator/templates/page/new.tsx +++ b/packages/generator/templates/page/new.tsx @@ -10,7 +10,7 @@ import {__ModelName__Form, FORM_ERROR} from "app/__modelNamesPath__/components/_ const New__ModelName__Page: BlitzPage = () => { const router = useRouter() if (process.env.parentModel) { - const __parentModelId__ = useParam("__parentModelId__", "number") + const __parentModelId__ = useParam("__parentModelId__", "number")! } const [create__ModelName__Mutation] = useMutation(create__ModelName__) diff --git a/packages/server/src/stages/route-import-manifest/route-import-manifest.ts b/packages/server/src/stages/route-import-manifest/route-import-manifest.ts index 456693574d..95ae3c528a 100644 --- a/packages/server/src/stages/route-import-manifest/route-import-manifest.ts +++ b/packages/server/src/stages/route-import-manifest/route-import-manifest.ts @@ -67,10 +67,10 @@ export function generateManifest( return `${name}(query: { ${[ ...parameters.map( - (param) => param.name + (param.optional ? "?" : "") + ": string | number | undefined", + (param) => param.name + (param.optional ? "?" : "") + ": string | number", ), ...multipleParameters.map( - (param) => param.name + (param.optional ? "?" : "") + ": (string | number | undefined)[]", + (param) => param.name + (param.optional ? "?" : "") + ": (string | number)[]", ), ].join("; ")} } & ParsedUrlQueryInput): RouteUrlObject` }, From 15428a9ba94767c3f7890bd6d37c59b3fb7ef3bd Mon Sep 17 00:00:00 2001 From: Francesco Sardo Date: Sun, 6 Jun 2021 17:08:41 +0100 Subject: [PATCH 3/3] Move ! assertion to usage in Links --- packages/generator/templates/page/__modelIdParam__.tsx | 10 +++++----- .../generator/templates/page/__modelIdParam__/edit.tsx | 8 ++++---- packages/generator/templates/page/index.tsx | 10 +++++----- packages/generator/templates/page/new.tsx | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/generator/templates/page/__modelIdParam__.tsx b/packages/generator/templates/page/__modelIdParam__.tsx index 35105bfc41..0585d47edb 100644 --- a/packages/generator/templates/page/__modelIdParam__.tsx +++ b/packages/generator/templates/page/__modelIdParam__.tsx @@ -8,7 +8,7 @@ export const __ModelName__ = () => { const router = useRouter() const __modelId__ = useParam("__modelId__", "number") if (process.env.parentModel) { - const __parentModelId__ = useParam("__parentModelId__", "number")! + const __parentModelId__ = useParam("__parentModelId__", "number") } const [delete__ModelName__Mutation] = useMutation(delete__ModelName__) const [__modelName__] = useQuery(get__ModelName__, {id: __modelId__} ) @@ -25,7 +25,7 @@ export const __ModelName__ = () => { Edit @@ -42,7 +42,7 @@ export const __ModelName__ = () => { if (window.confirm("This will be deleted")) { await delete__ModelName__Mutation({id: __modelName__.id}) if (process.env.parentModel) { - router.push(Routes.__ModelNames__Page({ __parentModelId__ })) + router.push(Routes.__ModelNames__Page({ __parentModelId__: __parentModelId__! })) } else { router.push(Routes.__ModelNames__Page()) } @@ -59,14 +59,14 @@ export const __ModelName__ = () => { const Show__ModelName__Page: BlitzPage = () => { if (process.env.parentModel) { - const __parentModelId__ = useParam("__parentModelId__", "number")! + const __parentModelId__ = useParam("__parentModelId__", "number") } return (

- + __ModelNames__ diff --git a/packages/generator/templates/page/__modelIdParam__/edit.tsx b/packages/generator/templates/page/__modelIdParam__/edit.tsx index 9f60ef0851..4c80b563c8 100644 --- a/packages/generator/templates/page/__modelIdParam__/edit.tsx +++ b/packages/generator/templates/page/__modelIdParam__/edit.tsx @@ -9,7 +9,7 @@ export const Edit__ModelName__ = () => { const router = useRouter() const __modelId__ = useParam("__modelId__", "number") if (process.env.parentModel) { - const __parentModelId__ = useParam("__parentModelId__", "number")! + const __parentModelId__ = useParam("__parentModelId__", "number") } const [__modelName__, {setQueryData}] = useQuery(get__ModelName__, {id: __modelId__}) const [update__ModelName__Mutation] = useMutation(update__ModelName__) @@ -40,7 +40,7 @@ export const Edit__ModelName__ = () => { await setQueryData(updated) router.push( process.env.parentModel - ? Routes.Show__ModelName__Page({ __parentModelId__, __modelId__: updated.id }) + ? Routes.Show__ModelName__Page({ __parentModelId__: __parentModelId__!, __modelId__: updated.id }) : Routes.Show__ModelName__Page({ __modelId__: updated.id }), ) } catch (error) { @@ -58,7 +58,7 @@ export const Edit__ModelName__ = () => { const Edit__ModelName__Page: BlitzPage = () => { if (process.env.parentModel) { - const __parentModelId__ = useParam("__parentModelId__", "number")! + const __parentModelId__ = useParam("__parentModelId__", "number") } return ( @@ -69,7 +69,7 @@ const Edit__ModelName__Page: BlitzPage = () => {

- + __ModelNames__ diff --git a/packages/generator/templates/page/index.tsx b/packages/generator/templates/page/index.tsx index cd47940011..100ae133cb 100644 --- a/packages/generator/templates/page/index.tsx +++ b/packages/generator/templates/page/index.tsx @@ -13,9 +13,9 @@ export const __ModelNames__List = () => { const router = useRouter() const page = Number(router.query.page) || 0 if (process.env.parentModel) { - const __parentModelId__ = useParam("__parentModelId__", "number")! + const __parentModelId__ = useParam("__parentModelId__", "number") const [{__modelNames__, hasMore}] = usePaginatedQuery(get__ModelNames__, { - where: {__parentModel__: {id: __parentModelId__}}, + where: {__parentModel__: {id: __parentModelId__!}}, orderBy: {id: "asc"}, skip: ITEMS_PER_PAGE * page, take: ITEMS_PER_PAGE, @@ -62,7 +62,7 @@ export const __ModelNames__List = () => { {__modelNames__.map((__modelName__) => (

  • - + {__modelName__.name} @@ -88,7 +88,7 @@ export const __ModelNames__List = () => { const __ModelNames__Page: BlitzPage = () => { if (process.env.parentModel) { - const __parentModelId__ = useParam("__parentModelId__", "number")! + const __parentModelId__ = useParam("__parentModelId__", "number") } return ( @@ -100,7 +100,7 @@ const __ModelNames__Page: BlitzPage = () => {

    - + Create __ModelName__ diff --git a/packages/generator/templates/page/new.tsx b/packages/generator/templates/page/new.tsx index 2e0a5361d1..d6e24fbaad 100644 --- a/packages/generator/templates/page/new.tsx +++ b/packages/generator/templates/page/new.tsx @@ -10,7 +10,7 @@ import {__ModelName__Form, FORM_ERROR} from "app/__modelNamesPath__/components/_ const New__ModelName__Page: BlitzPage = () => { const router = useRouter() if (process.env.parentModel) { - const __parentModelId__ = useParam("__parentModelId__", "number")! + const __parentModelId__ = useParam("__parentModelId__", "number") } const [create__ModelName__Mutation] = useMutation(create__ModelName__) @@ -29,7 +29,7 @@ const New__ModelName__Page: BlitzPage = () => { try { const __modelName__ = await create__ModelName__Mutation( process.env.parentModel - ? {...values, __parentModelId__} + ? {...values, __parentModelId__: __parentModelId__!} : values, ) router.push( @@ -48,7 +48,7 @@ const New__ModelName__Page: BlitzPage = () => {

    - + __ModelNames__