Skip to content

Conversation

@richardshiue
Copy link
Contributor

@richardshiue richardshiue commented Jan 6, 2026

Description


Checklist

General

  • I've included relevant documentation or comments for the changes introduced.
  • I've tested the changes in multiple environments (e.g., different browsers, operating systems).

Testing

  • I've added or updated tests to validate the changes introduced for AppFlowy Web.

Feature-Specific

  • For feature additions, I've added a preview (video, screenshot, or demo) in the "Feature Preview" section.
  • I've verified that this feature integrates seamlessly with existing functionality.

Summary by Sourcery

Support normalized cover offset for document and database covers to control image positioning across views.

New Features:

  • Add support for cover offset on document, database, and mobile recent covers to control vertical image alignment.

Enhancements:

  • Normalize and clamp cover offset values in shared utilities and apply them consistently when rendering covers and publishing view metadata.
  • Allow ImageRender to accept and merge custom style overrides while preserving loading and error handling behavior.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 6, 2026

Reviewer's Guide

Adds support for a normalized vertical offset on document cover images and propagates this offset through view metadata, database row metadata, and rendering components so covers are clamped and displayed with the correct object position across web, mobile, database, and publish views.

Sequence diagram for updating and rendering a document cover with offset

sequenceDiagram
  actor User
  participant ViewCoverActions
  participant ViewMetaPreview
  participant CoverUtils
  participant Backend
  participant ViewCoverComponent
  participant ImageRender

  User->>ViewCoverActions: select new cover (type, value)
  ViewCoverActions->>ViewMetaPreview: onUpdateCover( newCover )

  ViewMetaPreview->>CoverUtils: clampCoverOffset( newCover.offset )
  CoverUtils-->>ViewMetaPreview: clampedOffset
  ViewMetaPreview->>ViewMetaPreview: normalizeCover( newCover )

  ViewMetaPreview->>Backend: updatePage( viewId, extra.cover{ type, value, offset } )
  Backend-->>ViewMetaPreview: success

  User->>ViewMetaPreview: view updated document
  ViewMetaPreview->>ViewCoverComponent: render cover with coverOffset
  ViewCoverComponent->>CoverUtils: coverOffsetToObjectPosition( offset )
  CoverUtils-->>ViewCoverComponent: objectPosition
  ViewCoverComponent->>ImageRender: render image with style.objectPosition
  ImageRender-->>User: cover shown with correct vertical offset
Loading

Class diagram for updated cover-related types and components

classDiagram
  class ViewCover {
    +CoverType type
    +string value
    +number offset
  }

  class ViewMetaCover {
  }

  class RowMetaCover {
    +string data
    +RowCoverType cover_type
    +number offset
  }

  class RowMeta {
    +RowMetaCover cover
    +string icon
    +boolean isEmptyDocument
  }

  class ViewExtra {
    +ViewCover cover
  }

  class UpdatePagePayload {
    +string name
    +ViewExtra extra
  }

  class ViewMetaPreview {
    -ViewMetaCover cover
    -ViewMetaCover normalizeCover( ViewMetaCover cover )
    -void handleUpdateCover( ViewMetaCover newCover )
  }

  class ViewCoverComponent {
    +string coverValue
    +string coverType
    +number coverOffset
  }

  class MobileRecentViewCover {
    +ViewCover cover
  }

  class DatabaseRowHeader {
    -void setRowCover( ViewCover cover )
    -RowMeta rowMeta
  }

  class PublishViewMetaHook {
    +ViewMetaCover cover
  }

  class CoverUtils {
    <<utility>>
    +number clampCoverOffset( number offset )
    +string coverOffsetToObjectPosition( number offset )
  }

  class ImageRender {
    +string src
    +object style
  }

  ViewMetaCover --|> ViewCover
  ViewExtra --> ViewCover
  UpdatePagePayload --> ViewExtra
  ViewMetaPreview --> ViewMetaCover
  ViewMetaPreview ..> CoverUtils
  ViewMetaPreview ..> ViewCoverComponent
  ViewCoverComponent --> ViewCover
  ViewCoverComponent ..> ImageRender
  ViewCoverComponent ..> CoverUtils
  MobileRecentViewCover --> ViewCover
  MobileRecentViewCover ..> ImageRender
  MobileRecentViewCover ..> CoverUtils
  DatabaseRowHeader --> RowMeta
  DatabaseRowHeader ..> CoverUtils
  RowMeta --> RowMetaCover
  PublishViewMetaHook --> ViewMetaCover
  PublishViewMetaHook ..> CoverUtils
  ImageRender <.. DatabaseRowHeader
