Skip to content

Commit 8217be7

Browse files
committed
adding a green flash to new rows in the history table on refresh
1 parent 95a6874 commit 8217be7

File tree

2 files changed

+80
-12
lines changed

2 files changed

+80
-12
lines changed

debug_toolbar/static/debug_toolbar/css/toolbar.css

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

debug_toolbar/static/debug_toolbar/js/history.js

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,73 @@ 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+
function pluckData(array, key) {
14+
const data = [];
15+
array.forEach(function (obj) {
16+
data.push(obj.dataset[key]);
17+
});
18+
return data;
19+
}
20+
21+
function refreshHistory() {
22+
const formTarget = djDebug.querySelector(".refreshHistory");
23+
const container = document.getElementById("djdtHistoryRequests");
24+
const oldIds = new Set(
25+
pluckData(container.querySelectorAll("tr[data-store-id]"), "storeId")
26+
);
27+
28+
return ajaxForm(formTarget)
29+
.then(function (data) {
30+
// Remove existing rows first then re-populate with new data
31+
container
32+
.querySelectorAll("tr[data-store-id]")
33+
.forEach(function (node) {
34+
node.remove();
35+
});
36+
data.requests.forEach(function (request) {
37+
container.innerHTML = request.content + container.innerHTML;
38+
});
39+
})
40+
.then(function () {
41+
const allIds = new Set(
42+
pluckData(
43+
container.querySelectorAll("tr[data-store-id]"),
44+
"storeId"
45+
)
46+
);
47+
const newIds = difference(allIds, oldIds);
48+
const lastRequestId = newIds.values().next().value;
49+
return {
50+
allIds,
51+
newIds,
52+
lastRequestId,
53+
};
54+
})
55+
.then(function (refreshInfo) {
56+
refreshInfo.newIds.forEach(function (newId) {
57+
const row = container.querySelector(
58+
`tr[data-store-id="${newId}"]`
59+
);
60+
row.classList.add("flash-new");
61+
});
62+
setTimeout(() => {
63+
container
64+
.querySelectorAll("tr[data-store-id]")
65+
.forEach((row) => {
66+
row.classList.remove("flash-new");
67+
});
68+
}, 2000);
69+
});
70+
}
71+
572
$$.on(djDebug, "click", ".switchHistory", function (event) {
673
event.preventDefault();
774
const newStoreId = this.dataset.storeId;
@@ -36,16 +103,5 @@ $$.on(djDebug, "click", ".switchHistory", function (event) {
36103

37104
$$.on(djDebug, "click", ".refreshHistory", function (event) {
38105
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-
});
106+
refreshHistory();
51107
});

0 commit comments

Comments
 (0)