Skip to content

Conversation

@hmhngx
Copy link
Contributor

@hmhngx hmhngx commented Dec 11, 2025

Description

Enhances suffix unit conversion deletion to properly cascade delete related units/conversions when no dependencies exist, with improved UI warnings and consistency with unit edit/delete routes. Builds on the deletion branch of PR #1470.

Key improvements:

  • Fixed async race condition in removeAdditionalConversionsAndUnits() using Promise.all
  • Added dependency validation before deletion (checks meters/groups usage)
  • Enhanced bidirectional conversion handling
  • Added row-level locking for concurrent operation safety
  • Improved UI warnings showing affected meters/groups
  • Added DB layer methods for cascading deletions
  • Enhanced simulation to account for suffix unit cascades
  • Added depth limiting to prevent infinite loops in nested suffix chains
  • Added orphan detection and performance optimizations

Fixes #1448

Type of change

  • Note merging this changes the database configuration.
  • This change requires a documentation update

Checklist

  • I have followed the OED pull request ideas
  • I have removed text in ( ) from the issue request
  • You acknowledge that every person contributing to this work has signed the OED Contributing License Agreement and each author is listed in the Description section.

Limitations

None. All edge cases from PR #1470 have been addressed including bidirectional conversions, nested suffix chains, concurrent deletions, and orphan prevention.

MatthewTran22 and others added 28 commits December 10, 2025 23:54
Co-authored-by: Ngoc Pham (Vy) <[email protected]>
Co-authored-by: Wei Li <[email protected]>
Co-authored-by: Alngdi Mohsen <[email protected]>
- Added group dependency checking in error handling
- Moved dependency checking to happen before confirmation modal
- Update error message formatting to use React elements matching conversion deletion style
- Reorder dependency checks: conversions first (highest priority), then meters/groups
- Add logic to limit default graphic unit messages when conversion errors exist
- Implement proper modal navigation to return to main units page on error
- Add cancel modal for error notifications with proper action handling
- Use structured message elements with bold text, lists, and proper formatting
- Follow mentor feedback to match PR OpenEnergyDashboard#1505 patterns and logic
- Add English translations for unit deletion warnings
- Add French translations with proper translation markers
- Add Spanish translations for all supported languages
- Include keys for:
  - unit.delete.meter.default.lost
  - unit.delete.group.default.lost
  - unit.default.graphic.unit
  - unit.delete.restricted
- Support comprehensive error messaging in all languages
- Implement database transaction for unit deletion with default graphic unit updates
- Update meters: SET default_graphic_unit = NULL WHERE default_graphic_unit = unitId
- Update groups: SET default_graphic_unit = NULL WHERE default_graphic_unit = unitId
- Delete unit after updating dependent records
- Follow same transaction pattern as conversion deletion
- Ensure database consistency during unit deletion process
- Update success message to reflect meter/group updates
- Remove unnecessary default graphic unit checks (caught by conversion checks)
- Fix message formatting to match conversion deletion style
- Add forceCancel to error modal
- Remove unused groupDataByID import
- Remove unit.delete.meter.default.lost
- Remove unit.delete.group.default.lost
- Remove unit.default.graphic.unit
- Keys no longer needed after removing default graphic unit checks
- Remove unnecessary transaction code for default graphic unit updates
- Extract req.body.id to const unitId
- Simplify to direct unit deletion only
…ponent

- Change actionConfirmMessage prop from required to optional
- Conditionally render ModalBody only when actionConfirmMessage is provided
- Allows modals with forceCancel=true to work without confirmation message when needed
- Simplify message building by pushing directly to msgElements instead of using intermediate arrays
- Fix spacing in conversion error messages (add space before unit name in quotes)
- Improve meter error message: make it bold and use 'The following meters use' for clarity
- Move error header to beginning of message array using splice for better structure
- Add actionConfirmMessage to cancel modal to display error messages when deletion is blocked
- Remove unnecessary conditional checks and simplify control flow
- Add 'unit.delete.meters.use' key in English, French, and Spanish
- Supports clearer error message format: 'The following meters use [unit] as meter unit'
…onversion involving a suffix unit is deleted.
- Add checkUnitDependencies service for validation
- Fix async race condition in removeAdditionalConversionsAndUnits
- Add bidirectional conversion support and depth limiting
- Enhance simulation to account for suffix unit cascades
- Add getConversionsByUnitId method
- Add deleteConversionAndRelatedSuffixes with dependency checks
- Add dependency checks before suffix unit cleanup
- Handle bidirectional conversions safely
- Add row-level locking for concurrent operations
- Improve error messages with meter/group details
- Show affected meters/groups in deletion warnings
- Improve suffix unit warning formatting
- Add translation keys for dependency warnings
- Fix setHelpLayout import in CompareLineChartComponent
- Remove duplicate refreshingReadings in appStateSlice
@huss
Copy link
Member

huss commented Dec 11, 2025

Thanks to @hmhngx for this contribution. I have not looked into why but a lot of files are showing as changes and about a dozen have merge conflicts. It appears work already in development is showing as changes. This need to be resolved before this PR can be reviewed. We can discuss if you like.

@hmhngx
Copy link
Contributor Author

hmhngx commented Dec 11, 2025 via email

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.

enhance suffix unit conversions