Skip to content

Commit

Permalink
fix(sonar): fix code smells medium
Browse files Browse the repository at this point in the history
  • Loading branch information
lailabjil committed Dec 13, 2023
1 parent b93e5b3 commit c73be6e
Show file tree
Hide file tree
Showing 21 changed files with 152 additions and 137 deletions.
26 changes: 12 additions & 14 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,18 @@ const App = () => {
}
}, [auth]);

return (
<>
{initialized && !error ? (
<EdtRoutes />
) : !error ? (
<LoadingFull
message={t("page.home.loading.message")}
thanking={t("page.home.loading.thanking")}
/>
) : (
<ErrorPage errorCode={error} atInit={true} />
)}
</>
);
const renderErrorOrLoadingPage = () => {
return !error ? (
<LoadingFull
message={t("page.home.loading.message")}
thanking={t("page.home.loading.thanking")}
/>
) : (
<ErrorPage errorCode={error} atInit={true} />
);
};

return <>{initialized && !error ? <EdtRoutes /> : renderErrorOrLoadingPage()}</>;
};

export default App;
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ const LoopNavigator = (props: LoopNavigatorProps) => {

const backClick = useCallback(
(event: React.MouseEvent) => {
onPrevious && onPrevious(event);
onPrevious?.(event);
},
[onPrevious],
);
const nextClick = useCallback(
(event: React.MouseEvent) => {
onNext && onNext(event);
onNext?.(event);
},
[onNext],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ const SurveyPageStep = (props: SurveyPageStepProps) => {
);
};

const stylePageMobileTabletWhenIOS = (isOpen: boolean) => {
return isOpen ? "80vh" : "87vh";
};

const useStyles = makeStylesEdt<{ isMobile: boolean; isIOS: boolean; isOpen: boolean }>({
"name": { SurveyPageStep },
})((theme, { isIOS, isOpen }) => ({
Expand All @@ -203,7 +207,7 @@ const useStyles = makeStylesEdt<{ isMobile: boolean; isIOS: boolean; isOpen: boo
},
pageMobileTablet: {
height: "100%",
maxHeight: isIOS ? (isOpen ? "80vh" : "87vh") : "94vh",
maxHeight: isIOS ? stylePageMobileTabletWhenIOS(isOpen) : "94vh",
},
}));

Expand Down
4 changes: 2 additions & 2 deletions src/components/edt/ActivityCard/ActivityOrRouteCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ const ActivityOrRouteCard = (props: ActivityOrRouteCardProps) => {
);

const onEditIn = useCallback((e: React.MouseEvent) => {
onEdit && onEdit();
onEdit?.();
e.stopPropagation();
}, []);

const onDeleteIn = useCallback((e: React.MouseEvent) => {
onDelete && onDelete();
onDelete?.();
e.stopPropagation();
}, []);

Expand Down
54 changes: 36 additions & 18 deletions src/components/edt/DayCard/DayCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ const getClassClose = (isClose: boolean, classNameClose: any, classNameNotClose?
return isClose ? classNameClose : classNameNotClose ?? "";
};

const getClassModePersist = (
modeReviewer: boolean,
classNameReviewer: any,
classNameInterviewer: any,
) => {
return modeReviewer ? classNameReviewer : classNameInterviewer;
};

const DayCard = (props: DayCardProps) => {
const { labelledBy, describedBy, onClick, firstName, surveyDate, idSurvey, isClose, tabIndex } =
props;
Expand All @@ -43,14 +51,20 @@ const DayCard = (props: DayCardProps) => {
const stateSurvey = getStatutSurvey(idSurvey);
const isItMobile = isMobile();

const getLeftBoxClassReviewer = () => {
return isItMobile ? classes.leftReviewerBoxMobile : classes.leftReviewerBox;
};

const getLeftBoxClassInterviewer = () => {
return isItMobile ? classes.leftBoxMobile : classes.leftBox;
};

const getLeftBoxClass = () => {
return modeReviewer
? isItMobile
? classes.leftReviewerBoxMobile
: classes.leftReviewerBox
: isItMobile
? classes.leftBoxMobile
: classes.leftBox;
return getClassModePersist(
modeReviewer,
getLeftBoxClassReviewer(),
getLeftBoxClassInterviewer(),
);
};

return (
Expand Down Expand Up @@ -84,13 +98,11 @@ const DayCard = (props: DayCardProps) => {
</Box>
</Box>
<Box
className={
modeReviewer
? isItMobile
? classes.scoreReviewerBoxMobile
: classes.scoreReviewerBox
: classes.scoreBox
}
className={getClassModePersist(
modeReviewer,
isItMobile ? classes.scoreReviewerBoxMobile : classes.scoreReviewerBox,
classes.scoreBox,
)}
>
{modeReviewer && (
<Box className={classes.qualityScoreBox}>
Expand All @@ -105,7 +117,11 @@ const DayCard = (props: DayCardProps) => {
<Box
className={cx(
classes.progressBox,
isItMobile && modeReviewer ? classes.progressBoxReviewerMobile : "",
getClassModePersist(
isItMobile && modeReviewer,
classes.progressBoxReviewerMobile,
"",
),
)}
>
<PourcentProgress
Expand All @@ -117,9 +133,11 @@ const DayCard = (props: DayCardProps) => {
</Box>
</Box>
<Box
className={
modeReviewer ? (isItMobile ? classes.statusBoxMobile : classes.statusBox) : ""
}
className={getClassModePersist(
modeReviewer,
isItMobile ? classes.statusBoxMobile : classes.statusBox,
"",
)}
>
{modeReviewer &&
(stateSurvey == StateSurveyEnum.INIT ? (
Expand Down
20 changes: 13 additions & 7 deletions src/components/edt/WeekCard/WeekCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ interface WeekCardProps {
tabIndex: number;
}

const getClassModePersist = (
modeReviewer: boolean,
classNameReviewer: any,
classNameInterviewer: any,
) => {
return modeReviewer ? classNameReviewer : classNameInterviewer;
};

const WeekCard = (props: WeekCardProps) => {
const { labelledBy, describedBy, onClick, firstName, surveyDate, isClose, tabIndex } = props;
const { classes, cx } = useStyles();
Expand Down Expand Up @@ -63,13 +71,11 @@ const WeekCard = (props: WeekCardProps) => {
</Box>
</Box>
<Box
className={
modeReviewer
? isItMobile
? classes.scoreReviewerBoxMobile
: classes.scoreReviewerBox
: classes.scoreBox
}
className={getClassModePersist(
modeReviewer,
isItMobile ? classes.scoreReviewerBoxMobile : classes.scoreReviewerBox,
classes.scoreBox,
)}
>
<Box
className={cx(
Expand Down
4 changes: 2 additions & 2 deletions src/orchestrator/Orchestrator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const callbackHolder: { getData(): LunaticData; getErrors(): { [key: stri
};

export type OrchestratorProps = {
source?: LunaticModel | undefined;
source?: LunaticModel;
data?: LunaticData;
cbHolder: { getData(): LunaticData; getErrors(): { [key: string]: [] } };
page: string;
Expand Down Expand Up @@ -65,7 +65,7 @@ const getDataOfCurrentBinding = (
// partie collected dejà set (mode enquete) -> set values of collected (value current lunawtic) to edited
// and collected remains with the collected value on bdd
if (collected) {
if (collected && editedSaved && Array.isArray(collected)) {
if (editedSaved && Array.isArray(collected)) {
collected = getDataOfLoop(collected, editedSaved, iteration);
}
dataOfField.EDITED = collected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,10 @@ const ActivityOrRoutePlannerPage = () => {
);
};

const styleSurveyPageBoxTabletWhenIOS = (isOpen: boolean) => {
return isOpen ? "80vh" : "87vh";
};

const useStyles = makeStylesEdt<{ isIOS: boolean; modifiable: boolean; isOpen: boolean }>({
"name": { ActivityOrRoutePlannerPage },
})((theme, { isIOS, modifiable, isOpen }) => ({
Expand Down Expand Up @@ -953,7 +957,7 @@ const useStyles = makeStylesEdt<{ isIOS: boolean; modifiable: boolean; isOpen: b
},
surveyPageBoxTablet: {
height: "100vh",
maxHeight: isIOS ? (isOpen ? "80vh" : "87vh") : "94vh",
maxHeight: isIOS ? styleSurveyPageBoxTabletWhenIOS(isOpen) : "94vh",
},
outletBoxDesktop: {
flexGrow: "12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ const ActivityDurationPage = () => {

dayjs.extend(customParseFormat);
if (startTime && endTime) {
setStartEndTime(isAfter, startTime, endTime);
const setter = setStartEndTime(isAfter, startTime, endTime);
startTimeDay = setter[0] as dayjs.Dayjs;
endTimeDay = setter[1] as dayjs.Dayjs;
isAfter = setter[2] as boolean;
}
}
return isAfter;
Expand All @@ -95,6 +98,7 @@ const ActivityDurationPage = () => {
if (startTimeDay.isAfter(endTimeDay)) {
isAfter = true;
}
return [startTimeDay, endTimeDay, isAfter];
};

// when the start time < 4 and the end time is >=4, it is counted as the same day
Expand Down
7 changes: 5 additions & 2 deletions src/pages/help/install/InstallPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ const InstallPage = () => {
stepImage = mapSteps?.get(device)?.get(navigator)?.[step - 2] ?? "";
}, [step]);

console.log(device, navigator);
const getIconStep = () => {
return step < stepFinal ? download : finalization;
};

return (
<InstallPageStep
iconTitle={step == 1 ? installation : step < stepFinal ? download : finalization}
iconTitle={step == 1 ? installation : getIconStep()}
iconTitleAlt={t("accessibility.asset.installation-alt")}
title={t("component.help.install.common.title")}
description={
Expand Down
16 changes: 5 additions & 11 deletions src/pages/help/install/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,15 @@ import {
isWindows,
} from "react-device-detect";

export const isIOSDevice = () => {
return isIOS || isMacOs ? "ios" : "";
};

export const getDevice = () => {
return isAndroid || isWindows ? "android" : isIOS || isMacOs ? "ios" : "";
return isAndroid || isWindows ? "android" : isIOSDevice();
};

export const getNavigator = () => {
console.log(
"isChrome:",
isChrome,
"isEdge: ",
isEdge,
"isFirefox:",
isFirefox,
"isSafari:",
isSafari,
);
if (isChrome) {
return "chrome";
} else if (isEdge) {
Expand Down
4 changes: 1 addition & 3 deletions src/pages/home-surveyed/HomeSurveyed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,7 @@ const HomeSurveyedPage = () => {
}, []);

const validateSurveys = useCallback(() => {
validateAllEmptySurveys(idHousehold ?? "").then(() => {
//navigate(0);
});
validateAllEmptySurveys(idHousehold ?? "");
}, []);

const renderHomeReviewer = () => {
Expand Down
1 change: 0 additions & 1 deletion src/pages/surveys-overview/SurveysOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ const SurveysOverviewPage = () => {
setFilterValidatedResult(newFilterValidatedResult);
} else {
sortSearchResult(searchResult);
//setSearchResult(searchResult);
}
},
[searchResult, filterValidatedResult, campaingFilter],
Expand Down
4 changes: 1 addition & 3 deletions src/pages/work-time/weekly-planner/WeeklyPlanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const WeeklyPlannerPage = () => {
let dataWeeklyCallback = callbackData?.COLLECTED?.[FieldNameEnum.WEEKLYPLANNER]
.COLLECTED as any[];
if (data && dataWeeklyCallback && data?.length > dataWeeklyCallback.length) {
dataWeeklyCallback = data;
if (callbackData.COLLECTED) {
callbackData.COLLECTED[FieldNameEnum.WEEKLYPLANNER].COLLECTED = data;
callbackData.COLLECTED[FieldNameEnum.WEEKLYPLANNER].EDITED = data;
Expand All @@ -78,10 +77,9 @@ const WeeklyPlannerPage = () => {

response.names.forEach(name => {
let quartier = dataCopy?.COLLECTED?.[name].COLLECTED as string[];
//let arrayQuartiers = initHours(name);
quartier[currentDateIndex] = response.values[name] + "";

if (dataCopy && dataCopy.COLLECTED) {
if (dataCopy?.COLLECTED) {
dataCopy.COLLECTED[name].COLLECTED = quartier;
}

Expand Down
10 changes: 5 additions & 5 deletions src/service/api-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,9 @@ const remoteGetSurveyData = (
})
.catch(err => {
if (err.response?.status === 403) {
setError && setError(ErrorCodeEnum.NO_RIGHTS);
setError?.(ErrorCodeEnum.NO_RIGHTS);
} else {
setError && setError(ErrorCodeEnum.UNREACHABLE_SURVEYS_DATAS);
setError?.(ErrorCodeEnum.UNREACHABLE_SURVEYS_DATAS);
}
});
});
Expand Down Expand Up @@ -404,13 +404,13 @@ const remoteGetSurveyDataReviewer = (
withState?: boolean,
): Promise<SurveyData> => {
const isReviewerMode = isReviewer();
if (!isReviewerMode) setError && setError(ErrorCodeEnum.NO_RIGHTS);
if (!isReviewerMode) setError?.(ErrorCodeEnum.NO_RIGHTS);

return requestGetSurveyDataReviewer(idSurvey, setError, withState).catch(err => {
if (err.response?.status === 403) {
setError && setError(ErrorCodeEnum.NO_RIGHTS);
setError?.(ErrorCodeEnum.NO_RIGHTS);
} else {
setError && setError(ErrorCodeEnum.UNREACHABLE_SURVEYS_DATAS);
setError?.(ErrorCodeEnum.UNREACHABLE_SURVEYS_DATAS);
}
return Promise.reject(null);
});
Expand Down
4 changes: 1 addition & 3 deletions src/service/loop-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ const ignoreVariablesCondtionals = (
//is page of values of conditional = true
if (isPageOfConditional) {
const mustShowPageOfConditional =
valueOfConditional &&
valueOfConditional?.[iteration] != null &&
valueOfConditional?.[iteration] == "true";
valueOfConditional?.[iteration] != null && valueOfConditional?.[iteration] == "true";
return ifIgnoreVariables(component, data, iteration, mustShowPageOfConditional);
} else return false;
};
Expand Down
Loading

0 comments on commit c73be6e

Please sign in to comment.