Skip to content

Conversation

Copy link

Copilot AI commented Dec 2, 2025

Implements DHIS2-20136

Description

Addresses duplicate code and unnecessary complexity introduced during the port from line-listing-app.

Consolidated Options Constants (src/constants/options.ts)

  • OPTIONS_SECTION_KEYS_LINE_LIST and OPTIONS_SECTION_KEYS_PIVOT_TABLE were identical arrays, now sharing a single source

Centralized Header Map Utilities (src/modules/visualization.ts)

  • Added reversedHeadersMap - pre-computed reverse map for O(1) lookups
  • Added getDimensionIdFromHeaderName() utility using the pre-computed map
  • Removed duplicate Object.keys(headersMap).find() pattern from 4 locations

Removed Duplicate Code in Metadata Helpers (src/components/app-wrapper/metadata-helpers/visualization.ts)

  • Removed local DIMENSION_METADATA_PROP_MAP - now imports dimensionMetadataPropMap from @modules/visualization
  • Removed local getDefaultOrgUnitMetadata and getDefaultOrgUnitLabel - now imports from @modules/metadata

Before:

// Duplicated in 4 files
const idMatch = Object.keys(headersMap).find(
    (key) => headersMap[key] === dimensionId
) ?? ''

After:

// Single source in visualization.ts
export const reversedHeadersMap = Object.entries(headersMap).reduce(...)
export const getDimensionIdFromHeaderName = (headerName: string) => 
    reversedHeadersMap[headerName]

Quality checklist

  • [N/A] Dashboard tested
  • [N/A] Cypress and/or Jest tests added/updated
  • [N/A] Docs added
  • [N/A] d2-ci dependency replaced

ToDos

  • Consolidate duplicate constants
  • Extract common header lookup logic
  • Address code review feedback
  • Review and consolidate duplicates in metadata-helpers/visualization.ts

Known issues

  • Pre-existing test failure (isSubsetOf is not a function) unrelated to these changes - Node.js version compatibility issue with ES2023 Set method

Screenshots

N/A - refactoring only, no UI changes

Original prompt

This section details on the original issue you should resolve

<issue_title>Remove duplicate logic and unnecessary complexity</issue_title>
<issue_description>The current state of this application has been ported from https://github.com/dhis2/line-listing-app. We are concerned that during this process we have:

  1. Ported identical code twice
  2. Have migrated code that has unneeded complexity

A general review of the codebase to identify and remove these points would be beneficial. </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 12 commits December 2, 2025 14:44
Co-authored-by: HendrikThePendric <353236+HendrikThePendric@users.noreply.github.com>
Co-authored-by: HendrikThePendric <353236+HendrikThePendric@users.noreply.github.com>
Co-authored-by: HendrikThePendric <353236+HendrikThePendric@users.noreply.github.com>
Co-authored-by: HendrikThePendric <353236+HendrikThePendric@users.noreply.github.com>
Co-authored-by: HendrikThePendric <353236+HendrikThePendric@users.noreply.github.com>
Co-authored-by: HendrikThePendric <353236+HendrikThePendric@users.noreply.github.com>
Co-authored-by: HendrikThePendric <353236+HendrikThePendric@users.noreply.github.com>
Co-authored-by: HendrikThePendric <353236+HendrikThePendric@users.noreply.github.com>
Co-authored-by: HendrikThePendric <353236+HendrikThePendric@users.noreply.github.com>
Co-authored-by: HendrikThePendric <353236+HendrikThePendric@users.noreply.github.com>
Co-authored-by: HendrikThePendric <353236+HendrikThePendric@users.noreply.github.com>
Co-authored-by: HendrikThePendric <353236+HendrikThePendric@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove duplicate logic and unnecessary complexity refactor: remove duplicate logic and consolidate utility functions Dec 2, 2025
Copy link
Collaborator

@HendrikThePendric HendrikThePendric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are looking good so far. @copilot could you check one specific file: src/components/app-wrapper/metadata-helpers/visualization.ts. I think we could be doing the same thing a few times there. Also, please carefully check the files in the src/modules dir, these have all been ported and renamed over several PRs by 3 different people. The risk that we ended up with overlapping logic there seems quite significant.

@dhis2-bot
Copy link

🚀 Deployed on https://pr-108.event-visualizer.netlify.dhis2.org

@dhis2-bot dhis2-bot temporarily deployed to netlify December 3, 2025 08:26 Inactive
@HendrikThePendric
Copy link
Collaborator

@copilot your commit 237256d does not follow our commit naming schemes, please reword it.

Co-authored-by: HendrikThePendric <353236+HendrikThePendric@users.noreply.github.com>
Copy link
Author

Copilot AI commented Dec 3, 2025

Changes are looking good so far. @copilot could you check one specific file: src/components/app-wrapper/metadata-helpers/visualization.ts. I think we could be doing the same thing a few times there....

Reviewed both files as requested. Found and removed duplicate code in src/components/app-wrapper/metadata-helpers/visualization.ts:

  1. DIMENSION_METADATA_PROP_MAP - Was duplicated, now imports dimensionMetadataPropMap from @modules/visualization
  2. getDefaultOrgUnitMetadata and getDefaultOrgUnitLabel - Were duplicated, now imports from @modules/metadata

The src/modules directory looks clean - the shared utilities are properly centralized there. Commit: 9c7f93b

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • download.cypress.io
    • Triggering command: /usr/local/bin/node /usr/local/bin/node dist/index.js --exec install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copy link
Author

Copilot AI commented Dec 3, 2025

@copilot your commit 237256d does not follow our commit naming schemes, please reword it.

I'm unable to reword that commit as it has already been pushed to the remote branch and I don't have access to force push. The commit would need to be amended manually or via an interactive rebase by someone with push access. All subsequent commits in this PR follow the conventional commit format (e.g., refactor:, chore:).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove duplicate logic and unnecessary complexity

3 participants