Skip to content

Commit

Permalink
feat: add configuration for non docker platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
davdarras committed Jun 16, 2023
1 parent 568c9be commit f1516ae
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 10 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "public-enemy",
"version": "2.0.4",
"version": "2.0.5",
"description": "Check and test questionnaire models",
"repository": {
"type": "git",
Expand Down Expand Up @@ -90,6 +90,7 @@
"lint-staged": "^13.0.4",
"prettier": "^2.7.1",
"vite": "^4.1.4",
"vite-plugin-top-level-await": "^1.3.1",
"vite-tsconfig-paths": "^4.0.5",
"vitest": "^0.29.2"
}
Expand Down
1 change: 1 addition & 0 deletions public/configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
File renamed without changes.
5 changes: 5 additions & 0 deletions src/core/utils/configuration/get-configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const basePath = `${window.location.origin}`;

const getFile = (url: string) => fetch(url).then((r) => r.json());

export const getConfiguration = () => getFile(`${basePath}/configuration.json`);
2 changes: 2 additions & 0 deletions src/core/utils/configuration/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { getEnvVar } from "./env";
export { getConfiguration } from "./get-configuration";
2 changes: 1 addition & 1 deletion src/test/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ThemeProvider } from "@emotion/react";
import { render, RenderOptions } from "@testing-library/react";
import { getMessages, LocaleType } from "core/i18n/messages";
import { NotifierProvider } from "core/infrastructure/Notifier";
import { getEnvVar } from "core/utils/env";
import { getEnvVar } from "core/utils/configuration/env";
import { SnackbarProvider } from "notistack";
import React, { ReactElement } from "react";
import { IntlProvider } from "react-intl";
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/QuestionnaireEditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { ApiError } from "core/application/model/error";
import { useApiQuery } from "core/infrastructure/hooks/useApiQuery";
import { useCsvChecks } from "core/infrastructure/hooks/useCsvChecks";
import useNotifier from "core/infrastructure/Notifier";
import { getEnvVar } from "core/utils/env";
import { getEnvVar } from "core/utils/configuration/env";
import * as React from "react";
import { memo, useEffect, useState } from "react";
import { useIntl } from "react-intl";
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/base/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AppBar from "@mui/material/AppBar";
import IconButton from "@mui/material/IconButton";
import Toolbar from "@mui/material/Toolbar";
import Typography from "@mui/material/Typography";
import { getEnvVar } from "core/utils/env";
import { getEnvVar } from "core/utils/configuration/env";
import { memo } from "react";
import { useIntl } from "react-intl";
import { makeStyles } from "tss-react/mui";
Expand Down
17 changes: 16 additions & 1 deletion src/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import "@fontsource/roboto/500.css";
import "@fontsource/roboto/700.css";
import { CssBaseline } from "@mui/material";
import { getMessages, LocaleType } from "core/i18n/messages";
import { getEnvVar } from "core/utils/env";
import { getConfiguration } from "core/utils/configuration";
import { getEnvVar } from "core/utils/configuration/env";
import { SnackbarProvider } from "notistack";
import React from "react";
import ReactDOM from "react-dom/client";
Expand All @@ -15,6 +16,20 @@ import reportWebVitals from "../reportWebVitals";
import { Application } from "./root/Application";
import { appTheme } from "./theme";

/* /!\ used in production mode where env config is used after build time
should not be used in docker environment
*/
await getConfiguration()
.then((conf) => {
if (Object.keys(conf).length) {
console.log("plop");
window._env_ = conf;
}
})
.catch((e) => {
console.log(e);
});

