Skip to content

Commit cd69b46

Browse files
committed
Added site ID -> site name linkage in cloud encryption key UI
1 parent 8b717d2 commit cd69b46

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

webroot/adm/cloud-encryption-key.html

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ <h3>Output</h3>
4545
}
4646
},
4747
{
48-
name: "Site ID",
48+
name: "Site",
4949
formatter: (cell, row) => {
50-
return gridjs.html(`<span class="${row.cells[4].data}">${cell}</span>`)
50+
return gridjs.html(`<span class="${row.cells[4].data}">${cell.siteId} - ${cell.siteName}</span>`)
5151
}
5252
},
5353
{
@@ -71,14 +71,16 @@ <h3>Output</h3>
7171
sort: true,
7272
search: {
7373
selector: (cell, rowIndex, cellIndex) => {
74-
if (cellIndex === 0 || cellIndex === 1) {
74+
if (cellIndex === 0) {
7575
return cell;
76+
} else if (cellIndex === 1) {
77+
return `${cell.siteId} - ${cell.siteName}`;
7678
}
7779
}
7880
},
7981
language: {
8082
search: {
81-
placeholder: "Search by Key ID or Site ID..."
83+
placeholder: "Search by Key ID or Site..."
8284
}
8385
}
8486
})
@@ -99,30 +101,23 @@ <h3>Output</h3>
99101
}
100102

101103
const updateGrid = (grid, data) => {
102-
const now = new Date();
103-
104-
const groupedData = data.cloudEncryptionKeys.reduce((acc, entry) => {
105-
if (!acc[entry.siteId]) {
106-
acc[entry.siteId] = [];
104+
const groupedData = data.cloudEncryptionKeys.reduce((acc, key) => {
105+
if (!acc[key.siteId]) {
106+
acc[key.siteId] = [];
107107
}
108-
acc[entry.siteId].push(entry);
108+
acc[key.siteId].push(key);
109109
return acc;
110110
}, {});
111111

112112
const gridData = [];
113113
for (const siteId in groupedData) {
114-
const entries = groupedData[siteId];
115-
const latestEntry = entries.reduce((latest, entry) => new Date(entry.activates) > new Date(latest.activates) ? entry : latest);
116-
117-
entries.forEach((entry) => {
118-
let style = "";
119-
if (entry === latestEntry) {
120-
style = "active";
121-
} else {
122-
style = "inactive";
123-
}
114+
const keys = groupedData[siteId];
115+
const latestKey = keys.reduce((latest, key) => new Date(key.activates) > new Date(latest.activates) ? key : latest);
116+
117+
keys.forEach((key) => {
118+
let style = key === latestKey ? "active" : "inactive";
124119

125-
gridData.push([ entry.id, entry.siteId, entry.activates, entry.created, style ]);
120+
gridData.push([ key.id, { siteId: key.siteId, siteName: key.siteName }, key.activates, key.created, style ]);
126121
});
127122
}
128123

@@ -144,7 +139,21 @@ <h3>Output</h3>
144139

145140
$("#doList").on("click", function () {
146141
clearGrid(grid);
147-
doApiCallWithCallback("GET", "/api/cloud-encryption-key/list", (text) => updateGrid(grid, JSON.parse(text)), errorCallback);
142+
doApiCallWithCallback("GET", "/api/site/list", (text) => {
143+
const sites = JSON.parse(text);
144+
const siteDict = sites.reduce((acc, site) => {
145+
acc[site.id] = site.name;
146+
return acc;
147+
}, {});
148+
149+
doApiCallWithCallback("GET", "/api/cloud-encryption-key/list", (text) => {
150+
const data = JSON.parse(text);
151+
data.cloudEncryptionKeys.forEach((key) => {
152+
key.siteName = !siteDict[key.siteId] ? "Unknown site" : siteDict[key.siteId]
153+
});
154+
updateGrid(grid, data);
155+
}, errorCallback);
156+
}, errorCallback);
148157
});
149158
});
150159
</script>

0 commit comments

Comments
 (0)