From a16faa27cd0088361c1a486a68c98e731ab57878 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Mon, 26 Aug 2024 11:25:36 +1000 Subject: [PATCH] FEATURE: Allow showing site text search in selected locale (#28453) When searching for site texts for admin using the english version of the text, previously we would show the english version in the results _even if_ there was another locale translated version available when a locale was selected from the dropdown. This commit adds a "Only show results in selected locale" checkbox option which will instead make it so the results shown are in the target locale, making it easier for translators to tell when there is actually translations vs. missing tranlsations. --- .../addon/components/site-text-summary.gjs | 63 ++++++++++ .../addon/components/site-text-summary.hbs | 9 -- .../addon/components/site-text-summary.js | 41 ------ .../controllers/admin-site-text-index.js | 26 +++- .../addon/routes/admin-site-text-index.js | 1 + .../admin/addon/templates/site-text-index.hbs | 12 +- .../stylesheets/common/admin/admin_base.scss | 2 +- .../admin/site_texts_controller.rb | 13 +- config/locales/client.en.yml | 1 + .../admin/site_texts_controller_spec.rb | 17 +++ spec/system/admin_site_texts_spec.rb | 119 ++++++++++++++++++ .../page_objects/pages/admin_site_texts.rb | 53 ++++++++ 12 files changed, 300 insertions(+), 57 deletions(-) create mode 100644 app/assets/javascripts/admin/addon/components/site-text-summary.gjs delete mode 100644 app/assets/javascripts/admin/addon/components/site-text-summary.hbs delete mode 100644 app/assets/javascripts/admin/addon/components/site-text-summary.js create mode 100644 spec/system/admin_site_texts_spec.rb create mode 100644 spec/system/page_objects/pages/admin_site_texts.rb diff --git a/app/assets/javascripts/admin/addon/components/site-text-summary.gjs b/app/assets/javascripts/admin/addon/components/site-text-summary.gjs new file mode 100644 index 00000000000..5eb204fc135 --- /dev/null +++ b/app/assets/javascripts/admin/addon/components/site-text-summary.gjs @@ -0,0 +1,63 @@ +import Component from "@glimmer/component"; +import { fn } from "@ember/helper"; +import { action } from "@ember/object"; +import didInsert from "@ember/render-modifiers/modifiers/did-insert"; +import DButton from "discourse/components/d-button"; +import concatClass from "discourse/helpers/concat-class"; +import highlightHTML from "discourse/lib/highlight-html"; +import { bind } from "discourse-common/utils/decorators"; + +export default class SiteTextSummary extends Component { + @action + highlightSearchTerm(element) { + const term = this.#searchTerm(); + + if (term) { + highlightHTML( + element.querySelector(".site-text-id, .site-text-value"), + term, + { + className: "text-highlight", + } + ); + } + } + + @action + onClick() { + this.args.editAction(this.siteText); + } + + @bind + #searchTerm() { + const regex = this.args.searchRegex; + const siteText = this.args.siteText; + + if (regex && siteText) { + const matches = siteText.value.match(new RegExp(regex, "i")); + if (matches) { + return matches[0]; + } + } + + return this.args.term; + } + + +} diff --git a/app/assets/javascripts/admin/addon/components/site-text-summary.hbs b/app/assets/javascripts/admin/addon/components/site-text-summary.hbs deleted file mode 100644 index d73f2be2ea9..00000000000 --- a/app/assets/javascripts/admin/addon/components/site-text-summary.hbs +++ /dev/null @@ -1,9 +0,0 @@ - -

{{this.siteText.id}}

-
{{this.siteText.value}}
- -
\ No newline at end of file diff --git a/app/assets/javascripts/admin/addon/components/site-text-summary.js b/app/assets/javascripts/admin/addon/components/site-text-summary.js deleted file mode 100644 index 1add22e7b9e..00000000000 --- a/app/assets/javascripts/admin/addon/components/site-text-summary.js +++ /dev/null @@ -1,41 +0,0 @@ -import Component from "@ember/component"; -import { classNameBindings, classNames } from "@ember-decorators/component"; -import highlightHTML from "discourse/lib/highlight-html"; - -@classNames("site-text") -@classNameBindings("siteText.overridden") -export default class SiteTextSummary extends Component { - didInsertElement() { - super.didInsertElement(...arguments); - - const term = this._searchTerm(); - - if (term) { - highlightHTML( - this.element.querySelector(".site-text-id, .site-text-value"), - term, - { - className: "text-highlight", - } - ); - } - } - - click() { - this.editAction(this.siteText); - } - - _searchTerm() { - const regex = this.searchRegex; - const siteText = this.siteText; - - if (regex && siteText) { - const matches = siteText.value.match(new RegExp(regex, "i")); - if (matches) { - return matches[0]; - } - } - - return this.term; - } -} diff --git a/app/assets/javascripts/admin/addon/controllers/admin-site-text-index.js b/app/assets/javascripts/admin/addon/controllers/admin-site-text-index.js index aba95fbc457..d4ce5a2dad9 100644 --- a/app/assets/javascripts/admin/addon/controllers/admin-site-text-index.js +++ b/app/assets/javascripts/admin/addon/controllers/admin-site-text-index.js @@ -20,13 +20,21 @@ export default class AdminSiteTextIndexController extends Controller { @tracked overridden; @tracked outdated; @tracked untranslated; + @tracked onlySelectedLocale; @tracked model; @tracked searching = false; @tracked preferred = false; - queryParams = ["q", "overridden", "outdated", "locale", "untranslated"]; + queryParams = [ + "q", + "overridden", + "outdated", + "locale", + "untranslated", + "onlySelectedLocale", + ]; get resolvedOverridden() { return [true, "true"].includes(this.overridden) ?? false; @@ -40,6 +48,10 @@ export default class AdminSiteTextIndexController extends Controller { return [true, "true"].includes(this.untranslated) ?? false; } + get resolvedOnlySelectedLocale() { + return [true, "true"].includes(this.onlySelectedLocale) ?? false; + } + get resolvedLocale() { return this.locale ?? this.siteSettings.default_locale; } @@ -59,6 +71,7 @@ export default class AdminSiteTextIndexController extends Controller { outdated: this.resolvedOutdated, locale: this.resolvedLocale, untranslated: this.resolvedUntranslated, + only_selected_locale: this.resolvedOnlySelectedLocale, }); } finally { this.searching = false; @@ -119,6 +132,17 @@ export default class AdminSiteTextIndexController extends Controller { discourseDebounce(this, this._performSearch, 400); } + @action + toggleOnlySelectedLocale() { + if (this.resolvedOnlySelectedLocale) { + this.onlySelectedLocale = null; + } else { + this.onlySelectedLocale = true; + } + this.searching = true; + discourseDebounce(this, this._performSearch, 400); + } + @action search() { const q = this.q; diff --git a/app/assets/javascripts/admin/addon/routes/admin-site-text-index.js b/app/assets/javascripts/admin/addon/routes/admin-site-text-index.js index 07a231cf6f9..77c6b223399 100644 --- a/app/assets/javascripts/admin/addon/routes/admin-site-text-index.js +++ b/app/assets/javascripts/admin/addon/routes/admin-site-text-index.js @@ -22,6 +22,7 @@ export default class AdminSiteTextIndexRoute extends Route { outdated: params.outdated ?? false, untranslated: params.untranslated ?? false, locale: params.locale ?? this.siteSettings.default_locale, + only_selected_locale: params.onlySelectedLocale ?? false, }); } } diff --git a/app/assets/javascripts/admin/addon/templates/site-text-index.hbs b/app/assets/javascripts/admin/addon/templates/site-text-index.hbs index 330c3c41cb0..52e9aa33530 100644 --- a/app/assets/javascripts/admin/addon/templates/site-text-index.hbs +++ b/app/assets/javascripts/admin/addon/templates/site-text-index.hbs @@ -25,7 +25,7 @@ + + {{#if this.showUntranslated}}