Skip to content

Commit 5d03c53

Browse files
gonematthiask
andauthored
adding a green flash to new rows in the history table on refresh (#1578)
* Adding a green flash to new rows in the history table on refresh * Update debug_toolbar/static/debug_toolbar/css/toolbar.css Co-authored-by: Matthias Kestenholz <mk@feinheit.ch>
1 parent e951347 commit 5d03c53

File tree

3 files changed

+87
-12
lines changed

3 files changed

+87
-12
lines changed

debug_toolbar/static/debug_toolbar/css/toolbar.css

+12
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,18 @@
607607
#djDebug .djdt-highlighted {
608608
background-color: lightgrey;
609609
}
610+
@keyframes djdt-flash-new {
611+
from {
612+
background-color: green;
613+
}
614+
to {
615+
background-color: inherit;
616+
}
617+
}
618+
#djDebug .flash-new {
619+
animation: djdt-flash-new 1s;
620+
}
621+
610622
.djdt-hidden {
611623
display: none;
612624
}

debug_toolbar/static/debug_toolbar/js/history.js

+74-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,79 @@ import { $$, ajaxForm } from "./utils.js";
22

33
const djDebug = document.getElementById("djDebug");
44

5+
function difference(setA, setB) {
6+
const _difference = new Set(setA);
7+
for (const elem of setB) {
8+
_difference.delete(elem);
9+
}
10+
return _difference;
11+
}
12+
13+
/**
14+
* Create an array of dataset properties from a NodeList.
15+
* @param nodes
16+
* @param key
17+
* @returns {[]}
18+
*/
19+
function pluckData(nodes, key) {
20+
const data = [];
21+
nodes.forEach(function (obj) {
22+
data.push(obj.dataset[key]);
23+
});
24+
return data;
25+
}
26+
27+
function refreshHistory() {
28+
const formTarget = djDebug.querySelector(".refreshHistory");
29+
const container = document.getElementById("djdtHistoryRequests");
30+
const oldIds = new Set(
31+
pluckData(container.querySelectorAll("tr[data-store-id]"), "storeId")
32+
);
33+
34+
return ajaxForm(formTarget)
35+
.then(function (data) {
36+
// Remove existing rows first then re-populate with new data
37+
container
38+
.querySelectorAll("tr[data-store-id]")
39+
.forEach(function (node) {
40+
node.remove();
41+
});
42+
data.requests.forEach(function (request) {
43+
container.innerHTML = request.content + container.innerHTML;
44+
});
45+
})
46+
.then(function () {
47+
const allIds = new Set(
48+
pluckData(
49+
container.querySelectorAll("tr[data-store-id]"),
50+
"storeId"
51+
)
52+
);
53+
const newIds = difference(allIds, oldIds);
54+
const lastRequestId = newIds.values().next().value;
55+
return {
56+
allIds,
57+
newIds,
58+
lastRequestId,
59+
};
60+
})
61+
.then(function (refreshInfo) {
62+
refreshInfo.newIds.forEach(function (newId) {
63+
const row = container.querySelector(
64+
`tr[data-store-id="${newId}"]`
65+
);
66+
row.classList.add("flash-new");
67+
});
68+
setTimeout(() => {
69+
container
70+
.querySelectorAll("tr[data-store-id]")
71+
.forEach((row) => {
72+
row.classList.remove("flash-new");
73+
});
74+
}, 2000);
75+
});
76+
}
77+
578
$$.on(djDebug, "click", ".switchHistory", function (event) {
679
event.preventDefault();
780
const newStoreId = this.dataset.storeId;
@@ -36,16 +109,5 @@ $$.on(djDebug, "click", ".switchHistory", function (event) {
36109

37110
$$.on(djDebug, "click", ".refreshHistory", function (event) {
38111
event.preventDefault();
39-
const container = document.getElementById("djdtHistoryRequests");
40-
ajaxForm(this).then(function (data) {
41-
// Remove existing rows first then re-populate with new data
42-
container
43-
.querySelectorAll("tr[data-store-id]")
44-
.forEach(function (node) {
45-
node.remove();
46-
});
47-
data.requests.forEach(function (request) {
48-
container.innerHTML = request.content + container.innerHTML;
49-
});
50-
});
112+
refreshHistory();
51113
});

docs/changes.rst

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Next version
1212
django-debug-toolbar can now use Django’s test settings tools, like
1313
``@override_settings``, to reconfigure the toolbar during tests.
1414
* Optimize rendering of SQL panel, saving about 30% of its run time.
15+
* New records in history panel will flash green.
1516

1617
3.2.4 (2021-12-15)
1718
------------------

0 commit comments

Comments
 (0)