@inseefr/lunatic 3.8.1-rc.0 → 3.8.1-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Suggester/Suggester.js +11 -8
- package/components/Suggester/Suggester.js.map +1 -1
- package/components/Suggester/Suggester.spec.js +67 -24
- package/components/Suggester/Suggester.spec.js.map +1 -1
- package/components/Suggester/useSuggestions.js +1 -1
- package/components/Suggester/useSuggestions.js.map +1 -1
- package/esm/components/Suggester/Suggester.js +12 -9
- package/esm/components/Suggester/Suggester.js.map +1 -1
- package/esm/components/Suggester/Suggester.spec.js +70 -24
- package/esm/components/Suggester/Suggester.spec.js.map +1 -1
- package/esm/components/Suggester/useSuggestions.js +2 -2
- package/esm/components/Suggester/useSuggestions.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Suggester/Suggester.spec.tsx +84 -25
- package/src/components/Suggester/Suggester.tsx +11 -8
- package/src/components/Suggester/useSuggestions.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -15,6 +15,8 @@ export function Suggester(props: LunaticComponentProps<'Suggester'>) {
|
|
|
15
15
|
return <WrappedSuggester {...props} key={suggesterKey} />;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
const ARBITRARY_ID = 'OTHER';
|
|
19
|
+
|
|
18
20
|
export function WrappedSuggester({
|
|
19
21
|
storeName,
|
|
20
22
|
id,
|
|
@@ -44,7 +46,7 @@ export function WrappedSuggester({
|
|
|
44
46
|
// so we can break the rule of hooks here
|
|
45
47
|
const computeSelectedOptions = (): [SuggesterOptionType] | [] => {
|
|
46
48
|
if (arbitraryValue) {
|
|
47
|
-
return [{ id:
|
|
49
|
+
return [{ id: ARBITRARY_ID, label: arbitraryValue, value: ARBITRARY_ID }];
|
|
48
50
|
}
|
|
49
51
|
if (!value) {
|
|
50
52
|
return [];
|
|
@@ -154,14 +156,15 @@ export function WrappedSuggester({
|
|
|
154
156
|
useEffect(() => {
|
|
155
157
|
// Fix display issue (when handleChanges is called outside this component (in management mode, return to FORCED value by example)
|
|
156
158
|
// "value" does'nt match selectedOption's "id"
|
|
157
|
-
if (
|
|
159
|
+
if (selectedOptions[0]?.id !== value) {
|
|
158
160
|
const actualSelection = computeSelectedOptions();
|
|
159
|
-
const selectedOptionsWithLabel =
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
const selectedOptionsWithLabel = actualSelection.map((selection) => {
|
|
162
|
+
if (selection.id === ARBITRARY_ID) return selection;
|
|
163
|
+
return {
|
|
164
|
+
...selection,
|
|
165
|
+
label: getLabelById(selection.id),
|
|
166
|
+
};
|
|
167
|
+
}) as [SuggesterOptionType];
|
|
165
168
|
setSelectedOptions(selectedOptionsWithLabel);
|
|
166
169
|
}
|
|
167
170
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -51,7 +51,7 @@ export function useStore({ storeName }: { storeName: string }) {
|
|
|
51
51
|
setStoreState: setState,
|
|
52
52
|
getLabelById: (id: any) => {
|
|
53
53
|
if (!id) return '';
|
|
54
|
-
return store.search?.getFieldsById(id)
|
|
54
|
+
return store.search?.getFieldsById(id)?.label ?? '';
|
|
55
55
|
},
|
|
56
56
|
};
|
|
57
57
|
}
|