mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-21 14:09:34 +01:00
feat: remove groupId and replace it with groupBy
This commit is contained in:
@@ -8,7 +8,7 @@ test("group alphabetically", () => {
|
||||
.split("")
|
||||
.map((a) => ({ title: a, item: true }));
|
||||
let ret = groupArray(alphabet, {
|
||||
groupId: "abc",
|
||||
groupBy: "abc",
|
||||
sortDirection: "asc",
|
||||
sortBy: "title",
|
||||
}).filter((v) => !v.item);
|
||||
|
||||
@@ -56,10 +56,9 @@ const groupedTest = (type) =>
|
||||
dateCreated: getLastWeekTimestamp() - 604800000 * 2,
|
||||
});
|
||||
let grouped = groupArray(db.notes.all, {
|
||||
groupId: type,
|
||||
groupBy: type,
|
||||
sortDirection: "desc",
|
||||
sortBy: "dateCreated",
|
||||
groupBy: "dateCreated",
|
||||
});
|
||||
expect(grouped.length).toBeGreaterThan(0);
|
||||
expect(grouped.some((i) => i.type === "header")).toBe(true);
|
||||
|
||||
@@ -63,9 +63,8 @@ class Settings {
|
||||
getGroupOptions(key) {
|
||||
return (
|
||||
this._settings.groupOptions[key] || {
|
||||
groupId: undefined,
|
||||
groupBy: undefined,
|
||||
sortBy: "dateEdited",
|
||||
groupBy: "dateEdited",
|
||||
sortDirection: "desc",
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* @typedef {{
|
||||
* groupId: "abc" | "year" | "month" | "week" | undefined,
|
||||
* groupBy: "dateCreated" | "dateDeleted" | "dateEdited",
|
||||
* groupBy: "abc" | "year" | "month" | "week" | undefined,
|
||||
* sortBy: "dateCreated" | "dateDeleted" | "dateEdited" | "title",
|
||||
* sortDirection: "desc" | "asc"
|
||||
* }} GroupOptions
|
||||
|
||||
@@ -44,13 +44,12 @@ const KEY_SELECTORS = {
|
||||
export function groupArray(
|
||||
array,
|
||||
options = {
|
||||
groupId: undefined,
|
||||
groupBy: undefined,
|
||||
sortBy: "dateEdited",
|
||||
groupBy: "dateEdited",
|
||||
sortDirection: "desc",
|
||||
}
|
||||
) {
|
||||
const keySelector = KEY_SELECTORS[options.groupId || "default"];
|
||||
const keySelector = KEY_SELECTORS[options.groupBy || "default"];
|
||||
if (options.sortBy && options.sortDirection)
|
||||
fastsort(array).by(getSortSelectors(options));
|
||||
|
||||
@@ -60,7 +59,7 @@ export function groupArray(
|
||||
? "Pinned"
|
||||
: item.conflicted
|
||||
? "Conflicted"
|
||||
: keySelector(item, options.groupBy);
|
||||
: keySelector(item, options.sortBy);
|
||||
|
||||
let group = groups.get(groupTitle) || [];
|
||||
group.push(item);
|
||||
|
||||
Reference in New Issue
Block a user