const queryClient = new QueryClient({
defaultOptions: {
queries: {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/pages/QuestionnaireDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Grid, IconButton, Stack, Typography } from "@mui/material";
import { Questionnaire } from "core/application/model";
import { useApiMutation } from "core/infrastructure/hooks/useApiMutation";
import { useApiQuery } from "core/infrastructure/hooks/useApiQuery";
import { getEnvVar } from "core/utils/env";
import { getEnvVar } from "core/utils/configuration/env";
import { memo } from "react";
import { useIntl } from "react-intl";
import { Link, useNavigate, useParams } from "react-router-dom";
Expand Down
2 changes: 1 addition & 1 deletion src/ui/pages/SurveyUnitListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Questionnaire, SurveyUnitsData } from "core/application/model";
import { useNotifier } from "core/infrastructure";
import { useApiMutation } from "core/infrastructure/hooks/useApiMutation";
import { useApiQuery } from "core/infrastructure/hooks/useApiQuery";
import { getEnvVar } from "core/utils/env";
import { getEnvVar } from "core/utils/configuration/env";
import { memo, useEffect, useState } from "react";
import { useIntl } from "react-intl";
import { useQueryClient } from "react-query";
Expand Down
2 changes: 1 addition & 1 deletion src/ui/root/Application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
createQuestionnaireRepository,
createSurveyUnitRepository,
} from "core/infrastructure";
import { getEnvVar } from "core/utils/env";
import { getEnvVar } from "core/utils/configuration/env";
import { memo, useState } from "react";
import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom";
import { makeStyles } from "tss-react/mui";
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"baseUrl": "src",
"target": "es5",
"target": "es2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
Expand Down
16 changes: 15 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@

import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
import topLevelAwait from "vite-plugin-top-level-await";
import viteTsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
server: {
port: 3000,
},
plugins: [react(), viteTsconfigPaths()],
plugins: [
react(),
viteTsconfigPaths(),
topLevelAwait({
// The export name of top-level await promise for each chunk module
promiseExportName: "__tla",
// The function to generate import names of top-level await promise in each chunk module
promiseImportName: (i) => `__tla_${i}`,
}),
],
test: {
globals: true,
environment: "jsdom",
Expand All @@ -18,4 +28,8 @@ export default defineConfig({
},
setupFiles: ["src/setupTests.ts"],
},

build: {
target: "es2017",
},
});
85 changes: 85 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1032,11 +1032,82 @@
resolved "https://registry.yarnpkg.com/@remix-run/router/-/router-1.0.3.tgz#953b88c20ea00d0eddaffdc1b115c08474aa295d"
integrity sha512-ceuyTSs7PZ/tQqi19YZNBc5X7kj1f8p+4DIyrcIYFY9h+hd1OKm4RqtiWldR9eGEvIiJfsqwM4BsuCtRIuEw6Q==

"@rollup/plugin-virtual@^3.0.1":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@rollup/plugin-virtual/-/plugin-virtual-3.0.1.tgz#cea7e489481cc0ca91516c047f8c53c1cfb1adf6"
integrity sha512-fK8O0IL5+q+GrsMLuACVNk2x21g3yaw+sG2qn16SnUd3IlBsQyvWxLMGHmCmXRMecPjGRSZ/1LmZB4rjQm68og==

"@sinclair/typebox@^0.25.16":
version "0.25.24"
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.25.24.tgz#8c7688559979f7079aacaf31aa881c3aa410b718"
integrity sha512-XJfwUVUKDHF5ugKwIcxEgc9k8b7HbznCp6eUfWgu710hMPNIO4aw4/zB5RogDQz8nd6gyCDpU9O/m6qYEWY6yQ==

"@swc/[email protected]":
version "1.3.64"
resolved "https://registry.yarnpkg.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.64.tgz#a5accdd6814c85803827e15d25e19258d365b889"
integrity sha512-gSPld6wxZBZoEvZXWmNfd+eJGlGvrEXmhMBCUwSccpuMa0KqK7F6AAZVu7kFkmlXPq2kS8owjk6/VXnVBmm5Vw==

"@swc/[email protected]":
version "1.3.64"
resolved "https://registry.yarnpkg.com/@swc/core-darwin-x64/-/core-darwin-x64-1.3.64.tgz#87c786267ae52aa25e0e317bd6cc22fe6ecb3e70"
integrity sha512-SJd1pr+U2pz5ZVv5BL36CN879Pn1V0014uVNlB+6yNh3e8T0fjUbtRJcbFiBB+OeYuJ1UNUeslaRJtKJNtMH7A==

"@swc/[email protected]":
version "1.3.64"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.64.tgz#144fb02dbcb5dabdff07e7ec6ba2e113e9d8cd5c"
integrity sha512-XE60bZS+qO+d8IQYAayhn3TRqyzVmQeOsX2B1yUHuKZU3Zb/mt/cmD/HLzZZW7J3z19kYf2na7Hvmnt3amUGoA==

"@swc/[email protected]":
version "1.3.64"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.64.tgz#58c185276fd15def9e6a164e7cd006572443aedb"
integrity sha512-+jcUua4cYLRMqDicv+4AaTZUGgYWXkXVI9AzaAgfkMNLU2TMXwuYXopxk1giAMop88+ovzYIqrxErRdu70CgtQ==

"@swc/[email protected]":
version "1.3.64"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.64.tgz#9eed899e2f0aaf60d7894b08741528a9a01c4f1a"
integrity sha512-50MI8NFYUKhLncqY2piM/XOnNqZT6zY2ZoNOFsy63/T2gAYy1ts4mF4YUEkg4XOA2zhue1JSLZBUrHQXbgMYUQ==

