From 7d2121bca4ba5996c17db5de067e28bf9802f30f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=B8vring?= Date: Tue, 10 Sep 2024 09:44:11 +0200 Subject: [PATCH 1/5] Removes defaultTitle from updateWindowTitle --- __test__/projects/updateWindowTitle.test.ts | 12 ------------ src/app/(authed)/(home)/[...slug]/page.tsx | 8 ++++---- src/features/projects/domain/updateWindowTitle.ts | 12 +++--------- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/__test__/projects/updateWindowTitle.test.ts b/__test__/projects/updateWindowTitle.test.ts index 86509b38..87df773c 100644 --- a/__test__/projects/updateWindowTitle.test.ts +++ b/__test__/projects/updateWindowTitle.test.ts @@ -1,19 +1,9 @@ import { updateWindowTitle } from "@/features/projects/domain" -test("It uses default title when there is no selection", async () => { - const store: { title: string } = { title: "" } - updateWindowTitle({ - storage: store, - defaultTitle: "Demo Docs" - }) - expect(store.title).toEqual("Demo Docs") -}) - test("It leaves out specification when the specification has a generic name", async () => { const store: { title: string } = { title: "" } updateWindowTitle({ storage: store, - defaultTitle: "Demo Docs", project: { id: "foo", name: "foo", @@ -49,7 +39,6 @@ test("It leaves out version when it is the defualt version", async () => { const store: { title: string } = { title: "" } updateWindowTitle({ storage: store, - defaultTitle: "Demo Docs", project: { id: "foo", name: "foo", @@ -81,7 +70,6 @@ test("It adds version when it is not the defualt version", async () => { const store: { title: string } = { title: "" } updateWindowTitle({ storage: store, - defaultTitle: "Demo Docs", project: { id: "foo", name: "foo", diff --git a/src/app/(authed)/(home)/[...slug]/page.tsx b/src/app/(authed)/(home)/[...slug]/page.tsx index bc605617..7e2635e4 100644 --- a/src/app/(authed)/(home)/[...slug]/page.tsx +++ b/src/app/(authed)/(home)/[...slug]/page.tsx @@ -12,17 +12,17 @@ export default function Page() { useEffect(() => { navigateToSelectionIfNeeded() }, [project, version, specification, navigateToSelectionIfNeeded]) - // Update the window title to match selected project. - const siteName = process.env.NEXT_PUBLIC_FRAMNA_DOCS_TITLE || "" useEffect(() => { + if (!project) { + return + } updateWindowTitle({ storage: document, - defaultTitle: siteName, project, version, specification }) - }, [siteName, project, version, specification]) + }, [project, version, specification]) return ( <> {project && version && specification && diff --git a/src/features/projects/domain/updateWindowTitle.ts b/src/features/projects/domain/updateWindowTitle.ts index 3f239c03..a29e39fd 100644 --- a/src/features/projects/domain/updateWindowTitle.ts +++ b/src/features/projects/domain/updateWindowTitle.ts @@ -4,24 +4,18 @@ import OpenApiSpecification from "./OpenApiSpecification" export default function updateWindowTitle({ storage, - defaultTitle, project, version, specification, }: { storage: { title: string }, - defaultTitle: string, - project?: Project, + project: Project, version?: Version, specification?: OpenApiSpecification }) { - if (!project || !version || !specification) { - storage.title = defaultTitle - return - } - if (!isSpecificationNameGeneric(specification.name)) { + if (version && specification && !isSpecificationNameGeneric(specification.name)) { storage.title = `${project.displayName} / ${version.name} / ${specification.name}` - } else if (!version.isDefault) { + } else if (version && !version.isDefault) { storage.title = `${project.displayName} / ${version.name}` } else { storage.title = project.displayName From be97f01dc2784c88258432aeb60ed5eb93103a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=B8vring?= Date: Tue, 10 Sep 2024 09:57:19 +0200 Subject: [PATCH 2/5] Reads NEXT_PUBLIC_FRAMNA_DOCS_TITLE on server-side --- src/features/sidebar/view/SplitView.tsx | 6 +++++- src/features/sidebar/view/internal/sidebar/Header.tsx | 3 +-- src/features/sidebar/view/internal/sidebar/Sidebar.tsx | 10 ++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/features/sidebar/view/SplitView.tsx b/src/features/sidebar/view/SplitView.tsx index 3f2387c4..eeb97921 100644 --- a/src/features/sidebar/view/SplitView.tsx +++ b/src/features/sidebar/view/SplitView.tsx @@ -2,6 +2,9 @@ import ClientSplitView from "./internal/ClientSplitView" import { projectDataSource } from "@/composition" import BaseSidebar from "./internal/sidebar/Sidebar" import ProjectList from "./internal/sidebar/projects/ProjectList" +import { env } from "@/common" + +const SITE_NAME = env.getOrThrow("NEXT_PUBLIC_FRAMNA_DOCS_TITLE") const SplitView = ({ children }: { children?: React.ReactNode }) => { return ( @@ -15,7 +18,8 @@ export default SplitView const Sidebar = () => { return ( - + // The site name is passed as a property to ensure the environment variable is read server-side. + ) diff --git a/src/features/sidebar/view/internal/sidebar/Header.tsx b/src/features/sidebar/view/internal/sidebar/Header.tsx index 6311ddae..59c425a7 100644 --- a/src/features/sidebar/view/internal/sidebar/Header.tsx +++ b/src/features/sidebar/view/internal/sidebar/Header.tsx @@ -5,8 +5,7 @@ import { Box, Button, Typography } from "@mui/material" import { useRouter } from "next/navigation" import { useCloseSidebarOnSelection } from "@/features/sidebar/data" -const Header = () => { - const siteName = process.env.NEXT_PUBLIC_FRAMNA_DOCS_TITLE +const Header = ({ siteName }: { siteName?: string }) => { const router = useRouter() const { closeSidebarIfNeeded } = useCloseSidebarOnSelection() return ( diff --git a/src/features/sidebar/view/internal/sidebar/Sidebar.tsx b/src/features/sidebar/view/internal/sidebar/Sidebar.tsx index 00f16add..a5f39481 100644 --- a/src/features/sidebar/view/internal/sidebar/Sidebar.tsx +++ b/src/features/sidebar/view/internal/sidebar/Sidebar.tsx @@ -7,7 +7,13 @@ import UserButton from "./user/UserButton" import SettingsList from "./settings/SettingsList" import NewProjectButton from "./NewProjectButton" -const Sidebar = ({ children }: { children?: React.ReactNode }) => { +const Sidebar = ({ + siteName, + children +}: { + siteName?: string + children?: React.ReactNode +}) => { const [isScrolledToTop, setScrolledToTop] = useState(true) const [isScrolledToBottom, setScrolledToBottom] = useState(true) const scrollableAreaRef = useRef(null) @@ -32,7 +38,7 @@ const Sidebar = ({ children }: { children?: React.ReactNode }) => { }, []) return ( <> -
+
Date: Tue, 10 Sep 2024 09:59:28 +0200 Subject: [PATCH 3/5] Reads NEXT_PUBLIC_FRAMNA_DOCS_HELP_URL from server-side --- src/features/sidebar/view/SplitView.tsx | 5 +++-- src/features/sidebar/view/internal/sidebar/Sidebar.tsx | 4 +++- .../sidebar/view/internal/sidebar/settings/SettingsList.tsx | 3 +-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/features/sidebar/view/SplitView.tsx b/src/features/sidebar/view/SplitView.tsx index eeb97921..65207b91 100644 --- a/src/features/sidebar/view/SplitView.tsx +++ b/src/features/sidebar/view/SplitView.tsx @@ -5,6 +5,7 @@ import ProjectList from "./internal/sidebar/projects/ProjectList" import { env } from "@/common" const SITE_NAME = env.getOrThrow("NEXT_PUBLIC_FRAMNA_DOCS_TITLE") +const HELP_URL = env.get("NEXT_PUBLIC_FRAMNA_DOCS_HELP_URL") const SplitView = ({ children }: { children?: React.ReactNode }) => { return ( @@ -18,8 +19,8 @@ export default SplitView const Sidebar = () => { return ( - // The site name is passed as a property to ensure the environment variable is read server-side. - + // The site name and help URL are passed as a properties to ensure the environment variables are read server-side. + ) diff --git a/src/features/sidebar/view/internal/sidebar/Sidebar.tsx b/src/features/sidebar/view/internal/sidebar/Sidebar.tsx index a5f39481..0dc8b2b8 100644 --- a/src/features/sidebar/view/internal/sidebar/Sidebar.tsx +++ b/src/features/sidebar/view/internal/sidebar/Sidebar.tsx @@ -9,9 +9,11 @@ import NewProjectButton from "./NewProjectButton" const Sidebar = ({ siteName, + helpURL, children }: { siteName?: string + helpURL?: string children?: React.ReactNode }) => { const [isScrolledToTop, setScrolledToTop] = useState(true) @@ -83,7 +85,7 @@ const Sidebar = ({ /> - + ) diff --git a/src/features/sidebar/view/internal/sidebar/settings/SettingsList.tsx b/src/features/sidebar/view/internal/sidebar/settings/SettingsList.tsx index 5486ab7f..09046656 100644 --- a/src/features/sidebar/view/internal/sidebar/settings/SettingsList.tsx +++ b/src/features/sidebar/view/internal/sidebar/settings/SettingsList.tsx @@ -31,8 +31,7 @@ const SettingsItem = ({ onClick, icon, children }: { ) } -const SettingsList = () => { - const helpURL = process.env.NEXT_PUBLIC_FRAMNA_DOCS_HELP_URL +const SettingsList = ({ helpURL }: { helpURL?: string }) => { return ( Date: Tue, 10 Sep 2024 10:01:12 +0200 Subject: [PATCH 4/5] Removes NEXT_PUBLIC_ from environment variables --- .env.example | 6 +++--- src/app/(authed)/(home)/(welcome)/page.tsx | 2 +- src/app/(authed)/(home)/new/page.tsx | 2 +- src/app/auth/signin/page.tsx | 4 ++-- src/app/layout.tsx | 4 ++-- src/composition.ts | 2 +- src/features/sidebar/view/SplitView.tsx | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.env.example b/.env.example index 27d200ff..664e6d27 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,8 @@ FRAMNA_DOCS_BASE_URL=http://localhost:3000 FRAMNA_DOCS_PROJECT_CONFIGURATION_FILENAME=.shape-docs.yml -NEXT_PUBLIC_FRAMNA_DOCS_TITLE=Framna Docs -NEXT_PUBLIC_FRAMNA_DOCS_DESCRIPTION=Documentation for Framna's APIs -NEXT_PUBLIC_FRAMNA_DOCS_HELP_URL=https://github.com/shapehq/framna-docs/wiki +FRAMNA_DOCS_TITLE=Framna Docs +FRAMNA_DOCS_DESCRIPTION=Documentation for Framna's APIs +FRAMNA_DOCS_HELP_URL=https://github.com/shapehq/framna-docs/wiki NEXTAUTH_URL_INTERNAL=http://localhost:3000 NEXTAUTH_SECRET=use [openssl rand -base64 32] to generate a 32 bytes value REDIS_URL=localhost diff --git a/src/app/(authed)/(home)/(welcome)/page.tsx b/src/app/(authed)/(home)/(welcome)/page.tsx index 2400dcb8..bd421cb3 100644 --- a/src/app/(authed)/(home)/(welcome)/page.tsx +++ b/src/app/(authed)/(home)/(welcome)/page.tsx @@ -2,7 +2,7 @@ import { Box, Typography } from "@mui/material" import { grey } from "@mui/material/colors" import { env } from "@/common" -const SITE_NAME = env.getOrThrow("NEXT_PUBLIC_FRAMNA_DOCS_TITLE") +const SITE_NAME = env.getOrThrow("FRAMNA_DOCS_TITLE") const Page = () => { return ( diff --git a/src/app/(authed)/(home)/new/page.tsx b/src/app/(authed)/(home)/new/page.tsx index 8c9dfc2b..c8359ee3 100644 --- a/src/app/(authed)/(home)/new/page.tsx +++ b/src/app/(authed)/(home)/new/page.tsx @@ -3,7 +3,7 @@ import NewProjectSteps from "@/features/new-project/view/NewProjectSteps" import { env, splitOwnerAndRepository } from "@/common" import MessageLinkFooter from "@/common/ui/MessageLinkFooter" -const HELP_URL = env.get("NEXT_PUBLIC_FRAMNA_DOCS_HELP_URL") +const HELP_URL = env.get("FRAMNA_DOCS_HELP_URL") const Page = () => { const repositoryNameSuffix = env.getOrThrow("REPOSITORY_NAME_SUFFIX") diff --git a/src/app/auth/signin/page.tsx b/src/app/auth/signin/page.tsx index 72a4926d..bc7788c9 100644 --- a/src/app/auth/signin/page.tsx +++ b/src/app/auth/signin/page.tsx @@ -7,8 +7,8 @@ import { faGithub } from "@fortawesome/free-brands-svg-icons" import SignInTexts from "@/features/auth/view/SignInTexts" import MessageLinkFooter from "@/common/ui/MessageLinkFooter" -const SITE_NAME = env.getOrThrow("NEXT_PUBLIC_FRAMNA_DOCS_TITLE") -const HELP_URL = env.get("NEXT_PUBLIC_FRAMNA_DOCS_HELP_URL") +const SITE_NAME = env.getOrThrow("FRAMNA_DOCS_TITLE") +const HELP_URL = env.get("FRAMNA_DOCS_HELP_URL") export default async function SignInPage() { return ( diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 2d39c968..9769fd6b 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -9,8 +9,8 @@ import { env } from "@/common" fontAwesomeConfig.autoAddCss = false export const metadata: Metadata = { - title: env.getOrThrow("NEXT_PUBLIC_FRAMNA_DOCS_TITLE"), - description: env.getOrThrow("NEXT_PUBLIC_FRAMNA_DOCS_DESCRIPTION") + title: env.getOrThrow("FRAMNA_DOCS_TITLE"), + description: env.getOrThrow("FRAMNA_DOCS_DESCRIPTION") } export default function RootLayout({ children }: { children: React.ReactNode }) { diff --git a/src/composition.ts b/src/composition.ts index 3e15ab76..7ab23475 100644 --- a/src/composition.ts +++ b/src/composition.ts @@ -194,7 +194,7 @@ export const gitHubHookHandler = new GitHubHookHandler({ }), eventHandler: new PostCommentPullRequestEventHandler({ pullRequestCommenter: new PullRequestCommenter({ - siteName: env.getOrThrow("NEXT_PUBLIC_FRAMNA_DOCS_TITLE"), + siteName: env.getOrThrow("FRAMNA_DOCS_TITLE"), domain: env.getOrThrow("FRAMNA_DOCS_BASE_URL"), repositoryNameSuffix: env.getOrThrow("REPOSITORY_NAME_SUFFIX"), projectConfigurationFilename: env.getOrThrow("FRAMNA_DOCS_PROJECT_CONFIGURATION_FILENAME"), diff --git a/src/features/sidebar/view/SplitView.tsx b/src/features/sidebar/view/SplitView.tsx index 65207b91..e179c6ff 100644 --- a/src/features/sidebar/view/SplitView.tsx +++ b/src/features/sidebar/view/SplitView.tsx @@ -4,8 +4,8 @@ import BaseSidebar from "./internal/sidebar/Sidebar" import ProjectList from "./internal/sidebar/projects/ProjectList" import { env } from "@/common" -const SITE_NAME = env.getOrThrow("NEXT_PUBLIC_FRAMNA_DOCS_TITLE") -const HELP_URL = env.get("NEXT_PUBLIC_FRAMNA_DOCS_HELP_URL") +const SITE_NAME = env.getOrThrow("FRAMNA_DOCS_TITLE") +const HELP_URL = env.get("FRAMNA_DOCS_HELP_URL") const SplitView = ({ children }: { children?: React.ReactNode }) => { return ( From 0bb70db54c603ec5fa61880116504d4c3dc889a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=B8vring?= Date: Tue, 10 Sep 2024 10:12:24 +0200 Subject: [PATCH 5/5] Reorders variables --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 664e6d27..a46cd461 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,8 @@ FRAMNA_DOCS_BASE_URL=http://localhost:3000 -FRAMNA_DOCS_PROJECT_CONFIGURATION_FILENAME=.shape-docs.yml FRAMNA_DOCS_TITLE=Framna Docs FRAMNA_DOCS_DESCRIPTION=Documentation for Framna's APIs FRAMNA_DOCS_HELP_URL=https://github.com/shapehq/framna-docs/wiki +FRAMNA_DOCS_PROJECT_CONFIGURATION_FILENAME=.shape-docs.yml NEXTAUTH_URL_INTERNAL=http://localhost:3000 NEXTAUTH_SECRET=use [openssl rand -base64 32] to generate a 32 bytes value REDIS_URL=localhost