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
refactor(client): remove the ribbon's file properties tab
Elian Doran0b589b64d3a6
diff --git a/apps/client/src/stylesheets/theme-next/ribbon.css b/apps/client/src/stylesheets/theme-next/ribbon.cssindex 20744d2c13..5d71aee649 100644--- a/apps/client/src/stylesheets/theme-next/ribbon.css+++ b/apps/client/src/stylesheets/theme-next/ribbon.css@@ -38,36 +38,17 @@ div.promoted-attributes-container {}/*- * File/Image Properties and Note Info+ * Image Properties*//* The property label */-.file-properties-widget .file-table th,.image-properties > div:first-child > span > strong {opacity: 0.65;font-weight: 500;vertical-align: top;}-.file-properties-widget .file-table td {- vertical-align: top;-}--.file-properties-widget {- container: info-section / inline-size;-}--.file-properties-widget .file-table {- margin: 12px;- width: unset;-}--.file-properties-widget td:has(.file-buttons) {- padding: 8px 0 0 0;-}-/* The button bar */-.file-properties-widget .file-buttons,.image-properties > div:last-of-type {padding: 0;margin: 0;@@ -76,10 +57,6 @@ div.promoted-attributes-container {gap: 12px;}-.file-properties-widget .file-buttons button {- white-space: nowrap;-}-/* The properties row for images */.image-properties > div:first-child {justify-content: flex-start !important;diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 07f1ccb186..a6712a466f 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1317,16 +1317,11 @@"deleted": "(deleted)"},"file_properties": {- "note_id": "Note ID","original_file_name": "Original file name",- "file_type": "File type",- "file_size": "File size","download": "Download","open": "Open externally",- "upload_new_revision": "Upload new revision","upload_success": "New file revision has been uploaded.",- "upload_failed": "Upload of a new file revision failed.",- "title": "File"+ "upload_failed": "Upload of a new file revision failed."},"image_properties": {"original_file_name": "Original file name",diff --git a/apps/client/src/widgets/ribbon/FilePropertiesTab.css b/apps/client/src/widgets/ribbon/FilePropertiesTab.cssdeleted file mode 100644index c0e62cf1b1..0000000000--- a/apps/client/src/widgets/ribbon/FilePropertiesTab.css+++ /dev/null@@ -1,15 +0,0 @@-.file-table {- width: 100%;- margin-top: 10px;-}--.file-table th, .file-table td {- padding: 5px;- overflow-wrap: anywhere;-}--.file-buttons {- padding: 10px;- display: flex;- justify-content: space-evenly;-}diff --git a/apps/client/src/widgets/ribbon/FilePropertiesTab.tsx b/apps/client/src/widgets/ribbon/FilePropertiesTab.tsxdeleted file mode 100644index 0325a9a2fd..0000000000--- a/apps/client/src/widgets/ribbon/FilePropertiesTab.tsx+++ /dev/null@@ -1,90 +0,0 @@-import "./FilePropertiesTab.css";--import { useContext } from "preact/hooks";--import FNote from "../../entities/fnote";-import { t } from "../../services/i18n";-import { downloadFileNote, openNoteExternally } from "../../services/open";-import protected_session_holder from "../../services/protected_session_holder";-import server from "../../services/server";-import toast from "../../services/toast";-import { formatSize } from "../../services/utils";-import Button from "../react/Button";-import { FormFileUploadButton } from "../react/FormFileUpload";-import { useNoteBlob, useNoteLabel } from "../react/hooks";-import { ParentComponent } from "../react/react_utils";-import { TabContext } from "./ribbon-interface";--export default function FilePropertiesTab({ note, ntxId }: Pick<TabContext, "note" | "ntxId">) {- const [ originalFileName ] = useNoteLabel(note, "originalFileName");- const canAccessProtectedNote = !note?.isProtected || protected_session_holder.isProtectedSessionAvailable();- const blob = useNoteBlob(note);- const parentComponent = useContext(ParentComponent);-- return (- <div className="file-properties-widget">- {note && (- <table className="file-table">- <tbody>- <tr>- <th className="text-nowrap">{t("file_properties.note_id")}:</th>- <td className="file-note-id selectable-text">{note.noteId}</td>- <th className="text-nowrap">{t("file_properties.original_file_name")}:</th>- <td className="file-filename selectable-text">{originalFileName ?? "?"}</td>- </tr>- <tr>- <th className="text-nowrap">{t("file_properties.file_type")}:</th>- <td className="file-filetype selectable-text">{note.mime}</td>- <th className="text-nowrap">{t("file_properties.file_size")}:</th>- <td className="file-filesize selectable-text">{formatSize(blob?.contentLength ?? 0)}</td>- </tr>-- <tr>- <td colSpan={4}>- <div className="file-buttons">- <Button- icon="bx bx-download"- text={t("file_properties.download")}- kind="primary"- disabled={!canAccessProtectedNote}- onClick={() => downloadFileNote(note, parentComponent, ntxId)}- />-- <Button- icon="bx bx-link-external"- text={t("file_properties.open")}- disabled={note.isProtected}- onClick={() => openNoteExternally(note.noteId, note.mime)}- />-- <FormFileUploadButton- icon="bx bx-folder-open"- text={t("file_properties.upload_new_revision")}- disabled={!canAccessProtectedNote}- onChange={buildUploadNewFileRevisionListener(note)}- />- </div>- </td>- </tr>- </tbody>- </table>- )}- </div>- );-}--export function buildUploadNewFileRevisionListener(note: FNote) {- return (fileToUpload: FileList | null) => {- if (!fileToUpload) {- return;- }-- server.upload(`notes/${note.noteId}/file`, fileToUpload[0]).then((result) => {- if (result.uploaded) {- toast.showMessage(t("file_properties.upload_success"));- } else {- toast.showError(t("file_properties.upload_failed"));- }- });- };-}diff --git a/apps/client/src/widgets/ribbon/NoteActions.css b/apps/client/src/widgets/ribbon/NoteActions.cssindex 63c6540648..c24c1a3005 100644--- a/apps/client/src/widgets/ribbon/NoteActions.css+++ b/apps/client/src/widgets/ribbon/NoteActions.css@@ -38,15 +38,15 @@ body.experimental-feature-new-layout .ribbon-button-container {opacity: 0.4;}}+}- .note-actions-custom {- display: flex;- align-items: center;- height: 36px;- gap: var(--button-gap);+.ribbon-button-container .note-actions-custom {+ display: flex;+ align-items: center;+ height: 36px;+ gap: var(--button-gap, 10px);- &> button:last-of-type {- margin-inline-end: 0.5em;- }+ &> button:last-of-type {+ margin-inline-end: 0.5em;}}diff --git a/apps/client/src/widgets/ribbon/NoteActions.tsx b/apps/client/src/widgets/ribbon/NoteActions.tsxindex 221dd1afd5..56c0af9874 100644--- a/apps/client/src/widgets/ribbon/NoteActions.tsx+++ b/apps/client/src/widgets/ribbon/NoteActions.tsx@@ -46,6 +46,7 @@ export default function NoteActions() {<CreatePaneButton /></>)}+ {!isNewLayout && note && ntxId && noteContext && <NoteActionsCustom note={note} ntxId={ntxId} noteContext={noteContext} typeActionsOnly />}{note && !isNewLayout && <RevisionsButton note={note} />}{note && note.type !== "launcher" && <NoteContextMenu note={note as FNote} noteContext={noteContext} />}</div>diff --git a/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx b/apps/client/src/widgets/ribbon/NoteActionsCustom.tsxindex 39ba9bed44..e343e0cdd2 100644--- a/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx+++ b/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx@@ -10,6 +10,8 @@ import { t } from "../../services/i18n";import { copyImageReferenceToClipboard } from "../../services/image";import { getHelpUrlForNote } from "../../services/in_app_help";import { downloadFileNote, openNoteExternally } from "../../services/open";+import server from "../../services/server";+import toast from "../../services/toast";import { createImageSrcUrl, isMobile, openInAppHelpFromUrl } from "../../services/utils";import { ViewTypeOptions } from "../collections/interface";import { buildSaveSqlToNoteHandler } from "../FloatingButtonsDefinitions";@@ -21,16 +23,17 @@ import { FormListItem } from "../react/FormList";import { useEffectiveReadOnly, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useTriliumEvent, useTriliumEvents, useTriliumOption } from "../react/hooks";import { isSplitEditorForcedReadOnly, resolveDisplayMode } from "../type_widgets/helpers/split_editor_mode";import { ParentComponent } from "../react/react_utils";-import { buildUploadNewFileRevisionListener } from "./FilePropertiesTab";import { buildUploadNewImageRevisionListener } from "./ImagePropertiesTab";interface NoteActionsCustomProps {note: FNote;ntxId: string;noteContext: NoteContext;+ /** Renders only the note type's own actions, leaving out those `FloatingButtons` shows on the old layout. */+ typeActionsOnly?: boolean;}-interface NoteActionsCustomInnerProps extends NoteActionsCustomProps {+interface NoteActionsCustomInnerProps extends Omit<NoteActionsCustomProps, "typeActionsOnly"> {noteMime: string;noteType: NoteType;isReadOnly: boolean;@@ -42,10 +45,10 @@ interface NoteActionsCustomInnerProps extends NoteActionsCustomProps {const cachedIsMobile = isMobile();/**- * Part of {@link NoteActions} on the new layout, but are rendered with a slight spacing+ * Part of {@link NoteActions}, but are rendered with a slight spacing* from the rest of the note items and the buttons differ based on the note type.*/-export default function NoteActionsCustom(props: NoteActionsCustomProps) {+export default function NoteActionsCustom({ typeActionsOnly, ...props }: NoteActionsCustomProps) {const { note } = props;const containerRef = useRef<HTMLDivElement>(null);const noteType = useNoteProperty(note, "type");@@ -72,14 +75,16 @@ export default function NoteActionsCustom(props: NoteActionsCustomProps) {ref={containerRef}className="note-actions-custom">- <RunActiveNoteButton {...innerProps } />- <SwitchSplitOrientationButton {...innerProps} />- <DisplayModeSwitcher {...innerProps} />- <SaveToNoteButton {...innerProps} />- <RefreshButton {...innerProps} />- {innerProps.note.noteId === "_backendLog" && <DownloadFileButton {...innerProps} />}- <CopyReferenceToClipboardButton {...innerProps} />- <InAppHelpButton {...innerProps} />+ {!typeActionsOnly && <>+ <RunActiveNoteButton {...innerProps } />+ <SwitchSplitOrientationButton {...innerProps} />+ <DisplayModeSwitcher {...innerProps} />+ <SaveToNoteButton {...innerProps} />+ <RefreshButton {...innerProps} />+ {innerProps.note.noteId === "_backendLog" && <DownloadFileButton {...innerProps} />}+ <CopyReferenceToClipboardButton {...innerProps} />+ <InAppHelpButton {...innerProps} />+ </>}<NoteActionsCustomInner {...innerProps} /></div>);@@ -117,6 +122,22 @@ function ImageActions(props: NoteActionsCustomInnerProps) {</>);}++function buildUploadNewFileRevisionListener(note: FNote) {+ return (fileToUpload: FileList | null) => {+ if (!fileToUpload) {+ return;+ }++ server.upload(`notes/${note.noteId}/file`, fileToUpload[0]).then((result) => {+ if (result.uploaded) {+ toast.showMessage(t("file_properties.upload_success"));+ } else {+ toast.showError(t("file_properties.upload_failed"));+ }+ });+ };+}//#endregion//#region Shared buttonsdiff --git a/apps/client/src/widgets/ribbon/RibbonDefinition.ts b/apps/client/src/widgets/ribbon/RibbonDefinition.tsindex a71f588bf1..45b4a00c5f 100644--- a/apps/client/src/widgets/ribbon/RibbonDefinition.ts+++ b/apps/client/src/widgets/ribbon/RibbonDefinition.ts@@ -1,7 +1,6 @@import { t } from "../../services/i18n";import options from "../../services/options";import EditedNotesTab from "./EditedNotesTab";-import FilePropertiesTab from "./FilePropertiesTab";import ImagePropertiesTab from "./ImagePropertiesTab";import NotePropertiesTab from "./NotePropertiesTab";import { TabConfiguration } from "./ribbon-interface";@@ -39,14 +38,6 @@ export const RIBBON_TAB_DEFINITIONS: TabConfiguration[] = [show: ({ note }) => !!note?.getLabelValue("pageUrl"),activate: true},- {- title: t("file_properties.title"),- icon: "bx bx-file",- content: FilePropertiesTab,- show: ({ note }) => note?.type === "file",- toggleCommand: "toggleRibbonTabFileProperties",- activate: ({ note }) => note?.mime !== "application/pdf"- },{title: t("image_properties.title"),icon: "bx bx-image",