Skip to content

fix: read-only banner, avoid rendering it while isLoading [Backport release/0.5.z]#1139

Merged
carlosthe19916 merged 1 commit into
release/0.5.zfrom
backport-1114-to-release/0.5.z
Jul 2, 2026
Merged

fix: read-only banner, avoid rendering it while isLoading [Backport release/0.5.z]#1139
carlosthe19916 merged 1 commit into
release/0.5.zfrom
backport-1114-to-release/0.5.z

Conversation

@trustify-ci-bot

@trustify-ci-bot trustify-ci-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Description

Backport of #1114 to release/0.5.z.

Summary by Sourcery

Adjust read-only handling to disable mutations while trustify info is loading and to avoid showing the read-only banner during loading, aligning with the updated trustify info query API.

Bug Fixes:

  • Prevent the global read-only banner from rendering while trustify instance information is still loading.

Enhancements:

  • Introduce an areMutationsDisabled flag in ReadOnlyContext and propagate it throughout the app to consistently disable mutating actions in read-only or loading states.
  • Update layout and data table components to rely on areMutationsDisabled for action disabling instead of read-only-specific helpers and tooltips.
  • Align ReadOnlyProvider and related hooks with the new trustify info query return shape and simplify query options.

Tests:

  • Update and extend ReadOnlyContext and DefaultLayout tests to cover the new areMutationsDisabled semantics and the absence of the banner during loading.

@sourcery-ai

sourcery-ai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This backport refactors the read-only handling to a generic "mutations disabled" concept, ensures the read-only banner is not shown while trustify info is loading, and simplifies read-only disabling by using standard isDisabled flags instead of custom helpers and tooltips across layout, buttons, and table actions.

Sequence diagram for read-only banner and loading/error handling in DefaultLayout

sequenceDiagram
  actor User
  participant DefaultLayout
  participant ReadOnlyContext
  participant ReadOnlyProvider
  participant useFetchTrustifyInfo
  participant LoadingWrapper
  participant Banner

  User->>DefaultLayout: render
  DefaultLayout->>ReadOnlyContext: useContext(ReadOnlyContext)
  ReadOnlyContext-->>DefaultLayout: isLoading, areMutationsDisabled

  DefaultLayout->>LoadingWrapper: render isFetching=isLoading
  LoadingWrapper->>ReadOnlyProvider: subscribe to context
  ReadOnlyProvider->>useFetchTrustifyInfo: call
  useFetchTrustifyInfo-->>ReadOnlyProvider: data, isLoading, error
  ReadOnlyProvider-->>ReadOnlyContext: { isLoading, areMutationsDisabled }

  alt [error]
    LoadingWrapper-->>Banner: render status=danger
  else [no error]
    opt [areMutationsDisabled && !isLoading]
      DefaultLayout-->>Banner: render read-only info
    end
  end
Loading

File-Level Changes

Change Details Files
Wrap the layout in a loading-aware wrapper and only show the read-only banner when mutations are disabled and not loading, with error handling for trustify info fetch failures.
  • Replace use of isReadOnly from ReadOnlyContext with isLoading and areMutationsDisabled in the default layout.
  • Wrap the read-only banner section in LoadingWrapper so content is hidden while trustify info is loading and an error banner is shown when the fetch fails.
  • Gate the read-only info banner on areMutationsDisabled instead of isReadOnly.
client/src/app/layout/default-layout.tsx
Change ReadOnlyContext to expose areMutationsDisabled, driven by trustify info, and update tests accordingly.
  • Modify ReadOnlyContext shape to provide isLoading and areMutationsDisabled instead of isReadOnly.
  • Update ReadOnlyProvider to consume useFetchTrustifyInfo.data, compute isReadOnly from trustifyInfo.readOnly, and derive areMutationsDisabled as isLoading
