Skip to content

A platform for community discussion. Free, open, simple.

UX: Sort AI translations by completion, show decimal between 99 and 100% (#35461)

Krisce9d2d543a84
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-translations.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-translations.gjs
index 2e3c811974f..fe07cbe5da0 100644
--- a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-translations.gjs
+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-translations.gjs
@@ -228,7 +228,12 @@ export default class AiTranslations extends Component {
const colors = this.chartColors;
const processedData = this.data.map(({ locale, total, done }) => {
- const donePercentage = (total > 0 ? (done / total) * 100 : 0).toFixed(0);
+ const rawPercentage = total > 0 ? (done / total) * 100 : 0;
+ // Show one decimal place when between 99.0 and 99.9 to avoid showing 100% when not complete
+ const donePercentage =
+ rawPercentage >= 99 && rawPercentage < 100 && rawPercentage % 1 !== 0
+ ? rawPercentage.toFixed(1)
+ : rawPercentage.toFixed(0);
const localeName = this.languageNameLookup.getLanguageName(locale);
const languageNameForTooltip = localeName.split(" (")[0];
diff --git a/plugins/discourse-ai/lib/translation/post_candidates.rb b/plugins/discourse-ai/lib/translation/post_candidates.rb
index 3a991e577a5..ee726753f9a 100644
--- a/plugins/discourse-ai/lib/translation/post_candidates.rb
+++ b/plugins/discourse-ai/lib/translation/post_candidates.rb
@@ -128,7 +128,12 @@ module DiscourseAi
LEFT JOIN non_target_locale_counts ntl ON ntl.base = s.base
SQL
- DB.query(sql).map { |r| { locale: r.locale, done: r.done, total: r.total } }
+ results = DB.query(sql).map { |r| { locale: r.locale, done: r.done, total: r.total } }
+
+ results.sort_by do |r|
+ percentage = r[:total] > 0 ? r[:done].to_f / r[:total] : 0
+ -percentage
+ end
end
def self.cache_key_for_type
diff --git a/plugins/discourse-ai/spec/lib/translation/post_candidates_spec.rb b/plugins/discourse-ai/spec/lib/translation/post_candidates_spec.rb
index df5ab1b69a5..de883cb5d90 100644
--- a/plugins/discourse-ai/spec/lib/translation/post_candidates_spec.rb
+++ b/plugins/discourse-ai/spec/lib/translation/post_candidates_spec.rb
@@ -70,13 +70,8 @@ describe DiscourseAi::Translation::PostCandidates do
Post.delete_all
result = DiscourseAi::Translation::PostCandidates.get_completion_all_locales
- expect(result).to eq(
- [
- { done: 0, locale: "en_GB", total: 0 },
- { done: 0, locale: "pt", total: 0 },
- { done: 0, locale: "es", total: 0 },
- ],
- )
+ expect(result.length).to eq(3)
+ expect(result).to all(include(done: 0, total: 0))
end
it "returns progress grouped by base locale (of en_GB) and correct totals" do
@@ -100,6 +95,8 @@ describe DiscourseAi::Translation::PostCandidates do
expect(result).to all(include(:locale, :done, :total))
+ expect(result.first[:locale]).to eq("en_GB")
+
en_entry = result.find { |r| r[:locale] == "en_GB" }
expect(en_entry).to be_present
# total is non-English posts (post2 + post3)