-
Notifications
You must be signed in to change notification settings - Fork 23
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-17655] Two event workspace #3726
Merged
eirikhaugstulen
merged 22 commits into
master
from
eh/feat/DHIS2-17655-two-event-workspace
Aug 14, 2024
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
e03ea54
feat: add plugin functionality
eirikhaugstulen 1b23658
Merge remote-tracking branch 'origin/master' into eh/feat/DHIS2-17591…
eirikhaugstulen 5b5497b
chore: flow
eirikhaugstulen 2504789
feat: support plugins in program stages
eirikhaugstulen e599d05
chore: flow
eirikhaugstulen 5e96878
fix: option set logic
eirikhaugstulen 1cb4612
fix: review
eirikhaugstulen c9aab55
fix: pass in cached element definitions
eirikhaugstulen 5dd3ac6
Merge remote-tracking branch 'refs/remotes/origin/master' into eh/fea…
eirikhaugstulen 0c446d1
chore: temp
eirikhaugstulen ff6e800
Merge remote-tracking branch 'refs/remotes/origin/master' into eh/fea…
eirikhaugstulen 0ed89ce
Merge remote-tracking branch 'refs/remotes/origin/master' into eh/fea…
eirikhaugstulen b44e501
fix: temp
eirikhaugstulen 4e41c05
Merge remote-tracking branch 'refs/remotes/origin/master' into eh/fea…
eirikhaugstulen a0e58b8
feat: add two event workspace functionality
eirikhaugstulen 6a8e097
Merge remote-tracking branch 'refs/remotes/origin/master' into eh/fea…
eirikhaugstulen b25455b
feat: lint
eirikhaugstulen 5561bd5
Merge remote-tracking branch 'refs/remotes/origin/master' into eh/fea…
eirikhaugstulen aea077f
feat: add subvalues
eirikhaugstulen ffcf09d
Merge remote-tracking branch 'refs/remotes/origin/master' into eh/fea…
eirikhaugstulen 97d11ba
chore: remove attribute
eirikhaugstulen 656b471
fix: add fallback for v39 and v40
eirikhaugstulen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...ture-core/components/WidgetTwoEventWorkspace/FlatListOrgUnitField/FlatListOrgUnitField.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,19 @@ | ||
// @flow | ||
import React from 'react'; | ||
import { useOrgUnitName } from '../../../metadataRetrieval/orgUnitName'; | ||
|
||
type Props = { | ||
orgUnitId: string, | ||
} | ||
|
||
export const FlatListOrgUnitField = ({ | ||
orgUnitId, | ||
}: Props) => { | ||
const { displayName } = useOrgUnitName(orgUnitId); | ||
|
||
return ( | ||
<span> | ||
{displayName} | ||
</span> | ||
); | ||
}; |
3 changes: 3 additions & 0 deletions
3
...ore_modules/capture-core/components/WidgetTwoEventWorkspace/FlatListOrgUnitField/index.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,3 @@ | ||
// @flow | ||
|
||
export { FlatListOrgUnitField } from './FlatListOrgUnitField'; |
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
96 changes: 96 additions & 0 deletions
96
...core_modules/capture-core/components/WidgetTwoEventWorkspace/hooks/useClientDataValues.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,96 @@ | ||
// @flow | ||
import { useConfig, useDataEngine } from '@dhis2/app-runtime'; | ||
import { useQuery } from 'react-query'; | ||
import type { RenderFoundation } from '../../../metaData'; | ||
import { convertClientToView, convertServerToClient } from '../../../converters'; | ||
import { buildUrl, pipe } from '../../../../capture-core-utils'; | ||
import { subValueGetterByElementType } from '../utils/getSubValueForDataValue'; | ||
import { makeQuerySingleResource } from '../../../utils/api'; | ||
|
||
type Props = {| | ||
linkedEventId: string, | ||
dataValues: Array<{| dataElement: string, value: any |}>, | ||
formFoundation: ?RenderFoundation, | ||
|} | ||
|
||
const convertFn = pipe(convertServerToClient, convertClientToView); | ||
|
||
const formatDataValues = async ( | ||
dataValues: Array<{| dataElement: string, value: any |}>, | ||
formFoundation: RenderFoundation, | ||
querySingleResource, | ||
linkedEventId, | ||
absoluteApiPath, | ||
) => { | ||
const elements = formFoundation.getElements(); | ||
|
||
const formattedDataValues = dataValues.map(async (dataValue) => { | ||
const element = elements.find(({ id }) => id === dataValue.dataElement); | ||
if (!element) { | ||
return null; | ||
} | ||
|
||
let value = dataValue.value; | ||
// $FlowFixMe - subValueGetterByElementType is only a subset of the full dataElementTypes | ||
if (subValueGetterByElementType[element.type]) { | ||
// $FlowFixMe | ||
value = await subValueGetterByElementType[element.type]({ | ||
dataElement: { | ||
id: element.id, | ||
value: dataValue.value, | ||
}, | ||
querySingleResource, | ||
eventId: linkedEventId, | ||
absoluteApiPath, | ||
}); | ||
} | ||
|
||
return { | ||
id: element.id, | ||
value: convertFn(value, element.type, element), | ||
}; | ||
}); | ||
|
||
const resolvedDataValues = await Promise.all(formattedDataValues); | ||
return resolvedDataValues.reduce((acc, dataValue) => { | ||
if (dataValue) { | ||
acc[dataValue.id] = dataValue.value; | ||
} | ||
return acc; | ||
}, {}); | ||
}; | ||
|
||
export const useClientDataValues = ({ | ||
linkedEventId, | ||
dataValues, | ||
formFoundation, | ||
}: Props) => { | ||
const dataEngine = useDataEngine(); | ||
const { baseUrl, apiVersion } = useConfig(); | ||
const querySingleResource = makeQuerySingleResource(dataEngine.query.bind(dataEngine)); | ||
const { data: clientValuesWithSubValues, isError, isLoading } = useQuery( | ||
['formattedDataValues', linkedEventId, dataValues], | ||
() => formatDataValues( | ||
dataValues, | ||
// $FlowFixMe | ||
formFoundation, | ||
querySingleResource, | ||
linkedEventId, | ||
buildUrl(baseUrl, `api/${apiVersion}`), | ||
), | ||
{ | ||
enabled: !!dataValues && | ||
!!formFoundation && | ||
!!linkedEventId && | ||
!!baseUrl && | ||
!!apiVersion && | ||
!!querySingleResource, | ||
}, | ||
); | ||
|
||
return { | ||
clientValuesWithSubValues, | ||
isError, | ||
isLoading, | ||
}; | ||
}; |
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
60 changes: 60 additions & 0 deletions
60
..._modules/capture-core/components/WidgetTwoEventWorkspace/utils/getSubValueForDataValue.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,60 @@ | ||
// @flow | ||
import { dataElementTypes } from '../../../metaData'; | ||
import type { QuerySingleResource } from '../../../utils/api'; | ||
import { featureAvailable, FEATURES } from '../../../../capture-core-utils'; | ||
|
||
type SubValueFunctionProps = { | ||
dataElement: Object, | ||
querySingleResource: QuerySingleResource, | ||
eventId: string, | ||
absoluteApiPath: string, | ||
} | ||
|
||
const getFileResourceSubvalue = async ({ dataElement, querySingleResource, eventId, absoluteApiPath }: SubValueFunctionProps) => { | ||
const { value } = dataElement; | ||
if (!value) return null; | ||
|
||
const { id, displayName: name } = await querySingleResource({ resource: `fileResources/${value}` }); | ||
return { | ||
id, | ||
name, | ||
url: `${absoluteApiPath}/events/files?dataElementUid=${dataElement.id}&eventUid=${eventId}`, | ||
}; | ||
}; | ||
|
||
const getImageSubvalue = async ({ dataElement, querySingleResource, eventId, absoluteApiPath }: SubValueFunctionProps) => { | ||
const { id: dataElementId, value } = dataElement; | ||
if (!value) return null; | ||
|
||
const { id, displayName: name } = await querySingleResource({ resource: `fileResources/${value}` }); | ||
return { | ||
id, | ||
name, | ||
...(featureAvailable(FEATURES.trackerImageEndpoint) ? | ||
{ | ||
url: `${absoluteApiPath}/tracker/events/${eventId}/dataValues/${dataElementId}/image`, | ||
previewUrl: `${absoluteApiPath}/tracker/events/${eventId}/dataValues/${dataElementId}/image?dimension=small`, | ||
} : { | ||
url: `${absoluteApiPath}/events/files?dataElementUid=${dataElementId}&eventUid=${eventId}`, | ||
previewUrl: `${absoluteApiPath}/events/files?dataElementUid=${dataElementId}&eventUid=${eventId}`, | ||
} | ||
), | ||
}; | ||
}; | ||
|
||
const getOrganisationUnitSubvalue = async ({ dataElement, querySingleResource }: SubValueFunctionProps) => { | ||
const organisationUnit = await querySingleResource({ | ||
resource: 'organisationUnits', | ||
id: dataElement.value, | ||
params: { | ||
fields: 'id,name', | ||
}, | ||
}); | ||
return { ...organisationUnit }; | ||
}; | ||
|
||
export const subValueGetterByElementType = { | ||
[dataElementTypes.FILE_RESOURCE]: getFileResourceSubvalue, | ||
[dataElementTypes.IMAGE]: getImageSubvalue, | ||
[dataElementTypes.ORGANISATION_UNIT]: getOrganisationUnitSubvalue, | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
A reminder that this URL is not working in
2.41
. The fix can be handled along with the rest of the places in DHIS2-17537. Thanks!