From 6f4bab98c1922e1c20282a580bb30e282e87ca08 Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Tue, 23 Jan 2024 00:17:24 +0100 Subject: [PATCH 1/2] Made client/[name] generate static pages --- pkgs/ui/next.config.js | 7 +++++++ pkgs/ui/nix/foverrides.nix | 1 + pkgs/ui/shell.nix | 7 ++++--- pkgs/ui/src/app/client/[name]/page.tsx | 21 +++++++++++++++++++ .../{[client_name]/page.tsx => client.tsx} | 10 +++------ pkgs/ui/src/components/sidebar/index.tsx | 4 ++-- pkgs/ui/tsconfig.json | 8 ++++++- 7 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 pkgs/ui/src/app/client/[name]/page.tsx rename pkgs/ui/src/app/client/{[client_name]/page.tsx => client.tsx} (97%) diff --git a/pkgs/ui/next.config.js b/pkgs/ui/next.config.js index 5b2d829..c1904cb 100644 --- a/pkgs/ui/next.config.js +++ b/pkgs/ui/next.config.js @@ -2,9 +2,16 @@ const nextConfig = { output: "export", images: { unoptimized: true }, + distDir: "build", eslint: { dirs: ["src"], }, + generateBuildId: async () => { + // This could be anything, using the latest git hash + return process.env.NEXT_BUILD_ID; + }, + outputFileTracing: true, + reactStrictMode: true, }; module.exports = nextConfig; diff --git a/pkgs/ui/nix/foverrides.nix b/pkgs/ui/nix/foverrides.nix index 5fb91a3..f9356d8 100644 --- a/pkgs/ui/nix/foverrides.nix +++ b/pkgs/ui/nix/foverrides.nix @@ -70,6 +70,7 @@ in # nextjs chaches some stuff in $HOME built.override.preBuild = '' export HOME=./home + export NEXT_BUILD_ID=$(git log -1 --pretty=format:"%H") echo "----------- GENERATE API TS ------------" diff --git a/pkgs/ui/shell.nix b/pkgs/ui/shell.nix index 44f89ea..6c265bc 100644 --- a/pkgs/ui/shell.nix +++ b/pkgs/ui/shell.nix @@ -8,7 +8,7 @@ pkgs.mkShell { fmod.config.floco.settings.nodePackage ]; shellHook = '' - ID=${pkg.built.tree} + export ID=${pkg.built.tree} currID=$(cat .floco/.node_modules_id 2> /dev/null) mkdir -p .floco @@ -22,10 +22,11 @@ pkgs.mkShell { ln -sf ${pkgs.roboto}/share/fonts ./src export PATH="$PATH:$(realpath ./node_modules)/.bin" - + export NEXT_BUILD_ID=$(git log -1 --pretty=format:"%H") # re-generate the api code - rm -rf src/api openapi.json + rm -f openapi.json + rm -rf src/api cp ${clanPkgs.clan-openapi}/openapi.json . orval ''; diff --git a/pkgs/ui/src/app/client/[name]/page.tsx b/pkgs/ui/src/app/client/[name]/page.tsx new file mode 100644 index 0000000..1068f34 --- /dev/null +++ b/pkgs/ui/src/app/client/[name]/page.tsx @@ -0,0 +1,21 @@ +import Client from "@/app/client/client"; +import { menuEntityEntries } from "@/components/sidebar"; + +export const dynamic = "error"; +export const dynamicParams = false; +/* +The generateStaticParams function can be used in combination with dynamic route segments +to statically generate routes at build time instead of on-demand at request time. +During next dev, generateStaticParams will be called when you navigate to a route. +During next build, generateStaticParams runs before the corresponding Layouts or Pages are generated. +https://nextjs.org/docs/app/api-reference/functions/generate-static-params +*/ +export function generateStaticParams() { + return menuEntityEntries.map((entry) => ({ + name: entry.label, + })); +} + +export default function Page({ params }: { params: { name: string } }) { + return ; +} diff --git a/pkgs/ui/src/app/client/[client_name]/page.tsx b/pkgs/ui/src/app/client/client.tsx similarity index 97% rename from pkgs/ui/src/app/client/[client_name]/page.tsx rename to pkgs/ui/src/app/client/client.tsx index 3e75111..c412d73 100644 --- a/pkgs/ui/src/app/client/[client_name]/page.tsx +++ b/pkgs/ui/src/app/client/client.tsx @@ -105,14 +105,10 @@ const AttachButton = ({ ); }; -export default function Client({ - params, -}: { - params: { client_name: string }; -}) { - const { client_name } = params; +export default function Client({ params }: { params: { name: string } }) { + const { name } = params; - const { entity: entity } = useGetEntityByNameOrDid(client_name); + const { entity: entity } = useGetEntityByNameOrDid(name); const { data: services, isLoading: services_loading, diff --git a/pkgs/ui/src/components/sidebar/index.tsx b/pkgs/ui/src/components/sidebar/index.tsx index 685930b..55bb214 100644 --- a/pkgs/ui/src/components/sidebar/index.tsx +++ b/pkgs/ui/src/components/sidebar/index.tsx @@ -33,7 +33,7 @@ type MenuEntry = { subMenuEntries?: MenuEntry[]; }; -const menuEntityEntries: MenuEntry[] = [ +export const menuEntityEntries: MenuEntry[] = [ { icon: , label: "C1", @@ -60,7 +60,7 @@ const menuEntityEntries: MenuEntry[] = [ }, ]; -const menuEntries: MenuEntry[] = [ +export const menuEntries: MenuEntry[] = [ { icon: , label: "Home", diff --git a/pkgs/ui/tsconfig.json b/pkgs/ui/tsconfig.json index ebe4baa..e0d506e 100644 --- a/pkgs/ui/tsconfig.json +++ b/pkgs/ui/tsconfig.json @@ -25,6 +25,12 @@ "@API/*": ["./src/api/*"] } }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], + "include": [ + "next-env.d.ts", + "**/*.ts", + "**/*.tsx", + ".next/types/**/*.ts", + "build/types/**/*.ts" + ], "exclude": ["node_modules"] } -- 2.51.0 From 2fb2a1d22a69fda067974552b2bad7ce71617e36 Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Tue, 23 Jan 2024 12:17:29 +0100 Subject: [PATCH 2/2] Fixed ui openapi.json bug. Reverted buildDir settings --- .gitea/workflows/ui_assets.yaml | 3 ++- pkgs/ui/next.config.js | 1 - pkgs/ui/shell.nix | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/ui_assets.yaml b/.gitea/workflows/ui_assets.yaml index d4e1088..2b81123 100644 --- a/.gitea/workflows/ui_assets.yaml +++ b/.gitea/workflows/ui_assets.yaml @@ -58,7 +58,8 @@ jobs: git commit -am "update ui-assets.nix" echo "Current branch: $GITHUB_REF_NAME" - git push origin HEAD:$GITHUB_REF_NAME + git push origin HEAD:"$GITHUB_REF_NAME" + echo "Done uploading" fi else echo "No UI files changed. Skipping asset build and push" diff --git a/pkgs/ui/next.config.js b/pkgs/ui/next.config.js index c1904cb..316bb41 100644 --- a/pkgs/ui/next.config.js +++ b/pkgs/ui/next.config.js @@ -2,7 +2,6 @@ const nextConfig = { output: "export", images: { unoptimized: true }, - distDir: "build", eslint: { dirs: ["src"], }, diff --git a/pkgs/ui/shell.nix b/pkgs/ui/shell.nix index 6c265bc..5de28bc 100644 --- a/pkgs/ui/shell.nix +++ b/pkgs/ui/shell.nix @@ -25,7 +25,7 @@ pkgs.mkShell { export NEXT_BUILD_ID=$(git log -1 --pretty=format:"%H") # re-generate the api code - rm -f openapi.json + rm -f --interactive=never openapi.json rm -rf src/api cp ${clanPkgs.clan-openapi}/openapi.json . orval -- 2.51.0