From 8dc2256ef6f7dd75cbdbbf2a562dd284718b34b7 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Tue, 8 Oct 2024 17:43:25 +0200 Subject: [PATCH] dialogs: unify the dialog titles Unify them to all use the form `$action $name` so all dialog titles use the same style. --- src/dialogs/delete.tsx | 19 +++++++++++-------- src/dialogs/editor.tsx | 3 ++- src/dialogs/permissions.jsx | 3 ++- test/check-application | 4 ++-- test/reference | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/dialogs/delete.tsx b/src/dialogs/delete.tsx index 2e7f2941..d3319311 100644 --- a/src/dialogs/delete.tsx +++ b/src/dialogs/delete.tsx @@ -25,6 +25,7 @@ import { Modal, ModalVariant } from '@patternfly/react-core/dist/esm/components/ import cockpit from 'cockpit'; import { InlineNotification } from 'cockpit-components-inline-notification'; import type { Dialogs, DialogResult } from 'dialogs'; +import { fmt_to_fragments } from 'utils'; import type { FolderFileInfo } from '../app'; @@ -40,23 +41,25 @@ const ConfirmDeletionDialog = ({ dialogResult, path, selected, setSelected } : { let modalTitle; if (selected.length > 1) { - modalTitle = cockpit.format(forceDelete ? _("Force delete $0 items") : _("Delete $0 items?"), selected.length); + const selectedJSX = {selected.length}; + modalTitle = fmt_to_fragments(forceDelete ? _("Force delete $0 items") : _("Delete $0 items?"), selectedJSX); } else { const selectedItem = selected[0]; + const selectedJSX = {selectedItem.name}; if (selectedItem.type === "reg") { - modalTitle = cockpit.format( - forceDelete ? _("Force delete file $0?") : _("Delete file $0?"), selectedItem.name + modalTitle = fmt_to_fragments( + forceDelete ? _("Force delete file $0?") : _("Delete file $0?"), selectedJSX ); } else if (selectedItem.type === "lnk") { - modalTitle = cockpit.format( - forceDelete ? _("Force delete link $0?") : _("Delete link $0?"), selectedItem.name + modalTitle = fmt_to_fragments( + forceDelete ? _("Force delete link $0?") : _("Delete link $0?"), selectedJSX ); } else if (selectedItem.type === "dir") { - modalTitle = cockpit.format( - forceDelete ? _("Force delete directory $0?") : _("Delete directory $0?"), selectedItem.name + modalTitle = fmt_to_fragments( + forceDelete ? _("Force delete directory $0?") : _("Delete directory $0?"), selectedJSX ); } else { - modalTitle = cockpit.format(forceDelete ? _("Force delete $0") : _("Delete $0?"), selectedItem.name); + modalTitle = fmt_to_fragments(forceDelete ? _("Force delete $0") : _("Delete $0?"), selectedJSX); } } diff --git a/src/dialogs/editor.tsx b/src/dialogs/editor.tsx index e2309440..0c79e1af 100644 --- a/src/dialogs/editor.tsx +++ b/src/dialogs/editor.tsx @@ -30,6 +30,7 @@ import { debounce } from "throttle-debounce"; import cockpit from 'cockpit'; import { EventEmitter } from 'cockpit/event.ts'; import type { Dialogs, DialogResult } from 'dialogs'; +import { fmt_to_fragments } from 'utils'; import "./editor.scss"; @@ -165,7 +166,7 @@ export const EditFileModal = ({ dialogResult, path } : { }; /* Translators: This is the title of a modal dialog. $0 represents a filename. */ - let title = <>{cockpit.format(state?.writable ? _("Edit “$0”") : _("View “$0”"), path)}; + let title = <>{fmt_to_fragments(state?.writable ? _("Edit $0") : _("View $0"), {path})}; if (!state.writable) { // TODO: dark mode and lack of spacing title = (<>{title}); diff --git a/src/dialogs/permissions.jsx b/src/dialogs/permissions.jsx index 5ab0b53c..2473082e 100644 --- a/src/dialogs/permissions.jsx +++ b/src/dialogs/permissions.jsx @@ -31,6 +31,7 @@ import { basename } from "cockpit-path"; import { useInit } from 'hooks'; import { etc_group_syntax, etc_passwd_syntax } from 'pam_user_parser'; import { superuser } from 'superuser'; +import { fmt_to_fragments } from 'utils.tsx'; import { useFilesContext } from '../app.tsx'; import { map_permissions, inode_types } from '../common.ts'; @@ -119,7 +120,7 @@ const EditPermissionsModal = ({ dialogResult, selected, path }) => { position="top" variant={ModalVariant.small} /* Translators: $0 represents a filename */ - title={cockpit.format(_("“$0” permissions"), selected.name)} + title={fmt_to_fragments(_("$0 permissions"), {selected.name})} description={inode_types[selected.type] || "Unknown type"} isOpen onClose={dialogResult.resolve} diff --git a/test/check-application b/test/check-application index 4e969788..3752d597 100755 --- a/test/check-application +++ b/test/check-application @@ -2292,7 +2292,7 @@ class TestFiles(testlib.MachineCase): # Opening an test file, editing and closing (discard) open_editor("test.txt") - b.wait_text(".pf-v5-c-modal-box__title", "Edit “/home/admin/test.txt”") + b.wait_text(".pf-v5-c-modal-box__title", "Edit /home/admin/test.txt") b.wait_text(".file-editor-modal textarea", "test\n") # Save button is disabled when not editing yet @@ -2401,7 +2401,7 @@ class TestFiles(testlib.MachineCase): b.go("/files#/?path=/etc") self.assert_last_breadcrumb("etc") open_editor("cockpit-files-test.cfg") - b.wait_text(".pf-v5-c-modal-box__title", "View “/etc/cockpit-files-test.cfg”Read-only") + b.wait_text(".pf-v5-c-modal-box__title", "View /etc/cockpit-files-test.cfgRead-only") b.assert_pixels(".file-editor-modal", "editor-modal-read-only") b.click(".pf-v5-c-modal-box__footer button.pf-m-secondary") diff --git a/test/reference b/test/reference index 3604d52f..b850a11e 160000 --- a/test/reference +++ b/test/reference @@ -1 +1 @@ -Subproject commit 3604d52f83a03997f6967325d5c5606796bba07f +Subproject commit b850a11e0c20e3f9bd0f02e4db9e36372ee82cc4