-
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.
chore: add selected values to existing queueables
- Loading branch information
ismay
committed
Jul 19, 2023
1 parent
7817038
commit 3f74f67
Showing
8 changed files
with
85 additions
and
13 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/components/FormFields/SequenceOrderField/SequenceOrderEditField.js
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,50 @@ | ||
import React from 'react' | ||
import { ReactFinalForm, CircularLoader, NoticeBox } from '@dhis2/ui' | ||
import i18n from '@dhis2/d2-i18n' | ||
import { jobTypesMap } from '../../../services/server-translations' | ||
import { useQueueables } from '../../../hooks/queueables' | ||
import SequenceTransfer from './SequenceTransfer' | ||
|
||
const { Field } = ReactFinalForm | ||
|
||
// The key under which this field will be sent to the backend | ||
const FIELD_NAME = 'sequence' | ||
const hasEnoughJobs = (value) => | ||
value?.length > 1 ? undefined : i18n.t('Please select at least two jobs') | ||
|
||
const SequenceOrderEditField = ({ selectedValues }) => { | ||
const { loading, error, data } = useQueueables() | ||
|
||
if (loading) { | ||
return <CircularLoader /> | ||
} | ||
|
||
if (error) { | ||
return ( | ||
<NoticeBox | ||
error | ||
title={i18n.t( | ||
'Something went wrong whilst fetching the queueable jobs' | ||
)} | ||
/> | ||
) | ||
} | ||
|
||
// The selected values aren't part of the queueables, so we need to add them | ||
const options = data.concat(selectedValues).map(({ name, id, type }) => ({ | ||
label: name, | ||
value: id, | ||
type: jobTypesMap[type], | ||
})) | ||
|
||
return ( | ||
<Field | ||
name={FIELD_NAME} | ||
component={SequenceTransfer} | ||
options={options} | ||
validate={hasEnoughJobs} | ||
/> | ||
) | ||
} | ||
|
||
export default SequenceOrderEditField |
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 +1,2 @@ | ||
export { default } from './SequenceOrderField' | ||
export { default as SequenceOrderField} from './SequenceOrderField' | ||
export { default as SequenceOrderEditField} from './SequenceOrderEditField' |
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
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