mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 19:11:58 +08:00
DEV: do not append/prepend if callback returns nothing (#9778)
This commit is contained in:
@ -32,10 +32,16 @@ function onChange(pluginApiIdentifiers, mutationFunction) {
|
|||||||
export function applyContentPluginApiCallbacks(content, component) {
|
export function applyContentPluginApiCallbacks(content, component) {
|
||||||
makeArray(component.pluginApiIdentifiers).forEach(key => {
|
makeArray(component.pluginApiIdentifiers).forEach(key => {
|
||||||
(_prependContentCallbacks[key] || []).forEach(c => {
|
(_prependContentCallbacks[key] || []).forEach(c => {
|
||||||
content = makeArray(c(component, content)).concat(content);
|
const prependedContent = c(component, content);
|
||||||
|
if (prependedContent) {
|
||||||
|
content = makeArray(prependedContent).concat(content);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
(_appendContentCallbacks[key] || []).forEach(c => {
|
(_appendContentCallbacks[key] || []).forEach(c => {
|
||||||
content = content.concat(makeArray(c(component, content)));
|
const appendedContent = c(component, content);
|
||||||
|
if (appendedContent) {
|
||||||
|
content = content.concat(makeArray(appendedContent));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -36,14 +36,18 @@ componentTest("modifySelectKit(identifier).appendContent", {
|
|||||||
name: "Alpaca"
|
name: "Alpaca"
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
api.modifySelectKit("combo-box").appendContent(() => {});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
async test(assert) {
|
async test(assert) {
|
||||||
await this.comboBox.expand();
|
await this.comboBox.expand();
|
||||||
const row = this.comboBox.rowByIndex(3);
|
|
||||||
assert.ok(row.exists());
|
assert.equal(this.comboBox.rows().length, 4);
|
||||||
assert.equal(row.value(), "alpaca");
|
|
||||||
|
const appendedRow = this.comboBox.rowByIndex(3);
|
||||||
|
assert.ok(appendedRow.exists());
|
||||||
|
assert.equal(appendedRow.value(), "alpaca");
|
||||||
|
|
||||||
await this.comboBox.collapse();
|
await this.comboBox.collapse();
|
||||||
|
|
||||||
@ -67,16 +71,18 @@ componentTest("modifySelectKit(identifier).prependContent", {
|
|||||||
name: "Alpaca"
|
name: "Alpaca"
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
api.modifySelectKit("combo-box").prependContent(() => {});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
afterEach() {},
|
|
||||||
|
|
||||||
async test(assert) {
|
async test(assert) {
|
||||||
await this.comboBox.expand();
|
await this.comboBox.expand();
|
||||||
const row = this.comboBox.rowByIndex(0);
|
|
||||||
assert.ok(row.exists());
|
assert.equal(this.comboBox.rows().length, 4);
|
||||||
assert.equal(row.value(), "alpaca");
|
|
||||||
|
const prependedRow = this.comboBox.rowByIndex(0);
|
||||||
|
assert.ok(prependedRow.exists());
|
||||||
|
assert.equal(prependedRow.value(), "alpaca");
|
||||||
|
|
||||||
await this.comboBox.collapse();
|
await this.comboBox.collapse();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user