diff --git a/src/qqq/components/forms/DynamicForm.tsx b/src/qqq/components/forms/DynamicForm.tsx index 0823648..8c59440 100644 --- a/src/qqq/components/forms/DynamicForm.tsx +++ b/src/qqq/components/forms/DynamicForm.tsx @@ -172,14 +172,10 @@ function QDynamicForm({formData, formLabel, bulkEditMode, bulkEditSwitchChangeHa {labelElement} const qController = Client.getInstance(); -function DynamicSelect({tableName, processName, fieldName, possibleValueSourceName, overrideId, fieldLabel, inForm, initialValue, initialDisplayValue, initialValues, onChange, isEditable, isMultiple, bulkEditMode, bulkEditSwitchChangeHandler, otherValues, variant, initiallyOpen, useCase}: Props) +function DynamicSelect({fieldPossibleValueProps, overrideId, fieldLabel, inForm, initialValue, initialValues, onChange, isEditable, isMultiple, bulkEditMode, bulkEditSwitchChangeHandler, otherValues, variant, initiallyOpen, useCase}: Props) { + const {fieldName, initialDisplayValue, possibleValueSourceName, possibleValues, processName, tableName} = fieldPossibleValueProps; + const [open, setOpen] = useState(initiallyOpen); const [options, setOptions] = useState([]); const [searchTerm, setSearchTerm] = useState(null); @@ -172,6 +166,35 @@ function DynamicSelect({tableName, processName, fieldName, possibleValueSourceNa setFieldValueRef = setFieldValue; } + + /******************************************************************************* + ** + *******************************************************************************/ + const filterInlinePossibleValues = (searchTerm: string, possibleValues: QPossibleValue[]): QPossibleValue[] => + { + return possibleValues.filter(pv => pv.label?.toLowerCase().startsWith(searchTerm)); + } + + + /*************************************************************************** + ** + ***************************************************************************/ + const loadResults = async (): Promise => + { + if(possibleValues) + { + return filterInlinePossibleValues(searchTerm, possibleValues) + } + else + { + return await qController.possibleValues(tableName, processName, possibleValueSourceName ?? fieldName, searchTerm ?? "", null, otherValues, useCase); + } + } + + + /*************************************************************************** + ** + ***************************************************************************/ useEffect(() => { if (firstRender) @@ -195,7 +218,7 @@ function DynamicSelect({tableName, processName, fieldName, possibleValueSourceNa (async () => { // console.log(`doing a search with ${searchTerm}`); - const results: QPossibleValue[] = await qController.possibleValues(tableName, processName, possibleValueSourceName ?? fieldName, searchTerm ?? "", null, otherValues, useCase); + const results: QPossibleValue[] = await loadResults(); if (tableMetaData == null && tableName) { @@ -218,7 +241,10 @@ function DynamicSelect({tableName, processName, fieldName, possibleValueSourceNa }; }, [searchTerm]); - // todo - finish... call it in onOpen? + + /*************************************************************************** + ** todo - finish... call it in onOpen? + ***************************************************************************/ const reloadIfOtherValuesAreChanged = () => { if (JSON.stringify(Object.fromEntries(otherValues)) != otherValuesWhenResultsWereLoaded) @@ -227,8 +253,10 @@ function DynamicSelect({tableName, processName, fieldName, possibleValueSourceNa { setLoading(true); setOptions([]); + console.log("Refreshing possible values..."); - const results: QPossibleValue[] = await qController.possibleValues(tableName, processName, possibleValueSourceName ?? fieldName, searchTerm ?? "", null, otherValues, useCase); + const results: QPossibleValue[] = await loadResults(); + setLoading(false); setOptions([...results]); setOtherValuesWhenResultsWereLoaded(JSON.stringify(Object.fromEntries(otherValues))); @@ -236,6 +264,10 @@ function DynamicSelect({tableName, processName, fieldName, possibleValueSourceNa } }; + + /*************************************************************************** + ** + ***************************************************************************/ const inputChanged = (event: React.SyntheticEvent, value: string, reason: string) => { // console.log(`input changed. Reason: ${reason}, setting search term to ${value}`); @@ -246,11 +278,19 @@ function DynamicSelect({tableName, processName, fieldName, possibleValueSourceNa } }; + + /*************************************************************************** + ** + ***************************************************************************/ const handleBlur = (x: any) => { setSearchTerm(null); }; + + /*************************************************************************** + ** + ***************************************************************************/ const handleChanged = (event: React.SyntheticEvent, value: any | any[], reason: string, details?: string) => { // console.log("handleChanged. value is:"); @@ -274,6 +314,10 @@ function DynamicSelect({tableName, processName, fieldName, possibleValueSourceNa } }; + + /*************************************************************************** + ** + ***************************************************************************/ const filterOptions = (options: { id: any; label: string; }[], state: FilterOptionsState<{ id: any; label: string; }>): { id: any; label: string; }[] => { ///////////////////////////////////////////////////////////////////////////////// @@ -283,6 +327,10 @@ function DynamicSelect({tableName, processName, fieldName, possibleValueSourceNa return (options); }; + + /*************************************************************************** + ** + ***************************************************************************/ // @ts-ignore const renderOption = (props: Object, option: any, {selected}) => { @@ -331,6 +379,10 @@ function DynamicSelect({tableName, processName, fieldName, possibleValueSourceNa ); }; + + /*************************************************************************** + ** + ***************************************************************************/ const bulkEditSwitchChanged = () => { const newSwitchValue = !switchChecked; @@ -351,7 +403,7 @@ function DynamicSelect({tableName, processName, fieldName, possibleValueSourceNa const autocomplete = ( - {!isDisabled &&
{msg}} />
} + {!isDisabled &&
{msg}} />
}
} diff --git a/src/qqq/components/query/FilterCriteriaRowValues.tsx b/src/qqq/components/query/FilterCriteriaRowValues.tsx index 793497a..0e4fa18 100644 --- a/src/qqq/components/query/FilterCriteriaRowValues.tsx +++ b/src/qqq/components/query/FilterCriteriaRowValues.tsx @@ -367,13 +367,11 @@ function FilterCriteriaRowValues({operatorOption, criteria, field, table, valueC ) : ( valueChangeHandler(null, 0, value)} variant="standard" @@ -402,8 +400,7 @@ function FilterCriteriaRowValues({operatorOption, criteria, field, table, valueC } return - + - + diff --git a/src/qqq/components/sharing/ShareModal.tsx b/src/qqq/components/sharing/ShareModal.tsx index 1a83082..2c7e73f 100644 --- a/src/qqq/components/sharing/ShareModal.tsx +++ b/src/qqq/components/sharing/ShareModal.tsx @@ -391,10 +391,9 @@ export default function ShareModal({open, onClose, tableMetaData, record}: Share . + */ + +import {QPossibleValue} from "@kingsrook/qqq-frontend-core/lib/model/QPossibleValue"; + +/******************************************************************************* + ** Properties attached to a (formik?) form field, to denote how it behaves as + ** as related to a possible value source. + *******************************************************************************/ +export interface FieldPossibleValueProps +{ + isPossibleValue?: boolean; + possibleValues?: QPossibleValue[]; + initialDisplayValue: string | null; + fieldName?: string; + tableName?: string; + processName?: string; + possibleValueSourceName?: string; +} + diff --git a/src/qqq/pages/records/query/GridFilterOperators.tsx b/src/qqq/pages/records/query/GridFilterOperators.tsx index c9b9517..fbf7a57 100644 --- a/src/qqq/pages/records/query/GridFilterOperators.tsx +++ b/src/qqq/pages/records/query/GridFilterOperators.tsx @@ -779,11 +779,9 @@ function InputPossibleValueSourceSingle(tableName: string, field: QFieldMetaData }} >