From 4894a07f902910a4a0c7b35b4e2659b3fa0f1bcb Mon Sep 17 00:00:00 2001 From: jasquat Date: Wed, 31 May 2023 15:58:35 -0400 Subject: [PATCH] attempt to store typeahead item as json object string w/ burnettk --- .../TypeaheadWidget/TypeaheadWidget.tsx | 37 +++++++++++++++---- .../src/routes/TaskShow.tsx | 1 + 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/spiffworkflow-frontend/src/rjsf/custom_widgets/TypeaheadWidget/TypeaheadWidget.tsx b/spiffworkflow-frontend/src/rjsf/custom_widgets/TypeaheadWidget/TypeaheadWidget.tsx index 3e8816db..9236ceac 100644 --- a/spiffworkflow-frontend/src/rjsf/custom_widgets/TypeaheadWidget/TypeaheadWidget.tsx +++ b/spiffworkflow-frontend/src/rjsf/custom_widgets/TypeaheadWidget/TypeaheadWidget.tsx @@ -1,19 +1,31 @@ -import { useRef, useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { ComboBox } from '@carbon/react'; import HttpService from '../../../services/HttpService'; +interface typeaheadArgs { + id: string; + onChange: any; + options: any; + value: any; +} + export default function TypeaheadWidget({ id, onChange, options: { category, itemFormat }, -}: { - id: string; - onChange: any; - options: any; -}) { + value, + ...args +}: typeaheadArgs) { const pathForCategory = (inputText: string) => { return `/connector-proxy/typeahead/${category}?prefix=${inputText}&limit=100`; }; + console.log('args', args); + console.log('value', value); + console.log('itemFormat', itemFormat); + + // if (value) { + // + // } const lastSearchTerm = useRef(''); const [items, setItems] = useState([]); @@ -21,6 +33,13 @@ export default function TypeaheadWidget({ const itemFormatRegex = /[^{}]+(?=})/g; const itemFormatSubstitutions = itemFormat.match(itemFormatRegex); + useEffect(() => { + if (value) { + setSelectedItem(JSON.parse(value)); + } + typeaheadSearch(value); + }, [value]); + const itemToString = (item: any) => { if (!item) { return null; @@ -51,12 +70,16 @@ export default function TypeaheadWidget({ } }; + console.log('selectedItem', selectedItem); + return ( { + console.log('event.selectedItem', event.selectedItem); setSelectedItem(event.selectedItem); - onChange(itemToString(event.selectedItem)); + // onChange(itemToString(event.selectedItem)); + onChange(JSON.stringify(event.selectedItem)); }} id={id} items={items} diff --git a/spiffworkflow-frontend/src/routes/TaskShow.tsx b/spiffworkflow-frontend/src/routes/TaskShow.tsx index 15d9c2d6..bd5c0e00 100644 --- a/spiffworkflow-frontend/src/routes/TaskShow.tsx +++ b/spiffworkflow-frontend/src/routes/TaskShow.tsx @@ -84,6 +84,7 @@ export default function TaskShow() { }, [params]); const processSubmitResult = (result: any) => { + return null; removeError(); if (result.ok) { navigate(`/tasks`);