attempt to store typeahead item as json object string w/ burnettk
This commit is contained in:
parent
781a7be04a
commit
d5d4fdac39
|
@ -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<any[]>([]);
|
||||
|
@ -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 (
|
||||
<ComboBox
|
||||
onInputChange={typeaheadSearch}
|
||||
onChange={(event: any) => {
|
||||
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}
|
||||
|
|
|
@ -84,6 +84,7 @@ export default function TaskShow() {
|
|||
}, [params]);
|
||||
|
||||
const processSubmitResult = (result: any) => {
|
||||
return null;
|
||||
removeError();
|
||||
if (result.ok) {
|
||||
navigate(`/tasks`);
|
||||
|
|
Loading…
Reference in New Issue