Skip to content

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

DEV: Convert 10 components to glimmer (#44766)

Jarek Radoszab1b8fcc79ee
diff --git a/frontend/discourse/admin/components/admin-report-table.gjs b/frontend/discourse/admin/components/admin-report-table.gjs
index 50ec03a8aef..fd1391ac5ed 100644
--- a/frontend/discourse/admin/components/admin-report-table.gjs
+++ b/frontend/discourse/admin/components/admin-report-table.gjs
@@ -1,8 +1,7 @@
-/* eslint-disable ember/no-classic-components */
-import Component from "@ember/component";
+import Component from "@glimmer/component";
+import { cached, tracked } from "@glimmer/tracking";
import { fn } from "@ember/helper";
-import { action, computed, set } from "@ember/object";
-import { tagName } from "@ember-decorators/component";
+import { action, get } from "@ember/object";
import AdminReportTableHeader from "discourse/admin/components/admin-report-table-header";
import AdminReportTableRow from "discourse/admin/components/admin-report-table-row";
import { makeArray } from "discourse/lib/helpers";
@@ -12,28 +11,23 @@ import { i18n } from "discourse-i18n";
const PAGES_LIMIT = 8;
-@tagName("")
export default class AdminReportTable extends Component {
- sortable = false;
- sortDirection = 1;
+ @tracked page = 0;
+ @tracked sortDirection = 1;
+ @tracked sortLabel;
- page = 0;
-
- @computed("options.perPage")
- get perPage() {
- return this.options?.perPage;
+ get data() {
+ return get(this.args.model, "data");
}
- set perPage(value) {
- set(this, "options.perPage", value);
+ get perPage() {
+ return this.args.options?.perPage;
}
- @computed("model.computedLabels.length")
get twoColumns() {
- return this.model?.computedLabels?.length === 2;
+ return this.args.model?.computedLabels?.length === 2;
}
- @computed("totalsForSample", "options.total", "model.dates_filtering")
get showTotalForSample() {
// check if we have at least one cell which contains a value
const sum = this.totalsForSample
@@ -41,42 +35,44 @@ export default class AdminReportTable extends Component {
.filter((item) => item != null)
.reduce((s, v) => s + v, 0);
- return sum >= 1 && this.options?.total && this.model?.dates_filtering;
+ return (
+ sum >= 1 &&
+ this.args.options?.total &&
+ get(this.args.model, "dates_filtering")
+ );
}
- @computed("model.total", "options.total", "twoColumns")
get showTotal() {
- return this.model?.total && this.options?.total && this.twoColumns;
+ return (
+ get(this.args.model, "total") &&
+ this.args.options?.total &&
+ this.twoColumns
+ );
}
- @computed("model.{average,data}", "totalsForSample.1.value", "twoColumns")
get showAverage() {
return (
- this.model?.average &&
- this.model?.data.length > 0 &&
+ get(this.args.model, "average") &&
+ this.data.length > 0 &&
this.totalsForSample?.[1]?.value &&
this.twoColumns
);
}
- @computed("totalsForSample.1.value", "model.data.length")
get averageForSample() {
- const averageLabel = this.model.computedLabels.at(-1);
+ const averageLabel = this.args.model.computedLabels.at(-1);
return averageLabel.compute({
- y: (this.totalsForSample?.[1]?.value / this.model?.data?.length).toFixed(
- 0
- ),
+ y: (this.totalsForSample?.[1]?.value / this.data?.length).toFixed(0),
}).formattedValue;
}
- @computed("model.data.length")
get showSortingUI() {
- return this.model?.data?.length >= 5;
+ return this.data?.length >= 5;
}
- @computed("totalsForSampleRow", "model.computedLabels")
+ @cached
get totalsForSample() {
- return this.model?.computedLabels?.map((label) => {
+ return this.args.model?.computedLabels?.map((label) => {
const computedLabel = label.compute(this.totalsForSampleRow);
computedLabel.type = label.type;
computedLabel.property = label.mainProperty;
@@ -84,21 +80,22 @@ export default class AdminReportTable extends Component {
});
}
- @computed("model.total", "model.computedLabels")
get formattedTotal() {
- const totalLabel = this.model?.computedLabels?.at(-1);
- return totalLabel.compute({ y: this.model?.total }).formattedValue;
+ const totalLabel = this.args.model?.computedLabels?.at(-1);
+ return totalLabel.compute({ y: get(this.args.model, "total") })
+ .formattedValue;
}
- @computed("model.data", "model.computedLabels")
+ @cached
get totalsForSampleRow() {
- if (!this.model?.data || !this.model?.data?.length) {
+ const data = this.data;
+ if (!data || !data.length) {
return {};
}
let totalsRow = {};
- this.model?.computedLabels?.forEach((label) => {
+ this.args.model?.computedLabels?.forEach((label) => {
const reducer = (sum, row) => {
const computedLabel = label.compute(row);
const value = computedLabel.value;
@@ -110,19 +107,17 @@ export default class AdminReportTable extends Component {
}
};
- const total = this.model?.data?.reduce(reducer, 0);
+ const total = data.reduce(reducer, 0);
totalsRow[label.mainProperty] =
- label.type === "percent"
- ? Math.round(total / this.model?.data?.length)
- : total;
+ label.type === "percent" ? Math.round(total / data.length) : total;
});
return totalsRow;
}
- @computed("sortLabel", "sortDirection", "model.data.[]")
+ @cached
get sortedData() {
- const data = makeArray(this.model?.data);
+ const data = makeArray(this.data);
if (this.sortLabel) {
const compare = (label, direction) => {
@@ -140,7 +135,6 @@ export default class AdminReportTable extends Component {
return data;
}
- @computed("sortedData.[]", "perPage", "page")
get paginatedData() {
if (this.perPage < this.sortedData?.length) {
const start = this.perPage * this.page;
@@ -150,18 +144,14 @@ export default class AdminReportTable extends Component {
return this.sortedData;
}
- @computed("model.data", "perPage", "page")
get pages() {
- if (!this.model?.data || this.model?.data?.length <= this.perPage) {
+ const data = this.data;
+ if (!data || data.length <= this.perPage) {
return [];
}
const pagesIndexes = [];
- for (
- let i = 0;
- i < Math.ceil(this.model?.data?.length / this.perPage);
- i++
- ) {
+ for (let i = 0; i < Math.ceil(data.length / this.perPage); i++) {
pagesIndexes.push(i);
}
@@ -184,15 +174,15 @@ export default class AdminReportTable extends Component {
@action
changePage(page) {
- this.set("page", page);
+ this.page = page;
}
@action
sortByLabel(label) {
if (this.sortLabel === label) {
- this.set("sortDirection", this.sortDirection === 1 ? -1 : 1);
+ this.sortDirection = this.sortDirection === 1 ? -1 : 1;
} else {
- this.set("sortLabel", label);
+ this.sortLabel = label;
}
}
@@ -200,7 +190,6 @@ export default class AdminReportTable extends Component {
<div
class={{dConcatClass
"admin-report-table"
- (if this.sortable "sortable")
(if this.twoColumns "two-columns")
}}
...attributes
@@ -208,7 +197,7 @@ export default class AdminReportTable extends Component {
<table class="table">
<thead>
<tr>
- {{#each this.model.computedLabels as |label|}}
+ {{#each @model.computedLabels as |label|}}
<AdminReportTableHeader
@currentSortDirection={{this.sortDirection}}
@currentSortLabel={{this.sortLabel}}
@@ -217,7 +206,7 @@ export default class AdminReportTable extends Component {
@sortByLabel={{fn this.sortByLabel label}}
/>
{{else}}
- {{#each this.model.data as |data|}}
+ {{#each this.data as |data|}}
<th>{{data.x}}</th>
{{/each}}
{{/each}}
@@ -228,8 +217,8 @@ export default class AdminReportTable extends Component {
<AdminReportTableRow
@data={{data}}
@hasRelatedItems={{@hasRelatedItems}}
- @labels={{this.model.computedLabels}}
- @options={{this.options}}
+ @labels={{@model.computedLabels}}
+ @options={{@options}}
@reportFilters={{@reportFilters}}
@reportType={{@reportType}}
/>
diff --git a/frontend/discourse/admin/components/emoji-uploader.gjs b/frontend/discourse/admin/components/emoji-uploader.gjs
index 8169047bb04..54e5736e5a2 100644
--- a/frontend/discourse/admin/components/emoji-uploader.gjs
+++ b/frontend/discourse/admin/components/emoji-uploader.gjs
@@ -1,14 +1,15 @@
-/* eslint-disable ember/no-classic-components */
-import Component, { Input } from "@ember/component";
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { Input } from "@ember/component";
import { fn, hash } from "@ember/helper";
import { on } from "@ember/modifier";
-import { action, computed } from "@ember/object";
+import { action } from "@ember/object";
import { getOwner } from "@ember/owner";
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import { isEmpty } from "@ember/utils";
-import { tagName } from "@ember-decorators/component";
import withEventValue from "discourse/helpers/with-event-value";
import { uniqueItemsFromArray } from "discourse/lib/array-tools";
+import { resettableTracked } from "discourse/lib/tracked-tools";
import UppyUpload from "discourse/lib/uppy/uppy-upload";
import ComboBox from "discourse/select-kit/components/combo-box";
import DButton from "discourse/ui-kit/d-button";
@@ -16,8 +17,13 @@ import { i18n } from "discourse-i18n";
const DEFAULT_GROUP = "default";
-@tagName("")
export default class EmojiUploader extends Component {
+ @tracked name;
+ @tracked group = DEFAULT_GROUP;
+
+ /** @type {string[] | null} */
+ @resettableTracked newEmojiGroups = this.args.emojiGroups;
+
uppyUpload = new UppyUpload(getOwner(this), {
id: "emoji-uploader",
type: "emoji",
@@ -34,7 +40,7 @@ export default class EmojiUploader extends Component {
payload.name = this.name;
// if uploading multiple files, we can't use the name for every emoji
- this.set("name", null);
+ this.name = null;
}
if (!isEmpty(this.group) && this.group !== DEFAULT_GROUP) {
@@ -45,62 +51,27 @@ export default class EmojiUploader extends Component {
},
uploadDone: (upload) => {
- this.done(upload, this.group);
- this.set("name", null);
+ this.args.done(upload, this.group);
+ this.name = null;
},
});
- group = "default";
-
- /** @type {string[] | null} */
- emojiGroups = null;
-
- /** @type {string[] | null} */
- newEmojiGroups = null;
-
- @computed("name")
- get hasName() {
- return !isEmpty(this.name);
- }
-
- @computed("group")
- get hasGroup() {
- return !isEmpty(this.group);
- }
-
- @computed("uppyUpload.uploading", "uppyUpload.uploadProgress")
get buttonLabel() {
- if (this.uppyUpload?.uploading) {
- return `${i18n("admin.emoji.uploading")} ${this.uppyUpload?.uploadProgress}%`;
+ if (this.uppyUpload.uploading) {
+ return `${i18n("admin.emoji.uploading")} ${this.uppyUpload.uploadProgress}%`;
} else {
return i18n("admin.emoji.choose_files");
}
}
- @computed("uppyUpload.uploading")
- get buttonIcon() {
- if (this.uppyUpload?.uploading) {
- return "spinner";
- } else {
- return "plus";
- }
- }
-
- didReceiveAttrs() {
- super.didReceiveAttrs(...arguments);
- this.set("newEmojiGroups", this.emojiGroups);
- }
-
@action
createEmojiGroup(group) {
- let newEmojiGroups = this.newEmojiGroups;
if (group !== DEFAULT_GROUP) {
- newEmojiGroups = uniqueItemsFromArray(this.emojiGroups.concat([group]));
+ this.newEmojiGroups = uniqueItemsFromArray(
+ this.args.emojiGroups.concat([group])
+ );
}
- this.setProperties({
- newEmojiGroups,
- group,
- });
+ this.group = group;
}
@action
diff --git a/frontend/discourse/admin/components/watched-word-form.gjs b/frontend/discourse/admin/components/watched-word-form.gjs
index cb037b1c4f7..b9678ad64a2 100644
--- a/frontend/discourse/admin/components/watched-word-form.gjs
+++ b/frontend/discourse/admin/components/watched-word-form.gjs
@@ -1,10 +1,10 @@
-/* eslint-disable ember/no-classic-components, ember/no-observers */
-import Component, { Input } from "@ember/component";
-import { fn, hash } from "@ember/helper";
-import { action, computed } from "@ember/object";
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { Input } from "@ember/component";
+import { hash } from "@ember/helper";
+import { action } from "@ember/object";
+import { service } from "@ember/service";
import { isEmpty } from "@ember/utils";
-import { tagName } from "@ember-decorators/component";
-import { observes } from "@ember-decorators/object";
import WatchedWord from "discourse/admin/models/watched-word";
import { popupAjaxError } from "discourse/lib/ajax-error";
import TagChooser from "discourse/select-kit/components/tag-chooser";
@@ -13,52 +13,59 @@ import DButton from "discourse/ui-kit/d-button";
import DTextField from "discourse/ui-kit/d-text-field";
import { i18n } from "discourse-i18n";
-@tagName("")
export default class WatchedWordForm extends Component {
- formSubmitted = false;
+ @service siteSettings;
- /** @type {string | null} */
- actionKey = null;
- showMessage = false;
- isCaseSensitive = false;
- isHtml = false;
- selectedTags = [];
- words = [];
+ @tracked formSubmitted = false;
+ @tracked isCaseSensitive = false;
+ @tracked isHtml = false;
+ @tracked replacement;
+ @tracked replacementTags;
+
+ /** @type {{ id?: number | string, name: string }[]} */
+ @tracked selectedTags = [];
+
+ /** @type {string[]} */
+ @tracked words = [];
+
+ // keyed by action so switching to another action's page hides it
+ /** @type {{ text: string, actionKey: string } | null} */
+ @tracked shownMessage = null;
+
+ get message() {
+ return this.shownMessage?.actionKey === this.args.actionKey
+ ? this.shownMessage.text
+ : null;
+ }
- @computed("words.length")
get submitDisabled() {
return isEmpty(this.words);
}
- @computed("actionKey")
get canReplace() {
- return this.actionKey === "replace";
+ return this.args.actionKey === "replace";
}
- @computed("actionKey")
get canTag() {
- return this.actionKey === "tag";
+ return this.args.actionKey === "tag";
}
- @computed("actionKey")
get canLink() {
- return this.actionKey === "link";
+ return this.args.actionKey === "link";
}
- @computed("siteSettings.watched_words_regular_expressions")
get placeholderKey() {
- if (this.siteSettings?.watched_words_regular_expressions) {
+ if (this.siteSettings.watched_words_regular_expressions) {
return "admin.watched_words.form.placeholder_regexp";
} else {
return "admin.watched_words.form.placeholder";
}
}
- @computed("words.[]")
get isUniqueWord() {
- const existingWords = this.filteredContent || [];
+ const existingWords = this.args.filteredContent || [];
const filtered = existingWords.filter(
- (content) => content.action === this.actionKey
+ (content) => content.action === this.args.actionKey
);
const duplicate = filtered.find((content) => {
@@ -74,48 +81,40 @@ export default class WatchedWordForm extends Component {
return !duplicate;
}
- @observes("words.[]")
- removeMessage() {
- if (this.showMessage && !isEmpty(this.words)) {
- this.set("showMessage", false);
+ @action
+ changeWords(words) {
+ this.words = words;
+ if (!isEmpty(words)) {
+ this.shownMessage = null;
}
}
- @observes("actionKey")
- actionChanged() {
- this.setProperties({
- showMessage: false,
- });
- }
-
@action
changeSelectedTags(tags) {
- this.setProperties({
- selectedTags: tags,
- replacementTags: tags.map((t) =>
- typeof t.id === "number" ? { id: t.id, name: t.name } : { name: t.name }
- ),
- });
+ this.selectedTags = tags;
+ this.replacementTags = tags.map((t) =>
+ typeof t.id === "number" ? { id: t.id, name: t.name } : { name: t.name }
+ );
}
@action
submitForm() {
if (!this.isUniqueWord) {
- this.setProperties({
- showMessage: true,
- message: i18n("admin.watched_words.form.exists"),
- });
+ this.shownMessage = {
+ text: i18n("admin.watched_words.form.exists"),
+ actionKey: this.args.actionKey,
+ };
return;
}
if (!this.formSubmitted) {
- this.set("formSubmitted", true);
+ this.formSubmitted = true;
const watchedWord = WatchedWord.create({
words: this.words,
replacement: this.canReplace || this.canLink ? this.replacement : null,
replacementTags: this.canTag ? this.replacementTags : null,
- action: this.actionKey,
+ action: this.args.actionKey,
isCaseSensitive: this.isCaseSensitive,
isHtml: this.isHtml,
});
@@ -123,26 +122,28 @@ export default class WatchedWordForm extends Component {
watchedWord
.save()
.then((result) => {
- this.setProperties({
- words: [],
- replacement: "",
- replacementTags: [],
- selectedTags: [],
- showMessage: true,
- message: i18n("admin.watched_words.form.success"),
- isCaseSensitive: false,
- isHtml: false,
- });
+ this.words = [];
+ this.replacement = "";
+ this.replacementTags = [];
+ this.selectedTags = [];
+ this.isCaseSensitive = false;
+ this.isHtml = false;
+ this.shownMessage = {
+ text: i18n("admin.watched_words.form.success"),
+ actionKey: this.args.actionKey,
+ };
if (result.words) {
result.words.forEach((word) => {
- this.action(WatchedWord.create(word));
+ this.args.action(WatchedWord.create(word));
});
} else {
- this.action(result);
+ this.args.action(result);
}
})
.catch(popupAjaxError)
- .finally(this.set("formSubmitted", false));
+ .finally(() => {
+ this.formSubmitted = false;
+ });
}
}
@@ -154,7 +155,7 @@ export default class WatchedWordForm extends Component {
}}</label>
<WatchedWords
@id="watched-words"
- @onChange={{fn (mut this.words)}}
+ @onChange={{this.changeWords}}
@options={{hash
filterPlaceholder=this.placeholderKey
disabled=this.formSubmitted
@@ -251,7 +252,7 @@ export default class WatchedWordForm extends Component {
@label="admin.watched_words.form.add"
/>
- {{#if this.showMessage}}
+ {{#if this.message}}
<span class="success-message">{{this.message}}</span>
{{/if}}
</form>
diff --git a/frontend/discourse/app/components/bookmark-list.gjs b/frontend/discourse/app/components/bookmark-list.gjs
index 071ce398120..deeb09a5b68 100644
--- a/frontend/discourse/app/components/bookmark-list.gjs
+++ b/frontend/discourse/app/components/bookmark-list.gjs
@@ -1,11 +1,9 @@
-/* eslint-disable ember/no-classic-components, ember/require-tagless-components */
-import Component from "@ember/component";
+import Component from "@glimmer/component";
+import { fn } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
-import { dependentKeyCompat } from "@ember/object/compat";
import { service } from "@ember/service";
import { trustHTML } from "@ember/template";
-import { classNames } from "@ember-decorators/component";
import { Promise } from "rsvp";
import BookmarkActionsDropdown from "discourse/components/bookmark-actions-dropdown";
import BookmarkModal from "discourse/components/modal/bookmark";
@@ -38,26 +36,28 @@ import dReplaceEmoji from "discourse/ui-kit/helpers/d-replace-emoji";
import dTopicLink from "discourse/ui-kit/helpers/d-topic-link";
import { i18n } from "discourse-i18n";
-@classNames("bookmark-list-wrapper")
export default class BookmarkList extends Component {
+ @service appEvents;
@service dialog;
@service modal;
+ @service site;
+
+ #lastChecked = null;
get canDoBulkActions() {
- return this.bulkSelectHelper?.selected.length;
+ return this.args.bulkSelectHelper?.selected.length;
}
get selected() {
- return this.bulkSelectHelper?.selected;
+ return this.args.bulkSelectHelper?.selected;
}
get selectedCount() {
return this.selected?.length || 0;
}
- @dependentKeyCompat // for the classNameBindings
get bulkSelectEnabled() {
- return this.bulkSelectHelper?.bulkSelectEnabled;
+ return this.args.bulkSelectHelper?.bulkSelectEnabled;
}
@action
@@ -72,7 +72,7 @@ export default class BookmarkList extends Component {
null,
bookmark.attachedTo()
);
- this._removeBookmarkFromList(bookmark);
+ removeValueFromArray(this.args.content, bookmark);
resolve(true);
})
.catch((error) => {
@@ -110,10 +110,10 @@ export default class BookmarkList extends Component {
savedData,
bookmark.attachedTo()
);
- this.reload();
+ this.args.reload();
},
afterDelete: () => {
- this.reload();
+ this.args.reload();
},
},
});
@@ -131,18 +131,17 @@ export default class BookmarkList extends Component {
@action
togglePinBookmark(bookmark) {
- bookmark.togglePin().then(this.reload);
+ bookmark.togglePin().then(this.args.reload);
}
@action
toggleBulkSelect() {
- this.bulkSelectHelper?.toggleBulkSelect();
- this.rerender();
+ this.args.bulkSelectHelper?.toggleBulkSelect();
}
@action
selectAll() {
- this.bulkSelectHelper.autoAddBookmarksToBulkSelect = true;
+ this.args.bulkSelectHelper.autoAddBookmarksToBulkSelect = true;
document
.querySelectorAll("input.bulk-select:not(:checked)")
.forEach((el) => el.click());
@@ -150,47 +149,26 @@ export default class BookmarkList extends Component {
@action
clearAll() {
- this.bulkSelectHelper.autoAddBookmarksToBulkSelect = false;
+ this.args.bulkSelectHelper.autoAddBookmarksToBulkSelect = false;
document
.querySelectorAll("input.bulk-select:checked")
.forEach((el) => el.click());
}
- click(e) {
- const onClick = (sel, callback) => {
- let target = e.target.closest(sel);
-
- if (target) {
- callback(target);
- }
- };
-
- onClick("input.bulk-select", () => {
- const target = e.target;
- const bookmarkId = target.dataset.id;
- const bookmark = this.content.find(
- (item) => item.id.toString() === bookmarkId
- );
- this._toggleSelection(target, bookmark, this.lastChecked && e.shiftKey);
- });
- }
-
- _removeBookmarkFromList(bookmark) {
- removeValueFromArray(this.content, bookmark);
- }
-
- _toggleSelection(target, bookmark, isSelectingRange) {
+ @action
+ toggleBookmarkSelection(bookmark, event) {
+ const target = event.target;
const selected = this.selected;
if (target.checked) {
addUniqueValueToArray(selected, bookmark);
- if (isSelectingRange) {
+ if (this.#lastChecked && event.shiftKey) {
const bulkSelects = Array.from(
document.querySelectorAll("input.bulk-select")
),
from = bulkSelects.indexOf(target),
- to = bulkSelects.findIndex((el) => el.id === this.lastChecked.id),
+ to = bulkSelects.findIndex((el) => el.id === this.#lastChecked.id),
start = Math.min(from, to),
end = Math.max(from, to);
@@ -201,201 +179,184 @@ export default class BookmarkList extends Component {
checkbox.click();
});
}
- this.set("lastChecked", target);
+ this.#lastChecked = target;
} else {
removeValueFromArray(selected, bookmark);
- this.set("lastChecked", null);
+ this.#lastChecked = null;
}
}
<template>
- <DConditionalLoadingSpinner @condition={{this.loading}}>
- <DLoadMore @action={{this.loadMore}}>
- <table class="topic-list bookmark-list">
- <thead class="topic-list-header">
- <tr>
- {{#if this.site.desktopView}}
- <PluginOutlet @name="bookmark-list-table-header">
- {{#if this.bulkSelectEnabled}}
- <th class="bulk-select topic-list-data">
- <DButton
- class="bulk-select btn-flat"
- @action={{this.toggleBulkSelect}}
- @icon="list-check"
- @title="bookmarks.bulk.toggle"
- />
- </th>
- {{/if}}
- <th class="topic-list-data">
-
+ <div class="bookmark-list-wrapper" ...attributes>
+ <DConditionalLoadingSpinner @condition={{@loading}}>
+ <DLoadMore @action={{@loadMore}}>
+ <table class="topic-list bookmark-list">
+ <thead class="topic-list-header">
+ <tr>
+ {{#if this.site.desktopView}}
+ <PluginOutlet @name="bookmark-list-table-header">
{{#if this.bulkSelectEnabled}}
- <span class="bulk-select-topics">
- {{~#if this.canDoBulkActions}}
- <div class="bulk-select-bookmarks-dropdown">
- <span class="bulk-select-bookmark-dropdown__count">
- {{i18n
- "bookmarks.bulk.selected_count"
- count=this.selectedCount
- }}
- </span>
- <BulkSelectBookmarksDropdown
- @bulkSelectHelper={{this.bulkSelectHelper}}
- />
- </div>
-
- {{/if~}}
+ <th class="bulk-select topic-list-data">
<DButton
- class="btn btn-default bulk-select-all"
- @action={{this.selectAll}}
- @label="bookmarks.bulk.select_all"
+ class="bulk-select btn-flat"
+ @action={{this.toggleBulkSelect}}
+ @icon="list-check"
+ @title="bookmarks.bulk.toggle"
/>
+ </th>
+ {{/if}}
+ <th class="topic-list-data">
+
+ {{#if this.bulkSelectEnabled}}
+ <span class="bulk-select-topics">
+ {{~#if this.canDoBulkActions}}
+ <div class="bulk-select-bookmarks-dropdown">
+ <span
+ class="bulk-select-bookmark-dropdown__count"
+ >
+ {{i18n
+ "bookmarks.bulk.selected_count"
+ count=this.selectedCount
+ }}
+ </span>
+ <BulkSelectBookmarksDropdown
+ @bulkSelectHelper={{@bulkSelectHelper}}
+ />
+ </div>
+
+ {{/if~}}
+ <DButton
+ class="btn btn-default bulk-select-all"
+ @action={{this.selectAll}}
+ @label="bookmarks.bulk.select_all"
+ />
+ <DButton
+ class="btn btn-default bulk-clear-all"
+ @action={{this.clearAll}}
+ @label="bookmarks.bulk.clear_all"
+ />
+ </span>
+ {{else}}
<DButton
- class="btn btn-default bulk-clear-all"
- @action={{this.clearAll}}
- @label="bookmarks.bulk.clear_all"
+ class="btn-flat bulk-select"
+ @action={{this.toggleBulkSelect}}
+ @icon="list-check"
+ @title="bookmarks.bulk.toggle"
/>
- </span>
- {{else}}
- <DButton
- class="btn-flat bulk-select"
- @action={{this.toggleBulkSelect}}
- @icon="list-check"
- @title="bookmarks.bulk.toggle"
- />
- {{i18n "topic.title"}}
- {{/if~}}
- </th>
- <th class="topic-list-data">&nbsp;</th>
- <th class="post-metadata topic-list-data">{{i18n
- "post.bookmarks.updated"
- }}</th>
- <th class="post-metadata topic-list-data">{{i18n
- "activity"
- }}</th>
- <th>&nbsp;</th>
- </PluginOutlet>
- {{/if}}
- </tr>
- </thead>
- <tbody class="topic-list-body">
- {{#each this.content as |bookmark|}}
- <tr
- class={{dConcatClass
- "topic-list-item bookmark-list-item"
- (if bookmark.excerpt "excerpt-expanded" "")
- (if bookmark.hasMetadata "has-metadata" "")
- }}
- >
- {{#if this.bulkSelectEnabled}}
- <td class="bulk-select bookmark-list-data">
- <label for="bulk-select-{{bookmark.id}}">
- <input
- class="bulk-select"
- data-id={{bookmark.id}}
- id="bulk-select-{{bookmark.id}}"
- type="checkbox"
- />
- </label>
- </td>
+ {{i18n "topic.title"}}
+ {{/if~}}
+ </th>
+ <th class="topic-list-data">&nbsp;</th>
+ <th class="post-metadata topic-list-data">{{i18n
+ "post.bookmarks.updated"
+ }}</th>
+ <th class="post-metadata topic-list-data">{{i18n
+ "activity"
+ }}</th>
+ <th>&nbsp;</th>
+ </PluginOutlet>
{{/if}}
- <td class="main-link topic-list-data">
- <PluginOutlet
- @name="bookmark-list-before-link"
- @outletArgs={{lazyHash bookmark=bookmark}}
- />
+ </tr>
+ </thead>
+ <tbody class="topic-list-body">
+ {{#each @content as |bookmark|}}
+ <tr
+ class={{dConcatClass
+ "topic-list-item bookmark-list-item"
+ (if bookmark.excerpt "excerpt-expanded" "")
+ (if bookmark.hasMetadata "has-metadata" "")
+ }}
+ >
+ {{#if this.bulkSelectEnabled}}
+ <td class="bulk-select bookmark-list-data">
+ <label for="bulk-select-{{bookmark.id}}">
+ <input
+ class="bulk-select"
+ data-id={{bookmark.id}}
+ id="bulk-select-{{bookmark.id}}"
+ type="checkbox"
+ {{on
+ "click"
+ (fn this.toggleBookmarkSelection bookmark)
+ }}
+ />
+ </label>
+ </td>
+ {{/if}}
+ <td class="main-link topic-list-data">
+ <PluginOutlet
+ @name="bookmark-list-before-link"
+ @outletArgs={{lazyHash bookmark=bookmark}}
+ />
- <span class="link-top-line">
- {{#if bookmark.hasMetadata}}
- <div class="bookmark-metadata">
- {{#if bookmark.reminder_at}}
- <span
- class="bookmark-metadata-item bookmark-reminder
- {{if
- bookmark.reminderAtExpired
- 'bookmark-expired-reminder'
- }}"
- >
- {{dIcon "far-clock"}}{{bookmark.formattedReminder}}
- </span>
+ <span class="link-top-line">
+ {{#if bookmark.hasMetadata}}
+ <div class="bookmark-metadata">
+ {{#if bookmark.reminder_at}}
+ <span
+ class="bookmark-metadata-item bookmark-reminder
+ {{if
+ bookmark.reminderAtExpired
+ 'bookmark-expired-reminder'
+ }}"
+ >
+ {{dIcon
+ "far-clock"
+ }}{{bookmark.formattedReminder}}
+ </span>
+ {{/if}}
+ {{#if bookmark.name}}
+ <span class="bookmark-metadata-item">
+ {{dIcon "circle-info"}}<span>{{dReplaceEmoji
+ bookmark.name
+ }}</span>
+ </span>
+ {{/if}}
+ </div>
+ {{/if}}
+ <div class="bookmark-status-with-link">
+ {{#if bookmark.pinned}}
+ {{dIcon "thumbtack" class="bookmark-pinned"}}
{{/if}}
- {{#if bookmark.name}}
- <span class="bookmark-metadata-item">
- {{dIcon "circle-info"}}<span>{{dReplaceEmoji
- bookmark.name
- }}</span>
- </span>
+ {{#if bookmark.bookmarkableTopicAlike}}
+ <TopicStatus @topic={{bookmark.topicStatus}} />
+ {{dTopicLink bookmark.topicForList}}
+ {{else}}
+ <a
+ aria-level="2"
+ class="title"
+ href={{bookmark.bookmarkable_url}}
+ role="heading"
+ >
+ {{bookmark.fancy_title}}
+ </a>
{{/if}}
</div>
+ </span>
+ {{#if bookmark.bookmarkableTopicAlike}}
+ <div class="link-bottom-line">
+ {{dCategoryLink bookmark.category}}
+ {{dDiscourseTags
+ bookmark
+ mode="list"
+ tagsForUser=@tagsForUser
+ }}
+ </div>
{{/if}}
- <div class="bookmark-status-with-link">
- {{#if bookmark.pinned}}
- {{dIcon "thumbtack" class="bookmark-pinned"}}
- {{/if}}
- {{#if bookmark.bookmarkableTopicAlike}}
- <TopicStatus @topic={{bookmark.topicStatus}} />
- {{dTopicLink bookmark.topicForList}}
- {{else}}
- <a
- aria-level="2"
- class="title"
- href={{bookmark.bookmarkable_url}}
- role="heading"
- >
- {{bookmark.fancy_title}}
- </a>
- {{/if}}
- </div>
- </span>
- {{#if bookmark.bookmarkableTopicAlike}}
- <div class="link-bottom-line">
- {{dCategoryLink bookmark.category}}
- {{dDiscourseTags
- bookmark
- mode="list"
- tagsForUser=this.tagsForUser
- }}
- </div>
- {{/if}}
- {{#if
- (and
- this.site.mobileView
- bookmark.excerpt
- bookmark.user.avatar_template
- )
- }}
- <a
- class="avatar"
- data-user-card={{bookmark.user.username}}
- href={{bookmark.bookmarkableUser.path}}
- >
- {{dAvatar
- bookmark.bookmarkableUser
- avatarTemplatePath="avatar_template"
- usernamePath="username"
- namePath="name"
- imageSize="large"
- }}
- </a>
- {{/if}}
-
- {{! eslint-disable ember/template-no-invalid-interactive }}
- {{#if bookmark.excerpt}}
- <p
- class="post-excerpt"
- {{on "click" this.screenExcerptForExternalLink}}
- >{{trustHTML bookmark.excerpt}}</p>
- {{/if}}
- </td>
- {{#if this.site.desktopView}}
- <td class="author-avatar topic-list-data">
- {{#if bookmark.user.avatar_template}}
+ {{#if
+ (and
+ this.site.mobileView
+ bookmark.excerpt
+ bookmark.user.avatar_template
+ )
+ }}
<a
class="avatar"
data-user-card={{bookmark.user.username}}
- href={{bookmark.user.path}}
+ href={{bookmark.bookmarkableUser.path}}
>
{{dAvatar
- bookmark.user
+ bookmark.bookmarkableUser
avatarTemplatePath="avatar_template"
usernamePath="username"
namePath="name"
@@ -403,27 +364,54 @@ export default class BookmarkList extends Component {
}}
</a>
{{/if}}
+
+ {{! eslint-disable ember/template-no-invalid-interactive }}
+ {{#if bookmark.excerpt}}
+ <p
+ class="post-excerpt"
+ {{on "click" this.screenExcerptForExternalLink}}
+ >{{trustHTML bookmark.excerpt}}</p>
+ {{/if}}
</td>
- <td
- class="post-metadata topic-list-data updated-at"
- >{{dFormatDate bookmark.updated_at format="tiny"}}</td>
- <ActivityCell class="post-metadata" @topic={{bookmark}} />
- {{/if}}
- <td class="topic-list-data">
- <BookmarkActionsDropdown
- @bookmark={{bookmark}}
- @clearBookmarkReminder={{this.clearBookmarkReminder}}
- @editBookmark={{this.editBookmark}}
- @removeBookmark={{this.removeBookmark}}
- @togglePinBookmark={{this.togglePinBookmark}}
- />
- </td>
- </tr>
- {{/each}}
- </tbody>
- </table>
- <DConditionalLoadingSpinner @condition={{this.loadingMore}} />
- </DLoadMore>
- </DConditionalLoadingSpinner>
+ {{#if this.site.desktopView}}
+ <td class="author-avatar topic-list-data">
+ {{#if bookmark.user.avatar_template}}
+ <a
+ class="avatar"
+ data-user-card={{bookmark.user.username}}
+ href={{bookmark.user.path}}
+ >
+ {{dAvatar
+ bookmark.user
+ avatarTemplatePath="avatar_template"
+ usernamePath="username"
+ namePath="name"
+ imageSize="large"
+ }}
+ </a>
+ {{/if}}
+ </td>
+ <td
+ class="post-metadata topic-list-data updated-at"
+ >{{dFormatDate bookmark.updated_at format="tiny"}}</td>
+ <ActivityCell class="post-metadata" @topic={{bookmark}} />
+ {{/if}}
+ <td class="topic-list-data">
+ <BookmarkActionsDropdown
+ @bookmark={{bookmark}}
+ @clearBookmarkReminder={{this.clearBookmarkReminder}}
+ @editBookmark={{this.editBookmark}}
+ @removeBookmark={{this.removeBookmark}}
+ @togglePinBookmark={{this.togglePinBookmark}}
+ />
+ </td>
+ </tr>
+ {{/each}}
+ </tbody>
+ </table>
+ <DConditionalLoadingSpinner @condition={{@loadingMore}} />
+ </DLoadMore>
+ </DConditionalLoadingSpinner>
+ </div>
</template>
}
diff --git a/frontend/discourse/app/components/flag-action-type.gjs b/frontend/discourse/app/components/flag-action-type.gjs
index b62f05fc2d6..bcb93d8e4e8 100644
--- a/frontend/discourse/app/components/flag-action-type.gjs
+++ b/frontend/discourse/app/components/flag-action-type.gjs
@@ -1,95 +1,88 @@
-/* eslint-disable ember/no-classic-components */
-import Component, { Input, Textarea } from "@ember/component";
+import Component from "@glimmer/component";
import { fn } from "@ember/helper";
import { on } from "@ember/modifier";
-import { computed } from "@ember/object";
+import { action } from "@ember/object";
+import { service } from "@ember/service";
import { trustHTML } from "@ember/template";
-import { tagName } from "@ember-decorators/component";
+import withEventValue from "discourse/helpers/with-event-value";
import { applyValueTransformer } from "discourse/lib/transformer";
import { MAX_MESSAGE_LENGTH } from "discourse/models/post-action-type";
import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";
import { i18n } from "discourse-i18n";
-@tagName("")
export default class FlagActionType extends Component {
- @computed("flag.require_message", "selected")
+ @service site;
+ @service siteSettings;
+
get showMessageInput() {
- return this.flag?.require_message && this.selected;
+ return this.args.flag?.require_message && this.selected;
}
- @computed("flag.isIllegal", "selected")
get showConfirmation() {
- return this.flag?.isIllegal && this.selected;
+ return this.args.flag?.isIllegal && this.selected;
}
- @computed("flag.name_key")
get isNotifyUser() {
- return this.flag?.name_key === "notify_user";
+ return this.args.flag?.name_key === "notify_user";
}
get flagDescription() {
return applyValueTransformer("flag-description", this.description, {
- nameKey: this.flag.name_key,
+ nameKey: this.args.flag.name_key,
});
}
- @computed("flag.name_key")
get wrapperClassNames() {
- return `flag-action-type ${this.flag?.name_key}`;
+ return `flag-action-type ${this.args.flag?.name_key}`;
}
- @computed("flag.name_key")
get customPlaceholder() {
return applyValueTransformer(
"flag-custom-placeholder",
- i18n("flagging.custom_placeholder_" + this.flag?.name_key, {
+ i18n("flagging.custom_placeholder_" + this.args.flag?.name_key, {
defaultValue: i18n("flagging.custom_placeholder_notify_moderators"),
}),
- { nameKey: this.flag?.name_key }
+ { nameKey: this.args.flag?.name_key }
);
}
- @computed("flag.name", "flag.name_key", "username")
get formattedName() {
- if (["notify_user", "notify_moderators"].includes(this.flag?.name_key)) {
- return this.flag?.name?.replace(
+ const flag = this.args.flag;
+ if (["notify_user", "notify_moderators"].includes(flag?.name_key)) {
+ return flag?.name?.replace(
/{{username}}|%{username}/,
- this.username
+ this.args.username
);
} else {
return applyValueTransformer(
"flag-formatted-name",
- i18n("flagging.formatted_name." + this.flag?.name_key, {
- defaultValue: this.flag?.name,
+ i18n("flagging.formatted_name." + flag?.name_key, {
+ defaultValue: flag?.name,
}),
- { nameKey: this.flag?.name_key }
+ { nameKey: flag?.name_key }
);
}
}
- @computed("flag", "selectedFlag")
get selected() {
- return this.flag === this.selectedFlag;
+ return this.args.flag === this.args.selectedFlag;
}
- @computed("flag.description", "flag.short_description")
get description() {
return this.site.mobileView
- ? this.flag?.short_description
- : this.flag?.description;
+ ? this.args.flag?.short_description
+ : this.args.flag?.description;
}
- @computed("message.length")
get customMessageLengthClasses() {
- return this.message?.length <
+ return this.args.message?.length <
this.siteSettings.min_personal_message_post_length
? "too-short"
: "ok";
}
- @computed("message.length")
get customMessageLength() {
- const len = this.message?.length || 0;
+ const len = this.args.message?.length || 0;
const minLen = this.siteSettings.min_personal_message_post_length;
if (len === 0) {
return i18n("flagging.custom_message.at_least", { count: minLen });
@@ -102,6 +95,11 @@ export default class FlagActionType extends Component {
}
}
+ @action
+ changeConfirmed(event) {
+ this.args.onChangeConfirmed(event.target.checked);
+ }
+
<template>
<div class={{this.wrapperClassNames}}>
{{#if this.isNotifyUser}}
@@ -109,10 +107,11 @@ export default class FlagActionType extends Component {
<div class="controls">
<label class="radio checkbox-label">
<input
- id="radio_{{this.flag.name_key}}"
+ checked={{this.selected}}
+ id="radio_{{@flag.name_key}}"
name="post_action_type_index"
type="radio"
- {{on "click" (fn this.changePostActionType this.flag)}}
+ {{on "click" (fn @changePostActionType @flag)}}
/>
<div class="flag-action-type-details">
@@ -121,12 +120,13 @@ export default class FlagActionType extends Component {
}}</span>
{{#if this.showMessageInput}}
{{! eslint-disable-next-line ember/template-no-nested-interactive }}
- <Textarea
+ <textarea
aria-label={{i18n "flagging.notify_user_textarea_label"}}
class="flag-message"
name="message"
placeholder={{this.customPlaceholder}}
- @value={{this.message}}
+ value={{@message}}
+ {{on "input" (withEventValue @onChangeMessage)}}
/>
<div
class={{dConcatClass
@@ -140,33 +140,34 @@ export default class FlagActionType extends Component {
</div>
</label>
</div>
- {{#if this.staffFlagsAvailable}}
+ {{#if @staffFlagsAvailable}}
<hr />
<h3>{{i18n "flagging.notify_staff"}}</h3>
{{/if}}
{{else}}
- <div class="controls {{this.flag.name_key}}">
+ <div class="controls {{@flag.name_key}}">
<label class="radio checkbox-label">
<input
checked={{this.selected}}
- id="radio_{{this.flag.name_key}}"
+ id="radio_{{@flag.name_key}}"
name="post_action_type_index"
type="radio"
- {{on "click" (fn this.changePostActionType this.flag)}}
+ {{on "click" (fn @changePostActionType @flag)}}
/>
<div class="flag-action-type-details">
<strong class="flag-name">{{this.formattedName}}</strong>
<div class="description">{{trustHTML this.flagDescription}}</div>
{{#if this.showMessageInput}}
{{! eslint-disable-next-line ember/template-no-nested-interactive }}
- <Textarea
+ <textarea
aria-label={{i18n
"flagging.notify_moderators_textarea_label"
}}
class="flag-message"
name="message"
placeholder={{this.customPlaceholder}}
- @value={{this.message}}
+ value={{@message}}
+ {{on "input" (withEventValue @onChangeMessage)}}
/>
<div
class={{dConcatClass
@@ -181,10 +182,11 @@ export default class FlagActionType extends Component {
</label>
{{#if this.showConfirmation}}
<label class="checkbox-label flag-confirmation">
- <Input
+ <input
+ checked={{@isConfirmed}}
name="confirmation"
- @checked={{this.isConfirmed}}
- @type="checkbox"
+ type="checkbox"
+ {{on "change" this.changeConfirmed}}
/>
<span>{{i18n "flagging.confirmation_illegal"}}</span>
</label>
diff --git a/frontend/discourse/app/components/flag-selection.gjs b/frontend/discourse/app/components/flag-selection.gjs
index 7ef4e15ea07..12f81c9a04d 100644
--- a/frontend/discourse/app/components/flag-selection.gjs
+++ b/frontend/discourse/app/components/flag-selection.gjs
@@ -1,35 +1,13 @@
-/* eslint-disable ember/no-classic-components, ember/no-observers, ember/require-tagless-components */
-import Component from "@ember/component";
-import { next } from "@ember/runloop";
-import { observes } from "@ember-decorators/object";
import { i18n } from "discourse-i18n";
-// Mostly hacks because `flag.hbs` didn't use `radio-button`
-export default class FlagSelection extends Component {
- @observes("nameKey")
- selectedChanged() {
- next(this, this._selectRadio);
- }
-
- _selectRadio() {
- this.element.querySelector("input[type='radio']").checked = false;
-
- const nameKey = this.nameKey;
- if (!nameKey) {
- return;
- }
-
- const selector = this.element.querySelector("#radio_" + nameKey);
- if (selector) {
- selector.checked = "true";
- }
- }
-
- <template>
- {{#each this.flags as |f|}}
+const FlagSelection = <template>
+ <div ...attributes>
+ {{#each @flags as |f|}}
{{yield f}}
{{else}}
{{i18n "flagging.cant"}}
{{/each}}
- </template>
-}
+ </div>
+</template>;
+
+export default FlagSelection;
diff --git a/frontend/discourse/app/components/global-notice.gjs b/frontend/discourse/app/components/global-notice.gjs
index 19f27daf2ff..b698e5155d3 100644
--- a/frontend/discourse/app/components/global-notice.gjs
+++ b/frontend/discourse/app/components/global-notice.gjs
@@ -1,12 +1,9 @@
-/* eslint-disable ember/no-classic-components, ember/no-observers */
-import Component from "@ember/component";
+import Component from "@glimmer/component";
import { fn } from "@ember/helper";
import EmberObject, { action } from "@ember/object";
import { service } from "@ember/service";
import { trustHTML } from "@ember/template";
-import { tagName } from "@ember-decorators/component";
import cookie, { removeCookie } from "discourse/lib/cookie";
-import { bind } from "discourse/lib/decorators";
import { isDevelopment } from "discourse/lib/environment";
import { currentThemeId } from "discourse/lib/theme-selector";
import { DeferredTrackedSet } from "discourse/lib/tracked-tools";
@@ -69,21 +66,14 @@ class Notice extends EmberObject {
}
}
-@tagName("")
export default class GlobalNotice extends Component {
+ @service currentUser;
@service keyValueStore;
@service("logsNotice") logsNoticeService;
@service router;
-
- /** @type {Notice | null} */
- logNotice = null;
-
- constructor() {
- super(...arguments);
-
- this.logsNoticeService.addObserver("hidden", this._handleLogsNoticeUpdate);
- this.logsNoticeService.addObserver("text", this._handleLogsNoticeUpdate);
- }
+ @service session;
+ @service site;
+ @service siteSettings;
get visible() {
return !this.router.currentRouteName.startsWith("wizard.");
@@ -213,8 +203,19 @@ export default class GlobalNotice extends Component {
);
}
- if (this.get("logNotice")) {
- notices.push(this.get("logNotice"));
+ const logsNotice = this.logsNoticeService;
+ if (!logsNotice.hidden) {
+ notices.push(
+ Notice.create({
+ text: logsNotice.message,
+ id: "alert-logs-notice",
+ options: {
+ dismissable: true,
+ persistentDismiss: false,
+ onDismiss: () => logsNotice.set("text", ""),
+ },
+ })
+ );
}
return notices.concat(Array.from(_pluginNotices)).filter((notice) => {
@@ -244,16 +245,6 @@ export default class GlobalNotice extends Component {
});
}
- willDestroyElement() {
- super.willDestroyElement(...arguments);
-
- this.logsNoticeService.removeObserver("text", this._handleLogsNoticeUpdate);
- this.logsNoticeService.removeObserver(
- "hidden",
- this._handleLogsNoticeUpdate
- );
- }
-
@action
dismissNotice(notice) {
notice.options.onDismiss?.(notice);
@@ -271,22 +262,6 @@ export default class GlobalNotice extends Component {
}
}
- @bind
- _handleLogsNoticeUpdate() {
- const logNotice = Notice.create({
- text: trustHTML(this.logsNoticeService.message),
- id: "alert-logs-notice",
- options: {
- dismissable: true,
- persistentDismiss: false,
- visibility: () => !this.logsNoticeService.hidden,
- onDismiss: () => this.logsNoticeService.set("text", ""),
- },
- });
-
- this.set("logNotice", logNotice);
- }
-
<template>
<div class="global-notice">
{{#if this.visible}}
diff --git a/frontend/discourse/app/components/group-flair-inputs.gjs b/frontend/discourse/app/components/group-flair-inputs.gjs
index 442f22b7864..757236c1ca9 100644
--- a/frontend/discourse/app/components/group-flair-inputs.gjs
+++ b/frontend/discourse/app/components/group-flair-inputs.gjs
@@ -1,9 +1,6 @@
-/* eslint-disable ember/no-classic-components */
-import Component from "@ember/component";
+import Component from "@glimmer/component";
import { fn } from "@ember/helper";
-import { action, computed } from "@ember/object";
-import { tagName } from "@ember-decorators/component";
-import { on } from "@ember-decorators/object";
+import { action, get } from "@ember/object";
import UppyImageUploader from "discourse/components/uppy-image-uploader";
import getURL from "discourse/lib/get-url";
import { convertIconClass } from "discourse/lib/icon-library";
@@ -15,38 +12,31 @@ import DRadioButton from "discourse/ui-kit/d-radio-button";
import DTextField from "discourse/ui-kit/d-text-field";
import { i18n } from "discourse-i18n";
-@tagName("")
export default class GroupFlairInputs extends Component {
- @computed
- get demoAvatarUrl() {
- return getURL("/images/avatar.png");
- }
+ demoAvatarUrl = getURL("/images/avatar.png");
- @computed("model.flair_type")
- get flairPreviewIcon() {
- return this.model?.flair_type && this.model?.flair_type === "icon";
+ constructor() {
+ super(...arguments);
+
+ const icon = convertIconClass(this.args.model.flair_icon || "");
+ if (icon) {
+ ensureSpriteSymbol(icon);
+ }
}
- @computed("model.flair_icon")
- get flairPreviewIconUrl() {
- return this.model?.flair_icon
- ? convertIconClass(this.model?.flair_icon)
- : "";
+ get flairPreviewIcon() {
+ return get(this.args.model, "flair_type") === "icon";
}
- @computed("model.flair_type")
get flairPreviewImage() {
- return this.model?.flair_type && this.model?.flair_type === "image";
+ return get(this.args.model, "flair_type") === "image";
}
- @computed("model.flair_url")
get flairImageUrl() {
- return this.model?.flair_url && this.model?.flair_url?.includes("/")
- ? this.model?.flair_url
- : null;
+ const url = get(this.args.model, "flair_url");
+ return url?.includes("/") ? url : null;
}
- @computed("flairPreviewImage")
get flairPreviewLabel() {
const key = this.flairPreviewImage ? "image" : "icon";
return i18n(`groups.flair_preview_${key}`);
@@ -54,7 +44,7 @@ export default class GroupFlairInputs extends Component {
@action
setFlairImage(upload) {
- this.model.setProperties({
+ this.args.model.setProperties({
flair_url: getURL(upload.url),
flair_upload_id: upload.id,
});
@@ -62,21 +52,12 @@ export default class GroupFlairInputs extends Component {
@action
removeFlairImage() {
- this.model.setProperties({
+ this.args.model.setProperties({
flair_url: null,
flair_upload_id: null,
});
}
- @on("didInsertElement")
- _loadIcon() {
- const icon = convertIconClass(this.model.flair_icon || "");
-
- if (icon) {
- ensureSpriteSymbol(icon);
- }
- }
-
<template>
<div class="group-flair-inputs" ...attributes>
<div class="control-group">
@@ -89,7 +70,7 @@ export default class GroupFlairInputs extends Component {
<DRadioButton
@id="avatar-flair-icon"
@name="avatar-flair-icon"
- @selection={{this.model.flair_type}}
+ @selection={{@model.flair_type}}
@value="icon"
/>
{{i18n "groups.flair_type.icon"}}
@@ -99,7 +80,7 @@ export default class GroupFlairInputs extends Component {
<DRadioButton
@id="avatar-flair-image"
@name="avatar-flair-image"
- @selection={{this.model.flair_type}}
+ @selection={{@model.flair_type}}
@value="image"
/>
{{i18n "groups.flair_type.image"}}
@@ -108,11 +89,11 @@ export default class GroupFlairInputs extends Component {
{{#if this.flairPreviewIcon}}
<DIconGridPicker
- @label={{unless this.model.flair_icon (i18n "select_placeholder")}}
- @onChange={{fn (mut this.model.flair_icon)}}
+ @label={{unless @model.flair_icon (i18n "select_placeholder")}}
+ @onChange={{fn (mut @model.flair_icon)}}
@onlyAvailable={{false}}
@showCaret={{true}}
- @value={{this.model.flair_icon}}
+ @value={{@model.flair_icon}}
/>
{{else if this.flairPreviewImage}}
<UppyImageUploader
@@ -138,7 +119,7 @@ export default class GroupFlairInputs extends Component {
class="group-flair-bg-color input-xxlarge"
@name="flair_bg_color"
@placeholderKey="groups.flair_bg_color_placeholder"
- @value={{this.model.flair_bg_color}}
+ @value={{@model.flair_bg_color}}
/>
</div>
@@ -152,7 +133,7 @@ export default class GroupFlairInputs extends Component {
class="group-flair-color input-xxlarge"
@name="flair_color"
@placeholderKey="groups.flair_color_placeholder"
- @value={{this.model.flair_color}}
+ @value={{@model.flair_color}}
/>
</div>
{{/if}}
@@ -173,18 +154,18 @@ export default class GroupFlairInputs extends Component {
{{#if
(or
- this.model.flair_icon
+ @model.flair_icon
this.flairImageUrl
- this.model.flairBackgroundHexColor
+ @model.flairBackgroundHexColor
)
}}
<DAvatarFlair
- @flairBgColor={{this.model.flairBackgroundHexColor}}
- @flairColor={{this.model.flairHexColor}}
- @flairName={{this.model.name}}
+ @flairBgColor={{@model.flairBackgroundHexColor}}
+ @flairColor={{@model.flairHexColor}}
+ @flairName={{@model.name}}
@flairUrl={{if
this.flairPreviewIcon
- this.model.flair_icon
+ @model.flair_icon
(if this.flairPreviewImage this.flairImageUrl "")
}}
/>
diff --git a/frontend/discourse/app/components/modal/flag.gjs b/frontend/discourse/app/components/modal/flag.gjs
index 409e35dcbc8..6e6eacaefc0 100644
--- a/frontend/discourse/app/components/modal/flag.gjs
+++ b/frontend/discourse/app/components/modal/flag.gjs
@@ -1,5 +1,6 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
+import { fn } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
import { service } from "@ember/service";
@@ -242,16 +243,14 @@ export default class Flag extends Component {
@outletArgs={{lazyHash [email protected]}}
/>
<form>
- <FlagSelection
- @flags={{this.flagsAvailable}}
- @nameKey={{this.selected.name_key}}
- as |f|
- >
+ <FlagSelection @flags={{this.flagsAvailable}} as |f|>
<FlagActionType
@changePostActionType={{this.changePostActionType}}
@flag={{f}}
@isConfirmed={{this.isConfirmed}}
@message={{this.message}}
+ @onChangeConfirmed={{fn (mut this.isConfirmed)}}
+ @onChangeMessage={{fn (mut this.message)}}
@selectedFlag={{this.selected}}
@staffFlagsAvailable={{this.staffFlagsAvailable}}
@username={{@model.flagModel.username}}
diff --git a/frontend/discourse/tests/acceptance/admin-watched-words-test.js b/frontend/discourse/tests/acceptance/admin-watched-words-test.js
index de662194ee4..7f984a21b38 100644
--- a/frontend/discourse/tests/acceptance/admin-watched-words-test.js
+++ b/frontend/discourse/tests/acceptance/admin-watched-words-test.js
@@ -4,8 +4,10 @@ import {
findAll,
triggerKeyEvent,
visit,
+ waitFor,
} from "@ember/test-helpers";
import { test } from "qunit";
+import pretender, { response } from "discourse/tests/helpers/create-pretender";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { i18n } from "discourse-i18n";
@@ -81,6 +83,46 @@ acceptance("Admin - Watched Words", function (needs) {
assert.dom(".watched-words-list .case-sensitive").doesNotExist();
});
+ test("disables the form while saving", async function (assert) {
+ let release;
+ const held = new Promise((resolve) => (release = resolve));
+ pretender.post("/admin/customize/watched_words.json", async () => {
+ await held;
+ return response({
+ id: 1,
+ word: "poutine",
+ action: "block",
+ case_sensitive: false,
+ });
+ });
+
+ await visit("/admin/customize/watched_words/action/block");
+ await click(".select-kit-header.multi-select-header");
+ await fillIn(".select-kit-filter input", "poutine");
+ await triggerKeyEvent(".select-kit-filter input", "keydown", "Enter");
+
+ const submitted = click(".watched-word-form .btn-primary");
+ await waitFor(".case-sensitivity-checkbox input:disabled");
+
+ assert
+ .dom(".case-sensitivity-checkbox input")
+ .isDisabled("keeps the inputs disabled until the save finishes");
+
+ release();
+ await submitted;
+
+ assert.dom(".case-sensitivity-checkbox input").isNotDisabled();
+ assert
+ .dom(".watched-word-form .success-message")
+ .hasText(i18n("admin.watched_words.form.success"));
+
+ await visit("/admin/customize/watched_words/action/censor");
+
+ assert
+ .dom(".watched-word-form .success-message")
+ .doesNotExist("hides the message on another action's page");
+ });
+
test("add case-sensitive words", async function (assert) {
await visit("/admin/customize/watched_words/action/block");
assert
diff --git a/frontend/discourse/tests/acceptance/global-notice-test.js b/frontend/discourse/tests/acceptance/global-notice-test.js
new file mode 100644
index 00000000000..d27b38cf6ba
--- /dev/null
+++ b/frontend/discourse/tests/acceptance/global-notice-test.js
@@ -0,0 +1,31 @@
+import { click, visit } from "@ember/test-helpers";
+import { test } from "qunit";
+import KeyValueStore from "discourse/lib/key-value-store";
+import { acceptance } from "discourse/tests/helpers/qunit-helpers";
+
+const store = new KeyValueStore("discourse_");
+
+acceptance("Global notice - logs notice", function (needs) {
+ needs.user({ admin: true });
+ needs.settings({ alert_admins_if_errors_per_hour: 100 });
+
+ needs.hooks.beforeEach(() => {
+ store.setItem("logs-notice-text", "Errors are piling up");
+ });
+
+ needs.hooks.afterEach(() => {
+ store.removeItem("logs-notice-text");
+ });
+
+ test("shows the stored notice until it is dismissed", async function (assert) {
+ await visit("/");
+
+ assert
+ .dom(".alert-logs-notice .text")
+ .hasText("Errors are piling up", "shows the notice after a reload");
+
+ await click(".alert-logs-notice .close");
+
+ assert.dom(".alert-logs-notice").doesNotExist("hides the dismissed notice");
+ });
+});
diff --git a/frontend/discourse/tests/acceptance/user-bookmarks-test.js b/frontend/discourse/tests/acceptance/user-bookmarks-test.js
index c05af31baf1..900fc641dd7 100644
--- a/frontend/discourse/tests/acceptance/user-bookmarks-test.js
+++ b/frontend/discourse/tests/acceptance/user-bookmarks-test.js
@@ -84,3 +84,32 @@ acceptance("User's bookmarks - no bookmarks", function (needs) {
assert.dom("div.empty-state").exists("renders the empty-state message");
});
});
+
+acceptance("User's bookmarks - bulk select", function (needs) {
+ needs.user();
+
+ needs.pretender((server, helper) => {
+ server.get("/u/eviltrout/bookmarks.json", () => {
+ const json = cloneJSON(userFixtures["/u/eviltrout/bookmarks.json"]);
+ const bookmarks = json.user_bookmark_list.bookmarks;
+ bookmarks.push({ ...bookmarks[0], id: 9001 });
+ return helper.response(json);
+ });
+ });
+
+ test("shift-clicking selects the bookmarks in between", async function (assert) {
+ await visit("/u/eviltrout/activity/bookmarks");
+ await click(".bookmark-list thead .bulk-select");
+
+ const checkboxes = "input.bulk-select";
+ await click(`.bookmark-list-item:nth-child(1) ${checkboxes}`);
+ await click(`.bookmark-list-item:nth-child(3) ${checkboxes}`, {
+ shiftKey: true,
+ });
+
+ assert
+ .dom(`.bookmark-list-item ${checkboxes}:checked`)
+ .exists({ count: 3 }, "selects the whole range");
+ assert.dom(".bulk-select-bookmarks-dropdown").exists();
+ });
+});
diff --git a/frontend/discourse/tests/integration/components/flag-action-type-test.gjs b/frontend/discourse/tests/integration/components/flag-action-type-test.gjs
new file mode 100644
index 00000000000..b8311bc38d6
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/flag-action-type-test.gjs
@@ -0,0 +1,79 @@
+import { tracked } from "@glimmer/tracking";
+import { click, fillIn, render, rerender } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import FlagActionType from "discourse/components/flag-action-type";
+import FlagSelection from "discourse/components/flag-selection";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+
+const NOTIFY_USER = {
+ name_key: "notify_user",
+ name: "Send @%{username} a message",
+ description: "Talk to them",
+ require_message: true,
+};
+const ILLEGAL = {
+ name_key: "illegal",
+ name: "It's illegal",
+ description: "Breaks the law",
+ require_message: true,
+ isIllegal: true,
+};
+
+module("Integration | Component | FlagActionType", function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("checks the radio of the selected flag", async function (assert) {
+ const flags = [NOTIFY_USER, ILLEGAL];
+ const selected = tracked(ILLEGAL);
+ const select = (flag) => (selected.value = flag);
+
+ await render(
+ <template>
+ <FlagSelection @flags={{flags}} as |flag|>
+ <FlagActionType
+ @changePostActionType={{select}}
+ @flag={{flag}}
+ @selectedFlag={{selected.value}}
+ @username="eviltrout"
+ />
+ </FlagSelection>
+ </template>
+ );
+
+ assert.dom("#radio_illegal").isChecked();
+ assert.dom("#radio_notify_user").isNotChecked();
+
+ selected.value = NOTIFY_USER;
+ await rerender();
+
+ assert.dom("#radio_notify_user").isChecked("follows the selected flag");
+ assert.dom("#radio_illegal").isNotChecked();
+ });
+
+ test("reports the message and the confirmation", async function (assert) {
+ const message = tracked("");
+ const confirmed = tracked(false);
+ const changeMessage = (value) => (message.value = value);
+ const changeConfirmed = (value) => (confirmed.value = value);
+
+ await render(
+ <template>
+ <FlagActionType
+ @flag={{ILLEGAL}}
+ @isConfirmed={{confirmed.value}}
+ @message={{message.value}}
+ @onChangeConfirmed={{changeConfirmed}}
+ @onChangeMessage={{changeMessage}}
+ @selectedFlag={{ILLEGAL}}
+ />
+ </template>
+ );
+
+ await fillIn(".flag-message", "a reason");
+ assert.strictEqual(message.value, "a reason", "reports the message");
+
+ await click(".flag-confirmation input");
+ assert.true(confirmed.value, "reports the confirmation");
+ assert.dom(".flag-confirmation input").isChecked();
+ });
+});
diff --git a/frontend/discourse/tests/integration/components/group-flair-inputs-test.gjs b/frontend/discourse/tests/integration/components/group-flair-inputs-test.gjs
new file mode 100644
index 00000000000..9d43ccf860d
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/group-flair-inputs-test.gjs
@@ -0,0 +1,32 @@
+import EmberObject from "@ember/object";
+import { click, render } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import GroupFlairInputs from "discourse/components/group-flair-inputs";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import { i18n } from "discourse-i18n";
+
+module("Integration | Component | GroupFlairInputs", function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("follows the chosen flair type", async function (assert) {
+ const model = EmberObject.create({ name: "staff", flair_type: "icon" });
+
+ await render(<template><GroupFlairInputs @model={{model}} /></template>);
+
+ assert
+ .dom(".group-flair-inputs")
+ .includesText(i18n("groups.flair_preview_icon"));
+ assert.dom("#group-flair-uploader").doesNotExist();
+
+ await click("#avatar-flair-image");
+
+ assert.strictEqual(model.flair_type, "image", "writes the type");
+ assert.dom("#group-flair-uploader").exists("offers the image upload");
+ assert
+ .dom(".group-flair-inputs")
+ .includesText(
+ i18n("groups.flair_preview_image"),
+ "labels the preview for the image"
+ );
+ });
+});
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-bot-conversations.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-bot-conversations.gjs
index 1cd98bfb917..b1d7d56ccc4 100644
--- a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-bot-conversations.gjs
+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-bot-conversations.gjs
@@ -1,6 +1,5 @@
-/* eslint-disable ember/no-classic-components */
+import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
-import Component from "@ember/component";
import { fn } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
@@ -10,7 +9,6 @@ import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import { scheduleOnce } from "@ember/runloop";
import { service } from "@ember/service";
import { trustHTML } from "@ember/template";
-import { tagName } from "@ember-decorators/component";
import { modifier } from "ember-modifier";
import UserAutocompleteResults from "discourse/components/user-autocomplete-results";
import { popupAjaxError } from "discourse/lib/ajax-error";
@@ -34,7 +32,6 @@ import AiAgentLlmSelector from "discourse/plugins/discourse-ai/discourse/compone
import AiBotConversationsLayout from "discourse/plugins/discourse-ai/discourse/components/ai-bot-conversations-layout";
import { takeConversationDraft } from "discourse/plugins/discourse-ai/discourse/lib/ai-bot-conversation-draft";
-@tagName("")
export default class AiBotConversations extends Component {
@service aiCredits;
@service aiBotConversationsHiddenSubmit;
@@ -53,8 +50,6 @@ export default class AiBotConversations extends Component {
shiftHeldOnEnter = false;
- // Don't track this directly - we'll get it from uppyUpload
-
textarea = null;
uppyUpload = null;
fileInputEl = null;
@@ -101,8 +96,8 @@ export default class AiBotConversations extends Component {
}
};
- init() {
- super.init(...arguments);
+ constructor() {
+ super(...arguments);
this.uppyUpload = new UppyUpload(getOwner(this), {
id: "ai-bot-file-uploader",
@@ -142,12 +137,6 @@ export default class AiBotConversations extends Component {
uploadDone: (upload) => {
this.uploads.push(upload);
},
-
- // Fix: Don't try to set inProgressUploads directly
- onProgressUploadsChanged: () => {
- // This is just for UI triggers - we're already tracking inProgressUploads
- this.notifyPropertyChange("inProgressUploads");
- },
});
}
@@ -208,12 +197,13 @@ export default class AiBotConversations extends Component {
@action
onSelectionChanged({ agentName, llmName }) {
- if (!this.controller) {
+ const controller = this.args.controller;
+ if (!controller) {
return;
}
- this.controller.agent = agentName ? slugify(agentName) || agentName : null;
- this.controller.llm = llmName ? slugify(llmName) || llmName : null;
+ controller.agent = agentName ? slugify(agentName) || agentName : null;
+ controller.llm = llmName ? slugify(llmName) || llmName : null;
}
@action
diff --git a/plugins/discourse-cakeday/assets/javascripts/discourse/connectors/user-custom-preferences/user-date-of-birth-input.gjs b/plugins/discourse-cakeday/assets/javascripts/discourse/connectors/user-custom-preferences/user-date-of-birth-input.gjs
index f571bf52cb5..6c280b80c52 100644
--- a/plugins/discourse-cakeday/assets/javascripts/discourse/connectors/user-custom-preferences/user-date-of-birth-input.gjs
+++ b/plugins/discourse-cakeday/assets/javascripts/discourse/connectors/user-custom-preferences/user-date-of-birth-input.gjs
@@ -9,7 +9,10 @@ import { i18n } from "discourse-i18n";
export default class UserDateOfBirthInput extends Component {
@service siteSettings;
+ /** @type {number | null} */
@tracked month = null;
+
+ /** @type {string | null} */
@tracked day = null;
months = moment.months().map((name, index) => ({ name, value: index + 1 }));
diff --git a/plugins/discourse-gamification/assets/javascripts/discourse/components/gamification-leaderboard.gjs b/plugins/discourse-gamification/assets/javascripts/discourse/components/gamification-leaderboard.gjs
index e8204039ec4..3d7b40323da 100644
--- a/plugins/discourse-gamification/assets/javascripts/discourse/components/gamification-leaderboard.gjs
+++ b/plugins/discourse-gamification/assets/javascripts/discourse/components/gamification-leaderboard.gjs
@@ -1,12 +1,12 @@
-/* eslint-disable ember/no-classic-components */
-import Component from "@ember/component";
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
import { hash } from "@ember/helper";
-import { action, computed } from "@ember/object";
+import { action, get, set } from "@ember/object";
import { service } from "@ember/service";
-import { tagName } from "@ember-decorators/component";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import getURL from "discourse/lib/get-url";
+import { resettableTracked } from "discourse/lib/tracked-tools";
import PeriodChooser from "discourse/select-kit/components/period-chooser";
import { or } from "discourse/truth-helpers";
import DButton from "discourse/ui-kit/d-button";
@@ -47,49 +47,40 @@ function periodString(periodValue) {
}
}
-@tagName("")
export default class GamificationLeaderboard extends Component {
- @service router;
+ @service currentUser;
@service modal;
+ @service router;
+ @service site;
+ @service siteSettings;
+
+ @tracked loading = false;
+ @resettableTracked
+ period = periodString(this.args.model.leaderboard.default_period);
- eyelineSelector = ".user";
page = 1;
- loading = false;
canLoadMore = true;
- period = "all";
-
- init() {
- super.init(...arguments);
- const default_leaderboard_period = periodString(
- this.model.leaderboard.default_period
- );
- this.set("period", default_leaderboard_period);
- }
- @computed("model.reason")
get isNotReady() {
- return this.model?.reason !== undefined;
+ return get(this.args.model, "reason") !== undefined;
}
- @computed("model.users")
get currentUserRanking() {
- const user = this.model.personal;
- return user || null;
+ return get(this.args.model, "personal") || null;
}
- @computed("model.users")
get winners() {
- return this.model?.users?.slice(0, 3);
+ return get(this.args.model, "users")?.slice(0, 3);
}
- @computed("model.users.[]")
get ranking() {
- this.model?.users.forEach((user) => {
+ const users = get(this.args.model, "users");
+ users.forEach((user) => {
if (user.id === this.currentUser?.id) {
user.isCurrentUser = "true";
}
});
- return this.model?.users.slice(3);
+ return users.slice(3);
}
@action
@@ -103,38 +94,39 @@ export default class GamificationLeaderboard extends Component {
return;
}
- this.set("loading", true);
+ this.loading = true;
+ const model = this.args.model;
return ajax(
- `/leaderboard/${this.model.leaderboard.id}?page=${this.page}&period=${this.period}`
+ `/leaderboard/${model.leaderboard.id}?page=${this.page}&period=${this.period}`
)
.then((result) => {
if (result.users.length === 0) {
- this.set("canLoadMore", false);
+ this.canLoadMore = false;
}
- this.set("page", (this.page += 1));
- this.set("model.users", this.model.users.concat(result.users));
+ this.page += 1;
+ set(model, "users", model.users.concat(result.users));
})
- .finally(() => this.set("loading", false))
+ .finally(() => (this.loading = false))
.catch(popupAjaxError);
}
@action
changePeriod(period) {
- this.set("period", period);
- return ajax(
- `/leaderboard/${this.model.leaderboard.id}?period=${this.period}`
- )
+ this.period = period;
+ const model = this.args.model;
+
+ return ajax(`/leaderboard/${model.leaderboard.id}?period=${this.period}`)
.then((result) => {
if (result.users.length === 0) {
- this.set("canLoadMore", false);
- this.set("model.reason", result.reason);
+ this.canLoadMore = false;
+ set(model, "reason", result.reason);
}
- this.set("page", 1);
- this.set("model.users", result.users);
- this.set("model.personal", result.personal);
+ this.page = 1;
+ set(model, "users", result.users);
+ set(model, "personal", result.personal);
})
- .finally(() => this.set("loading", false))
+ .finally(() => (this.loading = false))
.catch(popupAjaxError);
}
@@ -146,7 +138,7 @@ export default class GamificationLeaderboard extends Component {
<template>
<div class="leaderboard">
<div class="page__header">
- <h1 class="page__title">{{this.model.leaderboard.name}}</h1>
+ <h1 class="page__title">{{@model.leaderboard.name}}</h1>
<DButton
class="-ghost"
@action={{this.showLeaderboardInfo}}
@@ -160,9 +152,7 @@ export default class GamificationLeaderboard extends Component {
class="leaderboard__period-chooser"
@action={{this.changePeriod}}
@fullDay={{false}}
- @options={{hash
- disabled=this.model.leaderboard.period_filter_disabled
- }}
+ @options={{hash [email protected]_filter_disabled}}
@period={{this.period}}
/>
{{#if this.currentUser.staff}}
@@ -181,7 +171,7 @@ export default class GamificationLeaderboard extends Component {
{{#if this.isNotReady}}
<div class="leaderboard__not-ready">
- <p>{{this.model.reason}}</p>
+ <p>{{@model.reason}}</p>
<DButton
class="btn-primary refresh"
@action={{this.refresh}}
diff --git a/plugins/discourse-gamification/test/javascripts/components/gamification-leaderboard-test.gjs b/plugins/discourse-gamification/test/javascripts/components/gamification-leaderboard-test.gjs
index 32b0ae48fe5..c13db7df3c0 100644
--- a/plugins/discourse-gamification/test/javascripts/components/gamification-leaderboard-test.gjs
+++ b/plugins/discourse-gamification/test/javascripts/components/gamification-leaderboard-test.gjs
@@ -1,6 +1,9 @@
-import { render } from "@ember/test-helpers";
+import { tracked } from "@glimmer/tracking";
+import { render, rerender } from "@ember/test-helpers";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import pretender, { response } from "discourse/tests/helpers/create-pretender";
+import selectKit from "discourse/tests/helpers/select-kit-helper";
import GamificationLeaderboard from "discourse/plugins/discourse-gamification/discourse/components/gamification-leaderboard";
module(
@@ -52,5 +55,65 @@ module(
assert.dom(".winner__name").hasText("id");
});
+ test("shows the users for the chosen period", async function (assert) {
+ this.siteSettings.prioritize_username_in_ux = true;
+ pretender.get("/leaderboard/3", (request) =>
+ response({
+ users: [{ username: `${request.queryParams.period}_winner` }],
+ personal: null,
+ })
+ );
+ const model = {
+ leaderboard: { id: 3, default_period: 0 },
+ personal: "",
+ users: [{ username: "all_time_winner" }],
+ };
+
+ await render(
+ <template><GamificationLeaderboard @model={{model}} /></template>
+ );
+
+ assert.dom(".winner__name").hasText("all_time_winner");
+
+ const chooser = selectKit(".leaderboard__period-chooser");
+ await chooser.expand();
+ await chooser.selectRowByValue("weekly");
+
+ assert
+ .dom(".winner__name")
+ .hasText("weekly_winner", "shows the period's users");
+ });
+ test("follows the default period of a new leaderboard", async function (assert) {
+ pretender.get("/leaderboard/:id", () =>
+ response({ users: [{ username: "winner" }], personal: null })
+ );
+ const model = tracked({
+ leaderboard: { id: 3, default_period: 0 },
+ personal: "",
+ users: [{ username: "winner" }],
+ });
+
+ await render(
+ <template><GamificationLeaderboard @model={{model.value}} /></template>
+ );
+
+ const chooser = selectKit(".leaderboard__period-chooser");
+ await chooser.expand();
+ await chooser.selectRowByValue("weekly");
+ assert.strictEqual(chooser.header().value(), "weekly");
+
+ model.value = {
+ leaderboard: { id: 4, default_period: 3 },
+ personal: "",
+ users: [{ username: "winner" }],
+ };
+ await rerender();
+
+ assert.strictEqual(
+ chooser.header().value(),
+ "monthly",
+ "resets to the new leaderboard's default"
+ );
+ });
}
);