Skip to content

Commit

Permalink
Merge branch 'fix/perf' into 'feat/sprint20'
Browse files Browse the repository at this point in the history
Fix/perf

See merge request insee/edt/pwa-edt!66
  • Loading branch information
lailabjil committed Mar 28, 2024
2 parents 882e727 + 53d6bc3 commit 2c882dd
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 173 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "edt",
"version": "3.14.4",
"dateVersion": "27/03/2024",
"version": "3.14.7",
"dateVersion": "28/03/2024",
"licence": "MIT",
"dependencies": {
"@emotion/react": "^11.10.4",
Expand Down
5 changes: 3 additions & 2 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"icons": [
{
"src": "favicon.ico",
"sizes": "48x48 32x32 16x16",
"sizes": "32x32 16x16",
"type": "image/x-icon"
},
{
Expand Down Expand Up @@ -219,5 +219,6 @@
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
"background_color": "#ffffff",
"prefer_related_applications": true
}
3 changes: 1 addition & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const App = () => {
const { t } = useTranslation();
const [initialized, setInitialized] = useState(false);
const [error, setError] = useState<ErrorCodeEnum | undefined>(undefined);
const auth = useAuth();

const getTokenHint = () => {
return localStorage.getItem("id_token") ?? undefined;
Expand All @@ -36,8 +37,6 @@ const App = () => {
};
const promisesToWait: Promise<any>[] = [];

const auth = useAuth();

useEffect(() => {
if (
window.location.search &&
Expand Down
4 changes: 3 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const oidcConfigSSO = {
userManager: createUserManager(),
};

const currentHost = `${window.location.protocol}//${window.location.hostname}`;

const oidcConfigOnline = {
onSignIn: () => {
//to remove keycloak params in url
Expand All @@ -33,7 +35,7 @@ const oidcConfigOnline = {

const oidcConfigOffline = {
automaticSilentRenew: !navigator.onLine,
silent_redirect_uri: "https://insee-edt.k8s.keyconsulting.fr/",
silent_redirect_uri: currentHost,
};

const oidcConfig = navigator.onLine ? oidcConfigOnline : oidcConfigOffline;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home-surveyed/HomeSurveyed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const HomeSurveyedPage = () => {
!survey.startsWith("activitySurvey") && !survey.startsWith("workTimeSurvey"),
);
if (navigator.onLine) {
getRemoteSavedSurveysDatas(idsSurveysSelected, setError).then(() => {
getRemoteSavedSurveysDatas(idsSurveysSelected, setError, false).then(() => {
initHome(idsSurveysSelected);
});
} else {
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 @@ -124,7 +124,6 @@ const SurveysOverviewPage = () => {

const initHouseholds = () => {
dataHouseholds = getListSurveysHousehold();

if (searchResult == null || searchResult.length == 0) {
setSearchResult(dataHouseholds);
}
Expand Down
103 changes: 54 additions & 49 deletions src/service/api-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,18 @@ const requestPutSurveyData = (
data: SurveyData,
token?: string,
): Promise<SurveyData> => {
return new Promise<SurveyData>(resolve => {
axios
.put(
stromaeBackOfficeApiBaseUrl + "api/survey-unit/" + idSurvey,
data,
getHeader(stromaeBackOfficeApiBaseUrl, token),
)
.then(() => {
resolve(data);
});
return new Promise((resolve, reject) => {

Check warning on line 171 in src/service/api-service.ts

View workflow job for this annotation

GitHub Actions / test_lint

'reject' is defined but never used

Check warning on line 171 in src/service/api-service.ts

View workflow job for this annotation

GitHub Actions / test_lint

'reject' is defined but never used
setTimeout(() => {
axios
.put(
stromaeBackOfficeApiBaseUrl + "api/survey-unit/" + idSurvey,
data,
getHeader(stromaeBackOfficeApiBaseUrl, token),
)
.then(() => {
resolve(data);
});
}, 1000);
});
};

Expand Down Expand Up @@ -235,15 +237,17 @@ const requestPutDataReviewer = (
token?: string,
): Promise<LunaticData> => {
return new Promise<LunaticData>(resolve => {
axios
.put(
stromaeBackOfficeApiBaseUrl + "api/survey-unit/" + idSurvey + "/data",
data,
getHeader(stromaeBackOfficeApiBaseUrl, token),
)
.then(() => {
resolve(data);
});
setTimeout(() => {
axios
.put(
stromaeBackOfficeApiBaseUrl + "api/survey-unit/" + idSurvey + "/data",
data,
getHeader(stromaeBackOfficeApiBaseUrl, token),
)
.then(() => {
resolve(data);
});
}, 1000);
});
};

Expand All @@ -253,25 +257,27 @@ const requestPutStateReviewer = (
token?: string,
): Promise<StateData> => {
return new Promise<StateData>(resolve => {
axios
.put(
stromaeBackOfficeApiBaseUrl + "api/survey-unit/" + idSurvey + "/state-data",
data,
getHeader(stromaeBackOfficeApiBaseUrl, token),
)
.then(() => {
resolve(data);
})
.catch(err => {
if (err.response?.status == 404) {
const stateData = {
state: StateDataStateEnum.INIT,
date: Date.now(),
currentPage: 0,
};
resolve(stateData);
}
});
setTimeout(() => {
axios
.put(
stromaeBackOfficeApiBaseUrl + "api/survey-unit/" + idSurvey + "/state-data",
data,
getHeader(stromaeBackOfficeApiBaseUrl, token),
)
.then(() => {
resolve(data);
})
.catch(err => {
if (err.response?.status == 404) {
const stateData = {
state: StateDataStateEnum.INIT,
date: Date.now(),
currentPage: 0,
};
resolve(stateData);
}
});
}, 1000);
});
};

Expand All @@ -281,18 +287,17 @@ const requestPutSurveyDataReviewer = (
stateData: StateData,
token?: string,
): Promise<SurveyData> => {
const promises = requestPutDataReviewer(idSurvey, data, token).then(() => {
return requestPutStateReviewer(idSurvey, stateData, token).then(() => {
return new Promise<SurveyData>(resolve => {
const surveyData: SurveyData = {
stateData: stateData,
data: data,
};
resolve(surveyData);
});
});
requestPutStateReviewer(idSurvey, stateData, token).then(() => {
requestPutDataReviewer(idSurvey, data, token);
});

return new Promise(resolve => {

Check warning on line 294 in src/service/api-service.ts

View workflow job for this annotation

GitHub Actions / test_lint

'resolve' is defined but never used

Check warning on line 294 in src/service/api-service.ts

View workflow job for this annotation

GitHub Actions / test_lint

'resolve' is defined but never used
const surveyData: SurveyData = {
stateData: stateData,
data: data,
};
return surveyData;
});
return promises;
};

const logout = () => {
Expand Down
3 changes: 2 additions & 1 deletion src/service/auth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ const createUserManager = () => {
});

userManager.events.addUserLoaded(user => {
console.log("add user");
console.log("add user", user);
setUserToken(user?.access_token || "");
});

userManager.events.addAccessTokenExpired(() => {
if (navigator.onLine) {
signinSilent(userManager);
Expand Down
Loading

0 comments on commit 2c882dd

Please sign in to comment.