Skip to content

Build your personal knowledge base with Trilium Notes

feat(client): reorder sort levels and size the dialog to them

BeatLinka6cfa1e9e01b
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index d3a88bd8d3..9e139f95c9 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -504,8 +504,10 @@
"label_name": "Label name",
"add_level": "Add level",
"remove_level": "Remove level",
- "ascending": "ascending",
- "descending": "descending",
+ "move_level_up": "Move level up",
+ "move_level_down": "Move level down",
+ "ascending": "Ascending",
+ "descending": "Descending",
"folders": "Folders",
"sort_folders_at_top": "sort folders at the top",
"natural_sort": "Natural Sort",
diff --git a/apps/client/src/widgets/dialogs/sort_child_notes.css b/apps/client/src/widgets/dialogs/sort_child_notes.css
index 7c7aae9c88..6839f8a7cb 100644
--- a/apps/client/src/widgets/dialogs/sort_child_notes.css
+++ b/apps/client/src/widgets/dialogs/sort_child_notes.css
@@ -1,4 +1,19 @@
.modal.sort-child-notes-dialog {
+ /* The criteria rows set the dialog's width; the prose wraps to it rather than widening it. */
+ :where(body:not(.mobile)) & .modal-dialog {
+ width: fit-content;
+ min-width: 440px;
+ }
+
+ .modal-body > :not(.sort-criteria),
+ .sort-levels-description {
+ contain: inline-size;
+ }
+
+ .sort-criteria {
+ margin-block: 8px 28px;
+ }
+
.sort-levels-description {
color: var(--muted-text-color);
margin-bottom: 8px;
@@ -25,9 +40,16 @@
min-width: 0;
}
+ /* Direction, reorder and remove sit at the row's end regardless of what the row holds. */
.tn-segmented-choice {
margin-inline-start: auto;
flex-shrink: 0;
}
+
+ .sort-level-up,
+ .sort-level-down,
+ .sort-level-remove {
+ flex-shrink: 0;
+ }
}
}
diff --git a/apps/client/src/widgets/dialogs/sort_child_notes.spec.tsx b/apps/client/src/widgets/dialogs/sort_child_notes.spec.tsx
index 318eb5ff3f..d52f7cac85 100644
--- a/apps/client/src/widgets/dialogs/sort_child_notes.spec.tsx
+++ b/apps/client/src/widgets/dialogs/sort_child_notes.spec.tsx
@@ -68,7 +68,7 @@ describe("SortChildNotesDialog", () => {
}
function buttonTitled(scope: Element, title: string) {
- return [ ...scope.querySelectorAll("button") ].find((button) => button.textContent?.trim() === title);
+ return scope.querySelector(`button[title="${title}"]`);
}
async function submit() {
@@ -110,6 +110,20 @@ describe("SortChildNotesDialog", () => {
}));
});
+ it("reorders levels with the arrows, which are off at the ends", async () => {
+ await click(container.querySelector(".sort-level-add"));
+ const [ first, second ] = levels();
+ await choose(second.querySelector("select"), "dateCreated");
+ expect(first.querySelector(".sort-level-up")).toHaveProperty("disabled", true);
+ expect(second.querySelector(".sort-level-down")).toHaveProperty("disabled", true);
+
+ await click(second.querySelector(".sort-level-up"));
+ await submit();
+ expect(put).toHaveBeenCalledWith("notes/parent/sort-children", expect.objectContaining({
+ sortBy: "dateCreated:asc,title:asc"
+ }));
+ });
+
it("keeps the only level from being removed", () => {
const remove = levels()[0].querySelector<HTMLButtonElement>(".sort-level-remove[disabled]");
expect(remove).not.toBeNull();
diff --git a/apps/client/src/widgets/dialogs/sort_child_notes.tsx b/apps/client/src/widgets/dialogs/sort_child_notes.tsx
index 71ca188964..fb1f84ea0d 100644
--- a/apps/client/src/widgets/dialogs/sort_child_notes.tsx
+++ b/apps/client/src/widgets/dialogs/sort_child_notes.tsx
@@ -43,6 +43,12 @@ export default function SortChildNotesDialog() {
setLevels(levels.map((level, i) => (i === index ? { ...level, ...change } : level)));
}
+ function moveLevel(index: number, offset: -1 | 1) {
+ const reordered = [ ...levels ];
+ [ reordered[index], reordered[index + offset] ] = [ reordered[index + offset], reordered[index] ];
+ setLevels(reordered);
+ }
+
async function onSubmit() {
await server.put(`notes/${parentNoteId}/sort-children`, {
sortBy: serializeSortLevels(levels),
@@ -59,7 +65,7 @@ export default function SortChildNotesDialog() {
<Modal
className="sort-child-notes-dialog"
title={t("sort_child_notes.sort_children_by")}
- size="lg" maxWidth={560}
+ size="lg" maxWidth={680}
onSubmit={onSubmit}
onHidden={() => setShown(false)}
show={shown}
@@ -68,59 +74,74 @@ export default function SortChildNotesDialog() {
<Button text={t("sort_child_notes.sort")} keyboardShortcut="Enter" />
</>}
>
- <h5>{t("sort_child_notes.sorting_criteria")}</h5>
- <p className="sort-levels-description">{t("sort_child_notes.sorting_criteria_description")}</p>
- <div className="sort-levels">
- {levels.map((level, index) => (
- <div className="sort-level" key={index}>
- <FormSelect
- className="sort-level-kind"
- values={[
- { key: "title", title: t("sort_child_notes.title") },
- { key: "dateCreated", title: t("sort_child_notes.date_created") },
- { key: "dateModified", title: t("sort_child_notes.date_modified") },
- { key: "label", title: t("sort_child_notes.label") }
- ]}
- keyProperty="key"
- titleProperty="title"
- currentValue={level.kind}
- onChange={(kind) => updateLevel(index, { kind: kind as SortKind })}
- />
- {level.kind === "label" && (
- <FormTextBox
- className="sort-level-label"
- placeholder={t("sort_child_notes.label_name")}
- required
- currentValue={level.labelName}
- onChange={(labelName) => updateLevel(index, { labelName })}
+ <div className="sort-criteria">
+ <h5>{t("sort_child_notes.sorting_criteria")}</h5>
+ <p className="sort-levels-description">{t("sort_child_notes.sorting_criteria_description")}</p>
+ <div className="sort-levels">
+ {levels.map((level, index) => (
+ <div className="sort-level" key={index}>
+ <FormSelect
+ className="sort-level-kind"
+ values={[
+ { key: "title", title: t("sort_child_notes.title") },
+ { key: "dateCreated", title: t("sort_child_notes.date_created") },
+ { key: "dateModified", title: t("sort_child_notes.date_modified") },
+ { key: "label", title: t("sort_child_notes.label") }
+ ]}
+ keyProperty="key"
+ titleProperty="title"
+ currentValue={level.kind}
+ onChange={(kind) => updateLevel(index, { kind: kind as SortKind })}
+ />
+ {level.kind === "label" && (
+ <FormTextBox
+ className="sort-level-label"
+ placeholder={t("sort_child_notes.label_name")}
+ required
+ currentValue={level.labelName}
+ onChange={(labelName) => updateLevel(index, { labelName })}
+ />
+ )}
+ <SegmentedChoice
+ options={[
+ { value: "asc", icon: "bx-sort-up", title: t("sort_child_notes.ascending") },
+ { value: "desc", icon: "bx-sort-down", title: t("sort_child_notes.descending") }
+ ]}
+ currentValue={level.descending ? "desc" : "asc"}
+ onChange={(direction) => updateLevel(index, { descending: direction === "desc" })}
+ />
+ <ActionButton
+ className="sort-level-up"
+ icon="bx bx-up-arrow-alt"
+ text={t("sort_child_notes.move_level_up")}
+ disabled={index === 0}
+ onClick={() => moveLevel(index, -1)}
/>
- )}
- <SegmentedChoice
- options={[
- { value: "asc", label: t("sort_child_notes.ascending") },
- { value: "desc", label: t("sort_child_notes.descending") }
- ]}
- currentValue={level.descending ? "desc" : "asc"}
- onChange={(direction) => updateLevel(index, { descending: direction === "desc" })}
- />
- <ActionButton
- className="sort-level-remove"
- icon="bx bx-x"
- text={t("sort_child_notes.remove_level")}
- disabled={levels.length === 1}
- onClick={() => setLevels(levels.filter((_, i) => i !== index))}
- />
- </div>
- ))}
+ <ActionButton
+ className="sort-level-down"
+ icon="bx bx-down-arrow-alt"
+ text={t("sort_child_notes.move_level_down")}
+ disabled={index === levels.length - 1}
+ onClick={() => moveLevel(index, 1)}
+ />
+ <ActionButton
+ className="sort-level-remove"
+ icon="bx bx-x"
+ text={t("sort_child_notes.remove_level")}
+ disabled={levels.length === 1}
+ onClick={() => setLevels(levels.filter((_, i) => i !== index))}
+ />
+ </div>
+ ))}
+ </div>
+ <Button
+ className="sort-level-add"
+ icon="bx bx-plus"
+ text={t("sort_child_notes.add_level")}
+ size="small"
+ onClick={() => setLevels([ ...levels, NEW_LEVEL ])}
+ />
</div>
- <Button
- className="sort-level-add"
- icon="bx bx-plus"
- text={t("sort_child_notes.add_level")}
- size="small"
- onClick={() => setLevels([ ...levels, NEW_LEVEL ])}
- />
- <br/>
<h5>{t("sort_child_notes.folders")}</h5>
<FormCheckbox