Skip to content

Commit 2d60bc3

Browse files
committed
[UI] Improve baseline error evaluation
Since table renders sometimes use callbacks from a previous table, there were some false-positive error messages when using baseline comparison. We now wait 2 seconds before triggering the error as the table might have been reloaded in the meantime.
1 parent 3d344e7 commit 2d60bc3

File tree

10 files changed

+120
-88
lines changed

10 files changed

+120
-88
lines changed

src/modules/renderers/dashboard.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,7 @@ renderDashboard <- function(id, data, options = NULL, path = NULL, rendererEnv =
471471
const offset=(meta.row+meta.settings._iDisplayStart)+(meta.col-", noRowHeaders, ")*", nrow(dataTmp), ";
472472
const secondaryMetric=", secondaryMetric, ";
473473
const refData=", toJSON(attr(dataTmp, "baselineComp")$secondaryData[[".primary"]]), "[offset];
474-
if (Math.abs(refData - data) > 1e-4 && window.alertPushed !== '", tableSessionId, "') {
475-
window.alertPushed = '", tableSessionId, "';
476-
Miro.modal('Something went wrong. Please dont trust the data! Also, please contact GAMS about this issue (id: 981273) via [email protected]', 'OK');
477-
}
474+
Miro.evaluateBaselineCompData(refData, data, ", toJSString(ns(paste0(indicator, "Table"))), ",", toJSString(tableSessionId), ");
478475
return '<span class=\"miro-pivot-primary-data\">'+pm+(pm===''?'':'", attr(dataTmp, "baselineComp")$metricSuffix[[1]], "')+'</span>'+(secondaryMetric===''?'':' ('+secondaryMetric+'",
479476
attr(dataTmp, "baselineComp")$metricSuffix[[2]], "'+')');}"
480477
)

src/modules/renderers/miro-pivot.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3792,10 +3792,7 @@ const pm=", if (!is.null(decimals)) paste0("DTWidget.formatRound(data,", as.char
37923792
const offset=(meta.row+meta.settings._iDisplayStart)+(meta.col-", noRowHeaders, ")*", nrow(dataTmp), ";
37933793
const secondaryMetric=", secondaryMetric, ";
37943794
const refData=", toJSON(attr(dataTmp, "baselineComp")$secondaryData[[".primary"]]), "[offset];
3795-
if (Math.abs(refData - data) > 1e-4 && window.alertPushed !== '", tableSessionId, "') {
3796-
window.alertPushed = '", tableSessionId, "';
3797-
Miro.modal('Something went wrong. Please dont trust the data! Also, please contact GAMS about this issue (id: 981273) via [email protected]', 'OK');
3798-
}
3795+
Miro.evaluateBaselineCompData(refData, data, ", toJSString(ns("pivotTable")), ",", toJSString(tableSessionId), ");
37993796
return '<span class=\"miro-pivot-primary-data\">'+pm+(pm===''?'':'", attr(dataTmp, "baselineComp")$metricSuffix[[1]], "')+'</span>'+(secondaryMetric===''?'':' ('+secondaryMetric+'",
38003797
attr(dataTmp, "baselineComp")$metricSuffix[[2]], "'+')');}"
38013798
)

src/modules/renderers/mirocompare_dashboard.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,7 @@ renderDashboardCompare <- function(input, output, session, data, options = NULL,
523523
const offset=(meta.row+meta.settings._iDisplayStart)+(meta.col-", noRowHeaders, ")*", nrow(dataTmp), ";
524524
const secondaryMetric=", secondaryMetric, ";
525525
const refData=", toJSON(attr(dataTmp, "baselineComp")$secondaryData[[".primary"]]), "[offset];
526-
if (Math.abs(refData - data) > 1e-4 && window.alertPushed !== '", tableSessionId, "') {
527-
window.alertPushed = '", tableSessionId, "';
528-
Miro.modal('Something went wrong. Please dont trust the data! Also, please contact GAMS about this issue (id: 981273) via [email protected]', 'OK');
529-
}
526+
Miro.evaluateBaselineCompData(refData, data, ", toJSString(ns(paste0(indicator, "Table"))), ",", toJSString(tableSessionId), ");
530527
return '<span class=\"miro-pivot-primary-data\">'+pm+(pm===''?'':'", attr(dataTmp, "baselineComp")$metricSuffix[[1]], "')+'</span>'+(secondaryMetric===''?'':' ('+secondaryMetric+'",
531528
attr(dataTmp, "baselineComp")$metricSuffix[[2]], "'+')');}"
532529
)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import modal from './modal';
2+
3+
export default class BaselineCompareErrorManager {
4+
errors = {};
5+
6+
evaluateData(refData, data, tableId, sessionId) {
7+
if (Math.abs(refData - data) > 1e-4) {
8+
if (
9+
!Object.hasOwn(this.errors, tableId) ||
10+
this.errors[tableId] !== sessionId
11+
) {
12+
this.errors[tableId] = sessionId;
13+
setTimeout(() => {
14+
if (
15+
Object.hasOwn(this.errors, tableId) &&
16+
this.errors[tableId] === sessionId
17+
) {
18+
modal(
19+
"Something went wrong. Please don't trust the data! Also, please contact GAMS about this issue (id: 981273) via [email protected]",
20+
'OK',
21+
);
22+
}
23+
}, 2000);
24+
}
25+
} else if (
26+
Object.hasOwn(this.errors, tableId) &&
27+
this.errors[tableId] !== sessionId
28+
) {
29+
// old error -> clear as we render a new table
30+
delete this.errors[tableId];
31+
}
32+
}
33+
}

src/srcjs/miro.js

Lines changed: 25 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import 'core-js/stable';
44
import AutoNumeric from 'autonumeric';
55

6+
import BaselineCompareErrorManager from './baseline_compare_error_manager';
7+
68
import {
79
sleep,
810
changeActiveButtons,
@@ -29,8 +31,11 @@ import {
2931
activateMiroPivotPresentationObservers,
3032
} from './miro_pivot';
3133

34+
export { default as modal } from './modal';
35+
3236
const loadingScreen = new LoadingScreen();
3337
const miroLogParser = new MiroLogParser();
38+
const baselineCompareErrorManager = new BaselineCompareErrorManager();
3439

3540
export function changeTab(object, idActive, idRefer) {
3641
const tabPane = object.closest('.tabbable');
@@ -42,6 +47,10 @@ export function changeTab(object, idActive, idRefer) {
4247
tabPane.find(`.tab-content div:nth-child(${idRefer})`).addClass('active');
4348
}
4449

50+
export function evaluateBaselineCompData(refData, data, tableId, sessionId) {
51+
baselineCompareErrorManager.evaluateData(refData, data, tableId, sessionId);
52+
}
53+
4554
export function slideToggleEl(data) {
4655
if (data.toggleIconDiv !== undefined) {
4756
if ($(data.id).is(':visible')) {
@@ -189,60 +198,6 @@ export function filterMiroDropdown(that) {
189198
});
190199
}
191200

192-
export function modal(
193-
msg,
194-
okButton,
195-
cancelButton,
196-
value,
197-
callback,
198-
...callbackArgs
199-
) {
200-
Shiny.modal.show({
201-
html: `<div id="shiny-modal" class="modal fade"
202-
tabindex="-1" data-backdrop="static" data-keyboard="false">
203-
<div class="modal-dialog modal-sm">
204-
<div class="modal-content">
205-
<div class="modal-body">
206-
${
207-
value == null
208-
? `<div class="text-break"><strong>${msg}</strong></div>`
209-
: `<div class="form-group shiny-input-container">
210-
<label class="control-label" for="miroPromptInput">${msg}</label>
211-
<input id="miroPromptInput" type="text" class="form-control" value="${value}"/>
212-
</div>`
213-
}
214-
</div>
215-
<div class="modal-footer">
216-
${cancelButton == null ? '' : `<button type="button" class="btn btn-default" data-dismiss="modal">${cancelButton}</button>`}
217-
<button id="miroModalConfirmButton" type="button"
218-
class="btn btn-default bt-highlight-1 bt-gms-confirm">${okButton}</button>
219-
</div>
220-
</div>
221-
</div>
222-
<script>$('#shiny-modal').modal().focus();</script>
223-
</div>`,
224-
});
225-
$(document).off('click', '#miroModalConfirmButton');
226-
if (value == null) {
227-
$(document).on('click', '#miroModalConfirmButton', () => {
228-
if (callback == null || callback(...callbackArgs) !== false) {
229-
$('#shiny-modal').modal('hide');
230-
}
231-
});
232-
} else {
233-
$(document).on('click', '#miroModalConfirmButton', () => {
234-
if (
235-
callback(
236-
document.getElementById('miroPromptInput').value,
237-
...callbackArgs,
238-
) !== false
239-
) {
240-
$('#shiny-modal').modal('hide');
241-
}
242-
});
243-
}
244-
}
245-
246201
export function parseKatex(element) {
247202
renderMathInElement(element, {
248203
throwOnError: false,
@@ -544,22 +499,18 @@ $(() => {
544499
this.href = data;
545500
});
546501
// miro dashboard value boxes click handler
547-
$(document).on(
548-
'click',
549-
'.custom-info-box',
550-
function () {
551-
const parentDiv = $(this).parent();
552-
let namespaceId = parentDiv[0].dataset.namespace;
553-
if (namespaceId == null) {
554-
// old dashboard renderers did not have namespace data attribute
555-
namespaceId = parentDiv[0].id.split('-');
556-
namespaceId = `${namespaceId[0]}-${namespaceId[1]}-`;
557-
}
558-
Shiny.setInputValue(`${namespaceId}showChart`, parentDiv.attr('id'), {
559-
priority: 'event',
560-
});
561-
},
562-
);
502+
$(document).on('click', '.custom-info-box', function () {
503+
const parentDiv = $(this).parent();
504+
let namespaceId = parentDiv[0].dataset.namespace;
505+
if (namespaceId == null) {
506+
// old dashboard renderers did not have namespace data attribute
507+
namespaceId = parentDiv[0].id.split('-');
508+
namespaceId = `${namespaceId[0]}-${namespaceId[1]}-`;
509+
}
510+
Shiny.setInputValue(`${namespaceId}showChart`, parentDiv.attr('id'), {
511+
priority: 'event',
512+
});
513+
});
563514

564515
$('.sidebar-toggle').click(() => {
565516
rerenderHot(400);
@@ -578,7 +529,8 @@ $(() => {
578529
Shiny.addCustomMessageHandler('gms-showLoadingScreen', (delay) => {
579530
loadingScreen.show(delay);
580531
});
581-
Shiny.addCustomMessageHandler('gms-hideLoadingScreen', (e) => { // eslint-disable-line no-unused-vars
532+
// eslint-disable-next-line no-unused-vars
533+
Shiny.addCustomMessageHandler('gms-hideLoadingScreen', (e) => {
582534
loadingScreen.hide();
583535
});
584536
Shiny.addCustomMessageHandler('gms-showEl', (data) => {
@@ -984,7 +936,8 @@ font-size:15pt;text-align:center;'>${data.data}</div>`
984936
Shiny.bindAll(dropdownContainer);
985937
});
986938
});
987-
Shiny.addCustomMessageHandler('gms-parseLog', (e) => { // eslint-disable-line no-unused-vars
939+
// eslint-disable-next-line no-unused-vars
940+
Shiny.addCustomMessageHandler('gms-parseLog', (e) => {
988941
if (miroLogParser.isInitialized !== true) {
989942
return;
990943
}

src/srcjs/modal.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* global $:false Shiny: false */
2+
3+
export default function modal(
4+
msg,
5+
okButton,
6+
cancelButton,
7+
value,
8+
callback,
9+
...callbackArgs
10+
) {
11+
Shiny.modal.show({
12+
html: `<div id="shiny-modal" class="modal fade"
13+
tabindex="-1" data-backdrop="static" data-keyboard="false">
14+
<div class="modal-dialog modal-sm">
15+
<div class="modal-content">
16+
<div class="modal-body">
17+
${
18+
value == null
19+
? `<div class="text-break"><strong>${msg}</strong></div>`
20+
: `<div class="form-group shiny-input-container">
21+
<label class="control-label" for="miroPromptInput">${msg}</label>
22+
<input id="miroPromptInput" type="text" class="form-control" value="${value}"/>
23+
</div>`
24+
}
25+
</div>
26+
<div class="modal-footer">
27+
${cancelButton == null ? '' : `<button type="button" class="btn btn-default" data-dismiss="modal">${cancelButton}</button>`}
28+
<button id="miroModalConfirmButton" type="button"
29+
class="btn btn-default bt-highlight-1 bt-gms-confirm">${okButton}</button>
30+
</div>
31+
</div>
32+
</div>
33+
<script>$('#shiny-modal').modal().focus();</script>
34+
</div>`,
35+
});
36+
$(document).off('click', '#miroModalConfirmButton');
37+
if (value == null) {
38+
$(document).on('click', '#miroModalConfirmButton', () => {
39+
if (callback == null || callback(...callbackArgs) !== false) {
40+
$('#shiny-modal').modal('hide');
41+
}
42+
});
43+
} else {
44+
$(document).on('click', '#miroModalConfirmButton', () => {
45+
if (
46+
callback(
47+
document.getElementById('miroPromptInput').value,
48+
...callbackArgs,
49+
) !== false
50+
) {
51+
$('#shiny-modal').modal('hide');
52+
}
53+
});
54+
}
55+
}

src/www/miro.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/www/miro.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/www/miro_admin.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/www/miro_admin.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)