REFACTOR: Don't use `layoutName` in select-kit (#10556)

Instead import the templates as modules, the way Ember CLI wants us to.
This commit is contained in:
Robin Ward 2020-08-28 15:30:20 -04:00 committed by GitHub
parent e1896f7e71
commit aae97457d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 86 additions and 50 deletions

View File

@ -11,6 +11,14 @@
"discourse-common/lib/raw-templates"
).__DISCOURSE_RAW_TEMPLATES;
// required for select kit to work without Ember CLI
Object.keys(Ember.TEMPLATES).forEach(k => {
if (k.indexOf("select-kit") === 0) {
let template = Ember.TEMPLATES[k];
define(k, () => template);
}
});
// ensure Discourse is added as a global
window.Discourse = Discourse;
})();

View File

@ -2,10 +2,10 @@ import { readOnly } from "@ember/object/computed";
import { schedule } from "@ember/runloop";
import ComboBoxSelectBoxHeaderComponent from "select-kit/components/combo-box/combo-box-header";
import discourseComputed from "discourse-common/utils/decorators";
import layout from "select-kit/templates/components/category-drop/category-drop-header";
export default ComboBoxSelectBoxHeaderComponent.extend({
layoutName:
"select-kit/templates/components/category-drop/category-drop-header",
layout,
classNames: ["category-drop-header"],
classNameBindings: ["categoryStyleClass"],
categoryStyleClass: readOnly("site.category_style"),

View File

@ -5,9 +5,10 @@ import { categoryBadgeHTML } from "discourse/helpers/category-link";
import { isEmpty, isNone } from "@ember/utils";
import { computed } from "@ember/object";
import { setting } from "discourse/lib/computed";
import layout from "select-kit/templates/components/category-row";
export default SelectKitRowComponent.extend({
layoutName: "select-kit/templates/components/category-row",
layout,
classNames: ["category-row"],
hideParentCategory: bool("selectKit.options.hideParentCategory"),
allowUncategorized: bool("selectKit.options.allowUncategorized"),

View File

@ -1,12 +1,11 @@
import { escapeExpression } from "discourse/lib/utilities";
import SelectKitRowComponent from "select-kit/components/select-kit/select-kit-row";
import { computed } from "@ember/object";
import layout from "select-kit/templates/components/color-palettes/color-palettes-row";
export default SelectKitRowComponent.extend({
classNames: ["color-palettes-row"],
layoutName:
"select-kit/templates/components/color-palettes/color-palettes-row",
layout,
palettes: computed("item.colors.[]", function() {
return (this.item.colors || [])

View File

@ -1,9 +1,10 @@
import { reads, and } from "@ember/object/computed";
import SingleSelectHeaderComponent from "select-kit/components/select-kit/single-select-header";
import { computed } from "@ember/object";
import layout from "select-kit/templates/components/combo-box/combo-box-header";
export default SingleSelectHeaderComponent.extend({
layoutName: "select-kit/templates/components/combo-box/combo-box-header",
layout,
classNames: ["combo-box-header"],
clearable: reads("selectKit.options.clearable"),
caretUpIcon: reads("selectKit.options.caretUpIcon"),

View File

@ -1,9 +1,10 @@
import SelectKitRowComponent from "select-kit/components/select-kit/select-kit-row";
import { escapeExpression } from "discourse/lib/utilities";
import { schedule } from "@ember/runloop";
import layout from "select-kit/templates/components/create-color-row";
export default SelectKitRowComponent.extend({
layoutName: "select-kit/templates/components/create-color-row",
layout,
classNames: ["create-color-row"],
didReceiveAttrs() {

View File

@ -1,10 +1,10 @@
import SingleSelectHeaderComponent from "select-kit/components/select-kit/single-select-header";
import { computed } from "@ember/object";
import { readOnly } from "@ember/object/computed";
import layout from "select-kit/templates/components/dropdown-select-box/dropdown-select-box-header";
export default SingleSelectHeaderComponent.extend({
layoutName:
"select-kit/templates/components/dropdown-select-box/dropdown-select-box-header",
layout,
classNames: ["btn-default", "dropdown-select-box-header"],
tagName: "button",
classNameBindings: ["btnClassName"],

View File

@ -1,9 +1,9 @@
import { readOnly } from "@ember/object/computed";
import SelectKitRowComponent from "select-kit/components/select-kit/select-kit-row";
import layout from "select-kit/templates/components/dropdown-select-box/dropdown-select-box-row";
export default SelectKitRowComponent.extend({
layoutName:
"select-kit/templates/components/dropdown-select-box/dropdown-select-box-row",
layout,
classNames: ["dropdown-select-box-row"],
description: readOnly("item.description")

View File

@ -1,7 +1,7 @@
import ComboBoxHeaderComponent from "select-kit/components/combo-box/combo-box-header";
import layout from "select-kit/templates/components/future-date-input-selector/future-date-input-selector-header";
export default ComboBoxHeaderComponent.extend({
layoutName:
"select-kit/templates/components/future-date-input-selector/future-date-input-selector-header",
layout,
classNames: "future-date-input-selector-header"
});

View File

@ -1,7 +1,7 @@
import SelectKitRowComponent from "select-kit/components/select-kit/select-kit-row";
import layout from "select-kit/templates/components/future-date-input-selector/future-date-input-selector-row";
export default SelectKitRowComponent.extend({
layoutName:
"select-kit/templates/components/future-date-input-selector/future-date-input-selector-row",
layout,
classNames: ["future-date-input-selector-row"]
});

View File

@ -1,7 +1,7 @@
import ComboBoxSelectBoxHeaderComponent from "select-kit/components/combo-box/combo-box-header";
import layout from "select-kit/templates/components/mini-tag-chooser/mini-tag-chooser-header";
export default ComboBoxSelectBoxHeaderComponent.extend({
layoutName:
"select-kit/templates/components/mini-tag-chooser/mini-tag-chooser-header",
layout,
classNames: ["mini-tag-chooser-header"]
});

View File

@ -1,10 +1,10 @@
import Component from "@ember/component";
import { computed } from "@ember/object";
import { reads, notEmpty } from "@ember/object/computed";
import layout from "select-kit/templates/components/mini-tag-chooser/selected-collection";
export default Component.extend({
layoutName:
"select-kit/templates/components/mini-tag-chooser/selected-collection",
layout,
classNames: ["mini-tag-chooser-selected-collection", "selected-tags"],
isVisible: notEmpty("selectedTags.[]"),
selectedTags: reads("collection.content.selectedTags.[]"),

View File

@ -3,10 +3,11 @@ import SelectKitComponent from "select-kit/components/select-kit";
import { computed } from "@ember/object";
import { isPresent } from "@ember/utils";
import { makeArray } from "discourse-common/lib/helpers";
import layout from "select-kit/templates/components/multi-select";
export default SelectKitComponent.extend({
pluginApiIdentifiers: ["multi-select"],
layoutName: "select-kit/templates/components/multi-select",
layout,
classNames: ["multi-select"],
multiSelect: true,

View File

@ -2,9 +2,10 @@ import I18n from "I18n";
import discourseComputed from "discourse-common/utils/decorators";
const { isEmpty } = Ember;
import SelectKitFilterComponent from "select-kit/components/select-kit/select-kit-filter";
import layout from "select-kit/templates/components/select-kit/select-kit-filter";
export default SelectKitFilterComponent.extend({
layoutName: "select-kit/templates/components/select-kit/select-kit-filter",
layout,
classNames: ["multi-select-filter"],
@discourseComputed("placeholder", "selectKit.hasSelection")

View File

@ -1,11 +1,11 @@
import SelectKitHeaderComponent from "select-kit/components/select-kit/select-kit-header";
import { computed } from "@ember/object";
import { makeArray } from "discourse-common/lib/helpers";
import layout from "select-kit/templates/components/multi-select/multi-select-header";
export default SelectKitHeaderComponent.extend({
classNames: ["multi-select-header"],
layoutName:
"select-kit/templates/components/multi-select/multi-select-header",
layout,
selectedNames: computed("selectedContent", function() {
return makeArray(this.selectedContent).map(c => this.getName(c));

View File

@ -1,10 +1,11 @@
import SelectedNameComponent from "select-kit/components/selected-name";
import { categoryBadgeHTML } from "discourse/helpers/category-link";
import { computed } from "@ember/object";
import layout from "select-kit/templates/components/multi-select/selected-category";
export default SelectedNameComponent.extend({
classNames: ["selected-category"],
layoutName: "select-kit/templates/components/multi-select/selected-category",
layout,
badge: computed("item", function() {
return categoryBadgeHTML(this.item, {

View File

@ -1,9 +1,10 @@
import CategoryRowComponent from "select-kit/components/category-row";
import { categoryBadgeHTML } from "discourse/helpers/category-link";
import discourseComputed from "discourse-common/utils/decorators";
import layout from "select-kit/templates/components/category-row";
export default CategoryRowComponent.extend({
layoutName: "select-kit/templates/components/category-row",
layout,
classNames: "none category-row",
@discourseComputed("category")

View File

@ -1,10 +1,10 @@
import DropdownSelectBoxHeaderComponent from "select-kit/components/dropdown-select-box/dropdown-select-box-header";
import discourseComputed from "discourse-common/utils/decorators";
import { fmt } from "discourse/lib/computed";
import layout from "select-kit/templates/components/notifications-filter/notifications-filter-header";
export default DropdownSelectBoxHeaderComponent.extend({
layoutName:
"select-kit/templates/components/notifications-filter/notifications-filter-header",
layout,
classNames: ["notifications-filter-header"],

View File

@ -1,9 +1,9 @@
import DropdownSelectBoxHeaderComponent from "select-kit/components/dropdown-select-box/dropdown-select-box-header";
import discourseComputed from "discourse-common/utils/decorators";
import layout from "select-kit/templates/components/period-chooser/period-chooser-header";
export default DropdownSelectBoxHeaderComponent.extend({
layoutName:
"select-kit/templates/components/period-chooser/period-chooser-header",
layout,
classNames: ["period-chooser-header"],
@discourseComputed("selectKit.isExpanded")

View File

@ -1,10 +1,10 @@
import I18n from "I18n";
import DropdownSelectBoxRowComponent from "select-kit/components/dropdown-select-box/dropdown-select-box-row";
import discourseComputed from "discourse-common/utils/decorators";
import layout from "select-kit/templates/components/period-chooser/period-chooser-row";
export default DropdownSelectBoxRowComponent.extend({
layoutName:
"select-kit/templates/components/period-chooser/period-chooser-row",
layout,
classNames: ["period-chooser-row"],
@discourseComputed("rowName")

View File

@ -1,13 +1,14 @@
import I18n from "I18n";
import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators";
import layout from "select-kit/templates/components/pinned-button";
export default Component.extend({
pluginApiIdentifiers: ["pinned-button"],
descriptionKey: "help",
classNames: "pinned-button",
classNameBindings: ["isHidden"],
layoutName: "select-kit/templates/components/pinned-button",
layout,
@discourseComputed("topic.pinned_globally", "pinned")
reasonText(pinnedGlobally, pinned) {

View File

@ -37,7 +37,6 @@ export default Component.extend(
UtilsMixin,
{
pluginApiIdentifiers: ["select-kit"],
layoutName: "select-kit/templates/components/select-kit",
classNames: ["select-kit"],
classNameBindings: [
"selectKit.isLoading:is-loading",

View File

@ -1,8 +1,9 @@
import Component from "@ember/component";
import { notEmpty } from "@ember/object/computed";
import layout from "select-kit/templates/components/select-kit/errors-collection";
export default Component.extend({
layoutName: "select-kit/templates/components/select-kit/errors-collection",
layout,
classNames: ["select-kit-errors-collection"],
tagName: "ul",
isVisible: notEmpty("collection.content")

View File

@ -1,9 +1,10 @@
import Component from "@ember/component";
import { computed } from "@ember/object";
import { bind } from "@ember/runloop";
import layout from "select-kit/templates/components/select-kit/select-kit-body";
export default Component.extend({
layoutName: "select-kit/templates/components/select-kit/select-kit-body",
layout,
classNames: ["select-kit-body"],
attributeBindings: ["selectKitId:data-select-kit-id"],
selectKitId: computed("selectKit.uniqueID", function() {

View File

@ -1,9 +1,9 @@
import Component from "@ember/component";
import { notEmpty } from "@ember/object/computed";
import layout from "select-kit/templates/components/select-kit/select-kit-collection";
export default Component.extend({
layoutName:
"select-kit/templates/components/select-kit/select-kit-collection",
layout,
classNames: ["select-kit-collection"],
tagName: "ul",
isVisible: notEmpty("collection")

View File

@ -1,6 +1,7 @@
import SelectKitRowComponent from "select-kit/components/select-kit/select-kit-row";
import layout from "select-kit/templates/components/select-kit/select-kit-row";
export default SelectKitRowComponent.extend({
layoutName: "select-kit/templates/components/select-kit/select-kit-row",
layout,
classNames: "create"
});

View File

@ -5,9 +5,10 @@ import { isPresent } from "@ember/utils";
import { computed } from "@ember/object";
import { not } from "@ember/object/computed";
import UtilsMixin from "select-kit/mixins/utils";
import layout from "select-kit/templates/components/select-kit/select-kit-filter";
export default Component.extend(UtilsMixin, {
layoutName: "select-kit/templates/components/select-kit/select-kit-filter",
layout,
classNames: ["select-kit-filter"],
classNameBindings: ["isExpanded:is-expanded"],
attributeBindings: ["selectKitId:data-select-kit-id"],

View File

@ -1,6 +1,7 @@
import SelectKitRowComponent from "select-kit/components/select-kit/select-kit-row";
import layout from "select-kit/templates/components/select-kit/select-kit-row";
export default SelectKitRowComponent.extend({
layoutName: "select-kit/templates/components/select-kit/select-kit-row",
layout,
classNames: "none"
});

View File

@ -4,9 +4,10 @@ import { computed } from "@ember/object";
import { makeArray } from "discourse-common/lib/helpers";
import { guidFor } from "@ember/object/internals";
import UtilsMixin from "select-kit/mixins/utils";
import layout from "select-kit/templates/components/select-kit/select-kit-row";
export default Component.extend(UtilsMixin, {
layoutName: "select-kit/templates/components/select-kit/select-kit-row",
layout,
classNames: ["select-kit-row"],
tagName: "li",
tabIndex: -1,

View File

@ -1,7 +1,8 @@
import SelectKitHeaderComponent from "select-kit/components/select-kit/select-kit-header";
import UtilsMixin from "select-kit/mixins/utils";
import layout from "select-kit/templates/components/select-kit/single-select-header";
export default SelectKitHeaderComponent.extend(UtilsMixin, {
layoutName: "select-kit/templates/components/select-kit/single-select-header",
layout,
classNames: ["single-select-header"]
});

View File

@ -2,10 +2,11 @@ import { computed, get, action } from "@ember/object";
import Component from "@ember/component";
import { makeArray } from "discourse-common/lib/helpers";
import UtilsMixin from "select-kit/mixins/utils";
import layout from "select-kit/templates/components/selected-name";
export default Component.extend(UtilsMixin, {
tagName: "",
layoutName: "select-kit/templates/components/selected-name",
layout,
name: null,
value: null,

View File

@ -1,10 +1,11 @@
import SelectKitComponent from "select-kit/components/select-kit";
import { computed } from "@ember/object";
import { isEmpty } from "@ember/utils";
import layout from "select-kit/templates/components/single-select";
export default SelectKitComponent.extend({
pluginApiIdentifiers: ["single-select"],
layoutName: "select-kit/templates/components/single-select",
layout,
classNames: ["single-select"],
singleSelect: true,

View File

@ -1,6 +1,7 @@
import SelectKitRowComponent from "select-kit/components/select-kit/select-kit-row";
import layout from "select-kit/templates/components/tag-chooser-row";
export default SelectKitRowComponent.extend({
layoutName: "select-kit/templates/components/tag-chooser-row",
layout,
classNames: ["tag-chooser-row"]
});

View File

@ -1,6 +1,7 @@
import ComboBoxSelectBoxHeaderComponent from "select-kit/components/combo-box/combo-box-header";
import layout from "select-kit/templates/components/tag-drop/tag-drop-header";
export default ComboBoxSelectBoxHeaderComponent.extend({
layoutName: "select-kit/templates/components/tag-drop/tag-drop-header",
layout,
classNames: "tag-drop-header"
});

View File

@ -1,6 +1,7 @@
import SelectKitRowComponent from "select-kit/components/select-kit/select-kit-row";
import layout from "select-kit/templates/components/tag-row";
export default SelectKitRowComponent.extend({
layoutName: "select-kit/templates/components/tag-row",
layout,
classNames: ["tag-row"]
});

View File

@ -1,8 +1,9 @@
import Component from "@ember/component";
import { action, computed } from "@ember/object";
import layout from "select-kit/templates/components/topic-notifications-button";
export default Component.extend({
layoutName: "select-kit/templates/components/topic-notifications-button",
layout,
classNames: ["topic-notifications-button"],
classNameBindings: ["isLoading"],
appendReason: true,

View File

@ -1,6 +1,7 @@
import SelectKitRowComponent from "select-kit/components/select-kit/select-kit-row";
import layout from "select-kit/templates/components/user-chooser/user-row";
export default SelectKitRowComponent.extend({
layoutName: "select-kit/templates/components/user-chooser/user-row",
layout,
classNames: ["user-row"]
});

View File

@ -6,6 +6,14 @@ export default Application.extend({
Resolver: buildResolver("wizard"),
start() {
// required for select kit to work without Ember CLI
Object.keys(Ember.TEMPLATES).forEach(k => {
if (k.indexOf("select-kit") === 0) {
let template = Ember.TEMPLATES[k];
define(k, () => template);
}
});
Object.keys(requirejs._eak_seen).forEach(key => {
if (/\/initializers\//.test(key)) {
const module = requirejs(key, null, null, true);