diff --git a/src/components/metadataFormControls/CategoryComboSelect/CategoryComboSelect.tsx b/src/components/metadataFormControls/CategoryComboSelect/CategoryComboSelect.tsx index c213c760..45d6b5b1 100644 --- a/src/components/metadataFormControls/CategoryComboSelect/CategoryComboSelect.tsx +++ b/src/components/metadataFormControls/CategoryComboSelect/CategoryComboSelect.tsx @@ -1,4 +1,3 @@ -import i18n from '@dhis2/d2-i18n' import React, { useCallback } from 'react' import { DEFAULT_CATEGORY_COMBO } from '../../../lib' import { PlainResourceQuery } from '../../../types' diff --git a/src/components/metadataFormControls/ModelSingleSelect/BaseModelSingleSelect.tsx b/src/components/metadataFormControls/ModelSingleSelect/BaseModelSingleSelect.tsx index b60d905b..e87635d4 100644 --- a/src/components/metadataFormControls/ModelSingleSelect/BaseModelSingleSelect.tsx +++ b/src/components/metadataFormControls/ModelSingleSelect/BaseModelSingleSelect.tsx @@ -1,6 +1,6 @@ import i18n from '@dhis2/d2-i18n' import React, { useCallback, useMemo } from 'react' -import { DisplayableModel, PartialLoadedDisplayableModel } from '../../../types/models' +import { PartialLoadedDisplayableModel } from '../../../types/models' import { SearchableSingleSelect, SearchableSingleSelectPropTypes, @@ -16,7 +16,7 @@ type OwnProps = { selected?: TModel available: TModel[] onChange: (selected: TModel | undefined) => void - noValueOption?: { value: string; label: string } | boolean + showNoValueOption?: { value: string; label: string } | boolean } export type BaseModelSingleSelectProps = Omit< @@ -30,7 +30,7 @@ export const BaseModelSingleSelect = ) => { const { allModelsMap, allSingleSelectOptions } = useMemo(() => { @@ -42,21 +42,20 @@ export const BaseModelSingleSelect = toDisplayOption(value) ) - if (noValueOption) { - const option = noValueOption === true ? { value: '', label: i18n.t('') } : noValueOption - allSingleSelectOptions.unshift(option) + if (showNoValueOption) { + allSingleSelectOptions.unshift({ value: '', label: i18n.t('') }) } return { allModelsMap, allSingleSelectOptions, } - }, [available, selected, noValueOption]) + }, [available, selected, showNoValueOption]) const handleOnChange: SearchableSingleSelectPropTypes['onChange'] = useCallback( ({ selected }) => { - // map the selected ids to the full model + // map the selected id to the full model const fullSelectedModel = allModelsMap.get(selected) onChange(fullSelectedModel) }, diff --git a/src/components/metadataFormControls/ModelSingleSelect/ModelSingleSelect.tsx b/src/components/metadataFormControls/ModelSingleSelect/ModelSingleSelect.tsx index d8f756fd..de0987eb 100644 --- a/src/components/metadataFormControls/ModelSingleSelect/ModelSingleSelect.tsx +++ b/src/components/metadataFormControls/ModelSingleSelect/ModelSingleSelect.tsx @@ -73,9 +73,10 @@ export const ModelSingleSelect = < lastPage.pager.nextPage ? lastPage.pager.page + 1 : undefined, getPreviousPageParam: (firstPage) => firstPage.pager.prevPage ? firstPage.pager.page - 1 : undefined, + staleTime: 60 * 1000, }) - const shouldFetchSelected = selected && selected.displayName === undefined + const shouldFetchSelected = !!selected && selected.displayName === undefined // if we just have the ID - fetch the displayName const selectedQuery = useQuery({ queryKey: [