From bd3ca68f591af0496661ae50abf395a8adc947ee Mon Sep 17 00:00:00 2001 From: Nicolas Vancea Date: Fri, 13 Oct 2023 13:30:07 +0200 Subject: [PATCH 1/3] Select first values from selects --- .../OpenApiSpecificationSelectorComponent.tsx | 18 +++++++++++++----- .../OpenApiSpecificationsComponent.tsx | 4 ++-- .../components/VersionSelectorComponent.tsx | 8 +++++++- src/lib/components/VersionsComponent.tsx | 8 +++++++- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/lib/components/OpenApiSpecificationSelectorComponent.tsx b/src/lib/components/OpenApiSpecificationSelectorComponent.tsx index 87e51959..d9f612ce 100644 --- a/src/lib/components/OpenApiSpecificationSelectorComponent.tsx +++ b/src/lib/components/OpenApiSpecificationSelectorComponent.tsx @@ -11,19 +11,27 @@ import { useForceUpdate } from "../utils/Hooks"; interface OpenApiSpecificationSelectorComponentProps { openApiSpecifications: IOpenApiSpecification[]; - openAPISpecification?: string; + openAPISpecification?: string; + versionName: string; + projectName: string; } const OpenApiSpecificationSelectorComponent: React.FC< OpenApiSpecificationSelectorComponentProps -> = ({ openApiSpecifications, openAPISpecification }) => { +> = ({ openApiSpecifications, openAPISpecification, projectName, versionName }) => { const router = useRouter(); + const firstOpenAPISpecification = openApiSpecifications[0]; + if ( + (!openAPISpecification || openAPISpecification.length == 0) && + firstOpenAPISpecification + ) { + router.push( + `/${projectName}/${versionName}/${firstOpenAPISpecification.name}` + ); + } const handleVersionChange = (event: SelectChangeEvent) => { const openApiSpecificationName = event.target.value; - const openApiSpecification = openApiSpecifications.find( - (x) => x.name === openApiSpecificationName - ); router.push(`/${getProject()}/${getVersion()}/${openApiSpecificationName}`); }; diff --git a/src/lib/components/OpenApiSpecificationsComponent.tsx b/src/lib/components/OpenApiSpecificationsComponent.tsx index 17d357a9..26f1ef8e 100644 --- a/src/lib/components/OpenApiSpecificationsComponent.tsx +++ b/src/lib/components/OpenApiSpecificationsComponent.tsx @@ -6,7 +6,6 @@ import OpenApiSpecificationSelectorComponent from "./OpenApiSpecificationSelecto interface OpenApiSpecificationsComponentProps { versionName: string; projectName: string; - user: IUser; openApiSpecificationRepository: IOpenApiSpecificationRepository; specificationName?: string; } @@ -16,7 +15,6 @@ const OpenApiSpecificationsComponent: React.FC< > = async ({ versionName, openApiSpecificationRepository, - user, projectName, specificationName, }) => { @@ -31,6 +29,8 @@ const OpenApiSpecificationsComponent: React.FC< ); }; diff --git a/src/lib/components/VersionSelectorComponent.tsx b/src/lib/components/VersionSelectorComponent.tsx index 0cd08922..e616bfa5 100644 --- a/src/lib/components/VersionSelectorComponent.tsx +++ b/src/lib/components/VersionSelectorComponent.tsx @@ -12,13 +12,19 @@ import { useRouter } from "next/navigation"; interface VersionSelectorComponentProps { versions: IVersion[]; version?: string; + projectName: string; } const VersionSelectorComponent: React.FC = ({ versions, - version + version, + projectName }) => { const router = useRouter(); + const firstVersion = versions[0]; + if ((!version || version.length == 0) && firstVersion) { + router.push(`/${projectName}/${firstVersion.name}`); + } const handleVersionChange = (event: SelectChangeEvent) => { const versionName = event.target.value; diff --git a/src/lib/components/VersionsComponent.tsx b/src/lib/components/VersionsComponent.tsx index 05690d13..a62b2d58 100644 --- a/src/lib/components/VersionsComponent.tsx +++ b/src/lib/components/VersionsComponent.tsx @@ -22,7 +22,13 @@ const VersionsComponent: React.FC = async ({ owner: "shapehq", } as IGitHubProject); - return ; + return ( + + ); }; export default VersionsComponent; From 5aaf1c2af9a9d6442f796165b0007b434ae2d633 Mon Sep 17 00:00:00 2001 From: Nicolas Vancea Date: Fri, 13 Oct 2023 13:33:52 +0200 Subject: [PATCH 2/3] Add ref when fetching files --- src/lib/projects/GitHubOpenAPISpecificationRepository.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/projects/GitHubOpenAPISpecificationRepository.ts b/src/lib/projects/GitHubOpenAPISpecificationRepository.ts index 6fe40a8b..f6c1214e 100644 --- a/src/lib/projects/GitHubOpenAPISpecificationRepository.ts +++ b/src/lib/projects/GitHubOpenAPISpecificationRepository.ts @@ -12,7 +12,7 @@ export class GitHubOpenApiSpecificationRepository implements IOpenApiSpecificati } async getOpenAPISpecifications(version: IGitHubVersion): Promise { - const content = await this.gitHubClient.getContent(version.owner, version.repository) + const content = await this.gitHubClient.getContent(version.owner, version.repository, version.name) return content.filter(e => { return this.isOpenAPISpecification(e.name) }) From 0a4e30612ce7c9768f9b90afd871ff5eba9c2066 Mon Sep 17 00:00:00 2001 From: Nicolas Vancea Date: Fri, 13 Oct 2023 13:37:31 +0200 Subject: [PATCH 3/3] Fix build --- src/app/[...slug]/page.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/[...slug]/page.tsx b/src/app/[...slug]/page.tsx index a1597e60..332c42d1 100644 --- a/src/app/[...slug]/page.tsx +++ b/src/app/[...slug]/page.tsx @@ -76,7 +76,6 @@ export default async function Page({ projectName={projectName} versionName={versionName} specificationName={specificationName} - user={user} /> ), }