discourse/app/assets/javascripts/admin/addon/components/site-text-summary.gjs
Martin Brennan a16faa27cd
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.
2024-08-26 11:25:36 +10:00

64 lines
1.6 KiB
Plaintext

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;
}
<template>
<div
class={{concatClass "site-text" (if @siteText.overridden "overridden")}}
{{didInsert this.highlightSearchTerm}}
data-site-text-id={{@siteText.id}}
>
<DButton
@label="admin.site_text.edit"
@action={{fn @editAction @siteText}}
class="btn-default site-text-edit"
/>
<h3 class="site-text-id">{{@siteText.id}}</h3>
<div class="site-text-value">{{@siteText.value}}</div>
<div class="clearfix"></div>
</div>
</template>
}