FIX: call onSelect plugin callbacks for noop rows (#6682)

This commit is contained in:
Joffrey JAFFEUX 2018-11-29 15:56:19 +01:00 committed by GitHub
parent 6b433b66f5
commit 8da8f5d0f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 1 deletions

View File

@ -265,6 +265,12 @@ export default SelectKitComponent.extend({
}
if (computedContentItem.__sk_row_type === "noopRow") {
applyOnSelectPluginApiCallbacks(
this.get("pluginApiIdentifiers"),
computedContentItem.value,
this
);
this._boundaryActionHandler("onSelect", computedContentItem.value);
return;
}

View File

@ -211,6 +211,12 @@ export default SelectKitComponent.extend({
select(computedContentItem) {
if (computedContentItem.__sk_row_type === "noopRow") {
applyOnSelectPluginApiCallbacks(
this.get("pluginApiIdentifiers"),
computedContentItem.value,
this
);
this._boundaryActionHandler("onSelect", computedContentItem.value);
return;
}

View File

@ -1,4 +1,7 @@
import componentTest from "helpers/component-test";
import { withPluginApi } from "discourse/lib/plugin-api";
import { clearCallbacks } from "select-kit/mixins/plugin-api";
moduleForComponent("multi-select", {
integration: true,
beforeEach: function() {
@ -317,3 +320,39 @@ componentTest("with forceEscape", {
);
}
});
componentTest("support modifying on select behavior through plugin api", {
template:
'<span class="on-select-test"></span>{{multi-select content=content}}',
beforeEach() {
withPluginApi("0.8.13", api => {
api.modifySelectKit("select-kit").onSelect((context, value) => {
find(".on-select-test").html(value);
});
});
this.set("content", [
{ id: "1", name: "robin" },
{ id: "2", name: "arpit", __sk_row_type: "noopRow" }
]);
},
async test(assert) {
await this.get("subject").expand();
await this.get("subject").selectRowByValue(1);
assert.equal(find(".on-select-test").html(), "1");
await this.get("subject").expand();
await this.get("subject").selectRowByValue(2);
assert.equal(
find(".on-select-test").html(),
"2",
"it calls onSelect for noopRows"
);
clearCallbacks();
}
});

View File

@ -488,7 +488,10 @@ componentTest("support modifying on select behavior through plugin api", {
});
});
this.set("content", [{ id: "1", name: "robin" }]);
this.set("content", [
{ id: "1", name: "robin" },
{ id: "2", name: "arpit", __sk_row_type: "noopRow" }
]);
},
async test(assert) {
@ -497,6 +500,15 @@ componentTest("support modifying on select behavior through plugin api", {
assert.equal(find(".on-select-test").html(), "1");
await this.get("subject").expand();
await this.get("subject").selectRowByValue(2);
assert.equal(
find(".on-select-test").html(),
"2",
"it calls onSelect for noopRows"
);
clearCallbacks();
}
});