attempt to store typeahead item as json object string w/ burnettk

This commit is contained in:
jasquat 2023-05-31 15:58:35 -04:00
parent ff61ba35b7
commit 4894a07f90
2 changed files with 31 additions and 7 deletions

View File

@ -1,19 +1,31 @@
import { useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
import { ComboBox } from '@carbon/react'; import { ComboBox } from '@carbon/react';
import HttpService from '../../../services/HttpService'; import HttpService from '../../../services/HttpService';
interface typeaheadArgs {
id: string;
onChange: any;
options: any;
value: any;
}
export default function TypeaheadWidget({ export default function TypeaheadWidget({
id, id,
onChange, onChange,
options: { category, itemFormat }, options: { category, itemFormat },
}: { value,
id: string; ...args
onChange: any; }: typeaheadArgs) {
options: any;
}) {
const pathForCategory = (inputText: string) => { const pathForCategory = (inputText: string) => {
return `/connector-proxy/typeahead/${category}?prefix=${inputText}&limit=100`; 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 lastSearchTerm = useRef('');
const [items, setItems] = useState<any[]>([]); const [items, setItems] = useState<any[]>([]);
@ -21,6 +33,13 @@ export default function TypeaheadWidget({
const itemFormatRegex = /[^{}]+(?=})/g; const itemFormatRegex = /[^{}]+(?=})/g;
const itemFormatSubstitutions = itemFormat.match(itemFormatRegex); const itemFormatSubstitutions = itemFormat.match(itemFormatRegex);
useEffect(() => {
if (value) {
setSelectedItem(JSON.parse(value));
}
typeaheadSearch(value);
}, [value]);
const itemToString = (item: any) => { const itemToString = (item: any) => {
if (!item) { if (!item) {
return null; return null;
@ -51,12 +70,16 @@ export default function TypeaheadWidget({
} }
}; };
console.log('selectedItem', selectedItem);
return ( return (
<ComboBox <ComboBox
onInputChange={typeaheadSearch} onInputChange={typeaheadSearch}
onChange={(event: any) => { onChange={(event: any) => {
console.log('event.selectedItem', event.selectedItem);
setSelectedItem(event.selectedItem); setSelectedItem(event.selectedItem);
onChange(itemToString(event.selectedItem)); // onChange(itemToString(event.selectedItem));
onChange(JSON.stringify(event.selectedItem));
}} }}
id={id} id={id}
items={items} items={items}

View File

@ -84,6 +84,7 @@ export default function TaskShow() {
}, [params]); }, [params]);
const processSubmitResult = (result: any) => { const processSubmitResult = (result: any) => {
return null;
removeError(); removeError();
if (result.ok) { if (result.ok) {
navigate(`/tasks`); navigate(`/tasks`);