Project: workspace-doctolib · Branch: HEAD · Mode: ` · **Model:**claude-opus-4-7`
Stats: 1 user messages, 29 tool calls, tools used: Bash, Read, Write.
Conversation
Turn 1 — User
Simplify the recently modified code in the treatment-plan repository for PR https://github.com/doctolib/treatment-plan/pull/3085
Worktree: /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/
Focus on the two changed files:
1. packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.tsx
2. packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx
Get the diff:
cd /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter && git diff main...HEAD
Apply simplifications for clarity, consistency, and maintainability while preserving all functionality. Run lint and tests after any changes to verify.
Turn 1 — Assistant
I'll analyze the recently modified code in the PR and apply simplifications. Let me start by examining the diff and the files.
Tools used:
Bash:cd /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/ && git diff main...HEAD
Tool results:
→ result (ok): <persisted-output> Output too large (476.7KB). Full output saved to: /Users/USER/.claude/projects/-Users-clertonra-workspace-doctolib/116b5e84-4b1c-4396-986a-6677b6aff27f/tool-results/ba948i2s6.txt
Preview (first 2KB): diff --git a/.claude/skills/delegate/PROMPT_TEMPLATE.md b/.claude/skills/delegate/PROMPT_TEMPLATE.md index 9d33a5475..77c46999f 100644 --- a/.claude/skills/delegate/PROMPT_TEMPLATE.md +++ b/.claude/skills/delegate/PROMPT_TEMPLATE.md @@ -13,6 +13,13 @@ If your task references a JI …(truncated, 1718 more chars)
Let me look at the specific files that need to be reviewed.
Tools used:
Bash:cd /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/ && git diff main...HEAD -- 'packages/tpf-national-health-records-ui/src/business/factories/filters/ …(truncated, 166 more chars)
Tool results:
→ result (ok): diff --git a/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx b/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx index 6ebba9269..00fd4cdbd 100644 --- a/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx +++ b/packages/tpf-national-health-records-ui/src/business/factories/filters/createNh …(truncated, 4677 more chars)
Now let me view the full files to understand the context.
Tools used:
Read:/Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.tsx
Tool results:
→ result (ok): 1 import { NhrDocumentVisibilityFilter } from '../../../components/NhrDocumentVisibilityFilter/NhrDocumentVisibilityFilter'
2 import type { FilterConfig, VisibilityOption } from '../../../types'
3
4 type VisibilityModeConfig = VisibilityOption & { isExclusive?: boolean }
5
6 type CreateNhrDocumentVisibilityFilterConfigOptions = {
7 groupLabel: string
8 visibilityModes: VisibilityModeConfig[]
9 }
10
11 export const createNhrDocumentVisibilityFilterConfig = ({
12 groupLabel,
13 visibili
…(truncated, 1247 more chars)
Tools used:
Read:/Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx
Tool results:
→ result (ok): 1 import { setup } from '@doctolib/test-helpers'
2 import { screen } from '@testing-library/react'
3 import { describe, expect, it, vi } from 'vitest'
4
5 import { mockPatientInfo } from '../../../test-helpers'
6 import { createNhrDocumentVisibilityFilterConfig } from './createNhrDocumentVisibilityFilterConfig'
7
8 const ctx = { patient: mockPatientInfo }
9
10 const defaultOptions = {
11 groupLabel: 'Document visibility',
12 visibilityModes: [
13 { filterKey: 'hiddenFromPatient', labe
…(truncated, 3915 more chars)
Now let me look at the related component to understand the full context.
Tools used:
Bash:find /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/components/NhrDocumentVisibilityFilter -type f 2>/dev/ …(truncated, 4 more chars)
Tool results:
→ result (ok): /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/components/NhrDocumentVisibilityFilter/NhrDocumentVisibilityFilter.test.tsx /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/components/NhrDocumentVisibilityFilter/NhrDocumentVisibilityFilter.tsx /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to- …(truncated, 133 more chars)
Tools used:
Read:/Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/components/NhrDocumentVisibilityFilter/NhrDocumentVisibilityFilter.tsx
Tool results:
→ result (ok): 1 import { Checkbox } from '@doctolib/design-system/Checkbox/v2'
2 import { Heading } from '@doctolib/design-system/Heading'
3
4 import type { VisibilityOption } from '../../types'
5
6 export type NhrDocumentVisibilityFilterProps = {
7 groupLabel: string
8 visibilityModes: VisibilityOption[]
9 filters: Record<string, boolean>
10 onChange: (filterKey: string, checked: boolean) => void
11 }
12
13 export const NhrDocumentVisibilityFilter = ({
14 groupLabel,
15 visibilityModes,
16 f
…(truncated, 600 more chars)
Tools used:
Bash:find /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/types -type f 2>/dev/null && grep -r "VisibilityOption …(truncated, 186 more chars)
Tool results:
→ result (ERROR): Exit code 1
Tools used:
Bash:find /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src -name "types*" -o -name "*.types.*" 2>/dev/null | head …(truncated, 4 more chars)
Tool results:
→ result (ok): /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/types.ts
Tools used:
Read:/Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/types.ts
Tool results:
→ result (ok): 1 import type { DesignSystemIconComponent } from '@doctolib/design-system-icons'
2 import type { NhrDocument, NhrResultStatus } from '@doctolib/tpf-national-health-records'
3 import type { ReactNode } from 'react'
4
5 export type NhrPatientInfo = {
6 fullName: string
7 gender: 'male' | 'female' | 'other'
8 birthDate: string
9 age: number
10 }
11
12 export type ColumnConfig = {
13 key: string
14 header: string
15 sortable: boolean
16 /** Only required when sortable: true. Return
…(truncated, 3703 more chars)
Now I have full context. Let me also check the related tests and similar factory files for patterns.
Tools used:
Bash:ls /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/business/factories/filters/
Tool results:
→ result (ok): createNhrDateSelectionFilterConfig.test.tsx createNhrDateSelectionFilterConfig.tsx createNhrDocumentCategoryFilterConfig.test.tsx createNhrDocumentCategoryFilterConfig.tsx createNhrDocumentStatusFilterConfig.test.tsx createNhrDocumentStatusFilterConfig.tsx createNhrDocumentVisibilityFilterConfig.test.tsx createNhrDocumentVisibilityFilterConfig.tsx
Tools used:
Read:/Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentStatusFilterConfig.tsx
Tool results:
→ result (ok): 1 import { NhrDocumentStatusFilter } from '../../../components/NhrDocumentList/NhrDocumentStatusFilter/NhrDocumentStatusFilter'
2 import type { FilterConfig, StatusOption } from '../../../types'
3
4 export const createNhrDocumentStatusFilterConfig = (statuses: StatusOption[], label: string): FilterConfig => ({
5 key: 'documentStatus',
6 render: (filters, onChange) => (
7 <NhrDocumentStatusFilter
8 label={label}
9 statuses={statuses}
10 value={statuses.filter((s) => fil
…(truncated, 158 more chars)
Now I have full context. Let me analyze the simplification opportunities:
Issues with createNhrDocumentVisibilityFilterConfig.tsx:
- Naming:
tappedMode— "tapped" is informal, should beclickedModeortoggledMode. - Variable name
_ignored: The destructure pattern with rename-then-discard is awkward. - Logic structure: Two separate
onChangecalls in branches with a duplicatedRecord<string, unknown>type. Can be unified. - Inconsistent type cast:
filters as Record<string, unknown>is used inside, whilefilters as Record<string, boolean>is passed to the component. forEachbuilding a record with mutation: Could beObject.fromEntries(map())for clarity, but a forEach mutation is also fine. Actually, usingreduceorObject.fromEntriesis cleaner.- The
mparameter name: Inconsistent — in some placesm, in othersmode. Usemode.
Issues with the test file:
- Massive duplication: Three new tests redefine the same
optionsandconfigsetup. This should be DRY'd via a helper similar to the existingrenderFilter.
Let me look at the existing helper and design a more unified approach.
Tools used:
Bash:cd /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui && cat package.json | grep -E '"(name|scripts)"' -A 20 | hea …(truncated, 5 more chars)
Tool results:
→ result (ok): "name": "@doctolib/tpf-national-health-records-ui", "version": "16.0.2", "repository": { "type": "git", "url": "git+https://github.com/doctolib/treatment-plan.git" }, "keywords": [ "upfront", "modular frontend", "smaller-scope" ], "author": "@doctolib/fire", "license": "Doctolib", "doctolib": { "upfront-type": "smaller-scope" }, "type": "module", "sideEffects": [ "./src/i18n.ts" ], "scripts": { "dev": "vite --host -d", "dev:mfr": "rsb …(truncated, 907 more chars)
Now I'll apply the simplifications. Let me first refactor the source file:
Tools used:
Write:/Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.tsx(1838 chars)
import { NhrDocumentVisibilityFilter } from '../../../components/NhrDocumentVisibilityFilter/NhrDocumentVisibilityFilter'
import type { FilterConfig, VisibilityOption } from '../../../types'
type VisibilityModeConfig = VisibilityOption & { isExclusive?: boolean }
…(truncated, 47 more lines)
Tool results:
→ result (ok): The file /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.tsx has been updated successfully.
Wait, let me reconsider. The original code does the find lookups inline and that's actually fine — extracting exclusiveMode outside the render closure is OK but might be a behavior change if visibilityModes is mutated externally. Looking again, it's the destructured argument so it's the same array — no behavior change.
However, looking at my refactor more carefully, I have a redundancy: exclusiveMode && exclusiveIsActive is redundant since exclusiveIsActive already implies exclusiveMode. Let me also reconsider the overall approach — the helper function buildPatch adds clarity but the inline approach was reasonable too. Let me simplify further and make sure I avoid over-engineering.
Tools used:
Write:/Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.tsx(1773 chars)
import { NhrDocumentVisibilityFilter } from '../../../components/NhrDocumentVisibilityFilter/NhrDocumentVisibilityFilter'
import type { FilterConfig, VisibilityOption } from '../../../types'
type VisibilityModeConfig = VisibilityOption & { isExclusive?: boolean }
…(truncated, 44 more lines)
Tool results:
→ result (ok): The file /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.tsx has been updated successfully.
Now let me simplify the test file by removing duplication:
Tools used:
Write:/Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx(3327 chars)
import { setup } from '@doctolib/test-helpers'
import { screen } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { mockPatientInfo } from '../../../test-helpers'
…(truncated, 82 more lines)
Tool results:
→ result (ok): The file /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx has been updated successfully.
Now let me run the tests and lint to verify everything works.
Tools used:
Bash:cd /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui && npx vitest run src/business/factories/filters/createNhrDo …(truncated, 53 more chars)
Tool results:
→ result (ok): zsh: command not found: npx
Tools used:
Bash:which npm node && ls /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/node_modules/.bin/ 2>/dev/null | grep -E 'vitest|eslint' | head
Tool results:
→ result (ERROR): Exit code 1 npm not found node not found
Tools used:
Bash:ls /Users/USER/.nvm/versions/node/ 2>/dev/null; ls /opt/homebrew/bin/ 2>/dev/null | grep -E '^(npm|node|pnpm)' ; ls ~/.local/share/mise 2>/dev/null; which mise
Tool results:
→ result (ok): nodelist2lbdb ⇒ ../Cellar/lbdb/0.57/bin/nodelist2lbdb pnpm ⇒ ../Cellar/pnpm/10.33.0/bin/pnpm downloads installs shims mise () { local command command="${1:-}" if [ "$#" = 0 ] then command /Users/USER/.local/bin/mise return fi shift case "$command" in (deactivate|shell|sh) if [[ ! " $@ " =~ " --help " ]] && [[ ! " $@ " =~ " -h " ]] then eval "$(command /Users/USER/.local/bin/mise "$command" "$@")" return $? fi ;; esac command /Users/USER/.local/bin/mise "$command" "$ …(truncated, 4 more chars)
Tools used:
Bash:eval "$(/Users/USER/.local/bin/mise activate bash)" && cd /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/ && /Users/USER/.local/bin/mise exe …(truncated, 35 more chars)
Tool results:
→ result (ok): (eval):unset:11: no such hash table element: _mise_hook /Users/USER/.local/share/mise/installs/node/24.14.1/bin/node /Users/USER/.local/share/mise/installs/npm/11.11.0/bin/npm
Tools used:
Bash:cd /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui && PATH="/Users/USER/.local/share/mise/installs/node/24 …(truncated, 212 more chars)
Tool results:
→ result (ok): RUN v3.2.4 /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui Running tests with seed "1777386259777"
✓ |@doctolib/tpf-national-health-records-ui| src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx > createNhrDocumentVisibilityFilterConfig > should reflect checked state from filters 27ms ✓ |@doctolib/tpf-national-health-records-ui| src/business/factories/filters/createNhrDocume …(truncated, 1706 more chars)
All 8 tests pass. Now let me run lint and type-check.
Tools used:
Bash:cd /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui && PATH="/Users/USER/.local/share/mise/installs/node/24 …(truncated, 283 more chars)
Tool results:
→ result (ok): (Bash completed with no output)
No lint errors. Let me also run type-check on the package.
Tools used:
Bash:cd /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui && PATH="/Users/USER/.local/share/mise/installs/node/24 …(truncated, 134 more chars)
Tool results:
→ result (ok): rsbuild.config.ts(1,10): error TS2305: Module '"@doctolib/upfront-dev/module-federation"' has no exported member 'createProducerRsbuildConfig'.
This error is unrelated to our changes (it's an existing rsbuild config issue). Let me confirm by checking it's not in our files.
Tools used:
Bash:cd /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/ && git stash && cd packages/tpf-national-health-records-ui && PATH="/Users/USER/.local/share/m …(truncated, 273 more chars)
Tool results:
→ result (ok): Saved working directory and index state WIP on fhir-2222_add-visible-to-all-filter: 5e0b715e2 fix(fhir-2222): strip isExclusive before forwarding to component and add uncheck test rsbuild.config.ts(1,10): error TS2305: Module '"@doctolib/upfront-dev/module-federation"' has no exported member 'createProducerRsbuildConfig'. On branch fhir-2222_add-visible-to-all-filter Your branch is ahead of 'origin/main' by 2 commits. (use "git push" to publish your local commits)
Changes not staged for commi …(truncated, 626 more chars)
Confirmed: the rsbuild error is pre-existing and unrelated to our changes. Let me also run prettier to make sure formatting is correct.
Tools used:
Bash:cd /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui && PATH="/Users/USER/.local/share/mise/installs/node/24 …(truncated, 293 more chars)
Tool results:
→ result (ok): Checking formatting... [warn] src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx [warn] Code style issues found in the above file. Run Prettier with --write to fix.
Tools used:
Bash:cd /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui && PATH="/Users/USER/.local/share/mise/installs/node/24 …(truncated, 293 more chars)
Tool results:
→ result (ok): src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.tsx 43ms (unchanged) src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx 20ms [This command modified 1 file you've previously read: packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx. Call Read before editing.]
Tools used:
Read:/Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx
Tool results:
→ result (ok): 1 import { setup } from '@doctolib/test-helpers'
2 import { screen } from '@testing-library/react'
3 import { describe, expect, it, vi } from 'vitest'
4
5 import { mockPatientInfo } from '../../../test-helpers'
6 import { createNhrDocumentVisibilityFilterConfig } from './createNhrDocumentVisibilityFilterConfig'
7
8 const ctx = { patient: mockPatientInfo }
9
10 const defaultOptions = {
11 groupLabel: 'Document visibility',
12 visibilityModes: [
13 { filterKey: 'hiddenFromPatient', labe
…(truncated, 3053 more chars)
Now let me also check the test issue — the test 'should uncheck the exclusive mode when a non-exclusive mode is checked while exclusive is active' uses exclusiveOptions which has isExclusive: true. Looking at this test: when the exclusive visibleToAll is true and the user clicks hiddenFromPatient (non-exclusive), the patch should set hiddenFromPatient: true and uncheck visibleToAll. This works correctly.
Let me run the tests one more time to verify everything still passes after prettier formatting:
Tools used:
Bash:cd /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui && PATH="/Users/USER/.local/share/mise/installs/node/24 …(truncated, 212 more chars)
Tool results:
→ result (ok): RUN v3.2.4 /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui Running tests with seed "1777386341825"
✓ |@doctolib/tpf-national-health-records-ui| src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx > createNhrDocumentVisibilityFilterConfig > should treat absent filter key as unchecked 21ms ✓ |@doctolib/tpf-national-health-records-ui| src/business/factories/filters/createNhrDocu …(truncated, 1705 more chars)
All 8 tests pass. Let me also verify the final output of both files.
Tools used:
Read:/Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.tsx
Tool results:
→ result (ok): File unchanged since last read. The content from the earlier Read tool_result in this conversation is still current — refer to that instead of re-reading.
Tools used:
Bash:cd /Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/ && git diff packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumen …(truncated, 147 more chars)
Tool results:
→ result (ok): diff --git a/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx b/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx index 00fd4cdbd..645abf57d 100644 --- a/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx +++ b/packages/tpf-national-health-records-ui/src/business/factories/filters/createNh …(truncated, 7453 more chars)
All checks pass. Here is a summary of the simplifications applied.
Summary of changes
packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.tsx
Source-file improvements (no behavior change):
- Extracted
stripIsExclusivehelper — replaces the inline({ isExclusive: _ignored, ...rest }) => restmapping with a named helper. Also removes the awkward_ignoredrename: ESLint convention is_for the ignored binding. - Hoisted invariants out of the render closure —
exclusiveMode(independent offilters) andpresentationModes(independent offilters/onChange) are now computed once when the filter config is created instead of on every render. Both depend only onvisibilityModes, which is closed over from the outer parameters, so behavior is identical. - Extracted
buildPatchfrom the JSXonChangeprop — collapsed the deeply-nestedif/elsearrow inside JSX into a small named function returning the patch. Cuts JSX nesting and lets the early-return pattern replace the else branch. - Used
Object.fromEntries(map(...))— replaced theforEach+ manual mutation pattern (build the exclusive-mode patch where every other key becomesfalse) with a declarativeObject.fromEntries(visibilityModes.map(...)). - Removed redundant cast — the inner
(filters as Record<string, unknown>)[exclusiveMode.filterKey]cast is dropped;filtersis already typed asRecord<string, unknown>inFilterConfig.render. - Renamed
tappedModetoclickedMode— “tapped” reads as informal/mobile-only;clickedModematches the(filterKey, checked)semantics from the underlyingCheckbox onChange. - Renamed lambda parameters
mtomode— consistent withpresentationModes/clickedMode/exclusiveModenaming throughout the file.
packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx
Test-file improvements (DRY, behavior unchanged — all 8 tests pass):
- Extracted
exclusiveOptionsto module scope — the three new tests each redeclared an identical localoptionsobject; pulled it next to the existingdefaultOptions. - Generalized
renderFilterto accept the options — addedoptions = defaultOptionsas the first parameter so all tests, including the exclusive-mode tests, route through the same helper instead of callingsetup(...config.render(...))directly. - Returned
onChangefrom the helper — destructure once (const { user, onChange } = renderFilter(...)) instead of declaringconst onChange = vi.fn()and threading it through manually. Cuts ~6 lines per affected test.
Verification
- Vitest: 8/8 tests pass for
createNhrDocumentVisibilityFilterConfig.test.tsx - ESLint: clean on both files
- Prettier: clean on both files
- TypeScript: only pre-existing unrelated
rsbuild.config.tserror (verified by stashing changes)
Files
/Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.tsx/Users/USER/workspace/doctolib/worktrees/treatment-plan/fhir-2222_add-visible-to-all-filter/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.test.tsx