@datalabz_/dashboard-kit 6.0.8 → 6.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/v4.js +1 -1
- package/v5.js +1 -1
- package/v6.js +79 -9
package/package.json
CHANGED
package/v4.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
let _activeTabId = '';
|
|
21
21
|
let _sections = []; // { id, label, load, loaded, errors }
|
|
22
22
|
let _title = '';
|
|
23
|
-
let _gitVer = '
|
|
23
|
+
let _gitVer = '320ab06'; // replaced at deploy: sed -i "s/320ab06/$(git rev-parse --short HEAD)/g" v4.js
|
|
24
24
|
let _calls = []; // System Info call log
|
|
25
25
|
let _sectionErrors = {}; // sectionId → error count
|
|
26
26
|
let _generation = 0;
|
package/v5.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
let _activeTabId = '';
|
|
21
21
|
let _sections = []; // { id, label, load, loaded, errors }
|
|
22
22
|
let _title = '';
|
|
23
|
-
let _gitVer = '
|
|
23
|
+
let _gitVer = '320ab06'; // replaced at deploy: sed -i "s/320ab06/$(git rev-parse --short HEAD)/g" v4.js
|
|
24
24
|
let _calls = []; // System Info call log
|
|
25
25
|
let _sectionErrors = {}; // sectionId → error count
|
|
26
26
|
let _generation = 0;
|
package/v6.js
CHANGED
|
@@ -20,10 +20,11 @@
|
|
|
20
20
|
let _activeTabId = '';
|
|
21
21
|
let _sections = []; // { id, label, load, loaded, errors }
|
|
22
22
|
let _title = '';
|
|
23
|
-
let _gitVer = '
|
|
23
|
+
let _gitVer = '320ab06'; // replaced at deploy: sed -i "s/320ab06/$(git rev-parse --short HEAD)/g" v6.js
|
|
24
24
|
let _calls = []; // System Info call log
|
|
25
25
|
let _sectionErrors = {}; // sectionId → error count
|
|
26
26
|
let _generation = 0;
|
|
27
|
+
let _abort = new AbortController(); // this generation's requests; _invalidateAll aborts them
|
|
27
28
|
let _ttEl = null;
|
|
28
29
|
let _pendingFilters = {}; // header filters a parent sent before boot, applied at boot
|
|
29
30
|
let _filtersRefused = false;
|
|
@@ -1583,6 +1584,8 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
1583
1584
|
|
|
1584
1585
|
function _invalidateAll() {
|
|
1585
1586
|
_generation++;
|
|
1587
|
+
_abort.abort();
|
|
1588
|
+
_abort = new AbortController();
|
|
1586
1589
|
_sections.forEach(function (s) { s.loaded = false; s.errors = 0; });
|
|
1587
1590
|
_sectionErrors = {};
|
|
1588
1591
|
_calls = [];
|
|
@@ -1605,27 +1608,38 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
1605
1608
|
// What a click point drawn by this load reports: this section, and the header filters and the
|
|
1606
1609
|
// context as the load started, not edits made since.
|
|
1607
1610
|
const ctx = { id: sec.id, localFilters: _headerSnapshot(), context: _contextSnapshot() };
|
|
1611
|
+
// Kept on the section for a render call that arrives without it (_ctxOf).
|
|
1612
|
+
sec.ctx = ctx;
|
|
1613
|
+
// A replaced load must not draw (see _superseded). It stops at its next query; these stop one that
|
|
1614
|
+
// catches that itself and draws anyway, a dashboard wrapping its queries in try/catch. Only while
|
|
1615
|
+
// the load runs: a handler it leaves behind calls and draws as it always has.
|
|
1616
|
+
let running = true;
|
|
1617
|
+
const replaced = function () { return running && gen !== _generation; };
|
|
1608
1618
|
try {
|
|
1609
1619
|
await sec.load({
|
|
1610
|
-
runQuery,
|
|
1620
|
+
runQuery: function (s, l, q, a, p) { return runQuery(s, l, q, a, p, running ? gen : null); },
|
|
1611
1621
|
formatCurrency,
|
|
1612
1622
|
formatPercent,
|
|
1613
1623
|
formatInteger: fmtInt,
|
|
1614
1624
|
formatDate: fmtDate,
|
|
1615
1625
|
formatDatetime: fmtDatetime,
|
|
1616
|
-
renderTable: function (c, r, o) { return renderTable(c, r, o, ctx); },
|
|
1617
|
-
renderKpiCard: function (c, i) { return renderKpiCard(c, i, ctx); },
|
|
1618
|
-
renderKpiStrip: function (c, i, o) { return renderKpiStrip(c, i, o, ctx); },
|
|
1619
|
-
renderInfoGrid: function (c, i, o) { return renderInfoGrid(c, i, o, ctx); },
|
|
1620
|
-
renderTotalsStrip: function (c, i, o) { return renderTotalsStrip(c, i, o, ctx); },
|
|
1626
|
+
renderTable: function (c, r, o) { if (!replaced()) return renderTable(c, r, o, ctx); },
|
|
1627
|
+
renderKpiCard: function (c, i) { if (!replaced()) return renderKpiCard(c, i, ctx); },
|
|
1628
|
+
renderKpiStrip: function (c, i, o) { if (!replaced()) return renderKpiStrip(c, i, o, ctx); },
|
|
1629
|
+
renderInfoGrid: function (c, i, o) { if (!replaced()) return renderInfoGrid(c, i, o, ctx); },
|
|
1630
|
+
renderTotalsStrip: function (c, i, o) { if (!replaced()) return renderTotalsStrip(c, i, o, ctx); },
|
|
1621
1631
|
escHtml: esc,
|
|
1622
1632
|
colorClass,
|
|
1623
1633
|
filters: DashboardKit.filters,
|
|
1624
1634
|
});
|
|
1635
|
+
running = false;
|
|
1625
1636
|
if (gen !== _generation) return;
|
|
1626
1637
|
sec.loaded = true;
|
|
1627
1638
|
sec.errors = _sectionErrors[sec.id] || 0;
|
|
1628
1639
|
} catch (e) {
|
|
1640
|
+
running = false;
|
|
1641
|
+
// Not a failure: a newer load replaced this one, and it reports its own.
|
|
1642
|
+
if (e && e.dkSuperseded && gen !== _generation) return;
|
|
1629
1643
|
// The real exception, stack and dkCall included — the panel and the report only get a phrase.
|
|
1630
1644
|
console.error('[DashboardKit] section "' + sec.id + '" failed:', e);
|
|
1631
1645
|
console.log('[DashboardKit] section "' + sec.id + '" failed:', e);
|
|
@@ -1696,8 +1710,29 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
1696
1710
|
}
|
|
1697
1711
|
|
|
1698
1712
|
// ── runQuery ──────────────────────────────────────────────────────────────────
|
|
1713
|
+
// A load that Refresh or new host params replaced must not draw: its rows are for the old period or
|
|
1714
|
+
// filters, and would land over the newer load's, with drillthrough points reporting either load's
|
|
1715
|
+
// filters. So a query a replaced load made never returns: it is aborted and throws this, which the
|
|
1716
|
+
// kit drops. A query no running load made — a handler's — is left as it always was: replacing
|
|
1717
|
+
// its section's load never touched it, so it must not start failing now (README → Rules).
|
|
1718
|
+
function _superseded() {
|
|
1719
|
+
const err = new Error('superseded by a newer load');
|
|
1720
|
+
err.dkSuperseded = true;
|
|
1721
|
+
return err;
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1699
1724
|
// One retry, only where _isRetryable says the same request may succeed.
|
|
1700
|
-
|
|
1725
|
+
// _gen: the generation of the running load() that handed this runQuery over, or null when that
|
|
1726
|
+
// load had finished. A call by the global name belongs to its section's load if that is running.
|
|
1727
|
+
async function runQuery(sectionId, callLabel, sql, args, params, _gen) {
|
|
1728
|
+
let gen = _gen;
|
|
1729
|
+
if (gen === undefined) {
|
|
1730
|
+
const sec = _sections.find(function (s) { return s.id === sectionId; });
|
|
1731
|
+
gen = sec && sec.pending && sec.runGen === _generation ? _generation : null;
|
|
1732
|
+
}
|
|
1733
|
+
const replaced = function () { return gen !== null && gen !== _generation; };
|
|
1734
|
+
if (replaced()) throw _superseded();
|
|
1735
|
+
const signal = gen === null ? undefined : _abort.signal;
|
|
1701
1736
|
const t0 = performance.now();
|
|
1702
1737
|
const entry = {
|
|
1703
1738
|
index: _calls.length + 1,
|
|
@@ -1728,9 +1763,11 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
1728
1763
|
method: 'POST',
|
|
1729
1764
|
headers: { 'Content-Type': 'application/json', Authorization: 'Bearer ' + _authToken },
|
|
1730
1765
|
body: JSON.stringify(body),
|
|
1766
|
+
signal: signal,
|
|
1731
1767
|
});
|
|
1732
1768
|
entry.status = res.status;
|
|
1733
1769
|
const text = await res.text();
|
|
1770
|
+
if (replaced()) throw _superseded();
|
|
1734
1771
|
entry.bytes = text.length;
|
|
1735
1772
|
let data;
|
|
1736
1773
|
try { data = JSON.parse(text); } catch { data = { _raw: text }; }
|
|
@@ -1764,6 +1801,8 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
1764
1801
|
entry.state = 'ok';
|
|
1765
1802
|
return data.rows;
|
|
1766
1803
|
} catch (err) {
|
|
1804
|
+
// Before anything is counted: an aborted fetch is no network error, and a replaced load no failure.
|
|
1805
|
+
if (replaced()) throw _superseded();
|
|
1767
1806
|
// The failed-response throw lands here too — already built.
|
|
1768
1807
|
if (err && err.dkCall) throw err;
|
|
1769
1808
|
entry.clientMs = Math.round(performance.now() - t0);
|
|
@@ -1945,6 +1984,15 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
1945
1984
|
}
|
|
1946
1985
|
}
|
|
1947
1986
|
|
|
1987
|
+
// A render call by its global name, or as DashboardKit.<render>, carries no ctx. Its section is
|
|
1988
|
+
// then the panel the container sits in, with the context that section's latest load started with.
|
|
1989
|
+
// A container outside every panel has none, and its points read the filters as they are now.
|
|
1990
|
+
function _ctxOf(container) {
|
|
1991
|
+
const panel = container.closest ? container.closest('.dk-panel') : null;
|
|
1992
|
+
const sec = panel && _sections.find(function (s) { return 'dk-panel-' + s.id === panel.id; });
|
|
1993
|
+
return sec ? sec.ctx : undefined;
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1948
1996
|
function _forgetPoints(container) {
|
|
1949
1997
|
if (container.id) delete _pointsByContainer[container.id];
|
|
1950
1998
|
_schedulePoints();
|
|
@@ -2001,6 +2049,7 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
2001
2049
|
|
|
2002
2050
|
function _registerPointsUnsafe(container, selector, ctx, spec) {
|
|
2003
2051
|
if (!container.id) return;
|
|
2052
|
+
ctx = ctx || _ctxOf(container);
|
|
2004
2053
|
const count = {};
|
|
2005
2054
|
spec.names.forEach(function (n) { count[n] = (count[n] || 0) + 1; });
|
|
2006
2055
|
const localFilters = ctx ? ctx.localFilters : _headerSnapshot();
|
|
@@ -3203,7 +3252,8 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
3203
3252
|
};
|
|
3204
3253
|
},
|
|
3205
3254
|
// Helpers are also passed into each load() function — that is the canonical
|
|
3206
|
-
// way to use them. They are mirrored here so DashboardKit.<helper>(…) works too
|
|
3255
|
+
// way to use them. They are mirrored here so DashboardKit.<helper>(…) works too,
|
|
3256
|
+
// and set as global names below.
|
|
3207
3257
|
runQuery,
|
|
3208
3258
|
setSectionState,
|
|
3209
3259
|
renderTable,
|
|
@@ -3220,6 +3270,26 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
3220
3270
|
escHtml: esc,
|
|
3221
3271
|
};
|
|
3222
3272
|
|
|
3273
|
+
// Set when the page loads the kit twice: the global names then still hold the first copy's helpers.
|
|
3274
|
+
const earlier = global.DashboardKit;
|
|
3223
3275
|
global.DashboardKit = DashboardKit;
|
|
3224
3276
|
|
|
3277
|
+
// The helpers as global names too, so a call outside the load() that lists it — a helper the
|
|
3278
|
+
// load() left out of its list, or one called from a function at the top of the script — finds it
|
|
3279
|
+
// instead of throwing a ReferenceError that shows only once its tab is opened. A load() argument
|
|
3280
|
+
// of the same name still wins inside that load(). Assigned, never declared: an assigned property
|
|
3281
|
+
// is configurable, so a page's own `function escHtml` or `const formatDate` still declares over
|
|
3282
|
+
// it, where a declaration here would make that a SyntaxError. A name the window already holds for
|
|
3283
|
+
// something else is left as it is.
|
|
3284
|
+
['runQuery', 'renderTable', 'renderKpiCard', 'renderKpiStrip', 'renderInfoGrid', 'renderTotalsStrip',
|
|
3285
|
+
'formatCurrency', 'formatInteger', 'formatPercent', 'formatDate', 'formatDatetime', 'colorClass',
|
|
3286
|
+
'escHtml'].forEach(function (name) {
|
|
3287
|
+
const ours = earlier && global[name] === earlier[name];
|
|
3288
|
+
if (Object.prototype.hasOwnProperty.call(global, name) && !ours) {
|
|
3289
|
+
console.warn('[DashboardKit] window.' + name + ' is already taken; use DashboardKit.' + name);
|
|
3290
|
+
} else {
|
|
3291
|
+
global[name] = DashboardKit[name];
|
|
3292
|
+
}
|
|
3293
|
+
});
|
|
3294
|
+
|
|
3225
3295
|
}(window));
|