Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[legacy-framework] Fix Routes manifest for pages with parent & child relationships (patch) #2424

Merged
merged 5 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/generator/templates/page/__modelIdParam__.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const __ModelName__ = () => {

<if condition="parentModel">
<Link
href={Routes.Edit__ModelName__Page({ __parentModelId__, __modelId__: __modelName__.id })}
href={Routes.Edit__ModelName__Page({ __parentModelId__: __parentModelId__!, __modelId__: __modelName__.id })}
>
<a>Edit</a>
</Link>
Expand All @@ -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())
}
Expand All @@ -66,7 +66,7 @@ const Show__ModelName__Page: BlitzPage = () => {
<div>
<p>
<if condition="parentModel">
<Link href={Routes.__ModelNames__Page({ __parentModelId__ })}>
<Link href={Routes.__ModelNames__Page({ __parentModelId__: __parentModelId__! })}>
<a>__ModelNames__</a>
</Link>
<else>
Expand Down
4 changes: 2 additions & 2 deletions packages/generator/templates/page/__modelIdParam__/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -69,7 +69,7 @@ const Edit__ModelName__Page: BlitzPage = () => {

<p>
<if condition="parentModel">
<Link href={Routes.__ModelNames__Page({ __parentModelId__ })}>
<Link href={Routes.__ModelNames__Page({ __parentModelId__: __parentModelId__! })}>
<a>__ModelNames__</a>
</Link>
<else>
Expand Down
17 changes: 12 additions & 5 deletions packages/generator/templates/page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const __ModelNames__List = () => {
if (process.env.parentModel) {
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,
Expand Down Expand Up @@ -61,9 +61,16 @@ export const __ModelNames__List = () => {
<ul>
{__modelNames__.map((__modelName__) => (
<li key={__modelName__.id}>
<Link href={Routes.Show__ModelName__Page({ __modelId__: __modelName__.id })}>
<a>{__modelName__.name}</a>
</Link>
<if condition="parentModel">
<Link href={Routes.Show__ModelName__Page({ __parentModelId__: __parentModelId__!, __modelId__: __modelName__.id })}>
<a>{__modelName__.name}</a>
</Link>
<else>
<Link href={Routes.Show__ModelName__Page({ __modelId__: __modelName__.id })}>
<a>{__modelName__.name}</a>
</Link>
</else>
</if>
</li>
))}
</ul>
Expand Down Expand Up @@ -93,7 +100,7 @@ const __ModelNames__Page: BlitzPage = () => {
<div>
<p>
<if condition="parentModel">
<Link href={Routes.New__ModelName__Page({ __parentModelId__ })}>
<Link href={Routes.New__ModelName__Page({ __parentModelId__: __parentModelId__! })}>
<a>Create __ModelName__</a>
</Link>
<else>
Expand Down
4 changes: 2 additions & 2 deletions packages/generator/templates/page/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -48,7 +48,7 @@ const New__ModelName__Page: BlitzPage = () => {

<p>
<if condition="parentModel">
<Link href={Routes.__ModelNames__Page({ __parentModelId__ })}>
<Link href={Routes.__ModelNames__Page({ __parentModelId__: __parentModelId__! })}>
<a>__ModelNames__</a>
</Link>
<else>
Expand Down