FIX: allows to use icon-picker in wizard (#13786)

- inlines dasherize helper in sk
- uses an ajax helper to load wizard's ajax lib when in wizard
- amends wizard's ajax lib to work with string as first arg
- disabled loading spinner in wizard as it's not available
This commit is contained in:
Joffrey JAFFEUX 2021-07-21 13:49:21 +02:00 committed by GitHub
parent 4da0a33524
commit 519528daa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 5 deletions

View File

@ -4,10 +4,10 @@ import {
enableMissingIconWarning,
} from "discourse-common/lib/icon-library";
import MultiSelectComponent from "select-kit/components/multi-select";
import { ajax } from "discourse/lib/ajax";
import { computed } from "@ember/object";
import { isDevelopment } from "discourse-common/config/environment";
import { makeArray } from "discourse-common/lib/helpers";
import { ajax } from "select-kit/lib/ajax-helper";
export default MultiSelectComponent.extend({
pluginApiIdentifiers: ["icon-picker"],

View File

@ -69,6 +69,10 @@ export default Component.extend(UtilsMixin, {
);
}),
dasherizedTitle: computed("title", function () {
return (this.title || "").replace(".", "-").dasherize();
}),
label: computed("rowLabel", "item.label", "title", "rowName", function () {
const label =
this.rowLabel ||

View File

@ -0,0 +1,8 @@
let ajax;
if (window.Discourse) {
ajax = requirejs("discourse/lib/ajax").ajax;
} else {
ajax = requirejs("wizard/lib/ajax").ajax;
}
export { ajax };

View File

@ -1,6 +1,6 @@
import I18n from "I18n";
import Mixin from "@ember/object/mixin";
import { ajax } from "discourse/lib/ajax";
import { ajax } from "select-kit/lib/ajax-helper";
import getURL from "discourse-common/lib/get-url";
import { isEmpty } from "@ember/utils";
import { makeArray } from "discourse-common/lib/helpers";

View File

@ -10,7 +10,9 @@
{{#select-kit/select-kit-body selectKit=selectKit id=(concat selectKit.uniqueID "-body")}}
{{#if selectKit.isLoading}}
<span class="is-loading">
{{#if site}}
{{loading-spinner size="small"}}
{{/if}}
</span>
{{else}}
{{#if selectKit.filter}}

View File

@ -1,5 +1,5 @@
{{#each icons as |icon|}}
{{d-icon icon translatedtitle=(dasherize title)}}
{{d-icon icon translatedtitle=dasherizedTitle}}
{{/each}}
<span class="name">

View File

@ -14,11 +14,20 @@ export function getToken() {
}
export function ajax(args) {
let url;
if (arguments.length === 2) {
url = arguments[0];
args = arguments[1];
} else {
url = args.url;
}
return new Promise((resolve, reject) => {
args.headers = { "X-CSRF-Token": getToken() };
args.success = (data) => run(null, resolve, data);
args.error = (xhr) => run(null, reject, xhr);
args.url = getUrl(args.url);
args.url = getUrl(url);
jQuery.ajax(args);
});
}