Skip to content

Commit

Permalink
feat(yarn): fix eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
lailabjil committed Oct 24, 2023
1 parent 053e1d8 commit 55f2f6a
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 69 deletions.
2 changes: 1 addition & 1 deletion e2e/e2e-reviewer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe("App.ts", () => {
expect(urlHome).toContain(urlHost + EdtRoutesNameEnum.REVIEWER_SURVEYS_OVERVIEW);

const numHouseholds = (await page.$$('[id^="householdCard-"]')).length;
//expect(numHouseholds).toBe(2);
expect(numHouseholds).toBe(2);

/* await page.click("#householdCard-0");
await page.waitForNavigation();*/
Expand Down
17 changes: 3 additions & 14 deletions src/orchestrator/Orchestrator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,8 @@ const renderLoading = () => {
};

export const OrchestratorForStories = (props: OrchestratorProps) => {
const {
source,
data,
cbHolder,
page,
subPage,
iteration,
componentSpecificProps,
overrideOptions,
idSurvey,
} = props;
const { source, data, cbHolder, page, subPage, iteration, componentSpecificProps, overrideOptions } =
props;
const { classes, cx } = useStyles();

const { getComponents, getCurrentErrors, getData } = lunatic.useLunatic(source, data, {
Expand Down Expand Up @@ -116,9 +107,7 @@ export const OrchestratorForStories = (props: OrchestratorProps) => {
const getDataInterviewer = () => {
const callbackholder = getData();
const dataCollected = Object.assign({}, callbackholder.COLLECTED);
const bindings: string[] = components?.filter(
(component: any) => component.componentType != "Sequence",
)[0]?.bindingDependencies;

if (callbackholder && dataCollected) {
for (let prop in FieldNameEnum as any) {
const dataOfField = dataCollected[prop];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,13 @@ import extensionDisabled from "assets/illustration/mui-icon/extension-grey.svg";
import extension from "assets/illustration/mui-icon/extension.svg";
import search from "assets/illustration/mui-icon/search.svg";
import { SEPARATOR_DEFAUT } from "constants/constants";
import { FieldNameEnum } from "enumerations/FieldNameEnum";
import { LoopEnum } from "enumerations/LoopEnum";
import React, { useCallback, useState } from "react";
import { useTranslation } from "react-i18next";
import { getLabelsWhenQuit } from "service/alert-service";
import { getAutoCompleteRef, getNomenclatureRef } from "service/referentiel-service";
import { surveyReadOnly } from "service/survey-activity-service";
import {
addToAutocompleteActivityReferentiel,
createNewActivityInCategory,
} from "service/survey-service";
import { createNewActivityInCategory } from "service/survey-service";
import { getSurveyIdFromUrl } from "utils/utils";

const MainActivityPage = () => {
Expand Down
1 change: 0 additions & 1 deletion src/service/api-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ const logout = () => {
const remoteGetSurveyData = (
idSurvey: string,
setError?: (error: ErrorCodeEnum) => void,
withState?: boolean,
): Promise<SurveyData> => {
return new Promise(resolve => {
axios
Expand Down
2 changes: 1 addition & 1 deletion src/service/survey-activity-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ const deleteActivity = (idSurvey: string, source: LunaticModel, iteration: numbe
}
});
saveData(idSurvey, data).then(() => {
return saveData(idSurvey,data);
return saveData(idSurvey, data);
});
}
};
Expand Down
122 changes: 75 additions & 47 deletions src/service/survey-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ import {
import { getFlatLocalStorageValue } from "./local-storage-service";
import { getScore } from "./survey-activity-service";
import { getUserRights, isReviewer } from "./user-service";
import { isUuid } from "uuidv4";
import { validate } from "uuid";

const datas = new Map<string, LunaticData>();
Expand Down Expand Up @@ -205,7 +204,7 @@ const initializeSurveysIdsAndSources = (setError: (error: ErrorCodeEnum) => void
}),
);
promises.push(
getRemoteSavedSurveysDatas(surveysIdsAct, setError, false).then(data => {
getRemoteSavedSurveysDatas(surveysIdsAct, setError, false).then(() => {
return initializeSurveysDatasCache();
}),
);
Expand All @@ -223,13 +222,6 @@ const initializeSurveysIdsAndSources = (setError: (error: ErrorCodeEnum) => void
});
};

const initializeSources = (setError: (error: ErrorCodeEnum) => void): Promise<any> => {
let distinctSources = [SourcesEnum.ACTIVITY_SURVEY, SourcesEnum.WORK_TIME_SURVEY];
return fetchSurveysSourcesByIds(distinctSources, setError).then(sources => {
return saveSources(sources);
});
};

const activitySurveyDemo = () => {
let activitySurveysIds: string[] = [];
let numInterviewer = 0;
Expand Down Expand Up @@ -516,7 +508,7 @@ const initializeListSurveys = () => {
});
return saveUserSurveysData({ data: userDatas });
})
.catch(error => {
.catch(() => {
return lunaticDatabase.get(USER_SURVEYS_DATA);
});
};
Expand Down Expand Up @@ -668,56 +660,92 @@ const dataIsChange = (idSurvey: string, dataAct: LunaticData) => {
return isChange;
};

const undefineVarSomeone = (data: LunaticData, modePersistence: ModePersistenceEnum, index: number) => {
const dataCollected = data.COLLECTED;
const undefineVarSomeone = (data: LunaticData, modePersistence: ModePersistenceEnum, index: number) => {
const dataCollected = data.COLLECTED;
const modeInterviewer = modePersistence == ModePersistenceEnum.COLLECTED;
if(dataCollected) {
const child = (modeInterviewer ? dataCollected[FieldNameEnum.CHILD].COLLECTED : dataCollected[FieldNameEnum.CHILD].EDITED) as (boolean|null)[];
const couple = (modeInterviewer ? dataCollected[FieldNameEnum.COUPLE].COLLECTED : dataCollected[FieldNameEnum.COUPLE].EDITED) as (boolean|null)[];
const parents = (modeInterviewer ? dataCollected[FieldNameEnum.PARENTS].COLLECTED : dataCollected[FieldNameEnum.PARENTS].EDITED) as (boolean|null)[];
const otherknow = (modeInterviewer ? dataCollected[FieldNameEnum.OTHERKNOWN].COLLECTED : dataCollected[FieldNameEnum.OTHERKNOWN].EDITED) as (boolean|null)[];
const other = (modeInterviewer ? dataCollected[FieldNameEnum.OTHER].COLLECTED : dataCollected[FieldNameEnum.OTHER].EDITED) as (boolean|null)[];

if(child) child[index] = null;
if(couple) couple[index] = null;
if(parents) parents[index] = null;
if(otherknow) otherknow[index] = null;
if(other) other[index] = null;
if (dataCollected) {
const child = (
modeInterviewer
? dataCollected[FieldNameEnum.CHILD].COLLECTED
: dataCollected[FieldNameEnum.CHILD].EDITED
) as (boolean | null)[];
const couple = (
modeInterviewer
? dataCollected[FieldNameEnum.COUPLE].COLLECTED
: dataCollected[FieldNameEnum.COUPLE].EDITED
) as (boolean | null)[];
const parents = (
modeInterviewer
? dataCollected[FieldNameEnum.PARENTS].COLLECTED
: dataCollected[FieldNameEnum.PARENTS].EDITED
) as (boolean | null)[];
const otherknow = (
modeInterviewer
? dataCollected[FieldNameEnum.OTHERKNOWN].COLLECTED
: dataCollected[FieldNameEnum.OTHERKNOWN].EDITED
) as (boolean | null)[];
const other = (
modeInterviewer
? dataCollected[FieldNameEnum.OTHER].COLLECTED
: dataCollected[FieldNameEnum.OTHER].EDITED
) as (boolean | null)[];

if (child) child[index] = null;
if (couple) couple[index] = null;
if (parents) parents[index] = null;
if (otherknow) otherknow[index] = null;
if (other) other[index] = null;
}
}
};

const undefineVarSecondaryActivity = (data: LunaticData, modePersistence: ModePersistenceEnum, index: number) => {
const dataCollected = data.COLLECTED;
const undefineVarSecondaryActivity = (
data: LunaticData,
modePersistence: ModePersistenceEnum,
index: number,
) => {
const dataCollected = data.COLLECTED;
const modeInterviewer = modePersistence == ModePersistenceEnum.COLLECTED;
if(dataCollected) {
const secondaryActivity = (modeInterviewer ? dataCollected[FieldNameEnum.SECONDARYACTIVITY].COLLECTED : dataCollected[FieldNameEnum.SECONDARYACTIVITY].EDITED) as (string|null)[];
const secondaryActivityLabel = (modeInterviewer ? dataCollected[FieldNameEnum.SECONDARYACTIVITY_LABEL].COLLECTED : dataCollected[FieldNameEnum.SECONDARYACTIVITY_LABEL].EDITED) as (string|null)[];

if(secondaryActivity) secondaryActivity[index] = null;
if(secondaryActivityLabel) secondaryActivityLabel[index] = null;
if (dataCollected) {
const secondaryActivity = (
modeInterviewer
? dataCollected[FieldNameEnum.SECONDARYACTIVITY].COLLECTED
: dataCollected[FieldNameEnum.SECONDARYACTIVITY].EDITED
) as (string | null)[];
const secondaryActivityLabel = (
modeInterviewer
? dataCollected[FieldNameEnum.SECONDARYACTIVITY_LABEL].COLLECTED
: dataCollected[FieldNameEnum.SECONDARYACTIVITY_LABEL].EDITED
) as (string | null)[];

if (secondaryActivity) secondaryActivity[index] = null;
if (secondaryActivityLabel) secondaryActivityLabel[index] = null;
}
}
};

const fixConditionals = (data: LunaticData) => {
const withSomeone = data.COLLECTED?.[FieldNameEnum.WITHSOMEONE];
const withSecondaryActivity = data.COLLECTED?.[FieldNameEnum.WITHSECONDARYACTIVITY];
const withSomeone = data.COLLECTED?.[FieldNameEnum.WITHSOMEONE];
const withSecondaryActivity = data.COLLECTED?.[FieldNameEnum.WITHSECONDARYACTIVITY];
const modePersistence = getModePersistence(data);

const arrayWithSomeone = modePersistence == ModePersistenceEnum.COLLECTED ? withSomeone?.COLLECTED : withSomeone?.EDITED;
const arrayWithSecondaryActivity = modePersistence == ModePersistenceEnum.COLLECTED ? withSecondaryActivity?.COLLECTED : withSecondaryActivity?.EDITED;
const arrayWithSomeone =
modePersistence == ModePersistenceEnum.COLLECTED ? withSomeone?.COLLECTED : withSomeone?.EDITED;
const arrayWithSecondaryActivity =
modePersistence == ModePersistenceEnum.COLLECTED
? withSecondaryActivity?.COLLECTED
: withSecondaryActivity?.EDITED;

arrayWithSomeone?.forEach((withSom:string,index:number) => {
if(withSom == 'false') {
undefineVarSomeone(data,modePersistence,index);
arrayWithSomeone?.forEach((withSom: string, index: number) => {
if (withSom == "false") {
undefineVarSomeone(data, modePersistence, index);
}
});

arrayWithSecondaryActivity?.forEach((withSecAct:string,index:number) => {
if(withSecAct == 'false') {
undefineVarSecondaryActivity(data,modePersistence,index);
arrayWithSecondaryActivity?.forEach((withSecAct: string, index: number) => {
if (withSecAct == "false") {
undefineVarSecondaryActivity(data, modePersistence, index);
}
});
}
};

const saveData = (idSurvey: string, data: LunaticData, localSaveOnly = false): Promise<LunaticData> => {
data.lastLocalSaveDate = Date.now();
Expand All @@ -729,7 +757,7 @@ const saveData = (idSurvey: string, data: LunaticData, localSaveOnly = false): P
const isReviewerMode = getUserRights() == EdtUserRightsEnum.REVIEWER;
fixConditionals(data);
const isChange = dataIsChange(idSurvey, data);

return lunaticDatabase.save(idSurvey, data).then(() => {
const promisesToWait: Promise<any>[] = [];
datas.set(idSurvey, data);
Expand Down Expand Up @@ -927,7 +955,7 @@ const createNewActivityInCategory = (
});
const indexParentCategory = ref.findIndex((opt: any) => opt.id == parentCategoryId);
ref[indexParentCategory] = categoryParent;
return saveReferentiels(currentData).then(data => {
return saveReferentiels(currentData).then(() => {
addToAutocompleteActivityReferentiel(newItem);
localStorage.setItem("selectedIdNewActivity", newActivity);
});
Expand Down

0 comments on commit 55f2f6a

Please sign in to comment.