mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 17:53:44 +08:00
FIX: Make watched words uploads work as intended (#17097)
* FIX: Make watched words uploads work as intended Currently when we upload a file containing watched words, it will always add the words to the action that was initially selected: this is the `block` action by default but if changing manually the action in the URL to `flag` for example, then this action will be selected and uploaded watched words will be categorised as `flag` no matter what. The problem lies with how the component works: it’s an Uppy object where extra data is defined to provide an action key to the server but when navigating to another listed action, while this action key is properly updated on the component itself, the underlying Uppy object has already been created and doesn’t care about the new value. This patch solves this by using the `_perFileData` method instead of `data`: the former is merged just before uploading a file whereas the latter is used when the Uppy object is created.
This commit is contained in:
parent
97e21b80a0
commit
1166db12b4
|
@ -3,7 +3,6 @@ import I18n from "I18n";
|
||||||
import UppyUploadMixin from "discourse/mixins/uppy-upload";
|
import UppyUploadMixin from "discourse/mixins/uppy-upload";
|
||||||
import { alias } from "@ember/object/computed";
|
import { alias } from "@ember/object/computed";
|
||||||
import bootbox from "bootbox";
|
import bootbox from "bootbox";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
|
||||||
|
|
||||||
export default Component.extend(UppyUploadMixin, {
|
export default Component.extend(UppyUploadMixin, {
|
||||||
type: "txt",
|
type: "txt",
|
||||||
|
@ -16,9 +15,8 @@ export default Component.extend(UppyUploadMixin, {
|
||||||
return { skipValidation: true };
|
return { skipValidation: true };
|
||||||
},
|
},
|
||||||
|
|
||||||
@discourseComputed("actionKey")
|
_perFileData() {
|
||||||
data(actionKey) {
|
return { action_key: this.actionKey };
|
||||||
return { action_key: actionKey };
|
|
||||||
},
|
},
|
||||||
|
|
||||||
uploadDone() {
|
uploadDone() {
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
import componentTest, {
|
||||||
|
setupRenderingTest,
|
||||||
|
} from "discourse/tests/helpers/component-test";
|
||||||
|
import {
|
||||||
|
createFile,
|
||||||
|
discourseModule,
|
||||||
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
import hbs from "htmlbars-inline-precompile";
|
||||||
|
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||||
|
import { click, waitFor } from "@ember/test-helpers";
|
||||||
|
import { isLegacyEmber } from "discourse-common/config/environment";
|
||||||
|
|
||||||
|
if (!isLegacyEmber()) {
|
||||||
|
discourseModule(
|
||||||
|
"Integration | Component | watched-word-uploader",
|
||||||
|
function (hooks) {
|
||||||
|
setupRenderingTest(hooks);
|
||||||
|
|
||||||
|
hooks.beforeEach(function () {
|
||||||
|
pretender.post(
|
||||||
|
"/admin/customize/watched_words/upload.json",
|
||||||
|
function () {
|
||||||
|
return response(200, {});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
componentTest("sets the proper action key on uploads", {
|
||||||
|
template: hbs`{{watched-word-uploader
|
||||||
|
id="watched-word-uploader"
|
||||||
|
actionKey=actionNameKey
|
||||||
|
done=doneUpload
|
||||||
|
}}`,
|
||||||
|
|
||||||
|
async test(assert) {
|
||||||
|
const done = assert.async();
|
||||||
|
this.set("actionNameKey", "flag");
|
||||||
|
this.set("doneUpload", function () {
|
||||||
|
assert.equal(
|
||||||
|
Object.entries(this._uppyInstance.getState().files)[0][1].meta
|
||||||
|
.action_key,
|
||||||
|
"flag"
|
||||||
|
);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
const words = createFile("watched-words.txt");
|
||||||
|
await this.container
|
||||||
|
.lookup("service:app-events")
|
||||||
|
.trigger("upload-mixin:watched-word-uploader:add-files", words);
|
||||||
|
await waitFor(".bootbox span.d-button-label");
|
||||||
|
await click(".bootbox span.d-button-label");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user