Skip to content

Improve suffix unit conversion deletion with cascade delete and UI warnings - #1693

Open
BunnyBea83 wants to merge 14 commits into
OpenEnergyDashboard:developmentfrom
BunnyBea83:BunnyBea83/issue1448
Open

Improve suffix unit conversion deletion with cascade delete and UI warnings#1693
BunnyBea83 wants to merge 14 commits into
OpenEnergyDashboard:developmentfrom
BunnyBea83:BunnyBea83/issue1448

Conversation

@BunnyBea83

@BunnyBea83 BunnyBea83 commented Aug 5, 2026

Copy link
Copy Markdown

Description

This PR solves OED's opporations for deleting conversions involving suffix units. Upon deletion of a suffix unit related conversion, OED created units and related conversions will be cascade deleted. UI warnings are inplace to notify the user of units and conversions that will be deleted, and groups/meters that will be affected by the deletion. This PR builds off of PR #1561 and PR #1470.

Key improvements:

  • Resolved merge conflicts and implemented work from PR Enhance suffix unit conversion deletion with dependency checks #1561
  • Suffix unit validations now account for Suffix Inputs and Suffix Analyzed during the simulateDeletion and Deletion phase of conversion deletion
  • Deletion of a Suffix Unit conversion will cascade delete OED created units in relation to the parent conversion
  • Cascade deletion within DB includes removing a units association to groups/meters, deleting conversions referencing the unit, and deleting units
  • UI warnings include affected meters/groups, units, and conversions related to the deletion of a suffix unit conversion
  • removeAdditionalConversionsAndUnits no longer 'hides' removed units. Removed units are completely deleted from the OED DB
    • Resolves discussion in issue#1448, when a unit is renamed the former unit is completely removed instead of 'hidden'
  • Included passing unit tests to confirm function of cascade deletion within suffixUnitDeletionTests.js

Partly Addresses #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

Multi-hop-generated suffix units are not yet covered by this cascade delete since it likely needs a
design decision before implementation.

This PR resolves cascade deletion for the direct/single-hop case (deleting a
conversion from a suffix root, or from an auto-created child, correctly
cleans up what it should). It does not yet handle units auto-created via
multi-hop paths (e.g. suffix unit → new auto-created unit→ further conversion). Since OED always attaches such units
directly to the root rather than the intermediate unit, deleting the
intermediate conversion currently leaves these orphaned. Possible implementations could include either a re-walk of valid paths after delete, or tracking explicit provenance on auto-created units, both of
which are a larger design change than this PR's scope. Flagging for
follow-up discussion with maintainers.

Before Deletion of multi-hop path 'metric Ton of TestUnit -> gallon'

image

After Deletion of multi-hop path

image

Deletion of TestUnit -> kg removes all OED created units

image

- 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 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
- Removed getConversionsByUnitId method as it is no longer used
- Removed deleteConversionAndRelatedSuffixes method as it is no longer used
- Refactored hide suffix functions to delete suffix functions
- Suffix checks now account for suffix inputs (type of unit = unit, suffix = <contains a string>) when checking for dependencies.
- Added deleteUnitSafely method
- Method checks for dependencies of the unit, clears unit connections to meters, groups, and conversions, then deletes the unit.
- Deletes suffix units instead of hiding them (setting displayable to None)
- Calls deleteUnitSafely to check for unit dependacies, deleting the unit, and cleaning cik
- isSuffixRelated function determines if a unit is a suffix unit based on unit type (Suffix Analyzed) or if the suffix field is filled in (Suffix Input)
Refactor:
- Altered suffix detection cases to call isSuffixRelated. Reduces code redundancy and accounts for Suffix inputs.
- Added code commentry
- Modified suffixTypeUnitsToDelete to a simpler display
- Added conversion.delete.suffix.conversions.to.delete prompt for conversion deletion display.
- Modified relatedConversions
Fix cascade deletion walking backward into parent suffix units

removeAdditionalConversionsAndUnits previously matched any conversion
touching a suffix unit as either source or destination, regardless of
direction. This caused cleanup started from a child unit (e.g.
deleting "kg of X" -> "gallon") to walk backward through the
parent-to-child conversion that created it, incorrectly cascading the
delete up to the parent unit itself.

Now only conversions where the unit is the source are followed,
except for bidirectional conversions, where both directions are
still valid since they genuinely work both ways.

- deleteUnitSafely now occurs after removeAdditionalConversionsAndUnits
Unit tests for suffix unit deletion tests for:
- Deletion of OED created units and their conversions
- Clearing a dependent meter's unit ID to allow the auto-created unit to be deleted
- Clearing converstions that reference OED created units
- Clears a group's default graphic unit reference instead of blocking deletion of the unit it points to
- Recursively cleaning up nested suffix chains
- Prevention of deleting parent unit when deleting conversion from child unit
- Deletion of bidirectional conversions relating to suffix units
- Clearing cik rows before unit deletion
- Prevention of deleting regular units when deleting a suffix related conversion
@huss

huss commented Aug 7, 2026

Copy link
Copy Markdown
Member

@BunnyBea83 Thank you for this PR. It will take me about a week to get to review this. The description seems to be fine from my quick review.

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.

2 participants