Skip to content

Commit d63645e

Browse files
committed
UIEXT-3031: Make uischema-provided possible values overwrite oneof possible values
UIEXT-3031 (Support multiple modes for file selection widget)
1 parent 0caa432 commit d63645e

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

.changeset/eleven-rings-invite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@knime/jsonforms": patch
3+
---
4+
5+
Prefer uischema possible values over oneOf options in RadioControl and ValueSwitchControl

packages/jsonforms/src/uiComponents/RadioControlBase.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ const uiComponent = computed(() =>
3333
const staticOptions: Ref<PossiblyDisabledOption[] | null | undefined> =
3434
ref(null);
3535
36-
const { possibleValues } = usePossibleValues(toRef(props, "control"));
36+
const { possibleValues } = usePossibleValues(toRef(props, "control"), {
37+
defaultOnNonProvided: null,
38+
});
3739
3840
const options = computed(() =>
39-
(staticOptions.value ?? possibleValues.value)?.map(disableOption),
41+
(possibleValues.value ?? staticOptions.value)?.map(disableOption),
4042
);
4143
4244
onMounted(() => {

packages/jsonforms/src/uiComponents/__tests__/RadioControl.test.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ describe("RadioControl", () => {
117117
]);
118118
});
119119

120-
it("uses possible values if oneOf is not given", async () => {
121-
delete props.control.schema.oneOf;
120+
it("uses possible values", async () => {
122121
props.control.uischema.options!.possibleValues = [
123122
{ id: "VAL 1", text: "Val 1" },
124123
{ id: "VAL 2", text: "Val 2" },
@@ -133,20 +132,4 @@ describe("RadioControl", () => {
133132
{ id: "VAL 2", text: "Val 2" },
134133
]);
135134
});
136-
137-
it("favors oneOf over possible Values", async () => {
138-
props.control.uischema.options!.possibleValues = [
139-
{ id: "VAL 1", text: "Val 1" },
140-
{ id: "VAL 2", text: "Val 2" },
141-
];
142-
const { wrapper } = await mountJsonFormsControlLabelContent(RadioControl, {
143-
props,
144-
});
145-
expect(
146-
wrapper.findComponent(RadioButtons).props().possibleValues,
147-
).toStrictEqual([
148-
{ id: "LOG", text: "Logarithmic" },
149-
{ id: "VALUE", text: "Linear" },
150-
]);
151-
});
152135
});

packages/jsonforms/src/uiComponents/composables/usePossibleValues.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,22 @@ export const usePossibleValues = <
1515
control: Ref<{
1616
uischema: ChoicesUiSchemaWithProvidedOptions<SpecialChoicesProps>;
1717
}>,
18+
options?: {
19+
defaultOnNonProvided?: [] | null; // default is []
20+
},
1821
) => {
1922
const uischema = computed(() => control.value.uischema);
2023
const providedPossibleValues = useProvidedState(uischema, "possibleValues");
2124
const possibleValues = computed(() => {
2225
if (uischema.value.providedOptions?.includes("possibleValues")) {
2326
return providedPossibleValues.value;
2427
}
25-
return uischema.value.options?.possibleValues ?? [];
28+
return (
29+
uischema.value.options?.possibleValues ??
30+
(typeof options?.defaultOnNonProvided === "undefined"
31+
? []
32+
: options?.defaultOnNonProvided)
33+
);
2634
});
2735
return { possibleValues };
2836
};

0 commit comments

Comments
 (0)