From a215d0d016bcd2c8e0ab9cfcd8cd746fbd1330d7 Mon Sep 17 00:00:00 2001 From: Aditya Khatri Date: Thu, 26 Dec 2024 14:30:29 +0545 Subject: [PATCH] Support singleselect, multiselect, scale, organigram LLM integration --- .../LeftPaneEntries/AssistItem/utils.ts | 122 +++++++++++++++++- 1 file changed, 119 insertions(+), 3 deletions(-) diff --git a/app/components/LeftPaneEntries/AssistItem/utils.ts b/app/components/LeftPaneEntries/AssistItem/utils.ts index 011a75087..38131e26e 100644 --- a/app/components/LeftPaneEntries/AssistItem/utils.ts +++ b/app/components/LeftPaneEntries/AssistItem/utils.ts @@ -6,8 +6,16 @@ import { import { Matrix1dWidget, Matrix1dValue, - Matrix2dValue, Matrix2dWidget, + Matrix2dValue, + SingleSelectWidget, + SingleSelectValue, + MultiSelectWidget, + MultiSelectValue, + ScaleWidget, + ScaleValue, + OrganigramWidget, + OrganigramValue, } from '#types/newAnalyticalFramework'; import { @@ -17,14 +25,17 @@ import { import { PartialAttributeType, } from '#components/entry/schema'; +import { + getOrganigramFlatOptions, +} from '#components/framework/CompactAttributeInput/OrganigramWidgetInput/utils'; type Matrix1dWidgetAttribute = getType; type Matrix2dWidgetAttribute = getType; -/* -type ScaleWidgetAttribute = getType; type SingleSelectWidgetAttribute = getType; type MultiSelectWidgetAttribute = getType; type OrganigramWidgetAttribute = getType; +type ScaleWidgetAttribute = getType; +/* type GeoLocationWidgetAttribute = getType; */ @@ -163,3 +174,108 @@ export function createMatrix2dAttrFromTags( data: { value }, }; } + +// TODO: Write tests +export function createSingleSelectAttrFromTags( + unsafeMapping: SingleSelectValue | undefined, + widget: SingleSelectWidget, +): SingleSelectWidgetAttribute | undefined { + const mapping = unsafeMapping as unknown; + if (!mapping || typeof mapping !== 'string') { + return undefined; + } + + const valueOption = widget.properties?.options.find((item) => item.key === mapping); + + if (!valueOption) { + return undefined; + } + + return { + clientId: randomString(), + widget: widget.id, + widgetVersion: widget.version, + widgetType: 'SELECT', + data: { value: mapping }, + }; +} + +// TODO: Write tests +export function createMultiSelectAttrFromTags( + unsafeMapping: MultiSelectValue | undefined, + widget: MultiSelectWidget, +): MultiSelectWidgetAttribute | undefined { + const mapping = unsafeMapping as unknown; + if (!mapping || !isValidStringArray(mapping)) { + return undefined; + } + + const validKeys = widget.properties?.options?.map((item) => item.key); + + const validOptions = mapping.filter((item) => validKeys?.includes(item)); + + if (validOptions.length < 1) { + return undefined; + } + + return { + clientId: randomString(), + widget: widget.id, + widgetVersion: widget.version, + widgetType: 'MULTISELECT', + data: { value: mapping }, + }; +} + +// TODO: Write tests +export function createScaleAttrFromTags( + unsafeMapping: ScaleValue | undefined, + widget: ScaleWidget, +): ScaleWidgetAttribute | undefined { + const mapping = unsafeMapping as unknown; + if (!mapping || typeof mapping !== 'string') { + return undefined; + } + + const valueOption = widget.properties?.options.find((item) => item.key === mapping); + + if (!valueOption) { + return undefined; + } + + return { + clientId: randomString(), + widget: widget.id, + widgetVersion: widget.version, + widgetType: 'SCALE', + data: { value: mapping }, + }; +} + +// TODO: Write tests +export function createOrganigramAttrFromTags( + unsafeMapping: OrganigramValue | undefined, + widget: OrganigramWidget, +): OrganigramWidgetAttribute | undefined { + const mapping = unsafeMapping as unknown; + if (!mapping || !isValidStringArray(mapping)) { + return undefined; + } + + const validKeys = getOrganigramFlatOptions(widget.properties?.options) + .map((item) => item.key); + + const validOptions = mapping.filter((item) => validKeys?.includes(item)); + + if (validOptions.length < 1) { + return undefined; + } + + return { + clientId: randomString(), + widget: widget.id, + widgetVersion: widget.version, + widgetType: 'ORGANIGRAM', + data: { value: mapping }, + }; +}