Remove select checkboxes when actions unavailable

This commit is contained in:
Shweelan Samson authored and Zaid Abdulla committed 2019-07-09 02:19:54 -07:00
1 parent 795a0f8273
commit b51c97e97a
1 file changed
+19 -12
+19 -12
View File
@@ -40,6 +40,19 @@ function renderTable(
recordActionsCallback?: Children | ((record: Record<string, any>) => Children)
): Children {
const records = data || [];
// Actions bar
let buttons: Children = [];
if (typeof actionsCallback === "function") {
buttons = actionsCallback(selected);
if (!Array.isArray(buttons)) buttons = [buttons];
} else if (Array.isArray(actionsCallback)) {
buttons = actionsCallback;
}
// Table header
const labels = [];
if (buttons.length) {
const selectAll = m("input", {
type: "checkbox",
checked: records.length && selected.size === records.length,
@@ -52,9 +65,9 @@ function renderTable(
},
disabled: !total
});
labels.push(m("th", selectAll));
}
// Table header
const labels = [m("th", selectAll)];
for (let i = 0; i < attributes.length; i++) {
const attr = attributes[i];
const label = attr.label;
@@ -87,6 +100,8 @@ function renderTable(
const rows = [];
for (const record of records) {
const id = record["_id"] || record["DeviceID.ID"].value[0];
const tds = [];
if (buttons.length) {
const checkbox = m("input", {
type: "checkbox",
checked: selected.has(id),
@@ -99,8 +114,9 @@ function renderTable(
e.redraw = false;
}
});
tds.push(m("td", checkbox));
}
const tds = [m("td", checkbox)];
for (const attr of attributes) {
const attrs = {};
let valueComponent;
@@ -180,15 +196,6 @@ function renderTable(
m("tr", m("td", { colspan: labels.length }, footerElements))
);
// Actions bar
let buttons: Children = [];
if (typeof actionsCallback === "function") {
buttons = actionsCallback(selected);
if (!Array.isArray(buttons)) buttons = [buttons];
} else if (Array.isArray(actionsCallback)) {
buttons = actionsCallback;
}
const children = [
m(
"table.table.highlight",