-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(template): use env var for cicd template check
refs #477
- Loading branch information
1 parent
38122c7
commit 6578c4d
Showing
15 changed files
with
94 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 11 additions & 13 deletions
24
apps/deploy-web/src/lib/nextjs/getValidatedServerSIdeProps.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
import { GetServerSidePropsContext, GetServerSidePropsResult, PreviewData } from "next/types"; | ||
import { GetServerSidePropsContext, GetServerSidePropsResult } from "next/types"; | ||
import type { ParsedUrlQuery } from "querystring"; | ||
import { z } from "zod"; | ||
|
||
export const getValidatedServerSideProps = < | ||
Props extends { [key: string]: any } = { [key: string]: any }, | ||
Params extends ParsedUrlQuery = ParsedUrlQuery, | ||
Preview extends PreviewData = PreviewData, | ||
Schema extends z.ZodObject<any, any, any> = z.ZodObject<{ params: z.ZodObject<any, any, any> }, any, any> | ||
>( | ||
type ContextParamsSchema = z.ZodObject<Record<string, z.ZodString | z.ZodNumber | z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodNumber>>>; | ||
|
||
type ContextSchema = z.ZodObject<{ params?: ContextParamsSchema; query?: ContextParamsSchema }>; | ||
|
||
export const getValidatedServerSideProps = <Props extends { [key: string]: any }, Schema extends ContextSchema = ContextSchema>( | ||
schema: Schema, | ||
handler: ( | ||
context: Omit<GetServerSidePropsContext<Params, Preview>, "params"> & { params: z.infer<Schema>["params"] } | ||
) => Promise<GetServerSidePropsResult<Props>> | ||
): ((context: GetServerSidePropsContext<Params, Preview>) => Promise<GetServerSidePropsResult<Props>>) => { | ||
handler: (context: Omit<GetServerSidePropsContext, "params" | "query"> & z.infer<Schema>) => Promise<GetServerSidePropsResult<Props>> | ||
): ((context: GetServerSidePropsContext<ParsedUrlQuery>) => Promise<GetServerSidePropsResult<Props>>) => { | ||
return context => { | ||
const { params } = schema.parse(context); | ||
return handler({ ...context, params }); | ||
const validated = schema.parse(context); | ||
|
||
return handler({ ...context, ...validated }); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { NewDeploymentContainer } from "@src/components/new-deployment/NewDeploymentContainer"; | ||
import { withSdlBuilder } from "@src/context/SdlBuilderProvider/SdlBuilderProvider"; | ||
import { getServerSideProps } from "../new-deployment"; | ||
|
||
export default withSdlBuilder({ | ||
componentsSet: "ssh", | ||
imageSource: "ssh-vms" | ||
})(NewDeploymentContainer); | ||
|
||
export { getServerSideProps }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,28 @@ | ||
import { NewDeploymentContainer } from "@src/components/new-deployment/NewDeploymentContainer"; | ||
import { z } from "zod"; | ||
|
||
import { NewDeploymentContainer, NewDeploymentContainerProps } from "@src/components/new-deployment/NewDeploymentContainer"; | ||
import { withSdlBuilder } from "@src/context/SdlBuilderProvider/SdlBuilderProvider"; | ||
import { getValidatedServerSideProps } from "@src/lib/nextjs/getValidatedServerSIdeProps"; | ||
import { services } from "@src/services/http/http-server.service"; | ||
|
||
export default withSdlBuilder()(NewDeploymentContainer); | ||
|
||
const contextSchema = z.object({ | ||
query: z.object({ | ||
templateId: z.string().optional() | ||
}) | ||
}); | ||
|
||
export const getServerSideProps = getValidatedServerSideProps<NewDeploymentContainerProps, typeof contextSchema>(contextSchema, async ({ query }) => { | ||
if (!query.templateId) { | ||
return { props: {} }; | ||
} | ||
|
||
const template = await services.template.findById(query.templateId); | ||
|
||
if (template && query.templateId) { | ||
return { props: { template, templateId: query.templateId } }; | ||
} | ||
|
||
return { props: {} }; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.