-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: DHIS2-9652 with save buttons #1260
Changes from all commits
684098e
d57dda9
7445483
1816123
4d8001c
5286ddc
1b119d4
73293c0
2cda0b2
7e1a12c
8e1f067
cdea6ec
6d55a6f
d2f3937
8c1caf9
e60d3b6
d3f343c
5b59256
776622a
8c91c49
584c058
f12add8
f428586
6048d42
9d89f52
39558c4
e9faaaa
56517a1
83dcbcd
9022a68
774a28a
e9b0b3f
a9bb19c
33d15b1
3d81661
05dbd79
a7ac966
89c15b9
89b776b
33c730d
ac340f4
34e96a2
5f9e41f
0dcb1f2
331529b
42f41c8
a01b33a
3d6107f
f471b34
1301c33
a43961a
3575dbf
a3dd10a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,70 @@ | ||
// @flow | ||
import React from 'react'; | ||
import React, { type ComponentType } from 'react'; | ||
import { Button } from '@dhis2/ui'; | ||
import { withStyles } from '@material-ui/core'; | ||
import { compose } from 'redux'; | ||
import { useScopeInfo } from '../../../hooks/useScopeInfo'; | ||
import { scopeTypes } from '../../../metaData'; | ||
import { EnrollmentDataEntry } from '../Enrollment'; | ||
import { useCurrentOrgUnitInfo } from '../../../hooks/useCurrentOrgUnitInfo'; | ||
import { useRegistrationFormInfoForSelectedScope } from '../common/useRegistrationFormInfoForSelectedScope'; | ||
import type { OwnProps } from './EnrollmentRegistrationEntry.types'; | ||
import { withSaveHandler } from '../../DataEntry'; | ||
|
||
export const EnrollmentRegistrationEntryComponent = ({ selectedScopeId, id, ...rest }: OwnProps) => { | ||
const { scopeType } = useScopeInfo(selectedScopeId); | ||
const { formId, registrationMetaData, formFoundation } = useRegistrationFormInfoForSelectedScope(selectedScopeId); | ||
const orgUnit = useCurrentOrgUnitInfo(); | ||
const styles = ({ typography }) => ({ | ||
marginTop: { | ||
marginTop: typography.pxToRem(2), | ||
}, | ||
}); | ||
|
||
return ( | ||
<> | ||
{ | ||
scopeType === scopeTypes.TRACKER_PROGRAM && formId && | ||
<EnrollmentDataEntry | ||
orgUnit={orgUnit} | ||
programId={selectedScopeId} | ||
formFoundation={formFoundation} | ||
enrollmentMetadata={registrationMetaData} | ||
id={id} | ||
{...rest} | ||
/> | ||
} | ||
</> | ||
); | ||
}; | ||
const EnrollmentRegistrationEntryPlain = | ||
({ | ||
id, | ||
selectedScopeId, | ||
enrollmentMetadata, | ||
saveButtonText, | ||
classes, | ||
onSave, | ||
...rest | ||
}: {...OwnProps, ...CssClasses}) => { | ||
const { scopeType } = useScopeInfo(selectedScopeId); | ||
const { formId, formFoundation } = useRegistrationFormInfoForSelectedScope(selectedScopeId); | ||
const orgUnit = useCurrentOrgUnitInfo(); | ||
|
||
return ( | ||
<> | ||
{ | ||
scopeType === scopeTypes.TRACKER_PROGRAM && formId && | ||
<> | ||
{/* $FlowFixMe */} | ||
<EnrollmentDataEntry | ||
orgUnit={orgUnit} | ||
programId={selectedScopeId} | ||
formFoundation={formFoundation} | ||
enrollmentMetadata={enrollmentMetadata} | ||
id={id} | ||
{...rest} | ||
/> | ||
{ | ||
onSave && | ||
<Button | ||
dataTest="dhis2-capture-create-and-link-button" | ||
primary | ||
onClick={onSave} | ||
className={classes.marginTop} | ||
> | ||
{saveButtonText} | ||
</Button> | ||
Comment on lines
+49
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Displaying the buttons only when there is an onSave function. I dont know what is your preference on this one. To my eyes using HOC component to display the buttons in this case seems kind of an overkill. Dont get me wrong HOC are great but I would use them in cases we want to share something between multiple components like you do on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, this is fine 👍 |
||
} | ||
|
||
</> | ||
} | ||
</> | ||
); | ||
}; | ||
|
||
export const EnrollmentRegistrationEntryComponent: ComponentType<OwnProps> = | ||
compose( | ||
withSaveHandler({ onGetFormFoundation: ({ enrollmentMetadata }) => enrollmentMetadata && enrollmentMetadata.enrollmentForm }), | ||
withStyles(styles), | ||
)(EnrollmentRegistrationEntryPlain); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
// @flow | ||
import type { RenderFoundation } from '../../../metaData/RenderFoundation'; | ||
import type { RegistrationFormMetadata } from '../common/types'; | ||
|
||
export type OwnProps = $ReadOnly<{| | ||
id: string, | ||
enrollmentMetadata: RegistrationFormMetadata, | ||
selectedScopeId: string, | ||
id: string | ||
saveButtonText: string, | ||
fieldOptions?: Object, | ||
onSave: (dataEntryId: string, itemId: string, formFoundation: RenderFoundation) => void, | ||
onPostProcessErrorMessage: Function, | ||
onGetUnsavedAttributeValues: Function, | ||
onUpdateField: Function, | ||
onStartAsyncUpdateField: Function, | ||
Comment on lines
+6
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am attempting to explicitly define the properties this components needs in order to be rendered. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, makes sense 👍 I did the same for the working lists. Let's settle on name though. I think I called it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point @JoakimSM. Yep for me the naming here is under discussion as well. Eg.
On the example above Again I agree we would like to align on a name here. I stole my name from the redux world, look here. Now if we agree on communicating the same thing we can be creative with a name. What do you think, would you find it useful to differentiate between the props that we pass on the component and the props that the component takes from redux? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for explaining. Our use cases are a bit different. |
||
|}> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,78 @@ | ||
// @flow | ||
import React from 'react'; | ||
import React, { type ComponentType } from 'react'; | ||
import { compose } from 'redux'; | ||
import { Button } from '@dhis2/ui'; | ||
import { withStyles } from '@material-ui/core'; | ||
import { useScopeInfo } from '../../../hooks/useScopeInfo'; | ||
import { scopeTypes } from '../../../metaData'; | ||
import { TrackedEntityInstanceDataEntry } from '../TrackedEntityInstance'; | ||
import { useCurrentOrgUnitInfo } from '../../../hooks/useCurrentOrgUnitInfo'; | ||
import type { OwnProps } from './TeiRegistrationEntry.types'; | ||
import { useRegistrationFormInfoForSelectedScope } from '../common/useRegistrationFormInfoForSelectedScope'; | ||
import { withSaveHandler } from '../../DataEntry'; | ||
|
||
|
||
export const TeiRegistrationEntryComponent = ({ selectedScopeId, id, ...rest }: OwnProps) => { | ||
const { scopeType } = useScopeInfo(selectedScopeId); | ||
const { formId, registrationMetaData, formFoundation } = useRegistrationFormInfoForSelectedScope(selectedScopeId); | ||
const orgUnit = useCurrentOrgUnitInfo(); | ||
const styles = ({ typography }) => ({ | ||
marginTop: { | ||
marginTop: typography.pxToRem(2), | ||
}, | ||
}); | ||
const TeiRegistrationEntryPlain = | ||
({ | ||
id, | ||
selectedScopeId, | ||
onSave, | ||
saveButtonText, | ||
teiRegistrationMetadata, | ||
fieldOptions, | ||
classes, | ||
onPostProcessErrorMessage, | ||
onGetUnsavedAttributeValues, | ||
...rest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: passOnProps |
||
}: { ...OwnProps, ...CssClasses }) => { | ||
const { scopeType } = useScopeInfo(selectedScopeId); | ||
const { formId, formFoundation } = useRegistrationFormInfoForSelectedScope(selectedScopeId); | ||
const orgUnit = useCurrentOrgUnitInfo(); | ||
|
||
return ( | ||
<> | ||
{ | ||
scopeType === scopeTypes.TRACKED_ENTITY_TYPE && formId && | ||
<TrackedEntityInstanceDataEntry | ||
orgUnit={orgUnit} | ||
formFoundation={formFoundation} | ||
programId={selectedScopeId} | ||
teiRegistrationMetadata={registrationMetaData} | ||
id={id} | ||
{...rest} | ||
/> | ||
} | ||
</> | ||
); | ||
}; | ||
return ( | ||
<> | ||
{ | ||
scopeType === scopeTypes.TRACKED_ENTITY_TYPE && formId && | ||
<> | ||
{/* $FlowFixMe */} | ||
<TrackedEntityInstanceDataEntry | ||
orgUnit={orgUnit} | ||
formFoundation={formFoundation} | ||
programId={selectedScopeId} | ||
teiRegistrationMetadata={teiRegistrationMetadata} | ||
id={id} | ||
fieldOptions={fieldOptions} | ||
onPostProcessErrorMessage={onPostProcessErrorMessage} | ||
onGetUnsavedAttributeValues={onGetUnsavedAttributeValues} | ||
{...rest} | ||
/> | ||
{ | ||
onSave && | ||
<Button | ||
dataTest="dhis2-capture-create-and-link-button" | ||
primary | ||
onClick={onSave} | ||
className={classes.marginTop} | ||
> | ||
{saveButtonText} | ||
</Button> | ||
} | ||
</> | ||
} | ||
</> | ||
); | ||
}; | ||
|
||
export const TeiRegistrationEntryComponent: ComponentType<OwnProps> = | ||
compose( | ||
withSaveHandler({ onGetFormFoundation: ({ teiRegistrationMetadata }) => { | ||
const form = teiRegistrationMetadata && teiRegistrationMetadata.form; | ||
return form; | ||
} }), | ||
withStyles(styles), | ||
)(TeiRegistrationEntryPlain); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
// @flow | ||
import type { RenderFoundation } from '../../../metaData/RenderFoundation'; | ||
import type { RegistrationFormMetadata } from '../common/types'; | ||
|
||
export type OwnProps = $ReadOnly<{| | ||
id: string, | ||
teiRegistrationMetadata: RegistrationFormMetadata, | ||
selectedScopeId: string, | ||
id: string | ||
saveButtonText: string, | ||
fieldOptions?: Object, | ||
onSave: (dataEntryId: string, itemId: string, formFoundation: RenderFoundation) => void, | ||
onGetUnsavedAttributeValues: Function, | ||
onPostProcessErrorMessage: Function, | ||
|}> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// @flow | ||
import type { TeiRegistration } from '../../../metaData/TrackedEntityType/TeiRegistration'; | ||
import type { Enrollment } from '../../../metaData/Program/Enrollment'; | ||
|
||
export type RegistrationFormMetadata = ?(TeiRegistration | Enrollment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: passOnProps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I will make a PR in the end renaming all the
rest
toonProps
.