FEATURE: mandatory fields for compact-list (#29357)
In this PR we introduced mandatory fields for `group-list` https://github.com/discourse/discourse/pull/26612 The same solution should apply to `compact-list`.
This commit is contained in:
parent
ca9549b04f
commit
11b62847e7
|
@ -5,4 +5,5 @@
|
|||
@onChange={{this.onChangeListSetting}}
|
||||
@onChangeChoices={{this.onChangeChoices}}
|
||||
@options={{hash allowAny=this.allowAny}}
|
||||
@mandatoryValues={{this.setting.mandatory_values}}
|
||||
/>
|
|
@ -0,0 +1,39 @@
|
|||
import EmberObject from "@ember/object";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
|
||||
module("Integration | Component | compact-list site-setting", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test("mandatory values", async function (assert) {
|
||||
this.set(
|
||||
"setting",
|
||||
EmberObject.create({
|
||||
allowsNone: undefined,
|
||||
category: "foo",
|
||||
description: "Choose setting",
|
||||
overridden: false,
|
||||
placeholder: null,
|
||||
preview: null,
|
||||
secret: false,
|
||||
setting: "foo_bar",
|
||||
type: "compact_list",
|
||||
validValues: undefined,
|
||||
default: "admin",
|
||||
mandatory_values: "admin",
|
||||
value: "admin|moderator",
|
||||
})
|
||||
);
|
||||
|
||||
await render(hbs`<SiteSetting @setting={{this.setting}} />`);
|
||||
|
||||
const subject = selectKit(".list-setting");
|
||||
|
||||
await subject.expand();
|
||||
|
||||
assert.dom(".selected-content button").hasClass("disabled");
|
||||
});
|
||||
});
|
|
@ -34,6 +34,9 @@ export default class SelectedChoice extends Component.extend(UtilsMixin) {
|
|||
|
||||
@computed("item")
|
||||
get readOnly() {
|
||||
if (typeof this.item === "string") {
|
||||
return this.mandatoryValuesArray.includes(this.item);
|
||||
}
|
||||
return this.mandatoryValuesArray.includes(this.item.id);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue