From 88d0627c8871cf294247fc0aff44876da5226bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Wed, 9 Feb 2022 10:26:56 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Nettoyage=20du=20fichier=20.env.tem?= =?UTF-8?q?plate=20+=20Ajout=20du=20devtool=20redux=20uniquement=20en=20mo?= =?UTF-8?q?de=20dev=20(#2001)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨ Déplace les scripts de traduction dans site * ✨ Nettoyage du fichier .env.template * ✨ Ajout du devtool redux uniquement en mode dev * ✨ Ajout d'une erreur si l'api github ne retourne pas un status 200 * ✨ Fix types * ✨ Temporary fix package import error * ⬆️ Update @redux-devtools/extension --- CONTRIBUTING.md | 1 + package.json | 4 +++- site/.env.template | 28 ++++++++++++++++------------ site/package.json | 7 ++++--- site/scripts/fetch-stats.js | 8 ++++++++ site/source/Provider.tsx | 16 ++++++++++------ site/source/types/app-env.d.ts | 6 +++--- site/vite.config.ts | 4 ++-- yarn.lock | 14 ++++++++++++++ 9 files changed, 61 insertions(+), 27 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bcdf08c47..3d2a21c02 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -162,6 +162,7 @@ yarn run i18n:check Pour traduire automatiquement les chaînes manquantes via l'api Deepl : ```sh +cd site yarn run i18n:rules:translate yarn run i18n:ui:translate diff --git a/package.json b/package.json index d8215c10f..c6884e993 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,9 @@ "test:type": "yarn workspaces run tsc --skipLibCheck --noEmit", "clean": "yarn workspaces run clean && rimraf node_modules", "start": "yarn workspace site start", - "moso:up": "yarn workspace modele-social run up && yarn workspace site upgrade modele-social" + "moso:up": "yarn workspace modele-social run up && yarn workspace site upgrade modele-social", + "i18n:check": "yarn workspace site i18n:check", + "i18n:translate": "yarn workspace site i18n:translate" }, "resolutions": { "@mui/styled-engine": "npm:@mui/styled-engine-sc@latest" diff --git a/site/.env.template b/site/.env.template index c2d1cb482..5f7a0649e 100644 --- a/site/.env.template +++ b/site/.env.template @@ -1,21 +1,25 @@ +### Variables utilisées par les scripts ### # Voir https://github.com/betagouv/compta-mon-entreprise/issues/3 -DEEPL_API_SECRET= -INSEE_SIRENE_API_SECRET= -MATOMO_TOKEN= +ALGOLIA_ADMIN_KEY= ATINTERNET_API_ACCESS_KEY= ATINTERNET_API_SECRET_KEY= +DEEPL_API_SECRET= ZAMMAD_API_SECRET_KEY= -ALGOLIA_APP_ID= -ALGOLIA_ADMIN_KEY= -ALGOLIA_SEARCH_KEY= -ALGOLIA_INDEX_PREFIX=monentreprise-{env}- -# Utiliser votre propre token +# Utilisez votre propre token (voir issue en haut pour en créé un) GITHUB_API_SECRET= -# Valeurs optionnelles -COMPANY_SEARCH_HOST=https://search-recherche-entreprises.fabrique.social.gouv.fr +### Variables utilisées par l'app ### +VITE_ALGOLIA_APP_ID= +VITE_ALGOLIA_SEARCH_KEY= +VITE_ALGOLIA_INDEX_PREFIX=monentreprise-{env}- +VITE_AT_INTERNET_SITE_ID= -# Valeurs pour l'app VITE_FR_BASE_URL="http://localhost:3000/mon-entreprise" -VITE_EN_BASE_URL="http://localhost:3000/infrance" \ No newline at end of file +VITE_EN_BASE_URL="http://localhost:3000/infrance" + +# Variables optionnelles +VITE_COMPANY_SEARCH_HOST=https://search-recherche-entreprises.fabrique.social.gouv.fr + +# https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/Features/Trace.md +VITE_REDUX_TRACE=true diff --git a/site/package.json b/site/package.json index 2264481f6..bed00633c 100644 --- a/site/package.json +++ b/site/package.json @@ -34,11 +34,11 @@ "test:record-http-calls:mon-entreprise": "cypress run --env record_http=", "algolia:update": "node scripts/search/update-data.js", "algolia:clean": "node scripts/search/clean.js", - "i18n:check": "yarn run i18n:rules:check && yarn run i18n:ui:check", - "i18n:translate": "yarn run i18n:rules:translate && yarn run i18n:ui:translate", + "i18n:check": "yarn i18n:rules:check && yarn i18n:ui:check", + "i18n:translate": "yarn i18n:rules:translate && yarn i18n:ui:translate", "i18n:rules:check": "node scripts/i18n/check-missing-rule-translation.js", "i18n:rules:translate": "node scripts/i18n/translate-rules.js", - "i18n:ui:check": "i18next -c scripts/i18n/parser.config.cjs && node scripts/i18n/check-missing-UI-translation", + "i18n:ui:check": "i18next -c scripts/i18n/parser.config.cjs && node scripts/i18n/check-missing-UI-translation.js", "i18n:ui:translate": "rm -rf source/locales/static-analysis-fr.json && i18next -c scripts/i18n/parser.config.cjs && node scripts/i18n/translate-ui.js" }, "resolutions": { @@ -99,6 +99,7 @@ "devDependencies": { "@react-types/numberfield": "^3.1.0", "@react-types/searchfield": "^3.1.2", + "@redux-devtools/extension": "^3.2.2", "@rollup/plugin-yaml": "^3.1.0", "@types/iframe-resizer": "^3.5.7", "@types/ramda": "^0.26.43", diff --git a/site/scripts/fetch-stats.js b/site/scripts/fetch-stats.js index 86d2f4609..de2775f89 100644 --- a/site/scripts/fetch-stats.js +++ b/site/scripts/fetch-stats.js @@ -251,6 +251,14 @@ async function fetchUserFeedbackIssues() { query, }), }) + + if (response.status != 200) { + console.error( + `❌ Github response status: ${response.status}\n` + + '\tCheck your GITHUB_API_SECRET key in site/.env\n' + ) + } + const data = await response.json() const issues = Object.entries(data.data.repository) .filter(([, value]) => !!value) diff --git a/site/source/Provider.tsx b/site/source/Provider.tsx index 470fe1564..9560f5c9f 100644 --- a/site/source/Provider.tsx +++ b/site/source/Provider.tsx @@ -14,15 +14,15 @@ import { createBrowserHistory } from 'history' import i18next from 'i18next' import logo from 'Images/logo-monentreprise.svg' import { useIframeResizer } from 'Hooks/useIframeResizer' -import React, { createContext, useMemo } from 'react' +import { createContext, ReactNode, useMemo } from 'react' import { HelmetProvider } from 'react-helmet-async' import { I18nextProvider } from 'react-i18next' import { Provider as ReduxProvider } from 'react-redux' import { Router } from 'react-router-dom' import reducers, { RootState } from 'Reducers/rootReducer' +import { composeWithDevToolsDevelopmentOnly } from '@redux-devtools/extension' import { applyMiddleware, - compose, createStore, Middleware, PreloadedState, @@ -59,9 +59,13 @@ type SiteName = 'mon-entreprise' | 'infrance' | 'publicodes' export const SiteNameContext = createContext(null) +const composeEnhancers = composeWithDevToolsDevelopmentOnly( + import.meta.env.VITE_REDUX_TRACE ? { trace: true, traceLimit: 25 } : {} +) + export type ProviderProps = { basename: SiteName - children: React.ReactNode + children: ReactNode sitePaths?: SitePaths initialStore?: PreloadedState onStoreCreated?: (store: Store) => void @@ -75,8 +79,8 @@ export default function Provider({ onStoreCreated, children, sitePaths = {} as SitePaths, -}: ProviderProps) { - const storeEnhancer = compose(applyMiddleware(...reduxMiddlewares)) +}: ProviderProps): JSX.Element { + const storeEnhancer = composeEnhancers(applyMiddleware(...reduxMiddlewares)) // Hack: useMemo is used to persist the store across hot reloads. const store = useMemo(() => { @@ -147,7 +151,7 @@ function BrowserRouterProvider({ children, basename, }: { - children: React.ReactNode + children: ReactNode basename: string }) { // The server rouer is only provided in the entry-server file diff --git a/site/source/types/app-env.d.ts b/site/source/types/app-env.d.ts index 13bc66949..202028a09 100644 --- a/site/source/types/app-env.d.ts +++ b/site/source/types/app-env.d.ts @@ -10,12 +10,12 @@ interface ImportMetaEnv { VITE_GIT_HEAD: string VITE_AT_INTERNET_SITE_ID: string - VITE_ATINTERNET_API_ACCESS_KEY: string - VITE_ATINTERNET_API_SECRET_KEY: string VITE_ALGOLIA_INDEX_PREFIX: string VITE_ALGOLIA_SEARCH_KEY: string VITE_ALGOLIA_APP_ID: string - VITE_REDUX_TRACE: string + VITE_COMPANY_SEARCH_HOST?: string + + VITE_REDUX_TRACE?: string } diff --git a/site/vite.config.ts b/site/vite.config.ts index 1beeab608..d2f7df368 100644 --- a/site/vite.config.ts +++ b/site/vite.config.ts @@ -83,7 +83,7 @@ function multipleSPA(options: MultipleSPAOptions): Plugin { const template = await fs.readFile(options.templatePath, 'utf-8') const filledTemplate = template .toString() - .replace(/\{\{(.+)\}\}/g, (_match, p1) => siteData[p1.trim()]) + .replace(/\{\{(.+)\}\}/g, (_match, p1) => siteData[(p1 as string).trim()]) return filledTemplate } return { @@ -159,7 +159,7 @@ function multipleSPA(options: MultipleSPAOptions): Plugin { function monEntrepriseDevServer(): Plugin { return { name: 'mon-entreprise', - configureServer(vite) { + configureServer() { // We could use native ViteJS watch API, but it would require changing // more code and maybe the whole "modele-social" package build process. watchDottedNames() diff --git a/yarn.lock b/yarn.lock index 209371cb3..3e1bbdd81 100644 --- a/yarn.lock +++ b/yarn.lock @@ -319,6 +319,13 @@ dependencies: regenerator-runtime "^0.13.4" +"@babel/runtime@^7.17.0": + version "7.17.2" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.17.2.tgz#66f68591605e59da47523c631416b18508779941" + integrity sha512-hzeyJyMA1YGdJTuWU0e/j4wKXrU4OMFvY2MSlaI9B7VQb0r5cxTE3EAIS2Q7Tn2RIcDkRvTA/v2JsAEhxe99uw== + dependencies: + regenerator-runtime "^0.13.4" + "@babel/standalone@^7.16.4": version "7.16.12" resolved "https://registry.yarnpkg.com/@babel/standalone/-/standalone-7.16.12.tgz#bfa53fe78d223a781ca4fd8e14139743b2e0a038" @@ -1476,6 +1483,13 @@ dependencies: "@react-types/shared" "^3.9.0" +"@redux-devtools/extension@^3.2.2": + version "3.2.2" + resolved "https://registry.yarnpkg.com/@redux-devtools/extension/-/extension-3.2.2.tgz#2d6da4df2c4d32a0aac54d824e46f52b1fd9fc4d" + integrity sha512-fKA2TWNzJF7wXSDwBemwcagBFudaejXCzH5hRszN3Z6B7XEJtEmGD77AjV0wliZpIZjA/fs3U7CejFMQ+ipS7A== + dependencies: + "@babel/runtime" "^7.17.0" + "@rollup/plugin-yaml@^3.1.0": version "3.1.0" resolved "https://registry.yarnpkg.com/@rollup/plugin-yaml/-/plugin-yaml-3.1.0.tgz#03a13039ba366fc8d39a1ab94a7debacdd776c2f"