-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use interpretations component from Analytics (DHIS2-15441) (#2430)
- Loading branch information
1 parent
c3110d8
commit 3550cfa
Showing
8 changed files
with
195 additions
and
635 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
111 changes: 111 additions & 0 deletions
111
src/components/Item/VisualizationItem/InterpretationReplyForm.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,111 @@ | ||
import { InterpretationThread } from '@dhis2/analytics' | ||
import { useDataQuery } from '@dhis2/app-runtime' | ||
import i18n from '@dhis2/d2-i18n' | ||
import { | ||
Layer, | ||
CenteredContent, | ||
CircularLoader, | ||
Button, | ||
IconChevronLeft16, | ||
spacers, | ||
} from '@dhis2/ui' | ||
import PropTypes from 'prop-types' | ||
import React, { useEffect } from 'react' | ||
|
||
const query = { | ||
interpretation: { | ||
resource: 'interpretations', | ||
id: ({ id }) => id, | ||
params: { | ||
fields: [ | ||
'access', | ||
'id', | ||
'text', | ||
'created', | ||
'createdBy[id, displayName]', | ||
'user[id,displayName]', | ||
'likes', | ||
'likedBy', | ||
'comments[access,id,text,created,createdBy[id,displayName]]', | ||
], | ||
}, | ||
}, | ||
} | ||
|
||
export const InterpretationReplyForm = ({ | ||
currentUser, | ||
interpretationId, | ||
onGoBackClicked, | ||
onInterpretationDeleted, | ||
dashboardRedirectUrl, | ||
initialFocus, | ||
}) => { | ||
const { data, refetch, loading, fetching } = useDataQuery(query, { | ||
lazy: true, | ||
}) | ||
const interpretation = data?.interpretation | ||
|
||
useEffect(() => { | ||
if (interpretationId) { | ||
refetch({ id: interpretationId }) | ||
} | ||
}, [interpretationId, refetch]) | ||
|
||
const onThreadUpdated = () => refetch({ id: interpretationId }) | ||
|
||
if (loading || !interpretation) { | ||
return ( | ||
<Layer> | ||
<CenteredContent> | ||
<CircularLoader /> | ||
</CenteredContent> | ||
</Layer> | ||
) | ||
} | ||
|
||
return ( | ||
<div | ||
style={{ | ||
padding: `${spacers.dp16} ${spacers.dp16} ${spacers.dp32} ${spacers.dp16}`, | ||
}} | ||
> | ||
<div | ||
style={{ | ||
marginBottom: spacers.dp8, | ||
}} | ||
> | ||
<Button | ||
small | ||
icon={<IconChevronLeft16 />} | ||
onClick={onGoBackClicked} | ||
> | ||
{i18n.t('Back to all interpretations')} | ||
</Button> | ||
</div> | ||
<InterpretationThread | ||
currentUser={currentUser} | ||
fetching={fetching} | ||
interpretation={interpretation} | ||
onInterpretationDeleted={onInterpretationDeleted} | ||
onThreadUpdated={onThreadUpdated} | ||
initialFocus={initialFocus} | ||
dashboardRedirectUrl={dashboardRedirectUrl} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
InterpretationReplyForm.displayName = 'InterpretationReplyForm' | ||
|
||
InterpretationReplyForm.defaultProps = { | ||
onInterpretationDeleted: Function.prototype, | ||
} | ||
|
||
InterpretationReplyForm.propTypes = { | ||
currentUser: PropTypes.object.isRequired, | ||
interpretationId: PropTypes.string.isRequired, | ||
onGoBackClicked: PropTypes.func.isRequired, | ||
dashboardRedirectUrl: PropTypes.string, | ||
initialFocus: PropTypes.bool, | ||
onInterpretationDeleted: PropTypes.func, | ||
} |
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 |
---|---|---|
|
@@ -16,5 +16,5 @@ | |
.scrollContainer { | ||
position: relative; | ||
overflow-y: auto; | ||
height: 334px; | ||
height: 376px; | ||
} |
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
Oops, something went wrong.