Table sorting preferences will be saved and reused based on the user’s selections
This commit is contained in:
@@ -78,3 +78,5 @@
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.opportunities-extension-install-base-table .opportunities-extension-account-plans-skeleton-bar { animation: none; }
|
||||
}
|
||||
.opportunities-extension-install-base-table .opportunities-extension-sort-button { min-height: 28px; padding: 4px 16px 4px 0; overflow-wrap: anywhere; }
|
||||
.opportunities-extension-install-base-table .opportunities-extension-sort-button::after { right: 0; font-size: 12px; }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
function createInstallBaseView({ MODAL_ID, createCloseIcon, formatOracleResponseDate, createSearch, environment }) {
|
||||
function createInstallBaseView({ MODAL_ID, createCloseIcon, formatOracleResponseDate, createSearch, tableSorting, environment }) {
|
||||
const { document } = environment;
|
||||
let active = null;
|
||||
const columns = [
|
||||
@@ -33,7 +33,8 @@ function createInstallBaseView({ MODAL_ID, createCloseIcon, formatOracleResponse
|
||||
}
|
||||
return String(value).trim();
|
||||
}
|
||||
function createTable(items, loading = false) {
|
||||
const sortColumns = columns.map(([key, , type]) => ({ key, type: ["amount", "quantity"].includes(type) ? "number" : type }));
|
||||
function createTable(items, loading = false, sorting = tableSorting.create("installed-base", sortColumns), onSort) {
|
||||
const table = element("table", "opportunities-extension-install-base-table");
|
||||
table.setAttribute("aria-label", "Installed base items");
|
||||
const head = element("thead");
|
||||
@@ -43,13 +44,14 @@ function createInstallBaseView({ MODAL_ID, createCloseIcon, formatOracleResponse
|
||||
const col = element("col");
|
||||
col.className = `install-base-col-${key}`;
|
||||
group.append(col);
|
||||
const th = element("th", "", label);
|
||||
const th = element("th");
|
||||
th.scope = "col";
|
||||
sorting.header(th, key, label, onSort, loading);
|
||||
header.append(th);
|
||||
});
|
||||
head.append(header);
|
||||
const body = element("tbody");
|
||||
(loading ? Array.from({ length: 8 }, () => ({})) : items).forEach(item => {
|
||||
(loading ? Array.from({ length: 8 }, () => ({})) : sorting.select(items)).forEach(item => {
|
||||
const row = element("tr");
|
||||
columns.forEach(([key, , type]) => {
|
||||
const cell = element("td");
|
||||
@@ -103,6 +105,7 @@ function createInstallBaseView({ MODAL_ID, createCloseIcon, formatOracleResponse
|
||||
const status = element("p", "opportunities-extension-install-base-message", "Loading installed base...");
|
||||
status.setAttribute("role", "status");
|
||||
let loadedItems = [], loaded = false, failure = "";
|
||||
const sorting = tableSorting.create("installed-base", sortColumns);
|
||||
const search = createSearch({ label: "Search installed base", onSearch: renderResults,
|
||||
getValues: item => columns.flatMap(([key, , type]) => [item[key], formatValue(item[key], type)]) });
|
||||
const toolbar = element("div", "opportunities-extension-customer-table-toolbar");
|
||||
@@ -115,7 +118,7 @@ function createInstallBaseView({ MODAL_ID, createCloseIcon, formatOracleResponse
|
||||
modal.addEventListener("keydown", event => {
|
||||
if (event.key === "Tab") {
|
||||
event.preventDefault();
|
||||
const controls = [close, search.input, content];
|
||||
const controls = [close, search.input, content, ...content.querySelectorAll("button")].filter(control => !control.disabled);
|
||||
const index = controls.indexOf(document.activeElement);
|
||||
controls[(index + (event.shiftKey ? -1 : 1) + controls.length) % controls.length].focus();
|
||||
}
|
||||
@@ -130,7 +133,10 @@ function createInstallBaseView({ MODAL_ID, createCloseIcon, formatOracleResponse
|
||||
: "No installed base items found for this customer.");
|
||||
status.setAttribute("role", failure ? "alert" : "status");
|
||||
content.append(status);
|
||||
if (!failure && items.length) content.append(createTable(items));
|
||||
if (!failure && items.length) content.append(createTable(items, false, sorting, key => {
|
||||
renderResults();
|
||||
content.querySelector(`[data-sort-key="${key}"]`)?.focus();
|
||||
}));
|
||||
content.scrollTop = 0;
|
||||
}
|
||||
return { render(items, error = "") {
|
||||
|
||||
Reference in New Issue
Block a user