-
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.
feat: add all setup fields plus dummy placeholders to required fields
- Loading branch information
Showing
13 changed files
with
181 additions
and
65 deletions.
There are no files selected for viewing
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
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
56 changes: 56 additions & 0 deletions
56
src/components/metadataFormControls/CategoryComboSelect/useInitialCategoryComboQuery.ts
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { useDataQuery } from '@dhis2/app-runtime' | ||
import { useRef } from 'react' | ||
import { DEFAULT_CATEGORY_COMBO } from '../../../lib' | ||
import { SelectOption } from '../../../types' | ||
import { FilteredCategoryCombo } from './types' | ||
|
||
type InitialCategoryComboQueryResult = { | ||
categoryCombo: FilteredCategoryCombo | ||
} | ||
|
||
const INITIAL_CATEGORY_COMBO_QUERY = { | ||
categoryCombo: { | ||
resource: 'categoryCombos', | ||
id: (variables: Record<string, string>) => variables.id, | ||
params: (variables: Record<string, string>) => { | ||
const params = { | ||
fields: ['id', 'displayName'], | ||
} | ||
|
||
if (variables.filter?.dataDimensionType) { | ||
params.filter = [ | ||
...params.filter, | ||
`dataDimensionType:eq:${variables.filter.dataDimensionType}`, | ||
] | ||
} | ||
|
||
return params | ||
}, | ||
}, | ||
} | ||
|
||
export function useInitialCategoryComboQuery({ | ||
selected, | ||
onComplete, | ||
filter, | ||
}: { | ||
onComplete: (option: SelectOption) => void | ||
selected?: string | ||
filter?: Record<string, string> | ||
}) { | ||
const initialSelected = useRef(selected) | ||
return useDataQuery<InitialCategoryComboQueryResult>( | ||
INITIAL_CATEGORY_COMBO_QUERY, | ||
{ | ||
lazy: | ||
!initialSelected.current || | ||
initialSelected.current === DEFAULT_CATEGORY_COMBO.id, | ||
variables: { id: selected, filter }, | ||
onComplete: (data) => { | ||
const categoryCombo = data.categoryCombo | ||
const { id: value, displayName: label } = categoryCombo | ||
onComplete({ value, label }) | ||
}, | ||
} | ||
) | ||
} |
40 changes: 0 additions & 40 deletions
40
src/components/metadataFormControls/CategoryComboSelect/useInitialOptionQuery.ts
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import i18n from '@dhis2/d2-i18n' | ||
import { Field, InputFieldFF } from '@dhis2/ui' | ||
import React from 'react' | ||
import { Field as FieldRFF, useField } from 'react-final-form' | ||
|
||
export function CategoryComboField() { | ||
const validate = () => {} | ||
const { input, meta } = useField('categoryCombo', { | ||
validateFields: [], | ||
validate, | ||
format: (categoryCombo) => categoryCombo && categoryCombo.id, | ||
parse: (id) => ({ id }), | ||
}) | ||
return ( | ||
<FieldRFF<string | undefined> | ||
component={InputFieldFF} | ||
inputWidth="400px" | ||
label={i18n.t('{{fieldLabel}} (required)', { | ||
fieldLabel: i18n.t('Category combination'), | ||
})} | ||
name="categoryCombo.id" | ||
/> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import i18n from '@dhis2/d2-i18n' | ||
import { InputFieldFF } from '@dhis2/ui' | ||
import React from 'react' | ||
import { Field as FieldRFF, useField } from 'react-final-form' | ||
|
||
export function PeriodTypeField() { | ||
const validate = () => {} | ||
const { input, meta } = useField('categoryCombo', { | ||
validateFields: [], | ||
validate, | ||
format: (categoryCombo) => categoryCombo && categoryCombo.id, | ||
parse: (id) => ({ id }), | ||
}) | ||
return ( | ||
<FieldRFF<string | undefined> | ||
component={InputFieldFF} | ||
inputWidth="400px" | ||
label={i18n.t('Period type')} | ||
name="periodType" | ||
/> | ||
|
||
// <Field | ||
// required | ||
// name="periodType" | ||
// label={i18n.t('{{fieldLabel}} (required)', { | ||
// fieldLabel: i18n.t('Period type'), | ||
// })} | ||
// error={meta.touched && !!meta.error} | ||
// validationText={meta.touched ? meta.error : undefined} | ||
// > | ||
// | ||
// <ModelSingleSelect | ||
// required | ||
// useInitialOptionQuery={useInitialCategoryComboQuery} | ||
// useOptionsQuery={useCategoryCombosQuery} | ||
// invalid={meta.touched && !!meta.error} | ||
// selected={input.value} | ||
// onChange={({ selected }) => { | ||
// input.onChange(selected) | ||
// input.onBlur() | ||
// }} | ||
// onBlur={input.onBlur} | ||
// onFocus={input.onFocus} | ||
// /> | ||
// </Field> | ||
) | ||
} |
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