Improve sorting toggle behavior

Last sorted column now takes precedence over any previously sorted
columns. This makes for a more intuitive user experience.
This commit is contained in:
Zaid Abdulla committed 2021-10-25 13:36:23 -07:00
1 parent 88a84788a5
commit dd722ba6e0
9 files changed
+40 -27

No files matched your search

+4 -3
View File
@@ -268,17 +268,18 @@ export const component: ClosureComponent = (): Component => {
}
function onSortChange(sortedAttrs): void {
const _sort = Object.assign({}, sort);
let _sort = Object.assign({}, sort);
for (const [index, direction] of Object.entries(sortedAttrs)) {
const param = memoizedGetSortable(attributes[index].parameter);
if (param) {
// Changing the priority of columns
delete _sort[param];
_sort[param] = direction;
if (direction) _sort = Object.assign({ [param]: direction }, _sort);
}
}
const ops = { sort: JSON.stringify(_sort) };
const ops = {};
if (Object.keys(_sort).length) ops["sort"] = JSON.stringify(_sort);
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
m.route.set("/devices", ops);
}
+5 -3
View File
@@ -107,14 +107,16 @@ export const component: ClosureComponent = (): Component => {
}
function onSortChange(sortAttrs): void {
const _sort = Object.assign({}, sort);
let _sort = Object.assign({}, sort);
for (const [index, direction] of Object.entries(sortAttrs)) {
// Changing the priority of columns
delete _sort[attributes[index].id];
_sort[attributes[index].id] = direction;
if (direction)
_sort = Object.assign({ [attributes[index].id]: direction }, _sort);
}
const ops = { sort: JSON.stringify(_sort) };
const ops = {};
if (Object.keys(_sort).length) ops["sort"] = JSON.stringify(_sort);
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
m.route.set("/faults", ops);
}
+5 -3
View File
@@ -151,14 +151,16 @@ export const component: ClosureComponent = (): Component => {
sortAttributes[i] = sort[attributes[i].id] || 0;
function onSortChange(sortAttrs): void {
const _sort = Object.assign({}, sort);
let _sort = Object.assign({}, sort);
for (const [index, direction] of Object.entries(sortAttrs)) {
// Changing the priority of columns
delete _sort[attributes[index].id];
_sort[attributes[index].id] = direction;
if (direction)
_sort = Object.assign({ [attributes[index].id]: direction }, _sort);
}
const ops = { sort: JSON.stringify(_sort) };
const ops = {};
if (Object.keys(_sort).length) ops["sort"] = JSON.stringify(_sort);
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
m.route.set("/admin/files", ops);
}
+1 -3
View File
@@ -79,8 +79,6 @@ function renderTable(
continue;
}
let direction = 1;
let symbol = getIcon("unsorted");
if (sortAttributes[i] > 0) symbol = getIcon("sorted-asc");
else if (sortAttributes[i] < 0) symbol = getIcon("sorted-dsc");
@@ -89,7 +87,7 @@ function renderTable(
"button",
{
onclick: () => {
if (sortAttributes[i] > 0) direction *= -1;
const direction = ((sortAttributes[i] + 2) % 3) - 1;
return onSortChange({ [i]: direction });
},
},
+5 -3
View File
@@ -205,14 +205,16 @@ export const component: ClosureComponent = (): Component => {
}
function onSortChange(sortAttrs): void {
const _sort = Object.assign({}, sort);
let _sort = Object.assign({}, sort);
for (const [index, direction] of Object.entries(sortAttrs)) {
// Changing the priority of columns
delete _sort[attributes[index].id];
_sort[attributes[index].id] = direction;
if (direction)
_sort = Object.assign({ [attributes[index].id]: direction }, _sort);
}
const ops = { sort: JSON.stringify(_sort) };
const ops = {};
if (Object.keys(_sort).length) ops["sort"] = JSON.stringify(_sort);
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
m.route.set("/admin/permissions", ops);
}
+5 -3
View File
@@ -190,14 +190,16 @@ export const component: ClosureComponent = (): Component => {
}
function onSortChange(sortAttrs): void {
const _sort = Object.assign({}, sort);
let _sort = Object.assign({}, sort);
for (const [index, direction] of Object.entries(sortAttrs)) {
// Changing the priority of columns
delete _sort[attributes[index].id];
_sort[attributes[index].id] = direction;
if (direction)
_sort = Object.assign({ [attributes[index].id]: direction }, _sort);
}
const ops = { sort: JSON.stringify(_sort) };
const ops = {};
if (Object.keys(_sort).length) ops["sort"] = JSON.stringify(_sort);
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
m.route.set("/admin/presets", ops);
}
+5 -3
View File
@@ -173,14 +173,16 @@ export const component: ClosureComponent = (): Component => {
sortAttributes[i] = sort[attributes[i].id] || 0;
function onSortChange(sortAttrs): void {
const _sort = Object.assign({}, sort);
let _sort = Object.assign({}, sort);
for (const [index, direction] of Object.entries(sortAttrs)) {
// Changing the priority of columns
delete _sort[attributes[index].id];
_sort[attributes[index].id] = direction;
if (direction)
_sort = Object.assign({ [attributes[index].id]: direction }, _sort);
}
const ops = { sort: JSON.stringify(_sort) };
const ops = {};
if (Object.keys(_sort).length) ops["sort"] = JSON.stringify(_sort);
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
m.route.set("/admin/provisions", ops);
}
+5 -3
View File
@@ -186,14 +186,16 @@ export const component: ClosureComponent = (): Component => {
}
function onSortChange(sortAttrs): void {
const _sort = Object.assign({}, sort);
let _sort = Object.assign({}, sort);
for (const [index, direction] of Object.entries(sortAttrs)) {
// Changing the priority of columns
delete _sort[attributes[index].id];
_sort[attributes[index].id] = direction;
if (direction)
_sort = Object.assign({ [attributes[index].id]: direction }, _sort);
}
const ops = { sort: JSON.stringify(_sort) };
const ops = {};
if (Object.keys(_sort).length) ops["sort"] = JSON.stringify(_sort);
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
m.route.set("/admin/users", ops);
}
+5 -3
View File
@@ -173,14 +173,16 @@ export const component: ClosureComponent = (): Component => {
sortAttributes[i] = sort[attributes[i].id] || 0;
function onSortChange(sortAttrs): void {
const _sort = Object.assign({}, sort);
let _sort = Object.assign({}, sort);
for (const [index, direction] of Object.entries(sortAttrs)) {
// Changing the priority of columns
delete _sort[attributes[index].id];
_sort[attributes[index].id] = direction;
if (direction)
_sort = Object.assign({ [attributes[index].id]: direction }, _sort);
}
const ops = { sort: JSON.stringify(_sort) };
const ops = {};
if (Object.keys(_sort).length) ops["sort"] = JSON.stringify(_sort);
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
m.route.set("/admin/virtualParameters", ops);
}