From f190310809c2690079c260aee3f54e0e1b066a9d Mon Sep 17 00:00:00 2001 From: Bjarke Madsen <bjarke@nordu.net> Date: Mon, 10 Feb 2025 09:51:30 +0100 Subject: [PATCH] Use a single entrypoint instead of one for report and one for survey --- compendium-frontend/bun.lock | 8 ++- compendium-frontend/package.json | 6 +- compendium-frontend/src/App.tsx | 32 +++++------ compendium-frontend/src/survey/App.tsx | 72 ------------------------ compendium-frontend/src/survey/index.tsx | 13 ----- compendium-frontend/survey.html | 11 ---- compendium-frontend/vite.config.ts | 4 -- 7 files changed, 23 insertions(+), 123 deletions(-) delete mode 100644 compendium-frontend/src/survey/App.tsx delete mode 100644 compendium-frontend/src/survey/index.tsx delete mode 100644 compendium-frontend/survey.html diff --git a/compendium-frontend/bun.lock b/compendium-frontend/bun.lock index d2dc8293..818aeaf9 100644 --- a/compendium-frontend/bun.lock +++ b/compendium-frontend/bun.lock @@ -9,7 +9,6 @@ "cartesian-product-multiple-arrays": "~1.0.9", "chart.js": "~4.4.7", "chartjs-plugin-datalabels": "~2.2.0", - "eslint-plugin-react-compiler": "^19.0.0-beta-27714ef-20250124", "html-to-image": "~1.11.11", "lodash": "~4.17.21", "react": "~19.0.0", @@ -34,8 +33,9 @@ "@typescript-eslint/parser": "~8.21.0", "@vitejs/plugin-react": "~4.3.4", "babel-plugin-react-compiler": "~19.0.0-beta-27714ef-20250124", - "eslint": "~9.18.0", + "eslint": "^9.19.0", "eslint-plugin-react": "~7.37.4", + "eslint-plugin-react-compiler": "^19.0.0-beta-27714ef-20250124", "eslint-plugin-react-hooks": "~5.1.0", "rollup-plugin-license": "~3.5.3", "sass": "~1.83.4", @@ -463,7 +463,7 @@ "escape-string-regexp": ["escape-string-regexp@4.0.0", "", {}, "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA=="], - "eslint": ["eslint@9.18.0", "", { "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.12.1", "@eslint/config-array": "^0.19.0", "@eslint/core": "^0.10.0", "@eslint/eslintrc": "^3.2.0", "@eslint/js": "9.18.0", "@eslint/plugin-kit": "^0.2.5", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.4.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", "chalk": "^4.0.0", "cross-spawn": "^7.0.6", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", "eslint-scope": "^8.2.0", "eslint-visitor-keys": "^4.2.0", "espree": "^10.3.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^8.0.0", "find-up": "^5.0.0", "glob-parent": "^6.0.2", "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.3" }, "peerDependencies": { "jiti": "*" }, "optionalPeers": ["jiti"], "bin": "bin/eslint.js" }, "sha512-+waTfRWQlSbpt3KWE+CjrPPYnbq9kfZIYUqapc0uBXyjTp8aYXZDsUH16m39Ryq3NjAVP4tjuF7KaukeqoCoaA=="], + "eslint": ["eslint@9.19.0", "", { "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.12.1", "@eslint/config-array": "^0.19.0", "@eslint/core": "^0.10.0", "@eslint/eslintrc": "^3.2.0", "@eslint/js": "9.19.0", "@eslint/plugin-kit": "^0.2.5", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.4.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", "chalk": "^4.0.0", "cross-spawn": "^7.0.6", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", "eslint-scope": "^8.2.0", "eslint-visitor-keys": "^4.2.0", "espree": "^10.3.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^8.0.0", "find-up": "^5.0.0", "glob-parent": "^6.0.2", "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.3" }, "peerDependencies": { "jiti": "*" }, "optionalPeers": ["jiti"], "bin": { "eslint": "bin/eslint.js" } }, "sha512-ug92j0LepKlbbEv6hD911THhoRHmbdXt2gX+VDABAW/Ir7D3nqKdv5Pf5vtlyY6HQMTEP2skXY43ueqTCWssEA=="], "eslint-plugin-react": ["eslint-plugin-react@7.37.4", "", { "dependencies": { "array-includes": "^3.1.8", "array.prototype.findlast": "^1.2.5", "array.prototype.flatmap": "^1.3.3", "array.prototype.tosorted": "^1.1.4", "doctrine": "^2.1.0", "es-iterator-helpers": "^1.2.1", "estraverse": "^5.3.0", "hasown": "^2.0.2", "jsx-ast-utils": "^2.4.1 || ^3.0.0", "minimatch": "^3.1.2", "object.entries": "^1.1.8", "object.fromentries": "^2.0.8", "object.values": "^1.2.1", "prop-types": "^15.8.1", "resolve": "^2.0.0-next.5", "semver": "^6.3.1", "string.prototype.matchall": "^4.0.12", "string.prototype.repeat": "^1.0.0" }, "peerDependencies": { "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9.7" } }, "sha512-BGP0jRmfYyvOyvMoRX/uoUeW+GqNj9y16bPQzqAHf3AYII/tDs+jMN0dBVkl88/OZwNGwrVFxE7riHsXVfy/LQ=="], @@ -925,6 +925,8 @@ "@typescript-eslint/typescript-estree/semver": ["semver@7.6.3", "", { "bin": "bin/semver.js" }, "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A=="], + "eslint/@eslint/js": ["@eslint/js@9.19.0", "", {}, "sha512-rbq9/g38qjfqFLOVPvwjIvFFdNziEC5S65jmjPw5r6A//QH+W91akh9irMwjDN8zKUTak6W9EsAv4m/7Wnw0UQ=="], + "fast-glob/glob-parent": ["glob-parent@5.1.2", "", { "dependencies": { "is-glob": "^4.0.1" } }, "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="], "@typescript-eslint/typescript-estree/minimatch/brace-expansion": ["brace-expansion@2.0.1", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA=="], diff --git a/compendium-frontend/package.json b/compendium-frontend/package.json index 85044efd..9dce0314 100644 --- a/compendium-frontend/package.json +++ b/compendium-frontend/package.json @@ -2,8 +2,6 @@ "name": "compendium-v2", "version": "1.0.0", "devDependencies": { - "babel-plugin-react-compiler": "~19.0.0-beta-27714ef-20250124", - "eslint-plugin-react-compiler": "^19.0.0-beta-27714ef-20250124", "@eslint/compat": "~1.2.5", "@eslint/eslintrc": "~3.2.0", "@eslint/js": "~9.18.0", @@ -13,8 +11,10 @@ "@typescript-eslint/eslint-plugin": "~8.21.0", "@typescript-eslint/parser": "~8.21.0", "@vitejs/plugin-react": "~4.3.4", - "eslint": "~9.18.0", + "babel-plugin-react-compiler": "~19.0.0-beta-27714ef-20250124", + "eslint": "^9.19.0", "eslint-plugin-react": "~7.37.4", + "eslint-plugin-react-compiler": "^19.0.0-beta-27714ef-20250124", "eslint-plugin-react-hooks": "~5.1.0", "rollup-plugin-license": "~3.5.3", "sass": "~1.83.4", diff --git a/compendium-frontend/src/App.tsx b/compendium-frontend/src/App.tsx index 7a01e779..70143095 100644 --- a/compendium-frontend/src/App.tsx +++ b/compendium-frontend/src/App.tsx @@ -1,4 +1,4 @@ -import { ReactElement, useEffect, lazy } from "react"; +import { ReactElement, lazy } from "react"; import { createBrowserRouter, RouterProvider, Outlet, useLocation } from "react-router-dom"; import Providers from "./Providers"; import { ConnectivityPage, ServiceCategory } from "./Schema"; @@ -65,6 +65,12 @@ const NetworkWeatherMapPage = lazy(() => import("./pages/Network/WeatherMap")); // Services Matrix const ServicesPage = lazy(() => import("./pages/Services/Services")); +// Survey +const SurveyLanding = lazy(() => import('./survey/Landing')); +const SurveyContainerComponent = lazy(() => import('./survey/SurveyContainerComponent')); +const SurveyManagementComponent = lazy(() => import('./survey/management/SurveyManagementComponent')); +const UserManagementComponent = lazy(() => import('./survey/management/UserManagementComponent')); + const GlobalLayout = () => { // this component is needed to provide a global layout for the app, including the navbar and footer, // and make them part of the react-router-dom context @@ -85,21 +91,6 @@ const GlobalLayout = () => { ) } -const RedirectToSurvey = () => { - const { pathname } = useLocation(); - - useEffect(() => { - // Only redirect if we're not already on a survey path - if (!pathname.startsWith('/survey')) { - window.location.replace(`/survey${pathname}`); - } else { - window.location.replace(pathname); - } - }, [pathname]); - - return <Landing /> -} - const router = createBrowserRouter([ { "path": "", @@ -168,7 +159,14 @@ const router = createBrowserRouter([ { path: "/service-management-framework", element: <ServiceManagementFrameworkPage /> }, { path: "/service-level-targets", element: <ServiceLevelTargetsPage /> }, { path: "/corporate-strategy", element: <CorporateStrategyPage /> }, - { path: "/survey/*", element: <RedirectToSurvey /> }, + + // survey + { path: "/survey/admin/surveys", element: <SurveyManagementComponent /> }, + { path: "/survey/admin/users", element: <UserManagementComponent /> }, + { path: "/survey/admin/inspect/:year", element: <SurveyContainerComponent loadFrom={"/api/response/inspect/"} /> }, + { path: "/survey/admin/try/:year", element: <SurveyContainerComponent loadFrom={"/api/response/try/"} /> }, + { path: "/survey/response/:year/:nren", element: <SurveyContainerComponent loadFrom={"/api/response/load/"} /> }, + { path: "/survey/*", element: <SurveyLanding /> }, { path: "*", element: <Landing /> }, ] } diff --git a/compendium-frontend/src/survey/App.tsx b/compendium-frontend/src/survey/App.tsx deleted file mode 100644 index e0c99f4f..00000000 --- a/compendium-frontend/src/survey/App.tsx +++ /dev/null @@ -1,72 +0,0 @@ -import { useEffect, lazy } from "react"; -import { createBrowserRouter, RouterProvider, Outlet, useLocation } from "react-router-dom"; -import Providers from "../Providers"; -import ExternalPageNavBar from "../components/global/ExternalPageNavBar"; -import GeantFooter from "../components/global/GeantFooter"; -import PrivacyModal from "../matomo/PrivacyModal"; - -import SurveyLanding from "./Landing"; - -const SurveyContainerComponent = lazy(() => import('./SurveyContainerComponent')); -const SurveyManagementComponent = lazy(() => import('./management/SurveyManagementComponent')); -const UserManagementComponent = lazy(() => import('./management/UserManagementComponent')); - -const RedirectToReport = ({ pathname }) => { - - useEffect(() => { - console.log(pathname) - // Only redirect if we're not already on a survey path - if (!pathname.startsWith('/survey')) { - window.location.replace(`${pathname}`); - } - }, [pathname]); - - return null; -} - -const GlobalLayout = () => { - // this component is needed to provide a global layout for the app, including the navbar and footer, - // and make them part of the react-router-dom context - const { pathname } = useLocation(); - // hacky workaround for supporting a landing page on the root path, as well as any undefined path - const hasOutlet = pathname !== "/survey" - return ( - <> - <Providers> - <RedirectToReport pathname={pathname} /> - <ExternalPageNavBar /> - <main className="grow"> - {hasOutlet ? <Outlet /> : <SurveyLanding />} - </main> - <PrivacyModal /> - </Providers> - <GeantFooter /> - </> - ) -} - -const router = createBrowserRouter([ - { - "path": "", - "element": <GlobalLayout />, - "children": [ - { path: "/survey/admin/surveys", element: <SurveyManagementComponent /> }, - { path: "/survey/admin/users", element: <UserManagementComponent /> }, - { path: "/survey/admin/inspect/:year", element: <SurveyContainerComponent loadFrom={"/api/response/inspect/"} /> }, - { path: "/survey/admin/try/:year", element: <SurveyContainerComponent loadFrom={"/api/response/try/"} /> }, - { path: "/survey/response/:year/:nren", element: <SurveyContainerComponent loadFrom={"/api/response/load/"} /> }, - { path: "*", element: <SurveyLanding /> }, - ] - } -]) - -function App() { - return ( - <div className="app"> - <RouterProvider router={router} /> - </div> - ); -} - -export default App - diff --git a/compendium-frontend/src/survey/index.tsx b/compendium-frontend/src/survey/index.tsx deleted file mode 100644 index 5aa6d5bf..00000000 --- a/compendium-frontend/src/survey/index.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import React from 'react'; -import { createRoot } from 'react-dom/client'; -import App from "./App"; -import 'bootstrap/dist/css/bootstrap.min.css'; -import '../main.scss'; - -const container = document.getElementById('root') as HTMLElement; -const root = createRoot(container); -root.render( - <React.StrictMode> - <App /> - </React.StrictMode> -) \ No newline at end of file diff --git a/compendium-frontend/survey.html b/compendium-frontend/survey.html deleted file mode 100644 index 0b50b4ac..00000000 --- a/compendium-frontend/survey.html +++ /dev/null @@ -1,11 +0,0 @@ -<!DOCTYPE html> -<html> -<head> - <meta charset="utf-8"/> - <title>Compendium Survey</title> -</head> -<body> - <div id="root"></div> - <script type="module" src="./src/survey/index.tsx"></script> -</body> -</html> \ No newline at end of file diff --git a/compendium-frontend/vite.config.ts b/compendium-frontend/vite.config.ts index 49fb8099..93d73a63 100644 --- a/compendium-frontend/vite.config.ts +++ b/compendium-frontend/vite.config.ts @@ -53,10 +53,6 @@ export default defineConfig({ outDir: outDir, sourcemap: process.env.NODE_ENV !== 'production', rollupOptions: { - input: { - report: path.resolve(__dirname, 'index.html'), - survey: path.resolve(__dirname, 'survey.html'), - }, output: { entryFileNames: '[name].js', assetFileNames: function (assetInfo) { -- GitLab