From 049d4f356ff4548f77267dcaa7c01dc6b9e3fa82 Mon Sep 17 00:00:00 2001 From: Laila Abjil Date: Thu, 11 Jan 2024 11:57:36 +0100 Subject: [PATCH] fix(sonar): fix code smells --- src/App.tsx | 27 +++++++++---------- .../SurveyPageStep/SurveyPageStep.tsx | 20 +++++++------- .../ActivityOrRoutePlanner.tsx | 19 +++---------- .../activity-summary/ActivitySummary.tsx | 7 +---- .../HelpSubCategoryActivity.tsx | 4 +-- src/pages/home-surveyed/HomeSurveyed.tsx | 19 +++++++------ .../surveys-overview/SurveysOverview.tsx | 13 ++++++--- .../weekly-planner/WeeklyPlanner.tsx | 15 ++++------- src/service/navigation-service.ts | 24 ++++++++--------- src/service/survey-service.ts | 21 +++++++-------- src/utils/utils.ts | 2 +- 11 files changed, 77 insertions(+), 94 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index eb80c19e..2fa5f72d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -88,20 +88,19 @@ const App = () => { } } }, [auth]); - return ( - <> - {initialized && !error ? ( - - ) : !error ? ( - - ) : ( - - )} - - ); + + const renderErrorOrLoadingPage = () => { + !error ? ( + + ) : ( + + ); + }; + + return <>{initialized && !error ? : renderErrorOrLoadingPage()}; }; export default App; diff --git a/src/components/commons/SurveyPage/SurveyPageStep/SurveyPageStep.tsx b/src/components/commons/SurveyPage/SurveyPageStep/SurveyPageStep.tsx index 8a17a888..eb9db393 100644 --- a/src/components/commons/SurveyPage/SurveyPageStep/SurveyPageStep.tsx +++ b/src/components/commons/SurveyPage/SurveyPageStep/SurveyPageStep.tsx @@ -131,17 +131,19 @@ const SurveyPageStep = (props: SurveyPageStepProps) => { modifiable: modifiable, }; + const nextRouteNav = useCallback(() => { + if (validateButton) { + return validateButton; + } else { + nextRoute + ? saveAndNavFullPath(idSurvey, nextRoute) + : saveAndNextStep(idSurvey, context.source, context.surveyRootPage, currentPage); + } + }, []); + const surveyPageNotStepProps = { idSurvey: idSurvey, - validate: - validateButton ?? - useCallback( - () => - nextRoute - ? saveAndNavFullPath(idSurvey, nextRoute) - : saveAndNextStep(idSurvey, context.source, context.surveyRootPage, currentPage), - [], - ), + validate: nextRouteNav, srcIcon: errorIcon, altIcon: errorAltIcon ? t(errorAltIcon) : undefined, onNavigateBack: useCallback(() => saveAndNav(idSurvey), []), diff --git a/src/pages/activity/activity-or-route-planner/ActivityOrRoutePlanner.tsx b/src/pages/activity/activity-or-route-planner/ActivityOrRoutePlanner.tsx index 841ee65d..cb1ebf96 100644 --- a/src/pages/activity/activity-or-route-planner/ActivityOrRoutePlanner.tsx +++ b/src/pages/activity/activity-or-route-planner/ActivityOrRoutePlanner.tsx @@ -75,7 +75,7 @@ import { surveyLocked, } from "service/survey-service"; import { isReviewer } from "service/user-service"; -import { getSurveyIdFromUrl } from "utils/utils"; +import { getClassCondition, getSurveyIdFromUrl } from "utils/utils"; import { v4 as uuidv4 } from "uuid"; const getSurveyDatePlanner = (idSurvey: string) => { @@ -237,10 +237,6 @@ const isMobileApp = () => { return !isPwa() && isMobile && (isIOS || isAndroid); }; -const getClassCondition = (classes: any, condition: boolean, classNameYes: any, classNameNo: any) => { - return condition ? classNameYes : classNameNo; -}; - const isLockedLabels = ( isLocked: boolean, variableEdited: boolean, @@ -659,7 +655,7 @@ const ActivityOrRoutePlannerPage = () => { {(isItDesktop || !isSubChildDisplayed) && ( @@ -683,7 +679,6 @@ const ActivityOrRoutePlannerPage = () => { > { > { > { )} { @@ -502,7 +502,6 @@ const ActivitySummaryPage = () => { { ); }; -const getClassCondition = (classes: any, condition: boolean, classNameYes: any, classNameNo: any) => { - return condition ? classNameYes : classNameNo; -}; - const useStyles = makeStylesEdt<{ modifiable: boolean }>({ "name": { ActivitySummaryPage } })( (theme, { modifiable }) => ({ infoBox: { diff --git a/src/pages/activity/help/HelpMainActivity/HelpSubCategoryActivity.tsx b/src/pages/activity/help/HelpMainActivity/HelpSubCategoryActivity.tsx index 19d2be69..bdfac9c4 100644 --- a/src/pages/activity/help/HelpMainActivity/HelpSubCategoryActivity.tsx +++ b/src/pages/activity/help/HelpMainActivity/HelpSubCategoryActivity.tsx @@ -54,10 +54,10 @@ const HelpSubCategoryActivity = () => { const source = getSource(SourcesEnum.ACTIVITY_SURVEY); const data = mockData(); - if (data && data.COLLECTED && data.COLLECTED[FieldNameEnum.MAINACTIVITY_ID]) + if (data?.COLLECTED?.[FieldNameEnum.MAINACTIVITY_ID]) data.COLLECTED[FieldNameEnum.MAINACTIVITY_ID].COLLECTED = ["120"]; - if (data && data.COLLECTED && data.COLLECTED[FieldNameEnum.MAINACTIVITY_ISFULLYCOMPLETED]) + if (data?.COLLECTED?.[FieldNameEnum.MAINACTIVITY_ISFULLYCOMPLETED]) data.COLLECTED[FieldNameEnum.MAINACTIVITY_ISFULLYCOMPLETED].COLLECTED = [false]; const [helpStep, setHelpStep] = React.useState(3); diff --git a/src/pages/home-surveyed/HomeSurveyed.tsx b/src/pages/home-surveyed/HomeSurveyed.tsx index c54e3047..7273baa5 100644 --- a/src/pages/home-surveyed/HomeSurveyed.tsx +++ b/src/pages/home-surveyed/HomeSurveyed.tsx @@ -252,12 +252,11 @@ const HomeSurveyedPage = () => { {renderReminderNote()} {interviewersUniques.map((interviewer, index) => ( - <> - - + ))} , @@ -273,7 +272,11 @@ const HomeSurveyedPage = () => { {renderReminderNote()} {groups.map((group, index) => ( - + ))} @@ -304,7 +307,7 @@ const HomeSurveyedPage = () => { {groups.map((group, index) => ( - + ))} diff --git a/src/pages/surveys-overview/SurveysOverview.tsx b/src/pages/surveys-overview/SurveysOverview.tsx index 99a2bc71..373a6d25 100644 --- a/src/pages/surveys-overview/SurveysOverview.tsx +++ b/src/pages/surveys-overview/SurveysOverview.tsx @@ -313,7 +313,7 @@ const SurveysOverviewPage = () => { homeIcon={home} homeIconAlt={t("accessibility.asset.mui-icon.home")} > - + {t("accessibility.asset.stats-alt")} {t("page.surveys-overview.title")} @@ -321,7 +321,7 @@ const SurveysOverviewPage = () => { { {process.env.REACT_APP_NODE_ENV !== "production" && ( - +