Skip to content

Commit

Permalink
fix(sonar): fix code smells low
Browse files Browse the repository at this point in the history
  • Loading branch information
lailabjil committed Dec 13, 2023
1 parent 8eecf7d commit 3ff1efa
Show file tree
Hide file tree
Showing 18 changed files with 156 additions and 147 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { makeStylesEdt } from "@inseefrlab/lunatic-edt";
import { Box } from "@mui/material";
import LinearProgress from "@mui/material/LinearProgress";
import React from "react";
import { useTranslation } from "react-i18next";

interface AddActivityOrRouteStepperStepperProps {
Expand All @@ -25,7 +24,7 @@ const AddActivityOrRouteStepper = (props: AddActivityOrRouteStepperStepperProps)
const { t } = useTranslation();
const { classes } = useStyles();
let stepIncrement = 100 / numberOfSteps;
const [progress] = React.useState(stepIncrement * lastCompletedStepNumber);
const progress = stepIncrement * lastCompletedStepNumber;

return (
<Box className={classes.stepper}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/edt/DayCharacteristic/DayCharacteristic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const DayCharacteristics = (props: DayCharacteristicsProps) => {
const id = openPopOver ? "edit-or-delete-popover" : undefined;

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

Expand Down
3 changes: 1 addition & 2 deletions src/components/edt/EndActivityStepper/EndActivityStepper.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { makeStylesEdt } from "@inseefrlab/lunatic-edt";
import { Box, CircularProgress } from "@mui/material";
import Typography from "@mui/material/Typography";
import React from "react";

interface EndActivityStepperProps {
numberOfSteps: number;
Expand All @@ -14,7 +13,7 @@ const EndActivityStepper = (props: EndActivityStepperProps) => {
const { numberOfSteps, lastCompletedStepNumber, currentStepNumber, currentStepLabel } = props;
const { classes } = useStyles();
let stepIncrement = 100 / numberOfSteps;
const [progress] = React.useState(stepIncrement * lastCompletedStepNumber);
const progress = stepIncrement * lastCompletedStepNumber;

return (
<Box className={classes.stepper}>
Expand Down
61 changes: 29 additions & 32 deletions src/components/edt/HelpMenu/HelpMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { makeStylesEdt } from "@inseefrlab/lunatic-edt";
import { Box, Modal } from "@mui/material";
import { Default, Mobile } from "components/commons/Responsive/Responsive";
import { LunaticModel } from "interface/lunatic/Lunatic";
import React from "react";
import HelpMenuInner from "./HelpMenuInner";

interface HelpMenuProps {
Expand All @@ -28,37 +27,35 @@ const HelpMenu = (props: HelpMenuProps) => {
className={classes.shadowBackground}
sx={{ display: open ? "visible" : "none" }}
></Box>
<React.Fragment>
<Modal
open={open}
onClose={handleClose}
aria-labelledby={labelledBy}
aria-describedby={describedBy}
>
<>
<Default>
<HelpMenuInner
handleClose={handleClose}
onClickContact={onClickContact}
onClickInstall={onClickInstall}
onClickHelp={onClickHelp}
className={classes.modal}
isMobile={false}
/>
</Default>
<Mobile>
<HelpMenuInner
handleClose={handleClose}
onClickContact={onClickContact}
onClickInstall={onClickInstall}
onClickHelp={onClickHelp}
className={classes.modal}
isMobile={true}
/>
</Mobile>
</>
</Modal>
</React.Fragment>
<Modal
open={open}
onClose={handleClose}
aria-labelledby={labelledBy}
aria-describedby={describedBy}
>
<>
<Default>
<HelpMenuInner
handleClose={handleClose}
onClickContact={onClickContact}
onClickInstall={onClickInstall}
onClickHelp={onClickHelp}
className={classes.modal}
isMobile={false}
/>
</Default>
<Mobile>
<HelpMenuInner
handleClose={handleClose}
onClickContact={onClickContact}
onClickInstall={onClickInstall}
onClickHelp={onClickHelp}
className={classes.modal}
isMobile={true}
/>
</Mobile>
</>
</Modal>
</>
);
};
Expand Down
1 change: 0 additions & 1 deletion src/components/edt/HouseholdCard/HouseholdCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ interface HouseholdCardProps {
closedSurveyLabel: string;
validatedSurveyLabel: string;
dataHousehold: any;
onClick?: () => void;
tabIndex: number;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,11 @@ const getIterationOrZero = (activity: ActivityRouteOrGap) => {
const displaySnackbar = (
idSurvey: string,
source: LunaticModel,
setSnackbarText: (value: React.SetStateAction<string | undefined>) => void,
setOpenSnackbar: (value: React.SetStateAction<boolean>) => void,
setSkip: (value: React.SetStateAction<boolean>) => void,
setters: {
setSnackbarText: (value: React.SetStateAction<string | undefined>) => void;
setOpenSnackbar: (value: React.SetStateAction<boolean>) => void;
setSkip: (value: React.SetStateAction<boolean>) => void;
},
skip: boolean,
overlaps: {
prev: string | undefined;
Expand All @@ -279,9 +281,16 @@ const displaySnackbar = (
const isActivityPlanner = isActivity(location);
if (isActivityPlanner) {
const act = getActivitiesOrRoutes(t, idSurvey, source);
setAlertSnackbar(setSnackbarText, setOpenSnackbar, skip, act.overlaps.length > 0, overlaps, t);
setAlertSnackbar(
setters.setSnackbarText,
setters.setOpenSnackbar,
skip,
act.overlaps.length > 0,
overlaps,
t,
);
} else {
setSkip(false);
setters.setSkip(false);
}
};

Expand Down Expand Up @@ -315,6 +324,23 @@ const init = (
}
};

const updateSubChildDisplayed = (
isSubchildDisplayed: boolean,
setIsSubChildDisplayed: React.Dispatch<React.SetStateAction<boolean>>,
) => {
const currentIsChildDisplay = isChildDisplayed(location.pathname);
if (currentIsChildDisplay !== isSubchildDisplayed) {
setIsSubChildDisplayed(currentIsChildDisplay);
}
};

const getAddLabel = (
activitiesRoutesOrGaps: ActivityRouteOrGap[],
t: TFunction<"translation", undefined>,
) => {
return activitiesRoutesOrGaps.length === 0 ? t("common.navigation.add") : undefined;
};

const ActivityOrRoutePlannerPage = () => {
const navigate = useNavigate();
const context: OrchestratorContext = useOutletContext();
Expand All @@ -323,7 +349,7 @@ const ActivityOrRoutePlannerPage = () => {
const location = useLocation();
let idSurvey = getSurveyIdFromUrl(context, location);
const { t } = useTranslation();
const [isSubchildDisplayed, setIsSubChildDisplayed] = React.useState(false);
const [isSubchildDisplayed, setIsSubChildDisplayed] = React.useState<boolean>(false);
const [isAddActivityOrRouteOpen, setIsAddActivityOrRouteOpen] = React.useState(false);
const [isRoute, setIsRoute] = React.useState(false);
const [addActivityOrRouteFromGap, setAddActivityOrRouteFromGap] = React.useState(false);
Expand Down Expand Up @@ -371,9 +397,11 @@ const ActivityOrRoutePlannerPage = () => {
displaySnackbar(
idSurvey,
source,
setSnackbarText,
setOpenSnackbar,
setSkip,
{
setSnackbarText,
setOpenSnackbar,
setSkip,
},
skip,
overlaps,
location,
Expand All @@ -394,10 +422,7 @@ const ActivityOrRoutePlannerPage = () => {
}, []);

useEffect(() => {
const currentIsChildDisplay = isChildDisplayed(location.pathname);
if (currentIsChildDisplay !== isSubchildDisplayed) {
setIsSubChildDisplayed(currentIsChildDisplay);
}
updateSubChildDisplayed(isSubchildDisplayed, setIsSubChildDisplayed);
}, [location]);

useEffect(() => {
Expand Down Expand Up @@ -543,11 +568,9 @@ const ActivityOrRoutePlannerPage = () => {
}, []);

const snackbarAction = (
<React.Fragment>
<IconButton size="small" aria-label="close" color="inherit" onClick={handleCloseSnackBar}>
<img src={close} alt={t("accessibility.asset.mui-icon.close")} />
</IconButton>
</React.Fragment>
<IconButton size="small" aria-label="close" color="inherit" onClick={handleCloseSnackBar}>
<img src={close} alt={t("accessibility.asset.mui-icon.close")} />
</IconButton>
);

const messagesEndRef = React.useRef<null | HTMLDivElement>(null);
Expand Down Expand Up @@ -652,9 +675,7 @@ const ActivityOrRoutePlannerPage = () => {
onFinish={closeActivity(false, idSurvey)}
onAdd={onOpenAddActivityOrRoute}
finishLabel={t("common.navigation.finish")}
addLabel={
activitiesRoutesOrGaps.length === 0 ? t("common.navigation.add") : undefined
}
addLabel={getAddLabel(activitiesRoutesOrGaps, t)}
activityProgressBar={true}
idSurvey={idSurvey}
score={score}
Expand Down Expand Up @@ -697,25 +718,23 @@ const ActivityOrRoutePlannerPage = () => {
{activitiesRoutesOrGaps.length !== 0 &&
(isReviewerMode() ? (
<Box className={classes.headerActivityLockBox}>
<>
<Alert
isAlertDisplayed={isAlertLockDisplayed}
onCompleteCallBack={lock}
onCancelCallBack={displayAlert(
setIsAlertLockDisplayed,
false,
)}
labels={isLockedLabels(
isLocked,
variableEdited,
t,
)}
icon={errorIcon}
errorIconAlt={t(
"page.alert-when-quit.alt-alert-icon",
)}
></Alert>
</>
<Alert
isAlertDisplayed={isAlertLockDisplayed}
onCompleteCallBack={lock}
onCancelCallBack={displayAlert(
setIsAlertLockDisplayed,
false,
)}
labels={isLockedLabels(
isLocked,
variableEdited,
t,
)}
icon={errorIcon}
errorIconAlt={t(
"page.alert-when-quit.alt-alert-icon",
)}
></Alert>
<Box className={classes.headerActivityBox}>
<Typography className={classes.label}>
{t(
Expand Down
55 changes: 23 additions & 32 deletions src/pages/activity/activity-summary/ActivitySummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -511,19 +511,14 @@ const ActivitySummaryPage = () => {
{activitiesRoutesOrGaps.length !== 0 &&
(isReviewerMode ? (
<Box className={classes.headerActivityLockBox}>
<>
<Alert
isAlertDisplayed={isAlertLockDisplayed}
onCompleteCallBack={lock}
onCancelCallBack={displayAlert(
setIsAlertLockDisplayed,
false,
)}
labels={getAlertLabelsLock(isLocked, variableEdited, t)}
icon={errorIcon}
errorIconAlt={t("page.alert-when-quit.alt-alert-icon")}
></Alert>
</>
<Alert
isAlertDisplayed={isAlertLockDisplayed}
onCompleteCallBack={lock}
onCancelCallBack={displayAlert(setIsAlertLockDisplayed, false)}
labels={getAlertLabelsLock(isLocked, variableEdited, t)}
icon={errorIcon}
errorIconAlt={t("page.alert-when-quit.alt-alert-icon")}
></Alert>
<Box className={classes.headerActivityBox}>
<Typography className={classes.label}>
{t("page.activity-planner.activity-for-day")}
Expand Down Expand Up @@ -678,25 +673,21 @@ const ActivitySummaryPage = () => {
</Button>
</>
) : (
<>
<Button variant="contained" className={classes.downloadButton}>
<PDFDownloadLink
className={classes.downloadLink}
document={
<ActivitiesSummaryExportTemplate exportData={exportData} />
}
fileName={
t("export.activities-summary.file-name") +
getValue(idSurvey, FieldNameEnum.FIRSTNAME) +
"_" +
getValue(idSurvey, FieldNameEnum.SURVEYDATE) +
".pdf"
}
>
{() => t("page.activity-summary.download-pdf")}
</PDFDownloadLink>
</Button>
</>
<Button variant="contained" className={classes.downloadButton}>
<PDFDownloadLink
className={classes.downloadLink}
document={<ActivitiesSummaryExportTemplate exportData={exportData} />}
fileName={
t("export.activities-summary.file-name") +
getValue(idSurvey, FieldNameEnum.FIRSTNAME) +
"_" +
getValue(idSurvey, FieldNameEnum.SURVEYDATE) +
".pdf"
}
>
{() => t("page.activity-summary.download-pdf")}
</PDFDownloadLink>
</Button>
)}
</FlexCenter>

Expand Down
2 changes: 1 addition & 1 deletion src/pages/activity/help/HelpActivity/HelpActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const HelpActivity = () => {
const navigate = useNavigate();
const { t } = useTranslation();

const [isSubchildDisplayed] = React.useState(false);
const isSubchildDisplayed = false;
const [isAddActivityOrRouteOpen, setIsAddActivityOrRouteOpen] = React.useState(false);
const [addActivityOrRouteFromGap, setAddActivityOrRouteFromGap] = React.useState(false);
const [gapStartTime, setGapStartTime] = React.useState<string>();
Expand Down
4 changes: 2 additions & 2 deletions src/pages/activity/help/HelpCheckbox/HelpCheckbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ const HelpCheckbox = () => {
const [backClickEvent, setBackClickEvent] = useState<React.MouseEvent>();
const [nextClickEvent, setNextClickEvent] = useState<React.MouseEvent>();
const [isAlertDisplayed, setIsAlertDisplayed] = useState<boolean>(false);
const [displayStepper] = useState<boolean>(true);
const [displayHeader] = useState<boolean>(true);
const displayStepper = true;
const displayHeader = true;

const specificProps = {
backClickEvent: backClickEvent,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/activity/help/HelpDuration/HelpDuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { LoopEnum } from "enumerations/LoopEnum";
import { SourcesEnum } from "enumerations/SourcesEnum";
import { SurveysIdsEnum } from "enumerations/SurveysIdsEnum";
import { callbackHolder, OrchestratorForStories } from "orchestrator/Orchestrator";
import React, { useCallback } from "react";
import { useCallback } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router";
import { getLoopInitialPage } from "service/loop-service";
Expand All @@ -39,7 +39,7 @@ const HelpDuration = () => {

const { classes, cx } = useStyles();

const [helpStep] = React.useState(1);
const helpStep = 1;

const activitiesAct = getActivitiesOrRoutes(t, idSurvey, source).activitiesRoutesOrGaps;

Expand Down
Loading

0 comments on commit 3ff1efa

Please sign in to comment.