From 16b49f3633bd16581d5f860c5685bd4811712aab Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Fri, 8 Nov 2024 09:31:52 +0000 Subject: [PATCH] feat: remove unused imports and variables --- src/core/usecases/visualizeSurvey/thunks.ts | 121 ++++++++---------- src/queen-service-worker.js | 1 - .../components/orchestrator/Orchestrator.tsx | 12 +- .../orchestrator/tools/functions.tsx | 9 +- src/ui/constants.ts | 1 - 5 files changed, 62 insertions(+), 82 deletions(-) diff --git a/src/core/usecases/visualizeSurvey/thunks.ts b/src/core/usecases/visualizeSurvey/thunks.ts index a382bafc..926345ad 100644 --- a/src/core/usecases/visualizeSurvey/thunks.ts +++ b/src/core/usecases/visualizeSurvey/thunks.ts @@ -19,80 +19,71 @@ export const name = 'visualizeSurvey' export const reducer = null export const thunks = { - loader: - (params: { requestUrl: string }) => - async (...args) => { - const { requestUrl } = params - const url = new URL(requestUrl) - const result = makeSearchParamsObjSchema(searchParamsSchema).safeParse( - url.searchParams - ) - - if (!result.success) { - console.error(result.error) - return null - } + loader: (params: { requestUrl: string }) => async () => { + const { requestUrl } = params + const url = new URL(requestUrl) + const result = makeSearchParamsObjSchema(searchParamsSchema).safeParse( + url.searchParams + ) - const { - questionnaire, - data, - readonly = false, - nomenclature, - } = result.data + if (!result.success) { + console.error(result.error) + return null + } - if (!questionnaire) { - return null - } + const { questionnaire, data, readonly = false, nomenclature } = result.data - // TEMP : for PE, we fetch source from Queen-api which provides wrapped object : {value: source} - // We must accept it and unwrap it - const fetchedSource = await fetchUrl< - Questionnaire | WrappedQuestionnaire - >({ - url: questionnaire, - }).catch((error) => { - if ( - error instanceof AxiosError && - error.response && - [400, 403, 404, 500].includes(error.response.status) - ) { - throw new Error(t('questionnaireNotFound', { questionnaireId: '' })) - } - throw error - }) + if (!questionnaire) { + return null + } - const isWrappedQuestionnaire = ( - source: Questionnaire | WrappedQuestionnaire - ): source is WrappedQuestionnaire => { - return ( - typeof source === 'object' && - Object.keys(source).length === 1 && - 'value' in source - ) + // TEMP : for PE, we fetch source from Queen-api which provides wrapped object : {value: source} + // We must accept it and unwrap it + const fetchedSource = await fetchUrl({ + url: questionnaire, + }).catch((error) => { + if ( + error instanceof AxiosError && + error.response && + [400, 403, 404, 500].includes(error.response.status) + ) { + throw new Error(t('questionnaireNotFound', { questionnaireId: '' })) } + throw error + }) - const source = isWrappedQuestionnaire(fetchedSource) - ? fetchedSource.value - : fetchedSource + const isWrappedQuestionnaire = ( + source: Questionnaire | WrappedQuestionnaire + ): source is WrappedQuestionnaire => { + return ( + typeof source === 'object' && + Object.keys(source).length === 1 && + 'value' in source + ) + } - const isQuestionnaireCompatible = isSurveyCompatibleWithQueen({ - questionnaire: source, - }) + const source = isWrappedQuestionnaire(fetchedSource) + ? fetchedSource.value + : fetchedSource - if (!isQuestionnaireCompatible) { - throw new Error(t('questionnaireNotCompatible')) - } + const isQuestionnaireCompatible = isSurveyCompatibleWithQueen({ + questionnaire: source, + }) + + if (!isQuestionnaireCompatible) { + throw new Error(t('questionnaireNotCompatible')) + } - const surveyUnit = data - ? await fetchUrl({ - url: data, - }) - : undefined + const surveyUnit = data + ? await fetchUrl({ + url: data, + }) + : undefined - const getReferentiel = nomenclature - ? (name: string) => fetchUrl({ url: nomenclature[name] }) - : undefined + const getReferentiel = nomenclature + ? (name: string) => fetchUrl({ url: nomenclature[name] }) + : undefined - return { source, surveyUnit, readonly, getReferentiel } - }, + return { source, surveyUnit, readonly, getReferentiel } + }, } satisfies Thunks diff --git a/src/queen-service-worker.js b/src/queen-service-worker.js index f43dea43..ff607306 100644 --- a/src/queen-service-worker.js +++ b/src/queen-service-worker.js @@ -12,7 +12,6 @@ importScripts( const { CacheableResponsePlugin } = workbox.cacheableResponse const { registerRoute } = workbox.routing const { NetworkFirst, CacheFirst } = workbox.strategies -const { RangeRequestsPlugin } = workbox.rangeRequests /** * Load env variable with swEnv.js (manage by vite-envs plugin) diff --git a/src/ui/components/orchestrator/Orchestrator.tsx b/src/ui/components/orchestrator/Orchestrator.tsx index 1224f7df..e87da19e 100644 --- a/src/ui/components/orchestrator/Orchestrator.tsx +++ b/src/ui/components/orchestrator/Orchestrator.tsx @@ -1,25 +1,21 @@ -import { - LunaticComponents, - useLunatic, - type LunaticData, -} from '@inseefr/lunatic' +import { LunaticComponents, useLunatic } from '@inseefr/lunatic' import Stack from '@mui/material/Stack' import type { Questionnaire, SurveyUnit } from 'core/model' import type { QuestionnaireState } from 'core/model/QuestionnaireState' import { useTranslation } from 'i18n' +import { useState } from 'react' import { tss } from 'tss-react/mui' import { useAutoNext } from 'ui/components/orchestrator/tools/useAutoNext' +import { Modal } from '../Modal' import { Header } from './Header/Header' import { LoopPanel } from './LoopPanel/LoopPanel' import { NavBar } from './NavBar/NavBar' import { Continue } from './buttons/Continue/Continue' import { useLunaticStyles } from './lunaticStyle' +import type { GetReferentiel } from './lunaticType' import { getinitialSurveyUnit } from './tools/functions' import { getQueenNavigation } from './tools/getQueenNavigation' import { useNavigationButtons } from './tools/useNavigationButtons' -import type { GetReferentiel } from './lunaticType' -import { Modal } from '../Modal' -import { useState } from 'react' const missingShortcut = { dontKnow: 'f2', refused: 'f4' } diff --git a/src/ui/components/orchestrator/tools/functions.tsx b/src/ui/components/orchestrator/tools/functions.tsx index 69a49b8d..e9509bb0 100644 --- a/src/ui/components/orchestrator/tools/functions.tsx +++ b/src/ui/components/orchestrator/tools/functions.tsx @@ -1,11 +1,6 @@ -import type { - PageTag, - Questionnaire, - SurveyUnit, - SurveyUnitData, -} from 'core/model' -import type { Component, Components } from '../lunaticType' import { EXTERNAL_RESOURCES_URL } from 'core/constants' +import type { PageTag, SurveyUnit, SurveyUnitData } from 'core/model' +import type { Component, Components } from '../lunaticType' /** * temporary : should be handle by Lunatic diff --git a/src/ui/constants.ts b/src/ui/constants.ts index bc9fbad8..349bd035 100644 --- a/src/ui/constants.ts +++ b/src/ui/constants.ts @@ -1,5 +1,4 @@ export const SHORTCUT_QUIT: string = 'alt+q' export const SHORTCUT_NEXT: string = 'alt+enter' export const SHORTCUT_PREVIOUS: string = 'alt+backspace' -export const SHORTCUT_FAST_FORWARD: string = 'alt+end' export const SHORCUT_MENU: string = 'alt+b'