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:
1 parent
88a84788a5
commit
dd722ba6e0
9 files changed
+40
-27
No files matched your search
+4
-3
@@ -268,17 +268,18 @@ export const component: ClosureComponent = (): Component => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onSortChange(sortedAttrs): void {
|
function onSortChange(sortedAttrs): void {
|
||||||
const _sort = Object.assign({}, sort);
|
let _sort = Object.assign({}, sort);
|
||||||
for (const [index, direction] of Object.entries(sortedAttrs)) {
|
for (const [index, direction] of Object.entries(sortedAttrs)) {
|
||||||
const param = memoizedGetSortable(attributes[index].parameter);
|
const param = memoizedGetSortable(attributes[index].parameter);
|
||||||
if (param) {
|
if (param) {
|
||||||
// Changing the priority of columns
|
// Changing the priority of columns
|
||||||
delete _sort[param];
|
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"];
|
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
|
||||||
m.route.set("/devices", ops);
|
m.route.set("/devices", ops);
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-3
@@ -107,14 +107,16 @@ export const component: ClosureComponent = (): Component => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onSortChange(sortAttrs): void {
|
function onSortChange(sortAttrs): void {
|
||||||
const _sort = Object.assign({}, sort);
|
let _sort = Object.assign({}, sort);
|
||||||
for (const [index, direction] of Object.entries(sortAttrs)) {
|
for (const [index, direction] of Object.entries(sortAttrs)) {
|
||||||
// Changing the priority of columns
|
// Changing the priority of columns
|
||||||
delete _sort[attributes[index].id];
|
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"];
|
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
|
||||||
m.route.set("/faults", ops);
|
m.route.set("/faults", ops);
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-3
@@ -151,14 +151,16 @@ export const component: ClosureComponent = (): Component => {
|
|||||||
sortAttributes[i] = sort[attributes[i].id] || 0;
|
sortAttributes[i] = sort[attributes[i].id] || 0;
|
||||||
|
|
||||||
function onSortChange(sortAttrs): void {
|
function onSortChange(sortAttrs): void {
|
||||||
const _sort = Object.assign({}, sort);
|
let _sort = Object.assign({}, sort);
|
||||||
for (const [index, direction] of Object.entries(sortAttrs)) {
|
for (const [index, direction] of Object.entries(sortAttrs)) {
|
||||||
// Changing the priority of columns
|
// Changing the priority of columns
|
||||||
delete _sort[attributes[index].id];
|
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"];
|
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
|
||||||
m.route.set("/admin/files", ops);
|
m.route.set("/admin/files", ops);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,8 +79,6 @@ function renderTable(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let direction = 1;
|
|
||||||
|
|
||||||
let symbol = getIcon("unsorted");
|
let symbol = getIcon("unsorted");
|
||||||
if (sortAttributes[i] > 0) symbol = getIcon("sorted-asc");
|
if (sortAttributes[i] > 0) symbol = getIcon("sorted-asc");
|
||||||
else if (sortAttributes[i] < 0) symbol = getIcon("sorted-dsc");
|
else if (sortAttributes[i] < 0) symbol = getIcon("sorted-dsc");
|
||||||
@@ -89,7 +87,7 @@ function renderTable(
|
|||||||
"button",
|
"button",
|
||||||
{
|
{
|
||||||
onclick: () => {
|
onclick: () => {
|
||||||
if (sortAttributes[i] > 0) direction *= -1;
|
const direction = ((sortAttributes[i] + 2) % 3) - 1;
|
||||||
return onSortChange({ [i]: direction });
|
return onSortChange({ [i]: direction });
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -205,14 +205,16 @@ export const component: ClosureComponent = (): Component => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onSortChange(sortAttrs): void {
|
function onSortChange(sortAttrs): void {
|
||||||
const _sort = Object.assign({}, sort);
|
let _sort = Object.assign({}, sort);
|
||||||
for (const [index, direction] of Object.entries(sortAttrs)) {
|
for (const [index, direction] of Object.entries(sortAttrs)) {
|
||||||
// Changing the priority of columns
|
// Changing the priority of columns
|
||||||
delete _sort[attributes[index].id];
|
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"];
|
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
|
||||||
m.route.set("/admin/permissions", ops);
|
m.route.set("/admin/permissions", ops);
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-3
@@ -190,14 +190,16 @@ export const component: ClosureComponent = (): Component => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onSortChange(sortAttrs): void {
|
function onSortChange(sortAttrs): void {
|
||||||
const _sort = Object.assign({}, sort);
|
let _sort = Object.assign({}, sort);
|
||||||
for (const [index, direction] of Object.entries(sortAttrs)) {
|
for (const [index, direction] of Object.entries(sortAttrs)) {
|
||||||
// Changing the priority of columns
|
// Changing the priority of columns
|
||||||
delete _sort[attributes[index].id];
|
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"];
|
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
|
||||||
m.route.set("/admin/presets", ops);
|
m.route.set("/admin/presets", ops);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,14 +173,16 @@ export const component: ClosureComponent = (): Component => {
|
|||||||
sortAttributes[i] = sort[attributes[i].id] || 0;
|
sortAttributes[i] = sort[attributes[i].id] || 0;
|
||||||
|
|
||||||
function onSortChange(sortAttrs): void {
|
function onSortChange(sortAttrs): void {
|
||||||
const _sort = Object.assign({}, sort);
|
let _sort = Object.assign({}, sort);
|
||||||
for (const [index, direction] of Object.entries(sortAttrs)) {
|
for (const [index, direction] of Object.entries(sortAttrs)) {
|
||||||
// Changing the priority of columns
|
// Changing the priority of columns
|
||||||
delete _sort[attributes[index].id];
|
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"];
|
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
|
||||||
m.route.set("/admin/provisions", ops);
|
m.route.set("/admin/provisions", ops);
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-3
@@ -186,14 +186,16 @@ export const component: ClosureComponent = (): Component => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onSortChange(sortAttrs): void {
|
function onSortChange(sortAttrs): void {
|
||||||
const _sort = Object.assign({}, sort);
|
let _sort = Object.assign({}, sort);
|
||||||
for (const [index, direction] of Object.entries(sortAttrs)) {
|
for (const [index, direction] of Object.entries(sortAttrs)) {
|
||||||
// Changing the priority of columns
|
// Changing the priority of columns
|
||||||
delete _sort[attributes[index].id];
|
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"];
|
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
|
||||||
m.route.set("/admin/users", ops);
|
m.route.set("/admin/users", ops);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,14 +173,16 @@ export const component: ClosureComponent = (): Component => {
|
|||||||
sortAttributes[i] = sort[attributes[i].id] || 0;
|
sortAttributes[i] = sort[attributes[i].id] || 0;
|
||||||
|
|
||||||
function onSortChange(sortAttrs): void {
|
function onSortChange(sortAttrs): void {
|
||||||
const _sort = Object.assign({}, sort);
|
let _sort = Object.assign({}, sort);
|
||||||
for (const [index, direction] of Object.entries(sortAttrs)) {
|
for (const [index, direction] of Object.entries(sortAttrs)) {
|
||||||
// Changing the priority of columns
|
// Changing the priority of columns
|
||||||
delete _sort[attributes[index].id];
|
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"];
|
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
|
||||||
m.route.set("/admin/virtualParameters", ops);
|
m.route.set("/admin/virtualParameters", ops);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user