DEV: Update watched-word-uploader uppy usage (#29280)

This commit is contained in:
David Taylor 2024-10-21 15:09:14 +01:00 committed by GitHub
parent 417e57d4ce
commit 43a0ea876a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 29 deletions

View File

@ -2,6 +2,7 @@
{{d-icon "upload"}} {{d-icon "upload"}}
{{i18n "admin.watched_words.form.upload"}} {{i18n "admin.watched_words.form.upload"}}
<input <input
{{did-insert this.uppyUpload.setup}}
class="hidden-upload-field" class="hidden-upload-field"
disabled={{this.addDisabled}} disabled={{this.addDisabled}}
type="file" type="file"

View File

@ -1,33 +1,29 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { alias } from "@ember/object/computed"; import { alias } from "@ember/object/computed";
import { getOwner } from "@ember/owner";
import { service } from "@ember/service";
import { classNames } from "@ember-decorators/component"; import { classNames } from "@ember-decorators/component";
import { dialog } from "discourse/lib/uploads"; import UppyUpload from "discourse/lib/uppy/uppy-upload";
import UppyUploadMixin from "discourse/mixins/uppy-upload";
import I18n from "discourse-i18n"; import I18n from "discourse-i18n";
@classNames("watched-words-uploader") @classNames("watched-words-uploader")
export default class WatchedWordUploader extends Component.extend( export default class WatchedWordUploader extends Component {
UppyUploadMixin @service dialog;
) {
type = "txt";
uploadUrl = "/admin/customize/watched_words/upload";
@alias("uploading") addDisabled; uppyUpload = new UppyUpload(getOwner(this), {
id: "watched-word-uploader",
preventDirectS3Uploads = true; type: "txt",
uploadUrl: "/admin/customize/watched_words/upload",
validateUploadedFilesOptions() { preventDirectS3Uploads: true,
return { skipValidation: true }; validateUploadedFilesOptions: {
} skipValidation: true,
},
_perFileData() { perFileData: () => ({ action_key: this.actionKey }),
return { action_key: this.actionKey }; uploadDone: () => {
} this.dialog.alert(I18n.t("admin.watched_words.form.upload_successful"));
uploadDone() {
if (this) {
dialog.alert(I18n.t("admin.watched_words.form.upload_successful"));
this.done(); this.done();
} },
} });
@alias("uppyUpload.uploading") addDisabled;
} }

View File

@ -11,7 +11,6 @@
/> />
<WatchedWordUploader <WatchedWordUploader
@id="watched-word-uploader"
@uploading={{this.uploading}} @uploading={{this.uploading}}
@actionKey={{this.actionNameKey}} @actionKey={{this.actionNameKey}}
@done={{this.uploadComplete}} @done={{this.uploadComplete}}

View File

@ -1,8 +1,8 @@
import { getOwner } from "@ember/owner";
import { render } from "@ember/test-helpers"; import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars"; import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit"; import { module, test } from "qunit";
import sinon from "sinon"; import sinon from "sinon";
import { dialog } from "discourse/lib/uploads";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import pretender, { response } from "discourse/tests/helpers/create-pretender"; import pretender, { response } from "discourse/tests/helpers/create-pretender";
import { createFile } from "discourse/tests/helpers/qunit-helpers"; import { createFile } from "discourse/tests/helpers/qunit-helpers";
@ -18,14 +18,16 @@ module("Integration | Component | watched-word-uploader", function (hooks) {
}); });
test("sets the proper action key on uploads", async function (assert) { test("sets the proper action key on uploads", async function (assert) {
const dialog = getOwner(this).lookup("service:dialog");
sinon.stub(dialog, "alert"); sinon.stub(dialog, "alert");
const done = assert.async(); const done = assert.async();
this.set("actionNameKey", "flag"); this.set("actionNameKey", "flag");
this.set("doneUpload", function () { this.set("doneUpload", function () {
assert.strictEqual( assert.strictEqual(
Object.entries(this._uppyInstance.getState().files)[0][1].meta Object.entries(
.action_key, this.uppyUpload.uppyWrapper.uppyInstance.getState().files
)[0][1].meta.action_key,
"flag" "flag"
); );
assert.ok( assert.ok(
@ -39,7 +41,6 @@ module("Integration | Component | watched-word-uploader", function (hooks) {
await render(hbs` await render(hbs`
<WatchedWordUploader <WatchedWordUploader
@id="watched-word-uploader"
@actionKey={{this.actionNameKey}} @actionKey={{this.actionNameKey}}
@done={{this.doneUpload}} @done={{this.doneUpload}}
/> />