From 14465960893981e8aba49f2cc0620944f2abea53 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Tue, 20 Aug 2024 09:59:43 +1000 Subject: [PATCH] UX: Apply admin interface guidelines to Backups page (#28051) This commit converts the Backups page in the admin interface to follow our new admin interface guidelines. As part of this work, I've also made `AdminPageHeader` and `AdminPageSubheader` components that can be reused on any admin page for consistency, that handle the title and action buttons and also breadcrumbs. Also renamed `AdminPluginFilteredSiteSettings` to `AdminFilteredSiteSettings` since it can be used generally to show a subset of filtered site settings, not only settings for a plugin. Not sure if it's ideal to have to define a new route for this for every config area, but not sure how else to do it right now. --- .../components/admin-backups-actions.gjs | 100 ++++++++++++ ...s.gjs => admin-filtered-site-settings.gjs} | 2 +- .../components/admin-page-action-button.gjs | 46 ++++++ .../addon/components/admin-page-header.gjs | 52 +++++++ .../addon/components/admin-page-subheader.gjs | 23 +++ .../admin-plugin-config-metadata.gjs | 4 +- .../addon/controllers/admin-backups-index.js | 36 ++--- .../controllers/admin-backups-settings.js | 11 ++ .../admin/addon/controllers/admin-backups.js | 9 +- .../addon/routes/admin-backups-settings.js | 15 ++ .../admin/addon/routes/admin-backups.js | 4 + .../routes/admin-plugins-show-settings.js | 8 +- .../admin/addon/routes/admin-route-map.js | 1 + .../admin/addon/templates/backups-index.hbs | 144 ++++++++---------- .../admin/addon/templates/backups-logs.hbs | 5 + .../addon/templates/backups-settings.hbs | 9 ++ .../admin/addon/templates/backups.hbs | 79 +++++----- .../admin/addon/templates/dashboard.hbs | 6 + .../addon/templates/plugins-show-settings.hbs | 2 +- .../app/components/uppy-backup-uploader.hbs | 2 +- .../stylesheets/common/admin/admin_base.scss | 1 + .../common/admin/admin_config_area.scss | 28 ++++ .../common/admin/admin_page_header.scss | 44 ++++++ .../stylesheets/common/admin/backups.scss | 68 ++------- .../stylesheets/common/admin/dashboard.scss | 2 - config/locales/client.en.yml | 7 + config/routes.rb | 1 + spec/system/admin_backups_spec.rb | 83 ++++++++++ spec/system/page_objects/admin_backups.rb | 69 +++++++++ .../page_objects/pages/admin_site_settings.rb | 10 +- 30 files changed, 649 insertions(+), 222 deletions(-) create mode 100644 app/assets/javascripts/admin/addon/components/admin-backups-actions.gjs rename app/assets/javascripts/admin/addon/components/{admin-plugin-filtered-site-settings.gjs => admin-filtered-site-settings.gjs} (96%) create mode 100644 app/assets/javascripts/admin/addon/components/admin-page-action-button.gjs create mode 100644 app/assets/javascripts/admin/addon/components/admin-page-header.gjs create mode 100644 app/assets/javascripts/admin/addon/components/admin-page-subheader.gjs create mode 100644 app/assets/javascripts/admin/addon/controllers/admin-backups-settings.js create mode 100644 app/assets/javascripts/admin/addon/routes/admin-backups-settings.js create mode 100644 app/assets/javascripts/admin/addon/templates/backups-settings.hbs create mode 100644 app/assets/stylesheets/common/admin/admin_page_header.scss create mode 100644 spec/system/admin_backups_spec.rb create mode 100644 spec/system/page_objects/admin_backups.rb diff --git a/app/assets/javascripts/admin/addon/components/admin-backups-actions.gjs b/app/assets/javascripts/admin/addon/components/admin-backups-actions.gjs new file mode 100644 index 00000000000..5f4d4b2e370 --- /dev/null +++ b/app/assets/javascripts/admin/addon/components/admin-backups-actions.gjs @@ -0,0 +1,100 @@ +import Component from "@glimmer/component"; +import { action } from "@ember/object"; +import { service } from "@ember/service"; +import routeAction from "discourse/helpers/route-action"; +import { ajax } from "discourse/lib/ajax"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import I18n from "discourse-i18n"; + +export default class AdminBackupsActions extends Component { + @service currentUser; + @service site; + @service dialog; + + @action + toggleReadOnlyMode() { + if (!this.site.isReadOnly) { + this.dialog.yesNoConfirm({ + message: I18n.t("admin.backups.read_only.enable.confirm"), + didConfirm: () => { + this.currentUser.set("hideReadOnlyAlert", true); + this.#toggleReadOnlyMode(true); + }, + }); + } else { + this.#toggleReadOnlyMode(false); + } + } + + get rollbackDisabled() { + return !this.rollbackEnabled; + } + + get rollbackEnabled() { + return ( + this.args.backups.canRollback && + this.args.backups.restoreEnabled && + !this.args.backups.isOperationRunning + ); + } + + async #toggleReadOnlyMode(enable) { + try { + await ajax("/admin/backups/readonly", { + type: "PUT", + data: { enable }, + }); + this.site.set("isReadOnly", enable); + } catch (err) { + popupAjaxError(err); + } + } + + +} diff --git a/app/assets/javascripts/admin/addon/components/admin-plugin-filtered-site-settings.gjs b/app/assets/javascripts/admin/addon/components/admin-filtered-site-settings.gjs similarity index 96% rename from app/assets/javascripts/admin/addon/components/admin-plugin-filtered-site-settings.gjs rename to app/assets/javascripts/admin/addon/components/admin-filtered-site-settings.gjs index 5b4d69160c6..82f775bfb05 100644 --- a/app/assets/javascripts/admin/addon/components/admin-plugin-filtered-site-settings.gjs +++ b/app/assets/javascripts/admin/addon/components/admin-filtered-site-settings.gjs @@ -11,7 +11,7 @@ import discourseDebounce from "discourse-common/lib/debounce"; import AdminSiteSettingsFilterControls from "admin/components/admin-site-settings-filter-controls"; import SiteSetting from "admin/components/site-setting"; -export default class AdminPluginFilteredSiteSettings extends Component { +export default class AdminFilteredSiteSettings extends Component { @service currentUser; @tracked visibleSettings; @tracked loading = true; diff --git a/app/assets/javascripts/admin/addon/components/admin-page-action-button.gjs b/app/assets/javascripts/admin/addon/components/admin-page-action-button.gjs new file mode 100644 index 00000000000..ef14f31203f --- /dev/null +++ b/app/assets/javascripts/admin/addon/components/admin-page-action-button.gjs @@ -0,0 +1,46 @@ +import DButton from "discourse/components/d-button"; + +export const AdminPageActionButton = ; +export const PrimaryButton = ; +export const DangerButton = ; +export const DefaultButton = ; diff --git a/app/assets/javascripts/admin/addon/components/admin-page-header.gjs b/app/assets/javascripts/admin/addon/components/admin-page-header.gjs new file mode 100644 index 00000000000..93d69088dda --- /dev/null +++ b/app/assets/javascripts/admin/addon/components/admin-page-header.gjs @@ -0,0 +1,52 @@ +import { hash } from "@ember/helper"; +import { htmlSafe } from "@ember/template"; +import DBreadcrumbsContainer from "discourse/components/d-breadcrumbs-container"; +import DBreadcrumbsItem from "discourse/components/d-breadcrumbs-item"; +import HorizontalOverflowNav from "discourse/components/horizontal-overflow-nav"; +import i18n from "discourse-common/helpers/i18n"; +import { + DangerButton, + DefaultButton, + PrimaryButton, +} from "admin/components/admin-page-action-button"; + +const AdminPageHeader = ; + +export default AdminPageHeader; diff --git a/app/assets/javascripts/admin/addon/components/admin-page-subheader.gjs b/app/assets/javascripts/admin/addon/components/admin-page-subheader.gjs new file mode 100644 index 00000000000..52140dc6649 --- /dev/null +++ b/app/assets/javascripts/admin/addon/components/admin-page-subheader.gjs @@ -0,0 +1,23 @@ +import { hash } from "@ember/helper"; +import i18n from "discourse-common/helpers/i18n"; +import { + DangerButton, + DefaultButton, + PrimaryButton, +} from "admin/components/admin-page-action-button"; + +const AdminPageSubheader = ; + +export default AdminPageSubheader; diff --git a/app/assets/javascripts/admin/addon/components/admin-plugin-config-metadata.gjs b/app/assets/javascripts/admin/addon/components/admin-plugin-config-metadata.gjs index c27dcd4d555..427ecc180bb 100644 --- a/app/assets/javascripts/admin/addon/components/admin-plugin-config-metadata.gjs +++ b/app/assets/javascripts/admin/addon/components/admin-plugin-config-metadata.gjs @@ -3,9 +3,9 @@ import i18n from "discourse-common/helpers/i18n"; const AdminPluginConfigMetadata =