Skip to content

Commit

Permalink
CLDR-17560 improve Dashboard robustness
Browse files Browse the repository at this point in the history
- use second param to callback() to return err instead of global
- popup err message if dashboard fails to load
  • Loading branch information
srl295 committed Jun 3, 2024
1 parent c1dc8c7 commit 311f93f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
20 changes: 7 additions & 13 deletions tools/cldr-apps/js/src/esm/cldrDash.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -362,17 +362,18 @@ class DashEntry {
}
}

let fetchErr = "";

let viewSetDataCallback = null;

/**
* @param {Function} callback called with results of data load
* @returns
*/
function doFetch(callback) {
viewSetDataCallback = callback;
fetchErr = "";
const locale = cldrStatus.getCurrentLocale();
const level = cldrCoverage.effectiveName(locale);
if (!locale || !level) {
fetchErr = "Please choose a locale and a coverage level first.";
callback(null, "Please choose a locale and a coverage level first.");
return;
}
const url = `api/summary/dashboard/${locale}/${level}`;
Expand All @@ -382,16 +383,10 @@ function doFetch(callback) {
.then((data) => data.json())
.then(setData)
.catch((err) => {
const msg = "Error loading Dashboard data: " + err;
console.error(msg);
fetchErr = msg;
cldrNotify.exception(err, "Loading dashboard data");
callback(null, `Error loading dashboard data: ${err}`);
});
}

function getFetchError() {
return fetchErr;
}

/**
* Set the data for the Dashboard, converting from json to a DashData object
*
Expand Down Expand Up @@ -602,7 +597,6 @@ async function getLocaleErrors(locale) {
export {
doFetch,
downloadXlsx,
getFetchError,
getLocaleErrors,
saveEntryCheckmark,
setData,
Expand Down
11 changes: 6 additions & 5 deletions tools/cldr-apps/js/src/views/DashboardWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export default {
};
},
created() {
mounted() {
if (cldrStatus.getPermissions()?.userIsTC) {
this.catIsHidden["Abstained"] = this.catCheckboxIsUnchecked[
"Abstained"
Expand Down Expand Up @@ -255,22 +255,23 @@ export default {
fetchData() {
if (!cldrStatus.getSurveyUser()) {
this.fetchErr = "Please log in to see the Dashboard.";
this.fetchErr.value = "Please log in to see the Dashboard.";
return;
}
this.locale = cldrStatus.getCurrentLocale();
this.level = cldrCoverage.effectiveName(this.locale);
if (!this.locale || !this.level) {
this.fetchErr = "Please choose a locale and a coverage level first.";
this.fetchErr.value =
"Please choose a locale and a coverage level first.";
return;
}
this.localeName = cldrLoad.getLocaleName(this.locale);
this.loadingMessage = `Loading ${this.localeName} dashboard at ${this.level} level`;
cldrDash.doFetch(this.setData);
this.fetchErr = cldrDash.getFetchError();
},
setData(data) {
setData(data, err) {
this.fetchErr = err || null;
this.data = data;
this.resetScrolling();
},
Expand Down

0 comments on commit 311f93f

Please sign in to comment.