Loading

File-Level Changes

Change Details Files
Normalize and store cover offset in shared types and metadata, ensuring values are clamped before use.
  • Extend ViewCover and related types to include an optional numeric offset field reused as ViewMetaCover.
  • Clamp cover.offset wherever cover data is read or persisted to keep it within [-1, 1].
  • Include offset in serialized database row meta cover JSON and RowMeta interface.
src/application/types.ts
src/application/database-yjs/row_meta.ts
src/application/database-yjs/database.type.ts
src/components/database/components/header/DatabaseRowHeader.tsx
src/components/publish/useViewMeta.ts
src/utils/cover.ts
Render cover images according to the normalized offset by mapping it to CSS object-position and threading it through cover-related components.
  • Add utility to convert a normalized offset to an object-position string and apply it in cover image renderers.
  • Pass coverOffset/offset props from view meta to ViewCover and MobileRecentViewCover and into ImageRender styles.
  • Initialize new covers (color, custom, Unsplash) with offset 0 so positioning is deterministic.
src/components/view-meta/ViewMetaPreview.tsx
src/components/view-meta/ViewCover.tsx
src/components/app/recent/MobileRecentViewCover.tsx
src/components/database/components/header/DatabaseRowHeader.tsx
src/components/view-meta/CoverPopover.tsx
src/utils/cover.ts
Make ImageRender support caller-provided style overrides while preserving loading and error handling behavior.
  • Accept a style prop in ImageRender, build a base style driven by loading/error state, and merge caller styles on top.
  • Ensure object-position from cover offset is applied via the merged style without breaking skeleton/loading behavior.
src/components/_shared/image-render/ImageRender.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

Copy link

@sourcery-ai sourcery-ai bot left a comment

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:

  • In row_meta.ts you’re now calling clampCoverOffset inside getMetaJSON, but there’s no corresponding import added in that file, which will cause a compile error; add the missing import from @/utils/cover.
  • You now normalize cover offsets both in ViewMetaPreview (via normalizeCover) and in useViewMeta; consider centralizing this normalization (e.g., a shared helper that returns a normalized ViewCover) to avoid duplicated logic and ensure consistent behavior across entry points.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `row_meta.ts` you’re now calling `clampCoverOffset` inside `getMetaJSON`, but there’s no corresponding import added in that file, which will cause a compile error; add the missing import from `@/utils/cover`.
- You now normalize cover offsets both in `ViewMetaPreview` (via `normalizeCover`) and in `useViewMeta`; consider centralizing this normalization (e.g., a shared helper that returns a normalized `ViewCover`) to avoid duplicated logic and ensure consistent behavior across entry points.

## Individual Comments

### Comment 1
<location> `src/components/_shared/image-render/ImageRender.tsx:23-26` </location>
<code_context>
+    height: loading ? 0 : '100%',
+    width: loading ? 1 : '100%',
+  };
+  const mergedStyle = {
+    ...baseStyle,
+    ...style,
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Allowing caller `style` to override internal error/loading styles could break expected behavior.

Because `mergedStyle` spreads `baseStyle` first and then `style`, callers can override `display`, `height`, and `width`. For instance, `style={{ display: 'block' }}` would cause the image to render even when `hasError` is true, bypassing error handling; similar overrides could break the loading skeleton. Consider reversing the spread order (`{ ...style, ...baseStyle }`) or explicitly locking down key properties like `display`, `height`, and `width` so external styles can’t violate the component’s core behavior.

```suggestion
  const mergedStyle = {
    ...style,
    ...baseStyle,
  };
```
</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.

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