Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(sort): lay the sort dialog out on cards
Elian Doran099294d22543
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 648a35cf07..0c3fb3e699 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -497,10 +497,10 @@"sort_children_by": "Sort children by...","sorting_criteria": "Sorting criteria","sorting_criteria_description": "Notes are sorted by the first level; the next level only decides between notes the previous ones left equal.",- "title": "title",- "date_created": "date created",- "date_modified": "date modified",- "label": "label",+ "title": "Title",+ "date_created": "Date created",+ "date_modified": "Date modified",+ "label": "Label","label_name": "Label name","add_level": "Add level","remove_level": "Remove level",@@ -508,11 +508,10 @@"move_level_down": "Move level down","ascending": "Ascending","descending": "Descending",- "folders": "Folders",- "sort_folders_at_top": "sort folders at the top",+ "sort_folders_at_top": "Sort folders at the top","folders_follow_first_level": "At the bottom instead when the first level is descending.",- "natural_sort": "Natural Sort",- "sort_with_respect_to_different_character_sorting": "sort with respect to different character sorting and collation rules in different languages or regions.",+ "natural_sort": "Natural sort",+ "sort_with_respect_to_different_character_sorting": "Sort with respect to different character sorting and collation rules in different languages or regions.","natural_sort_language": "Natural sort language","the_language_code_for_natural_sort": "The language code for natural sort, e.g. \"zh-CN\" for Chinese.","sort": "Sort"diff --git a/apps/client/src/widgets/dialogs/sort_child_notes.css b/apps/client/src/widgets/dialogs/sort_child_notes.cssindex 2d421e2155..e56f0f8636 100644--- a/apps/client/src/widgets/dialogs/sort_child_notes.css+++ b/apps/client/src/widgets/dialogs/sort_child_notes.css@@ -4,20 +4,13 @@max-width: 600px;}- .sort-criteria {- margin-block: 8px 28px;+ /* The cards carry their own spacing, as the other card-bearing dialogs do. */+ .tn-card {+ margin-bottom: 1rem;}- .sort-levels-description {- color: var(--muted-text-color);- margin-bottom: 8px;- }-- .sort-levels {- display: flex;- flex-direction: column;- gap: 8px;- margin-bottom: 8px;+ .tn-card:last-child {+ margin-bottom: 0;}.sort-level {@@ -25,8 +18,12 @@align-items: center;gap: 8px;+ /* The kind select takes whatever room the row does not otherwise need, so the direction+ and the row buttons sit at the end whether or not a label name is showing. It shares+ that room with the label name rather than taking it, so neither box is squeezed. */.sort-level-kind {- flex: 0 0 11em;+ flex: 1 1 11em;+ min-width: 0;}.sort-level-label {@@ -34,12 +31,7 @@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;- }-+ .tn-segmented-choice,.sort-level-up,.sort-level-down,.sort-level-remove {diff --git a/apps/client/src/widgets/dialogs/sort_child_notes.spec.tsx b/apps/client/src/widgets/dialogs/sort_child_notes.spec.tsxindex 2e1ea1aa07..162e7ebc34 100644--- a/apps/client/src/widgets/dialogs/sort_child_notes.spec.tsx+++ b/apps/client/src/widgets/dialogs/sort_child_notes.spec.tsx@@ -73,6 +73,14 @@ describe("SortChildNotesDialog", () => {return scope.querySelector(`button[title="${title}"]`);}+ async function flip(scope: Element | null) {+ const input = scope?.querySelector(".switch-toggle");+ if (!input) throw new Error("No toggle to flip.");+ await act(async () => {+ input.dispatchEvent(new Event("input", { bubbles: true }));+ });+ }+async function submit() {const form = container.querySelector("form");if (!form) throw new Error("The dialog has no form.");@@ -131,6 +139,12 @@ describe("SortChildNotesDialog", () => {}));});+ it("offers the natural sort language only while natural sort is on", async () => {+ expect(container.querySelector(".sort-locale")).toBeNull();+ await flip(container.querySelector(".sort-natural"));+ expect(container.querySelector(".sort-locale")).not.toBeNull();+ });+it("refuses a label name the attribute rules would not allow", async () => {await choose(levels()[0].querySelector("select"), "label");const input = levels()[0].querySelector<HTMLInputElement>(".sort-level-label");diff --git a/apps/client/src/widgets/dialogs/sort_child_notes.tsx b/apps/client/src/widgets/dialogs/sort_child_notes.tsxindex 1d1ba12722..1ab239da61 100644--- a/apps/client/src/widgets/dialogs/sort_child_notes.tsx+++ b/apps/client/src/widgets/dialogs/sort_child_notes.tsx@@ -11,10 +11,10 @@ import { t } from "../../services/i18n";import server from "../../services/server";import ActionButton from "../react/ActionButton";import Button from "../react/Button";-import FormCheckbox from "../react/FormCheckbox";-import FormGroup from "../react/FormGroup";+import { Card, CardSection, OptionCardSection } from "../react/Card";import FormSelect from "../react/FormSelect";import FormTextBox from "../react/FormTextBox";+import FormToggle from "../react/FormToggle";import { useTriliumEvent } from "../react/hooks";import Modal from "../react/Modal";import SegmentedChoice, { type SegmentedChoiceOption } from "../react/SegmentedChoice";@@ -93,90 +93,102 @@ export default function SortChildNotesDialog() {<Button text={t("sort_child_notes.sort")} keyboardShortcut="Enter" /></>}>- <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={kindOptions}- keyProperty="kind"- titleProperty="title"- currentValue={level.kind}- onChange={(kind) => updateLevel(index, { kind: kind as SortKind })}+ <Card+ heading={t("sort_child_notes.sorting_criteria")}+ description={t("sort_child_notes.sorting_criteria_description")}+ >+ {levels.map((level, index) => (+ <CardSection className="sort-level" key={index}>+ <FormSelect+ className="sort-level-kind"+ values={kindOptions}+ keyProperty="kind"+ 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+ pattern={ATTRIBUTE_NAME_PATTERN}+ currentValue={level.labelName}+ onChange={(labelName) => updateLevel(index, { labelName })}/>- {level.kind === "label" && (- <FormTextBox- className="sort-level-label"- placeholder={t("sort_child_notes.label_name")}- required- pattern={ATTRIBUTE_NAME_PATTERN}- currentValue={level.labelName}- onChange={(labelName) => updateLevel(index, { labelName })}- />- )}- <SegmentedChoice- options={directionOptions}- currentValue={level.direction}- onChange={(direction) => updateLevel(index, { direction })}- />- <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)}- />- <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-plus"- text={t("sort_child_notes.add_level")}- size="small"- onClick={() => setLevels([ ...levels, NEW_LEVEL ])}- />- </div>-- <h5>{t("sort_child_notes.folders")}</h5>- <FormCheckbox- label={t("sort_child_notes.sort_folders_at_top")}- hint={t("sort_child_notes.folders_follow_first_level")}- name="sort-folders-first"- currentValue={foldersFirst} onChange={setFoldersFirst}- />- <br />-- <h5>{t("sort_child_notes.natural_sort")}</h5>- <FormCheckbox- name="sort-natural"- label={t("sort_child_notes.sort_with_respect_to_different_character_sorting")}- currentValue={sortNatural} onChange={setSortNatural}- />- <FormGroup name="sort-locale" className="form-check" label={t("sort_child_notes.natural_sort_language")} description={t("sort_child_notes.the_language_code_for_natural_sort")}>- <FormTextBox currentValue={sortLocale} onChange={setSortLocale} />- </FormGroup>+ )}+ <SegmentedChoice+ options={directionOptions}+ currentValue={level.direction}+ onChange={(direction) => updateLevel(index, { direction })}+ />+ <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)}+ />+ <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))}+ />+ </CardSection>+ ))}++ <CardSection className="sort-level-add-row">+ <Button+ className="sort-level-add"+ icon="bx-plus"+ text={t("sort_child_notes.add_level")}+ size="small"+ onClick={() => setLevels([ ...levels, NEW_LEVEL ])}+ />+ </CardSection>+ </Card>++ <Card>+ <OptionCardSection+ name="sort-folders-first"+ label={t("sort_child_notes.sort_folders_at_top")}+ description={t("sort_child_notes.folders_follow_first_level")}+ >+ <FormToggle currentValue={foldersFirst} onChange={setFoldersFirst} />+ </OptionCardSection>++ <OptionCardSection+ className="sort-natural"+ name="sort-natural"+ label={t("sort_child_notes.natural_sort")}+ description={t("sort_child_notes.sort_with_respect_to_different_character_sorting")}+ subSectionsVisible={sortNatural}+ subSections={[+ <OptionCardSection+ key="locale"+ className="sort-locale"+ name="sort-locale"+ label={t("sort_child_notes.natural_sort_language")}+ description={t("sort_child_notes.the_language_code_for_natural_sort")}+ >+ <FormTextBox currentValue={sortLocale} onChange={setSortLocale} />+ </OptionCardSection>+ ]}+ >+ <FormToggle currentValue={sortNatural} onChange={setSortNatural} />+ </OptionCardSection>+ </Card></Modal>- )+ );}/** Writes the levels in the `#sorted` grammar with their directions, skipping a nameless label. */