feat(comments): visual indicator for data values with comments#164
feat(comments): visual indicator for data values with comments#164ifoche wants to merge 5 commits intodevelopmentfrom
Conversation
…with comments Add comment field to DataValueBase and extract it from the DHIS2 API response. CommentIcon now shows a green dot badge when the associated data value has a comment, threaded through DataElementItem. Enabled by default for all datasets with no configuration needed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
BundleMonNo change in files bundle size Groups updated (1)
Final result: ✅ View report in BundleMon website ➡️ |
- Extract hasComment() to domain utility in DataValue.ts (single source of truth, tested via production code not test-local copy) - Guard data value lookup behind !noComment to skip wasted work when comment icon is not rendered - Make hasComment a required boolean prop on CommentIcon - Remove unnecessary explicit comment: undefined from fixture Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove display:flex from CommentIcon wrapper that was inflating the icon size. Remove temporary console.log debug statements from the repository. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| period: Period; | ||
| categoryOptionComboId: Id; | ||
| isRequired?: boolean; | ||
| comment?: string; |
There was a problem hiding this comment.
I think making comment an optional parameter could lead to unexpected errors. In this case we're not assigning the comment property in the method checkCompulsoryAndBuildDataValues in file Dhis2DataValueRepository.
Also it protect us if we forgot to pass the comment any time we need to use the dataValue entity. We can add the fallback to an empty string as a default value.
| } | ||
|
|
||
| export function hasComment(dataValue: Pick<DataValueBase, "comment">): boolean { | ||
| return !!dataValue.comment; |
There was a problem hiding this comment.
Subjective, but I prefer dataValue.comment.length > 0 or Boolean(dataValue.comment).
| !noComment && | ||
| dataValueHasComment( | ||
| dataFormInfo.data.values.getOrEmpty(dataElement, { | ||
| orgUnitId: dataFormInfo.orgUnitId, |
There was a problem hiding this comment.
For orgUnitId it should be dataElement.orgUnit || dataFormInfo.orgUnitId. It will cover the case for the subnational dataSet where we need to save dataValues in a different orgUnit than the selected in the dataEntry.
Also using React.memo for the hasComment variable would be good.
- Make `comment` a required string (default "") on DataValueBase instead of optional, preventing missing-comment bugs in new code paths - Introduce DataValueLookup type for store get/getOrEmpty so callers don't need to pass comment for lookups - Use `dataValue.comment.length > 0` instead of `!!` in hasComment - Fix orgUnitId in DataElementItem to use dataElement.orgUnit fallback for subnational datasets - Wrap hasComment computation in React.useMemo - Update test fixtures and assertions to match new empty-string default Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@eperedo Thanks for the review! All three points have been addressed in e3aa009:
|
eperedo
left a comment
There was a problem hiding this comment.
Looks good, just a couple of things related to TS.
| | DataValueMultiText; | ||
|
|
||
| export type DataValueLookup = Pick<DataValueBase, "orgUnitId" | "period" | "categoryOptionComboId"> & | ||
| Partial<Pick<DataValueBase, "comment" | "isRequired">>; |
There was a problem hiding this comment.
The new type DataValueLookup is correct, but we don't need the comment or isRequired in the methods: get, getOrEmpty or getEmpty.
I think export type DataValueLookup = Pick<DataValueBase, "orgUnitId" | "period" | "categoryOptionComboId"> is enough, right?
| ): DataValue { | ||
| const resolvedDataElement = resolveDataElement(dataFormInfo, dataElement); | ||
| const dataValueBase: DataValueBase = { | ||
| const dataValueBase = { |
There was a problem hiding this comment.
And here we can use const dataValueBase: DataValueLookup = { ... } instead removing the type. Just to be extra safe in case we modify the object in the future with the type TS will yell at us if we introduce a wrong property.
Summary
commentfield toDataValueBaseand extracts it from the DHIS2 API response (already returned but previously discarded)CommentIconnow shows a small green dot badge when the data value has an existing commentDataElementItem— all form types (table, grid, grid-with-periods, etc.) inherit the indicator automaticallyCommentIndicator.spec.tsRelated Tasks
Test plan
yarn test— all 47 tests passyarn tsc --noEmit— no type errorsyarn lint— clean🤖 Generated with Claude Code