Skip to content

Commit 0b5fd43

Browse files
authored
Merge pull request #3012 from the-deep/feature/add-secondary-tagging-widgets-in-llm
Support singleselect, multiselect, scale, organigram LLM integration
2 parents 6c2b8ab + a215d0d commit 0b5fd43

File tree

1 file changed

+119
-3
lines changed
  • app/components/LeftPaneEntries/AssistItem

1 file changed

+119
-3
lines changed

app/components/LeftPaneEntries/AssistItem/utils.ts

Lines changed: 119 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ import {
66
import {
77
Matrix1dWidget,
88
Matrix1dValue,
9-
Matrix2dValue,
109
Matrix2dWidget,
10+
Matrix2dValue,
11+
SingleSelectWidget,
12+
SingleSelectValue,
13+
MultiSelectWidget,
14+
MultiSelectValue,
15+
ScaleWidget,
16+
ScaleValue,
17+
OrganigramWidget,
18+
OrganigramValue,
1119
} from '#types/newAnalyticalFramework';
1220

1321
import {
@@ -17,14 +25,17 @@ import {
1725
import {
1826
PartialAttributeType,
1927
} from '#components/entry/schema';
28+
import {
29+
getOrganigramFlatOptions,
30+
} from '#components/framework/CompactAttributeInput/OrganigramWidgetInput/utils';
2031

2132
type Matrix1dWidgetAttribute = getType<PartialAttributeType, { widgetType: 'MATRIX1D' }>;
2233
type Matrix2dWidgetAttribute = getType<PartialAttributeType, { widgetType: 'MATRIX2D' }>;
23-
/*
24-
type ScaleWidgetAttribute = getType<PartialAttributeType, { widgetType: 'SCALE' }>;
2534
type SingleSelectWidgetAttribute = getType<PartialAttributeType, { widgetType: 'SELECT' }>;
2635
type MultiSelectWidgetAttribute = getType<PartialAttributeType, { widgetType: 'MULTISELECT' }>;
2736
type OrganigramWidgetAttribute = getType<PartialAttributeType, { widgetType: 'ORGANIGRAM' }>;
37+
type ScaleWidgetAttribute = getType<PartialAttributeType, { widgetType: 'SCALE' }>;
38+
/*
2839
type GeoLocationWidgetAttribute = getType<PartialAttributeType, { widgetType: 'GEO' }>;
2940
*/
3041

@@ -163,3 +174,108 @@ export function createMatrix2dAttrFromTags(
163174
data: { value },
164175
};
165176
}
177+
178+
// TODO: Write tests
179+
export function createSingleSelectAttrFromTags(
180+
unsafeMapping: SingleSelectValue | undefined,
181+
widget: SingleSelectWidget,
182+
): SingleSelectWidgetAttribute | undefined {
183+
const mapping = unsafeMapping as unknown;
184+
if (!mapping || typeof mapping !== 'string') {
185+
return undefined;
186+
}
187+
188+
const valueOption = widget.properties?.options.find((item) => item.key === mapping);
189+
190+
if (!valueOption) {
191+
return undefined;
192+
}
193+
194+
return {
195+
clientId: randomString(),
196+
widget: widget.id,
197+
widgetVersion: widget.version,
198+
widgetType: 'SELECT',
199+
data: { value: mapping },
200+
};
201+
}
202+
203+
// TODO: Write tests
204+
export function createMultiSelectAttrFromTags(
205+
unsafeMapping: MultiSelectValue | undefined,
206+
widget: MultiSelectWidget,
207+
): MultiSelectWidgetAttribute | undefined {
208+
const mapping = unsafeMapping as unknown;
209+
if (!mapping || !isValidStringArray(mapping)) {
210+
return undefined;
211+
}
212+
213+
const validKeys = widget.properties?.options?.map((item) => item.key);
214+
215+
const validOptions = mapping.filter((item) => validKeys?.includes(item));
216+
217+
if (validOptions.length < 1) {
218+
return undefined;
219+
}
220+
221+
return {
222+
clientId: randomString(),
223+
widget: widget.id,
224+
widgetVersion: widget.version,
225+
widgetType: 'MULTISELECT',
226+
data: { value: mapping },
227+
};
228+
}
229+
230+
// TODO: Write tests
231+
export function createScaleAttrFromTags(
232+
unsafeMapping: ScaleValue | undefined,
233+
widget: ScaleWidget,
234+
): ScaleWidgetAttribute | undefined {
235+
const mapping = unsafeMapping as unknown;
236+
if (!mapping || typeof mapping !== 'string') {
237+
return undefined;
238+
}
239+
240+
const valueOption = widget.properties?.options.find((item) => item.key === mapping);
241+
242+
if (!valueOption) {
243+
return undefined;
244+
}
245+
246+
return {
247+
clientId: randomString(),
248+
widget: widget.id,
249+
widgetVersion: widget.version,
250+
widgetType: 'SCALE',
251+
data: { value: mapping },
252+
};
253+
}
254+
255+
// TODO: Write tests
256+
export function createOrganigramAttrFromTags(
257+
unsafeMapping: OrganigramValue | undefined,
258+
widget: OrganigramWidget,
259+
): OrganigramWidgetAttribute | undefined {
260+
const mapping = unsafeMapping as unknown;
261+
if (!mapping || !isValidStringArray(mapping)) {
262+
return undefined;
263+
}
264+
265+
const validKeys = getOrganigramFlatOptions(widget.properties?.options)
266+
.map((item) => item.key);
267+
268+
const validOptions = mapping.filter((item) => validKeys?.includes(item));
269+
270+
if (validOptions.length < 1) {
271+
return undefined;
272+
}
273+
274+
return {
275+
clientId: randomString(),
276+
widget: widget.id,
277+
widgetVersion: widget.version,
278+
widgetType: 'ORGANIGRAM',
279+
data: { value: mapping },
280+
};
281+
}

0 commit comments

Comments
 (0)