Improve sorting behavior by adding delay

This commit is contained in:
Divya Jagadish authored and Zaid Abdulla committed 2022-04-08 13:08:41 -07:00
1 parent 7941d929d2
commit dabf1b2f43
10 files changed
+75 -87

No files matched your search

+7 -11
View File
@@ -268,18 +268,14 @@ export const component: ClosureComponent = (): Component => {
}
function onSortChange(sortedAttrs): void {
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];
if (direction) _sort = Object.assign({ [param]: direction }, _sort);
}
const _sort = {};
for (const index of sortedAttrs) {
const param = memoizedGetSortable(
attributes[Math.abs(index) - 1].parameter
);
_sort[param] = Math.sign(index);
}
const ops = {};
if (Object.keys(_sort).length) ops["sort"] = JSON.stringify(_sort);
const ops = { sort: JSON.stringify(_sort) };
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
m.route.set("/devices", ops);
}
+4 -10
View File
@@ -107,16 +107,10 @@ export const component: ClosureComponent = (): Component => {
}
function onSortChange(sortAttrs): void {
let _sort = Object.assign({}, sort);
for (const [index, direction] of Object.entries(sortAttrs)) {
// Changing the priority of columns
delete _sort[attributes[index].id];
if (direction)
_sort = Object.assign({ [attributes[index].id]: direction }, _sort);
}
const ops = {};
if (Object.keys(_sort).length) ops["sort"] = JSON.stringify(_sort);
const _sort = {};
for (const index of sortAttrs)
_sort[attributes[Math.abs(index) - 1].id] = Math.sign(index);
const ops = { sort: JSON.stringify(_sort) };
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
m.route.set("/faults", ops);
}
+4 -10
View File
@@ -151,16 +151,10 @@ export const component: ClosureComponent = (): Component => {
sortAttributes[i] = sort[attributes[i].id] || 0;
function onSortChange(sortAttrs): void {
let _sort = Object.assign({}, sort);
for (const [index, direction] of Object.entries(sortAttrs)) {
// Changing the priority of columns
delete _sort[attributes[index].id];
if (direction)
_sort = Object.assign({ [attributes[index].id]: direction }, _sort);
}
const ops = {};
if (Object.keys(_sort).length) ops["sort"] = JSON.stringify(_sort);
const _sort = {};
for (const index of sortAttrs)
_sort[attributes[Math.abs(index) - 1].id] = Math.sign(index);
const ops = { sort: JSON.stringify(_sort) };
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
m.route.set("/admin/files", ops);
}
+24 -6
View File
@@ -20,6 +20,7 @@
import { ClosureComponent, Component, Children } from "mithril";
import { m } from "./components";
import { getIcon } from "./icons";
import debounce from "../lib/common/debounce";
interface Attribute {
id?: string;
@@ -36,7 +37,7 @@ function renderTable(
showMoreCallback: () => void,
selected: Set<string>,
sortAttributes: Record<string, any>,
onSortChange: (obj: Record<string, number>) => void,
onSort: (i: number) => void,
downloadUrl?: string,
valueCallback?: (attr: Attribute, record: Record<string, any>) => Children,
actionsCallback?: Children | ((sel: Set<string>) => Children),
@@ -86,9 +87,9 @@ function renderTable(
const sortable = m(
"button",
{
onclick: () => {
const direction = ((sortAttributes[i] + 2) % 3) - 1;
return onSortChange({ [i]: direction });
onclick: (e) => {
e.redraw = false;
onSort(i);
},
},
symbol
@@ -213,7 +214,10 @@ function renderTable(
const component: ClosureComponent = (): Component => {
let selected = new Set<string>();
let sortingfunction: (events: number[]) => void;
const onSort = debounce((events: number[]) => {
sortingfunction(events);
}, 500);
return {
view: (vnode) => {
const attributes = vnode.attrs["attributes"];
@@ -232,6 +236,20 @@ const component: ClosureComponent = (): Component => {
const id = record["_id"] || record["DeviceID.ID"].value[0];
if (selected.has(id)) _selected.add(id);
}
sortingfunction = (events) => {
const sortArray = new Set(
Object.keys(sortAttributes)
.map((x) => (parseInt(x) + 1) * sortAttributes[x])
.filter((x) => x)
);
for (const num of events) {
if (sortArray.delete(num + 1)) sortArray.add(-(num + 1));
else if (!sortArray.delete((num + 1) * -1)) sortArray.add(num + 1);
}
onSortChange(Array.from(sortArray).reverse());
};
selected = _selected;
return renderTable(
@@ -241,7 +259,7 @@ const component: ClosureComponent = (): Component => {
showMoreCallback,
selected,
sortAttributes,
onSortChange,
onSort,
downloadUrl,
valueCallback,
actionsCallback,
+4 -10
View File
@@ -205,16 +205,10 @@ export const component: ClosureComponent = (): Component => {
}
function onSortChange(sortAttrs): void {
let _sort = Object.assign({}, sort);
for (const [index, direction] of Object.entries(sortAttrs)) {
// Changing the priority of columns
delete _sort[attributes[index].id];
if (direction)
_sort = Object.assign({ [attributes[index].id]: direction }, _sort);
}
const ops = {};
if (Object.keys(_sort).length) ops["sort"] = JSON.stringify(_sort);
const _sort = {};
for (const index of sortAttrs)
_sort[attributes[Math.abs(index) - 1].id] = Math.sign(index);
const ops = { sort: JSON.stringify(_sort) };
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
m.route.set("/admin/permissions", ops);
}
+4 -10
View File
@@ -190,16 +190,10 @@ export const component: ClosureComponent = (): Component => {
}
function onSortChange(sortAttrs): void {
let _sort = Object.assign({}, sort);
for (const [index, direction] of Object.entries(sortAttrs)) {
// Changing the priority of columns
delete _sort[attributes[index].id];
if (direction)
_sort = Object.assign({ [attributes[index].id]: direction }, _sort);
}
const ops = {};
if (Object.keys(_sort).length) ops["sort"] = JSON.stringify(_sort);
const _sort = {};
for (const index of sortAttrs)
_sort[attributes[Math.abs(index) - 1].id] = Math.sign(index);
const ops = { sort: JSON.stringify(_sort) };
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
m.route.set("/admin/presets", ops);
}
+4 -10
View File
@@ -173,16 +173,10 @@ export const component: ClosureComponent = (): Component => {
sortAttributes[i] = sort[attributes[i].id] || 0;
function onSortChange(sortAttrs): void {
let _sort = Object.assign({}, sort);
for (const [index, direction] of Object.entries(sortAttrs)) {
// Changing the priority of columns
delete _sort[attributes[index].id];
if (direction)
_sort = Object.assign({ [attributes[index].id]: direction }, _sort);
}
const ops = {};
if (Object.keys(_sort).length) ops["sort"] = JSON.stringify(_sort);
const _sort = {};
for (const index of sortAttrs)
_sort[attributes[Math.abs(index) - 1].id] = Math.sign(index);
const ops = { sort: JSON.stringify(_sort) };
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
m.route.set("/admin/provisions", ops);
}
+4 -10
View File
@@ -186,16 +186,10 @@ export const component: ClosureComponent = (): Component => {
}
function onSortChange(sortAttrs): void {
let _sort = Object.assign({}, sort);
for (const [index, direction] of Object.entries(sortAttrs)) {
// Changing the priority of columns
delete _sort[attributes[index].id];
if (direction)
_sort = Object.assign({ [attributes[index].id]: direction }, _sort);
}
const ops = {};
if (Object.keys(_sort).length) ops["sort"] = JSON.stringify(_sort);
const _sort = {};
for (const index of sortAttrs)
_sort[attributes[Math.abs(index) - 1].id] = Math.sign(index);
const ops = { sort: JSON.stringify(_sort) };
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
m.route.set("/admin/users", ops);
}
+4 -10
View File
@@ -173,16 +173,10 @@ export const component: ClosureComponent = (): Component => {
sortAttributes[i] = sort[attributes[i].id] || 0;
function onSortChange(sortAttrs): void {
let _sort = Object.assign({}, sort);
for (const [index, direction] of Object.entries(sortAttrs)) {
// Changing the priority of columns
delete _sort[attributes[index].id];
if (direction)
_sort = Object.assign({ [attributes[index].id]: direction }, _sort);
}
const ops = {};
if (Object.keys(_sort).length) ops["sort"] = JSON.stringify(_sort);
const _sort = {};
for (const index of sortAttrs)
_sort[attributes[Math.abs(index) - 1].id] = Math.sign(index);
const ops = { sort: JSON.stringify(_sort) };
if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"];
m.route.set("/admin/virtualParameters", ops);
}