mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 20:15:44 +00:00
Framework for related field query manager
This commit is contained in:
@ -11,6 +11,7 @@ import {
|
|||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { Button, Center, Group, Loader, Stack, Text } from '@mantine/core';
|
import { Button, Center, Group, Loader, Stack, Text } from '@mantine/core';
|
||||||
import { UseFormReturnType, useForm } from '@mantine/form';
|
import { UseFormReturnType, useForm } from '@mantine/form';
|
||||||
|
import { useDebouncedValue } from '@mantine/hooks';
|
||||||
import { IconAlertCircle } from '@tabler/icons-react';
|
import { IconAlertCircle } from '@tabler/icons-react';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { AxiosResponse } from 'axios';
|
import { AxiosResponse } from 'axios';
|
||||||
@ -30,6 +31,8 @@ export type ApiFormFieldType = {
|
|||||||
label?: string;
|
label?: string;
|
||||||
value?: any;
|
value?: any;
|
||||||
fieldType?: string;
|
fieldType?: string;
|
||||||
|
api_url?: string;
|
||||||
|
model?: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
hidden?: boolean;
|
hidden?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
@ -101,7 +104,32 @@ function RelatedModelField({
|
|||||||
[form.values, field, definitions]
|
[form.values, field, definitions]
|
||||||
);
|
);
|
||||||
|
|
||||||
return <Select withinPortal={true} {...definition} data={[]} />;
|
const [value, setValue] = useState<string>('');
|
||||||
|
const [searchText] = useDebouncedValue(value, 500);
|
||||||
|
|
||||||
|
const selectQuery = useQuery({
|
||||||
|
enabled: !definition.disabled && !!definition.api_url && !definition.hidden,
|
||||||
|
queryKey: [`related-field-${definition.name}`, definition, searchText],
|
||||||
|
queryFn: async () => {
|
||||||
|
console.log('Searching for', searchText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function onSearchChange(value: string) {
|
||||||
|
console.log('Search change:', value, definition.api_url, definition.model);
|
||||||
|
setValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Select
|
||||||
|
withinPortal={true}
|
||||||
|
searchable={true}
|
||||||
|
onSearchChange={onSearchChange}
|
||||||
|
data={[]}
|
||||||
|
clearable={!definition.required}
|
||||||
|
{...definition}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -326,7 +354,9 @@ export function ApiForm({
|
|||||||
value: field.value,
|
value: field.value,
|
||||||
fieldType: field.type,
|
fieldType: field.type,
|
||||||
required: field.required,
|
required: field.required,
|
||||||
placeholder: field.placeholder
|
placeholder: field.placeholder,
|
||||||
|
api_url: field.api_url,
|
||||||
|
model: field.model
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user