feat(ui): improve the records table, view state and record dialog
Sortable record columns, filters and sort kept in the URL on the zones, zone and audit pages, a Show action that filters the records table to a problem's owner, Save and add another, a highlight of the saved row, an Audit history link on the zone page, and dialogs that keep typed input on a backdrop click.
This commit is contained in:
1 parent
a67183b646
commit
440f78ce9e
9 files changed
+419
-36
No files matched your search
+37
-4
@@ -266,11 +266,17 @@ export function handleError(err, options = {}) {
|
||||
}
|
||||
|
||||
export async function busy(button, task) {
|
||||
if (button) button.disabled = true;
|
||||
if (button) {
|
||||
button.disabled = true;
|
||||
button.setAttribute("aria-busy", "true");
|
||||
}
|
||||
try {
|
||||
return await task();
|
||||
} finally {
|
||||
if (button) button.disabled = false;
|
||||
if (button) {
|
||||
button.disabled = false;
|
||||
button.removeAttribute("aria-busy");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +284,7 @@ const FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]):not([t
|
||||
|
||||
function trapFocus(dialog, event) {
|
||||
if (event.key !== "Tab") return;
|
||||
const items = [...dialog.querySelectorAll(FOCUSABLE)].filter((el) => !el.hidden && el.offsetParent !== null);
|
||||
const items = [...dialog.querySelectorAll(FOCUSABLE)].filter((el) => !el.hidden && el.offsetParent !== null && !el.closest("[inert]"));
|
||||
if (items.length === 0) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
@@ -298,8 +304,11 @@ export function setupDialog(dialog) {
|
||||
if (dialog.dataset.ready) return;
|
||||
dialog.dataset.ready = "1";
|
||||
dialog.addEventListener("keydown", (event) => trapFocus(dialog, event));
|
||||
dialog.addEventListener("input", () => {
|
||||
dialog.dataset.dirty = "1";
|
||||
});
|
||||
dialog.addEventListener("click", (event) => {
|
||||
if (event.target === dialog) dialog.close();
|
||||
if (event.target === dialog && !dialog.dataset.dirty) dialog.close();
|
||||
});
|
||||
for (const button of dialog.querySelectorAll("[data-close]")) {
|
||||
button.addEventListener("click", () => dialog.close());
|
||||
@@ -314,6 +323,7 @@ export function openDialog(dialog) {
|
||||
setupDialog(dialog);
|
||||
const form = dialog.querySelector("form");
|
||||
if (form) clearErrors(form);
|
||||
delete dialog.dataset.dirty;
|
||||
dialog.showModal();
|
||||
const first = dialog.querySelector("input:not([type=hidden]):not([disabled]), select:not([disabled]), textarea");
|
||||
if (first) first.focus();
|
||||
@@ -389,6 +399,29 @@ export function zoneLink(name) {
|
||||
return h("a", { href: "/zones/" + encodeURIComponent(name), text: name });
|
||||
}
|
||||
|
||||
export function readQuery() {
|
||||
return new URLSearchParams(location.search);
|
||||
}
|
||||
|
||||
let queryRetry = null;
|
||||
|
||||
export function writeQuery(values) {
|
||||
clearTimeout(queryRetry);
|
||||
queryRetry = null;
|
||||
const params = new URLSearchParams();
|
||||
for (const [key, value] of Object.entries(values)) {
|
||||
if (value !== undefined && value !== null && value !== "") params.set(key, String(value));
|
||||
}
|
||||
const text = params.toString();
|
||||
const url = location.pathname + (text ? "?" + text : "") + location.hash;
|
||||
if (url === location.pathname + location.search + location.hash) return;
|
||||
try {
|
||||
history.replaceState(history.state, "", url);
|
||||
} catch (err) {
|
||||
queryRetry = setTimeout(() => writeQuery(values), 1000);
|
||||
}
|
||||
}
|
||||
|
||||
export function bindPasswordForm(form, submit) {
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
Reference in new issue
Block a user