Skip to content

Disable delete for in-use licenses, add tooltip#137

Open
amadulhaxxani wants to merge 3 commits intoclarin-v7from
136-disable-delete-button-in-license-administration-when-a-bitstream-is-connected
Open

Disable delete for in-use licenses, add tooltip#137
amadulhaxxani wants to merge 3 commits intoclarin-v7from
136-disable-delete-button-in-license-administration-when-a-bitstream-is-connected

Conversation

@amadulhaxxani
Copy link
Copy Markdown

Prevent deleting licenses that are attached to bitstreams

Disable the Delete button for licenses with attached bitstreams and display a tooltip explaining why deletion is prevented. Adds UI markup (ngbTooltip wrapper, aria-label, dsBtnDisabled and guarded click), a new isSelectedLicenseInUse() helper and a check in deleteLicense(). Adds unit tests covering disabled/enabled states and click behavior, and provides i18n strings for English and Czech for the disabled-tooltip.

Problem description

Administrators need protection against accidentally deleting licenses that are currently attached to one or more bitstreams. Without this safeguard, deleting an in-use license could leave orphaned bitstream-to-license mappings and create data inconsistency.

Analysis

The frontend license model already includes a bitstreams: number property (from the backend REST serialization). This field reflects the count of non-deleted mapped bitstreams and is available on every license in the paginated table. No backend change and no extra frontend API call is required.

The existing license-label delete flow in the same component already demonstrates the correct accessibility pattern: a wrapper span with ngbTooltip, conditional tabindex="0", and a button using [dsBtnDisabled]. This pattern is reused verbatim for the license delete button.

The current license delete button is a bottom action (not per-row), so the disable rule is applied to selectedLicense?.bitstreams > 0. The button remains disabled when no license is selected.

Changes made

  1. clarin-license-table.component.html — Replaced native [disabled] with the label-delete wrapper + tooltip + dsBtnDisabled pattern. Added ngbTooltip bound to the disabled-tooltip i18n key (only shown when bitstreams > 0). Added wrapper tabindex="0" for accessibility when disabled. Added icon (fas fa-trash) and aria-label to the button. Guarded click handler with selectedLicense != null && !isSelectedLicenseInUse().

  2. clarin-license-table.component.ts — Added isSelectedLicenseInUse(): boolean helper method returning this.selectedLicense?.bitstreams > 0. Added optional guard at the start of deleteLicense() to return if this.isSelectedLicenseInUse() is true.

  3. en.json5 — Added i18n key: "clarin-license.button.delete-license.disabled-tooltip": "License \"{{name}}\" cannot be deleted because it is attached to one or more bitstreams."

  4. cs.json5 — Added i18n key: "clarin-license.button.delete-license.disabled-tooltip": "Licenci \"{{name}}\" nelze smazat, protože jsou k ní připojeny jeden nebo více bitstreamů."

  5. clarin-license-table.component.spec.ts — Added test group "license delete button" covering:

    • Disabled state, aria-disabled, disabled class, tabindex, and tooltip binding when bitstreams > 0
    • Click on disabled button does not call delete service
    • Enabled state and successful delete when bitstreams === 0

Problems

None encountered. All changes compile, lint, and pass unit tests (5369 tests completed, 0 failed).

Sync verification

  • Translation keys added to both en.json5 and cs.json5; no sync tool needed (keys are static, no parametrization).

Copilot review

  • Requested review from Copilot

Prevent deleting licenses that are attached to bitstreams by disabling the Delete button and showing a tooltip explaining why. Adds UI markup (ngbTooltip wrapper, aria-label, dsBtnDisabled and guarded click), a new isSelectedLicenseInUse() helper and a check in deleteLicense(). Adds unit tests covering disabled/enabled states and click behavior, and provides i18n strings for English and Czech for the disabled-tooltip.
Copilot AI review requested due to automatic review settings April 27, 2026 13:39
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Prevents administrators from deleting CLARIN licenses that are currently referenced by bitstreams by disabling the delete action and explaining the reason via a tooltip, while also adding unit coverage and i18n strings.

Changes:

  • Disable the “Delete License” button when the selected license has bitstreams > 0, and show a tooltip explaining why.
  • Add isSelectedLicenseInUse() helper and a guard in deleteLicense() to block deletion for in-use licenses.
  • Add unit tests for disabled/enabled states and click behavior; add EN/CZ translations for the tooltip.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/assets/i18n/en.json5 Adds English tooltip text for disabled delete button
src/assets/i18n/cs.json5 Adds Czech tooltip text for disabled delete button
src/app/clarin-licenses/clarin-license-table/clarin-license-table.component.ts Adds “in use” helper + deletion guard
src/app/clarin-licenses/clarin-license-table/clarin-license-table.component.html Disables delete via dsBtnDisabled and adds tooltip wrapper
src/app/clarin-licenses/clarin-license-table/clarin-license-table.component.spec.ts Adds tests for delete button state and click behavior

Replace isNull with hasNoValue when validating selectedLicense.id in deleteLicense to correctly handle undefined/null values. Also add hasNoValue to the imports from shared/empty.util.
Update clarin-license-table component spec to import NgbTooltip and retrieve the tooltip instance from the delete wrapper's injector. Replace the previous assertion that inspected the DOM's ng-reflect-ngb-tooltip attribute with an assertion on deleteTooltip.ngbTooltip to verify the expected translation key. This makes the test more robust by avoiding reliance on Angular's rendered reflection attribute.
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.

Disable delete button in license administration when a bitstream is connected

2 participants