Refactor consumers of read-only state to use areMutationsDisabled and standard disabled props instead of custom read-only utilities and tooltips.
  • Update SbomToolbar to use areMutationsDisabled from ReadOnlyContext, remove READ_ONLY_TOOLTIP usage, and use DropdownItem.isDisabled instead of isAriaDisabled+Tooltip for the upload action.
  • Simplify ReadOnlyButton to always render a Button with isDisabled bound to areMutationsDisabled, removing tooltip behavior and READ_ONLY_TOOLTIP dependency.
  • Update ImporterList row actions to use areMutationsDisabled and isDisabled for enable/run/disable actions, in place of readOnlyActionProps and isAriaDisabled.
  • Update SbomGroupRow actions to disable Edit/Delete based on areMutationsDisabled and existing constraints (e.g., number_of_groups) instead of readOnlyActionProps.
  • Update AdvisoryTable actions to disable label editing and delete actions via areMutationsDisabled instead of readOnlyActionProps.
  • Update SbomTable actions to disable label edit and delete actions via areMutationsDisabled instead of readOnlyActionProps.
  • Remove ReadOnlyContext utils and its exports (readOnlyActionProps, READ_ONLY_TOOLTIP).
client/src/app/pages/sbom-list/sbom-toolbar.tsx
client/src/app/components/ReadOnlyButton.tsx
client/src/app/pages/importer-list/importer-list.tsx
client/src/app/pages/sbom-groups/sbom-groups-table.tsx
client/src/app/pages/advisory-list/advisory-table.tsx
client/src/app/pages/sbom-list/sbom-table.tsx
client/src/app/components/ReadOnlyContext/index.ts
client/src/app/components/ReadOnlyContext/utils.ts
Align DefaultLayout tests with the new loading and mutations-disabled semantics for the read-only banner.
  • Change the layout test helper to accept isLoading and areMutationsDisabled instead of isReadOnly.
  • Update banner visibility tests to check behavior when mutations are disabled vs allowed.
  • Add a new test case asserting that the read-only banner is not shown while trustify info is loading even if mutations would otherwise be disabled.
client/src/app/layout/default-layout.test.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@carlosthe19916 carlosthe19916 merged commit 5ce5ece into release/0.5.z Jul 2, 2026
13 checks passed
@github-project-automation github-project-automation Bot moved this to Done in Trustify Jul 2, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The change from isAriaDisabled + tooltip (READ_ONLY_TOOLTIP/readOnlyActionProps) to plain isDisabled (e.g., in ReadOnlyButton, SbomToolbar, importer/advisory/SBOM tables) removes the explicit explanation and accessible affordance for why actions are disabled; consider reintroducing an accessible hint (tooltip/aria-description) so users know the instance is in read-only mode when controls are disabled.
  • In useFetchTrustifyInfo the query options (staleTime, gcTime, refetch flags, retry) have been dropped; if this was not intentional, consider restoring them or documenting the new behavior, as it changes how often the trustify info is fetched and may impact perceived performance and consistency of the read-only state.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The change from `isAriaDisabled` + tooltip (`READ_ONLY_TOOLTIP`/`readOnlyActionProps`) to plain `isDisabled` (e.g., in `ReadOnlyButton`, `SbomToolbar`, importer/advisory/SBOM tables) removes the explicit explanation and accessible affordance for why actions are disabled; consider reintroducing an accessible hint (tooltip/aria-description) so users know the instance is in read-only mode when controls are disabled.
- In `useFetchTrustifyInfo` the query options (staleTime, gcTime, refetch flags, retry) have been dropped; if this was not intentional, consider restoring them or documenting the new behavior, as it changes how often the trustify info is fetched and may impact perceived performance and consistency of the read-only state.

## Individual Comments

### Comment 1
<location path="client/src/app/components/ReadOnlyButton.tsx" line_range="8-10" />
<code_context>
-/** Button that is automatically aria-disabled with a tooltip when the instance is in read-only mode. */
 export const ReadOnlyButton: React.FC<ButtonProps> = (props) => {
-  const { isReadOnly } = React.useContext(ReadOnlyContext);
+  const { areMutationsDisabled } = React.useContext(ReadOnlyContext);

-  if (isReadOnly) {
-    return (
-      <Tooltip content={READ_ONLY_TOOLTIP}>
-        <Button {...props} isAriaDisabled />
-      </Tooltip>
-    );
-  }
-
-  return <Button {...props} />;
+  return <Button {...props} isDisabled={areMutationsDisabled} />;
 };
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Switching from `isAriaDisabled` + tooltip to `isDisabled` may hurt accessibility and affordance.

With `isDisabled`, the button is no longer focusable and users lose the tooltip that explained why actions are blocked. This is an accessibility regression for keyboard and assistive tech users, and reduces UX clarity. If removing the tooltip is intentional, consider keeping `isAriaDisabled` (with an updated label/tooltip) or adding nearby explanatory text when `areMutationsDisabled` is true.

Suggested implementation:

```typescript
import { Button, Tooltip, type ButtonProps } from "@patternfly/react-core";

```

```typescript
export const ReadOnlyButton: React.FC<ButtonProps> = (props) => {
  const { areMutationsDisabled } = React.useContext(ReadOnlyContext);

  if (areMutationsDisabled) {
    return (
      <Tooltip content={READ_ONLY_TOOLTIP}>
        <Button {...props} isAriaDisabled />
      </Tooltip>
    );
  }

  return <Button {...props} />;
};

```

1. Ensure that `READ_ONLY_TOOLTIP` is defined and imported in this file (for example: `import { READ_ONLY_TOOLTIP } from "./constants";`), and update its text to describe that mutations/actions are currently disabled.
2. If your project uses the new JSX runtime and doesn't globally import `React`, either add `import * as React from "react";` at the top of this file or update `React.useContext` to `useContext` with a corresponding `import { useContext } from "react";`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +8 to +10
const { areMutationsDisabled } = React.useContext(ReadOnlyContext);

if (isReadOnly) {
return (
<Tooltip content={READ_ONLY_TOOLTIP}>
<Button {...props} isAriaDisabled />
</Tooltip>
);
}

return <Button {...props} />;
return <Button {...props} isDisabled={areMutationsDisabled} />;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Switching from isAriaDisabled + tooltip to isDisabled may hurt accessibility and affordance.

With isDisabled, the button is no longer focusable and users lose the tooltip that explained why actions are blocked. This is an accessibility regression for keyboard and assistive tech users, and reduces UX clarity. If removing the tooltip is intentional, consider keeping isAriaDisabled (with an updated label/tooltip) or adding nearby explanatory text when areMutationsDisabled is true.

Suggested implementation:

import { Button, Tooltip, type ButtonProps } from "@patternfly/react-core";
export const ReadOnlyButton: React.FC<ButtonProps> = (props) => {
  const { areMutationsDisabled } = React.useContext(ReadOnlyContext);

  if (areMutationsDisabled) {
    return (
      <Tooltip content={READ_ONLY_TOOLTIP}>
        <Button {...props} isAriaDisabled />
      </Tooltip>
    );
  }

  return <Button {...props} />;
};
  1. Ensure that READ_ONLY_TOOLTIP is defined and imported in this file (for example: import { READ_ONLY_TOOLTIP } from "./constants";), and update its text to describe that mutations/actions are currently disabled.
  2. If your project uses the new JSX runtime and doesn't globally import React, either add import * as React from "react"; at the top of this file or update React.useContext to useContext with a corresponding import { useContext } from "react";.

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.05%. Comparing base (96c9508) to head (e10a0c5).
⚠️ Report is 3 commits behind head on release/0.5.z.

Files with missing lines Patch % Lines
...ient/src/app/pages/importer-list/importer-list.tsx 0.00% 3 Missing ⚠️
client/src/app/components/ReadOnlyButton.tsx 0.00% 2 Missing ⚠️
...nt/src/app/pages/sbom-groups/sbom-groups-table.tsx 0.00% 2 Missing ⚠️
client/src/app/pages/sbom-list/sbom-toolbar.tsx 0.00% 2 Missing ⚠️
client/src/app/layout/default-layout.tsx 75.00% 1 Missing ⚠️
...ent/src/app/pages/advisory-list/advisory-table.tsx 0.00% 1 Missing ⚠️
client/src/app/pages/sbom-list/sbom-table.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##           release/0.5.z    #1139      +/-   ##
=================================================
- Coverage          51.10%   51.05%   -0.06%     
=================================================
  Files                256      256              
  Lines               5522     5518       -4     
  Branches            1672     1669       -3     
=================================================
- Hits                2822     2817       -5     
- Misses              2432     2434       +2     
+ Partials             268      267       -1     
Flag Coverage Δ
unit 6.26% <33.33%> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant