Skip to content

Commit

Permalink
feat: remove unused imports and variables
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelDemey committed Nov 8, 2024
1 parent fff05ff commit 16b49f3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 82 deletions.
121 changes: 56 additions & 65 deletions src/core/usecases/visualizeSurvey/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<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
})

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<SurveyUnit>({
url: data,
})
: undefined
const surveyUnit = data
? await fetchUrl<SurveyUnit>({
url: data,
})
: undefined

const getReferentiel = nomenclature
? (name: string) => fetchUrl<Nomenclature>({ url: nomenclature[name] })
: undefined
const getReferentiel = nomenclature
? (name: string) => fetchUrl<Nomenclature>({ url: nomenclature[name] })
: undefined

return { source, surveyUnit, readonly, getReferentiel }
},
return { source, surveyUnit, readonly, getReferentiel }
},
} satisfies Thunks
1 change: 0 additions & 1 deletion src/queen-service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 4 additions & 8 deletions src/ui/components/orchestrator/Orchestrator.tsx
Original file line number Diff line number Diff line change
@@ -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' }

Expand Down
9 changes: 2 additions & 7 deletions src/ui/components/orchestrator/tools/functions.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/ui/constants.ts
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 16b49f3

Please sign in to comment.