-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
59 additions
and
55 deletions.
There are no files selected for viewing
68 changes: 33 additions & 35 deletions
68
src/components/metadataFormControls/CategoryComboSelect/CategoryComboSelect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,39 @@ | ||
import i18n from '@dhis2/d2-i18n' | ||
import React, { forwardRef } from 'react' | ||
import { ModelSingleSelect } from '../ModelSingleSelect/ModelSingleSelectRefactor' | ||
import type { ModelSingleSelectProps } from '../ModelSingleSelect/ModelSingleSelectRefactor' | ||
import { useInitialOptionQuery } from './useInitialOptionQuery' | ||
import { useOptionsQuery } from './useOptionsQuery' | ||
import React from 'react' | ||
import { PlainResourceQuery } from '../../../types' | ||
import { CategoryCombo } from '../../../types/generated' | ||
import { DisplayableModel } from '../../../types/models' | ||
import { | ||
ModelSingleSelect, | ||
ModelSingleSelectProps, | ||
} from '../ModelSingleSelect/ModelSingleSelectRefactor' | ||
|
||
type CategoryComboSelectProps = ModelSingleSelectProps<DisplayableModel> & { | ||
required?: boolean | ||
export const categoryCombosSelectQuery = { | ||
resource: 'categoryCombos', | ||
params: { | ||
filter: 'isDefault:eq:false', | ||
fields: ['id', 'displayName'], | ||
}, | ||
} as const satisfies PlainResourceQuery | ||
|
||
type CategoryComboSelectProps<TCategoryCombo extends DisplayableModel> = Omit< | ||
ModelSingleSelectProps<TCategoryCombo>, | ||
'query' | ||
> & { | ||
query?: PlainResourceQuery | ||
} | ||
export const CategoryComboSelect = forwardRef(function CategoryComboSelect( | ||
{ | ||
onChange, | ||
invalid, | ||
disabled, | ||
placeholder = i18n.t('Category combo'), | ||
required, | ||
selected, | ||
showAllOption, | ||
onBlur, | ||
onFocus, | ||
}: CategoryComboSelectProps, | ||
ref | ||
) { | ||
|
||
export const CategoryComboSelect = < | ||
TCategoryCombo extends Partial<CategoryCombo> & DisplayableModel = Pick< | ||
CategoryCombo, | ||
'id' | 'displayName' | ||
> | ||
>({ | ||
query, | ||
...modelSingleSelectProps | ||
}: CategoryComboSelectProps<TCategoryCombo>) => { | ||
const resolvedQuery = query ?? categoryCombosSelectQuery | ||
return ( | ||
<ModelSingleSelect | ||
required={required} | ||
invalid={invalid} | ||
disabled={disabled} | ||
useInitialOptionQuery={useInitialOptionQuery} | ||
useOptionsQuery={useOptionsQuery} | ||
placeholder={placeholder} | ||
showAllOption={showAllOption} | ||
onChange={onChange} | ||
selected={selected} | ||
onBlur={onBlur} | ||
onFocus={onFocus} | ||
/> | ||
<ModelSingleSelect {...modelSingleSelectProps} query={resolvedQuery} /> | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './useInfiniteDataQuery' | ||
export { useBoundQueryFn } from './useBoundQueryFn' | ||
export { createBoundQueryFn } from './createBoundQueryFn' | ||
export { mergePlainResourceQueries } from './mergeQuery' | ||
Check failure on line 4 in src/lib/query/index.ts GitHub Actions / build
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters