Skip to content

feat: support expanding/collapsing toggle list in read-only mode#8755

Open
Ramrajnagar wants to merge 2 commits into
AppFlowy-IO:mainfrom
Ramrajnagar:fix/toggle-list-readonly-expand
Open

feat: support expanding/collapsing toggle list in read-only mode#8755
Ramrajnagar wants to merge 2 commits into
AppFlowy-IO:mainfrom
Ramrajnagar:fix/toggle-list-readonly-expand

Conversation

@Ramrajnagar

@Ramrajnagar Ramrajnagar commented May 24, 2026

Copy link
Copy Markdown

Feature Preview


PR Checklist

  • My code adheres to AppFlowy's Conventions
  • I've listed at least one issue that this PR fixes in the description above.
  • I've added a test(s) to validate changes in this PR, or this PR only contains semantic changes.
  • All existing tests are passing.

Summary by Sourcery

Support toggling the collapsed state of toggle list blocks while in read-only mode without persisting changes to the document.

New Features:

  • Allow users to expand and collapse toggle list blocks when the editor is not editable.

Enhancements:

  • Introduce an internal read-only collapsed state used for rendering and visuals, while preserving the stored collapsed attribute for editable sessions.

@CLAassistant

CLAassistant commented May 24, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@sourcery-ai

sourcery-ai Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds support for toggling the expanded/collapsed state of toggle list blocks while the document is in read‑only mode by separating the persisted collapsed state from a local UI-only state and routing all UI logic through an effective collapsed flag.

Sequence diagram for toggle collapse behavior in editable vs read_only mode

sequenceDiagram
  actor User
  participant ToggleListBlockComponentWidgetState as ToggleListBlockState
  participant EditorState

  User->>ToggleListBlockState: onCollapsed()
  ToggleListBlockState->>EditorState: editable
  alt editorState.editable == false
    ToggleListBlockState->>ToggleListBlockState: setState(_readOnlyCollapsed = !_effectiveCollapsed)
    ToggleListBlockState->>ToggleListBlockState: _effectiveCollapsed used in build()
  else editorState.editable == true
    ToggleListBlockState->>EditorState: transaction.updateNode(node, {collapsed: !collapsed})
    EditorState-->>ToggleListBlockState: updated node.attributes[collapsed]
    ToggleListBlockState->>ToggleListBlockState: _effectiveCollapsed uses collapsed
  end
Loading

File-Level Changes

Change Details Files
Introduce a UI-only collapsed state for toggle lists in read-only mode and route rendering logic through a unified effective collapsed flag.
  • Add a nullable _readOnlyCollapsed field and _effectiveCollapsed getter that falls back to the persisted collapsed attribute
  • Replace existing usages of collapsed in build/render logic (main build method, background color computation, placeholder visibility, and icon rotation) with _effectiveCollapsed to ensure consistent behavior between read-only and editable states
  • Update background color logic to depend on _effectiveCollapsed instead of the stored collapsed attribute so the visual state matches the UI state
frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart
Allow users to toggle the visual collapsed state of toggle lists in read-only mode without persisting changes to the document model.
  • Guard onCollapsed with an editorState.editable check to differentiate editable and read-only behavior
  • In read-only mode, update _readOnlyCollapsed via setState to flip the current _effectiveCollapsed value, avoiding any document transaction
  • In editable mode, preserve existing behavior by issuing a transaction that toggles the node's ToggleListBlockKeys.collapsed attribute
frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart

Possibly linked issues

  • #FR: The PR implements read-only expand/collapse behavior for toggle lists exactly as requested in the feature issue.

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

@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 left some high level feedback:

  • The _readOnlyCollapsed state is never reset when the editor transitions from read-only to editable (or when the underlying collapsed attribute changes), so once a user has toggled in read-only mode, _effectiveCollapsed may keep using a stale _readOnlyCollapsed instead of the persisted value; consider clearing or resyncing _readOnlyCollapsed in didUpdateWidget/didChangeDependencies when editorState.editable or node.attributes[ToggleListBlockKeys.collapsed] changes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `_readOnlyCollapsed` state is never reset when the editor transitions from read-only to editable (or when the underlying `collapsed` attribute changes), so once a user has toggled in read-only mode, `_effectiveCollapsed` may keep using a stale `_readOnlyCollapsed` instead of the persisted value; consider clearing or resyncing `_readOnlyCollapsed` in `didUpdateWidget`/`didChangeDependencies` when `editorState.editable` or `node.attributes[ToggleListBlockKeys.collapsed]` changes.

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.

@Ramrajnagar

Copy link
Copy Markdown
Author

Hi team! I have addressed the edge-case feedback regarding the _readOnlyCollapsed state resetting on external attribute changes in my latest commit.

The CLA is signed, and the PR is ready for your review and for the CI workflows to be approved. Thank you!

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