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(attributes): select every row from a checkbox in the toolbar
Elian Doran5d8d31a43d56
diff --git a/apps/client/src/stylesheets/theme-next/forms.css b/apps/client/src/stylesheets/theme-next/forms.cssindex bd11e33b77..b1217d3c7e 100644--- a/apps/client/src/stylesheets/theme-next/forms.css+++ b/apps/client/src/stylesheets/theme-next/forms.css@@ -456,6 +456,13 @@ optgroup {animation: checkbox-checked 150ms ease-out;}+ /* The mixed state of a box whose items are partly checked, such as a select-all box. */+ label.tn-checkbox:has(> input[type="checkbox"]:indeterminate)::after {+ mask-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3e%3cpath d='M4 10.5h16v3H4z' /%3e%3c/svg%3e");+ opacity: 1;+ transform: scale(1);+ }+/* Radio buttons */label.tn-radio::before,diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 3fddf8a6f0..103ae19d9d 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -913,7 +913,8 @@"delete_selection_confirm": "Delete the {{count}} selected attributes?","clear_clipboard": "Clear clipboard","to_copy_one": "{{count}} attribute to copy",- "to_copy_other": "{{count}} attributes to copy"+ "to_copy_other": "{{count}} attributes to copy",+ "select_all": "Select all"},"attribute_names": {"system": "System",diff --git a/apps/client/src/widgets/sidebar/AttributeList.css b/apps/client/src/widgets/sidebar/AttributeList.cssindex c1e298a8c0..2238770ac2 100644--- a/apps/client/src/widgets/sidebar/AttributeList.css+++ b/apps/client/src/widgets/sidebar/AttributeList.css@@ -47,6 +47,16 @@background-color: var(--selection-background-color);}+.attribute-list-panel .attribute-row.selected:has(+ .attribute-row.selected) {+ border-end-start-radius: 0;+ border-end-end-radius: 0;+}++.attribute-list-panel .attribute-row.selected + .attribute-row.selected {+ border-start-start-radius: 0;+ border-start-end-radius: 0;+}+/* While its value is edited (or the attribute created), the row lets the editor standing over it(see AttributeEditorOverlay.css) spill past the one line the row keeps to, and comes forward sothe editor is drawn over the rows below rather than under them. */@@ -121,10 +131,15 @@background-color: var(--main-background-color);--icon-button-size: 26px;- .attribute-selection-count {- color: var(--muted-text-color);- font-size: 0.85em;- white-space: nowrap;+ .form-checkbox {+ padding-inline-start: 4px;++ label {+ margin: 0;+ color: var(--muted-text-color);+ font-size: 0.85em;+ white-space: nowrap;+ }}.attribute-toolbar-read-only {diff --git a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx b/apps/client/src/widgets/sidebar/AttributeList.spec.tsxindex ec607442c6..fcf4e5c9ee 100644--- a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx+++ b/apps/client/src/widgets/sidebar/AttributeList.spec.tsx@@ -1154,6 +1154,29 @@ describe("AttributeList", () => {expect(firstPanel().className).not.toContain("selecting");});+ it("selects every row from the toolbar's checkbox, and clears the selection from it once all are", () => {+ renderPanel(noteWithAttributes());+ const box = container.querySelector<HTMLInputElement>(".attribute-toolbar .form-checkbox input");+ expect(box).not.toBeNull();+ expect(box?.checked).toBe(false);+ expect(box?.indeterminate).toBe(false);++ // Some rows selected: the box shows the mixed state, and a click selects the rest.+ checkbox(0).click();+ expect(box?.indeterminate).toBe(true);+ expect(box?.checked).toBe(false);++ act(() => box?.click());+ expect(selectedNames()).toEqual([ "author", "cssClass", "template", "inheritedLabel", "archived", "priority", "status" ]);+ expect(box?.checked).toBe(true);+ expect(box?.indeterminate).toBe(false);++ // All rows selected: a click clears the selection.+ act(() => box?.click());+ expect(selectedNames()).toEqual([]);+ expect(box?.checked).toBe(false);+ });+it("lets a note that cannot be edited be copied from, but not deleted from or pasted onto", async () => {const note = noteWithAttributes();note.isContentWritable = false;diff --git a/apps/client/src/widgets/sidebar/AttributeList.tsx b/apps/client/src/widgets/sidebar/AttributeList.tsxindex fdd2dd27aa..642b5f649c 100644--- a/apps/client/src/widgets/sidebar/AttributeList.tsx+++ b/apps/client/src/widgets/sidebar/AttributeList.tsx@@ -25,6 +25,7 @@ import { ColorChip, renderLabelValue } from "../attribute_widgets/label_value_diimport ActionButton from "../react/ActionButton";import SimpleBadge from "../react/Badge";import Dropdown from "../react/Dropdown";+import FormCheckbox from "../react/FormCheckbox";import { FormDropdownDivider, FormListHeader, FormListItem } from "../react/FormList";import { useActiveNoteContext, useTriliumEvent } from "../react/hooks";import Icon from "../react/Icon";@@ -352,6 +353,15 @@ export default function AttributeList() {setSelection(EMPTY_SELECTION);}+ function selectAll() {+ // Wraps up any open edit, as selecting a row does.+ commit();+ commitValueEdit();+ commitCreation();+ selectionAnchor.current = null;+ setSelection(new Set(selectableIds));+ }+/** Drops from the selection whatever the note no longer holds, so what is copied is what is shown. */function pruneSelection() {setSelection((current) => {@@ -740,6 +750,7 @@ export default function AttributeList() {const toolbar = note && (<AttributeToolbarselectionCount={selection.size}+ selectableCount={selectableIds.length}readOnly={!canEdit}held={canEdit ? heldAttributes : []}canAdd={canEdit}@@ -753,6 +764,7 @@ export default function AttributeList() {}}onDelete={() => void deleteSelection(selectedAttributes())}onClearSelection={clearSelection}+ onSelectAll={selectAll}/>);@@ -1581,16 +1593,21 @@ function getClipboardValue(attribute: Attribute) {}/**- * The panel's toolbar, above the cards. It holds pasting and adding; while rows are selected, it also- * holds the selection's count and actions. Its height stays the same either way, so starting or- * ending a selection moves nothing.+ * The panel's toolbar, above the cards. It holds the select-all checkbox, pasting and adding; while+ * rows are selected, it also holds the selection's count and actions. Its height stays the same+ * either way, so starting or ending a selection moves nothing.+ *+ * The checkbox's label is "Select all" with nothing selected and the count otherwise. It selects every+ * row unless all are selected already, in which case it clears the selection.** Paste and add stay at the trailing end in both states, and the selection's actions go before them.* Deleting is offered only when every selected row is the note's own. On a note that cannot be edited, a* lock and "Read-only" take the place of the paste and add buttons.*/-function AttributeToolbar({ selectionCount, readOnly, held, canAdd, canDelete, onAdd, onCopy, onPaste, onClearClipboard, onDelete, onClearSelection }: {+function AttributeToolbar({ selectionCount, selectableCount, readOnly, held, canAdd, canDelete, onAdd, onCopy, onPaste, onClearClipboard, onDelete, onSelectAll, onClearSelection }: {selectionCount: number;+ /** How many rows can be selected; the checkbox is left out when there are none. */+ selectableCount: number;/** Shows a read-only notice in place of the add and paste buttons, which a read-only note has none of. */readOnly: boolean;/** What there is to paste; empty when nothing is held or the note cannot be edited. */@@ -1602,33 +1619,43 @@ function AttributeToolbar({ selectionCount, readOnly, held, canAdd, canDelete, oonPaste: () => void;onClearClipboard: () => void;onDelete: () => void;+ onSelectAll: () => void;onClearSelection: () => void;}) {const isSelecting = selectionCount > 0;+ const allSelected = isSelecting && selectionCount >= selectableCount;return (<div class={clsx("attribute-toolbar", isSelecting && "selecting")} role="toolbar">- {isSelecting && (- <>- <ActionButton- icon="bx bx-x"- text={t("attribute_list_panel.clear_selection")}- onClick={onClearSelection}- />- <span class="attribute-selection-count">- {t("attribute_list_panel.selected", { count: selectionCount })}- </span>- </>+ {selectableCount > 0 && (+ <FormCheckbox+ name="attribute-select-all"+ label={isSelecting+ ? <span class="attribute-selection-count">{t("attribute_list_panel.selected", { count: selectionCount })}</span>+ : t("attribute_list_panel.select_all")}+ currentValue={allSelected}+ indeterminate={isSelecting && !allSelected}+ // A click on a partly checked box checks it, so `checked` alone tells the two actions apart.+ onChange={(checked) => checked ? onSelectAll() : onClearSelection()}+ />)}- {!isSelecting && readOnly && (- <span class="attribute-toolbar-read-only" title={t("breadcrumb_badges.read_only_locked_description")}>- <Icon icon="bx bx-lock-alt" />- {t("breadcrumb_badges.read_only_locked")}- </span>+ {isSelecting && (+ <ActionButton+ icon="bx bx-x"+ text={t("attribute_list_panel.clear_selection")}+ onClick={onClearSelection}+ />)}<div class="attribute-toolbar-actions">+ {!isSelecting && readOnly && (+ <span class="attribute-toolbar-read-only" title={t("breadcrumb_badges.read_only_locked_description")}>+ <Icon icon="bx bx-lock-alt" />+ {t("breadcrumb_badges.read_only_locked")}+ </span>+ )}+{isSelecting && (<ActionButtonicon="bx bx-copy"