"@swc/[email protected]":
version "1.3.64"
resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.64.tgz#40bc4ab88ef6f82cccb3e9a25ea2de1811cdffcf"
integrity sha512-bT8seQ41Q4J2JDgn2JpFCGNehGAIilAkZ476gEaKKroEWepBhkD0K1MspSSVYSJhLSGbBVSaadUEiBPxWgu1Rw==

"@swc/[email protected]":
version "1.3.64"
resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.64.tgz#c3f38b91fd5f68becdb7cb035d9bb257abc7c3ad"
integrity sha512-sJgh3TXCDOEq/Au4XLAgNqy4rVcLeywQBoftnV3rcvX1/u9OCSRzgKLgYc5d1pEN5AMJV1l4u26kbGlQuZ+yRw==

"@swc/[email protected]":
version "1.3.64"
resolved "https://registry.yarnpkg.com/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.64.tgz#c4597744a58a59f971e9eaac69ea45a306bef14d"
integrity sha512-zWIy+mAWDjtJjl4e4mmhQL7g9KbkOwcWbeoIk4C6NT4VpjnjdX1pMml/Ez2sF5J5cGBwu7B1ePfTe/kAE6G36Q==

"@swc/[email protected]":
version "1.3.64"
resolved "https://registry.yarnpkg.com/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.64.tgz#421f59c9343004e53765a9c17afe0e27ec17b427"
integrity sha512-6HMiuUeSMpTUAimb1E+gUNjy8m211oAzw+wjU8oOdA6iihWaLBz4TOhU9IaKZPPjqEcYGwqaT3tj5b5+mxde6Q==

"@swc/[email protected]":
version "1.3.64"
resolved "https://registry.yarnpkg.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.64.tgz#8ab1137d25a5814358fcbc6325b2c37ba2c7f5d5"
integrity sha512-c8Al0JJfmgnO9sg6w34PICibqI4p7iXywo+wOxjY88oFwMcfV5rGaif1Fe3RqxJP/1WtUV7lYuKKZrneMXtyLA==

"@swc/core@^1.3.10":
version "1.3.64"
resolved "https://registry.yarnpkg.com/@swc/core/-/core-1.3.64.tgz#544bf8be8de4e9908521020a075219a691982d0f"
integrity sha512-be1dk2pfjzBjFp/+p47/wvOAm7KpEtsi7hqI3ofox6pK3hBJChHgVTLVV9xqZm7CnYdyYYw3Z78hH6lrwutxXQ==
optionalDependencies:
"@swc/core-darwin-arm64" "1.3.64"
"@swc/core-darwin-x64" "1.3.64"
"@swc/core-linux-arm-gnueabihf" "1.3.64"
"@swc/core-linux-arm64-gnu" "1.3.64"
"@swc/core-linux-arm64-musl" "1.3.64"
"@swc/core-linux-x64-gnu" "1.3.64"
"@swc/core-linux-x64-musl" "1.3.64"
"@swc/core-win32-arm64-msvc" "1.3.64"
"@swc/core-win32-ia32-msvc" "1.3.64"
"@swc/core-win32-x64-msvc" "1.3.64"

"@testing-library/dom@^9.0.0":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-9.0.0.tgz#cc50e8df2a7dccff95555102beebbae60e95e95e"
Expand Down Expand Up @@ -4925,6 +4996,11 @@ util-deprecate@^1.0.1:
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==

uuid@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5"
integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==

v8-compile-cache-lib@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf"
Expand Down Expand Up @@ -4959,6 +5035,15 @@ [email protected]:
picocolors "^1.0.0"
vite "^3.0.0 || ^4.0.0"

vite-plugin-top-level-await@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/vite-plugin-top-level-await/-/vite-plugin-top-level-await-1.3.1.tgz#7e7293be01489b508692627529c0a3b3218a23a3"
integrity sha512-55M1h4NAwkrpxPNOJIBzKZFihqLUzIgnElLSmPNPMR2Fn9+JHKaNg3sVX1Fq+VgvuBksQYxiD3OnwQAUu7kaPQ==
dependencies:
"@rollup/plugin-virtual" "^3.0.1"
"@swc/core" "^1.3.10"
uuid "^9.0.0"

vite-tsconfig-paths@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/vite-tsconfig-paths/-/vite-tsconfig-paths-4.0.5.tgz#c7c54e2cf7ccc5e600db565cecd7b368a1fa8889"
Expand Down

0 comments on commit f1516ae

Please sign in to comment.