Skip to content

refactor(ui): split CommonUtils.tsx into domain-specific utility modules - #28389

Merged
shah-harshit merged 15 commits into
mainfrom
refactor/split-common-utils
May 27, 2026
Merged

shah-harshit merged 15 commits into
mainfrom
refactor/split-common-utils

Conversation

@shah-harshit

@shah-harshit shah-harshit commented May 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Split 900-line CommonUtils.tsx into 7 focused utility modules: FqnUtils, NumberUtils, ColorUtils, RecentActivityUtils, StringUtils, EntityDisplayUtils, FilterQueryUtils
  • Updated ~150 import paths across openmetadata-ui
  • Maintained re-exports in CommonUtils.tsx for backward compatibility
  • Lazy-loaded Loader component in EntityDisplayUtils.tsx

New Modules

Module Exports Purpose
FqnUtils.ts 4 FQN parsing (getPartialNameFromTableFQN, getNameFromFQN, etc.)
NumberUtils.ts 5 Number formatting (formatNumberWithComma, calculatePercentage, etc.)
ColorUtils.ts 6 Color operations (getRandomColor, entityChartColor, etc.)
RecentActivityUtils.ts 6 Recently viewed/searched state management
StringUtils.ts 6 String transforms (pluralize, removeOuterEscapes, etc.)
EntityDisplayUtils.tsx 8 JSX entity display helpers (getCountBadge, getServiceLogo, etc.)
FilterQueryUtils.ts 4 ES query builders and filter helpers

Ref

https://github.com/open-metadata/openmetadata-collate/issues/4230

Test plan

  • Verify zero new TypeScript errors (npx tsc --noEmit)
  • UI checkstyle passes (yarn ui-checkstyle:changed)
  • All existing Jest tests pass
  • Manual smoke test — pages using moved utils render correctly

🤖 Generated with Claude Code


Summary by Gitar

  • Refactor and Architecture:
    • Split CommonUtils.tsx into domain-specific modules: FqnUtils, NumberUtils, ColorUtils, RecentActivityUtils, StringUtils, EntityDisplayUtils, and FilterQueryUtils.
    • Migrated getTagValue to TagsUtils.tsx and updated import paths across affected components.
  • UI/UX Enhancements:
    • Added prepareLabel utility to EntityDisplayUtils.tsx for consistent entity FQN-to-label parsing.
    • Updated import paths for entity-related helpers like getEntityMissingError and entityChartColor to point to their new modular locations.
  • Import Cleanup:
    • Standardized import formatting and path resolution across numerous UI components and pages.
  • Permissions Update:
    • Updated DataAssetsHeader to restrict the 'Request Data Access' button rendering for admin users.
  • Knowledge Center Improvements:
    • Added TagClassBase to manage classification filters in KnowledgePageDetailComponent for better tag state control.
    • Centralized ADMONITION_TYPES definition in regex.constants.ts and refactored BlockEditor.constants.ts to consume the shared constant.

This will update automatically on new commits.

Split the 900-line CommonUtils.tsx catch-all into 7 focused modules:
- FqnUtils.ts (FQN parsing)
- NumberUtils.ts (math/formatting)
- ColorUtils.ts (color operations)
- RecentActivityUtils.ts (recently viewed/searched)
- StringUtils.ts (string transforms)
- EntityDisplayUtils.tsx (JSX entity display helpers)
- FilterQueryUtils.ts (ES query builders + filters)

Re-exports maintained in CommonUtils.tsx for backward compatibility.
Updated ~150 import paths across openmetadata-ui.

Ref: open-metadata/openmetadata-collate#4230

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@gitar-bot

gitar-bot Bot commented May 23, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

Refactors the 900-line CommonUtils.tsx into seven domain-specific utility modules to improve maintainability while maintaining backward compatibility via re-exports. No issues found.

Options

Display: compact → Showing less information.

Comment with these commands to change:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqubecloud

Copy link
Copy Markdown

@shah-harshit
shah-harshit merged commit 84952b2 into main May 27, 2026
56 of 57 checks passed
@shah-harshit
shah-harshit deleted the refactor/split-common-utils branch May 27, 2026 04:57
@gitar-bot

gitar-bot Bot commented May 27, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 1 resolved / 2 findings

Refactors the 900-line CommonUtils.tsx into seven focused domain-specific modules, improving maintainability and type safety. Note that a redundant conditional check remains in DatabaseDetailsPage that should be cleaned up.

💡 Quality: Redundant if (database) check in saveUpdatedDatabaseData

📄 openmetadata-ui/src/main/resources/ui/src/pages/DatabaseDetailsPage/DatabaseDetailsPage.tsx:286-294

In DatabaseDetailsPage.tsx, the saveUpdatedDatabaseData callback has if (!database) { return Promise.reject(...); } followed immediately by if (database) { jsonPatch = compare(database, updatedData); }. The second check is always true after the early return and adds unnecessary noise.

Remove the redundant `if (database)` block and assign `jsonPatch` directly.
const saveUpdatedDatabaseData = useCallback(
  (updatedData: Database) => {
    if (!database) {
      return Promise.reject(new Error('Database not loaded'));
    }
    const jsonPatch = compare(database, updatedData);

    return patchDatabaseDetails(database.id ?? '', jsonPatch);
  },
  [database]
);
✅ 1 resolved
✅ Bug: Duplicate pluralize import causes TypeScript compilation error

📄 openmetadata-ui/src/main/resources/ui/src/utils/DataInsightUtils.tsx:44 📄 openmetadata-ui/src/main/resources/ui/src/utils/DataInsightUtils.tsx:47
In DataInsightUtils.tsx, pluralize is imported twice — once from ./CommonUtils (line 44, newly added) and once from ./StringUtils (line 47, pre-existing). Since pluralize is not actually exported from CommonUtils.tsx (it lives in StringUtils.ts), this will cause a TypeScript compilation error: either a "Module has no exported member" error for the CommonUtils import, or a duplicate identifier error if both resolve.

🤖 Prompt for agents
Code Review: Refactors the 900-line CommonUtils.tsx into seven focused domain-specific modules, improving maintainability and type safety. Note that a redundant conditional check remains in DatabaseDetailsPage that should be cleaned up.

1. 💡 Quality: Redundant `if (database)` check in saveUpdatedDatabaseData
   Files: openmetadata-ui/src/main/resources/ui/src/pages/DatabaseDetailsPage/DatabaseDetailsPage.tsx:286-294

   In `DatabaseDetailsPage.tsx`, the `saveUpdatedDatabaseData` callback has `if (!database) { return Promise.reject(...); }` followed immediately by `if (database) { jsonPatch = compare(database, updatedData); }`. The second check is always true after the early return and adds unnecessary noise.

   Fix (Remove the redundant `if (database)` block and assign `jsonPatch` directly.):
   const saveUpdatedDatabaseData = useCallback(
     (updatedData: Database) => {
       if (!database) {
         return Promise.reject(new Error('Database not loaded'));
       }
       const jsonPatch = compare(database, updatedData);
   
       return patchDatabaseDetails(database.id ?? '', jsonPatch);
     },
     [database]
   );

Options

Display: compact → Showing less information.

Comment with these commands to change:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

This branch was previously deployed

1 inactive deployment
test — cf80e4c9 Deployed May 27, 2026 by shah-harshit via playwright-ci-postgresql (1, 6) #48677
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Add this label to run secure Github workflows on PRs UI UI specific issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants