Skip to content

feat: render conditional styling in formula cells and previews - #610

Merged
appflowy merged 2 commits into
mainfrom
codex/formula-conditional-style
Oct 7, 2026
Merged

appflowy merged 2 commits into
mainfrom
codex/formula-conditional-style

Conversation

@appflowy

@appflowy appflowy commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

Formula style() previously returned plain text, so if(Conversion > 90, style(format(Conversion), "red"), format(Conversion)) displayed every conversion in the default color. Preserve style runs through evaluation and caching, and render them in Formula cells and editor previews. Values above 90 are now red; exactly 90 keeps the default color.

The implementation supports text/background colors and bold, italic, underline, strikethrough, and code styles, plus selective unstyle(). Formatting survives conditionals, variables, concatenation, format, join, and repeat. Plain text remains the value used for comparisons, sorting, filtering, copying, and export.

Tests

The reporter's notion_formula_conversion_test_data.csv is included unchanged. The CSV Playwright BDD scenario populates all 12 rows, pastes the conversion formula, and checks actual computed text colors, editor preview, live transitions across the threshold, and persistence after reload.

All 23 options (five text formats, nine text colors, nine backgrounds) now have explicit individual browser coverage in formula-conditional-styling.feature. Each is applied and cleared through the editor, with strict assertions in both preview and saved cell. Every text leaf must match the expected computed foreground, background, font weight, italic style, decoration, font family and corner radius; an adjacent plain run must stay unstyled. A third scenario checks combined formatting, selective/full removal and color overrides. Engine tests assert exact style metadata for every token; renderer tests check exact emitted styles/classes and clearing.

  • Before the fix: the scenario failed on 91: actual rgb(33, 35, 42), expected red rgb(204, 78, 78).
  • After the fix: all 3 Playwright BDD scenarios passed in 3.0 minutes. The restored 23-option scenario passed again in 1.2 minutes after the regression probe. Traces confirm every one of the 23 apply-and-clear cases ran.
  • Before this test-only expansion, the full formula suite passed 21 suites / 3,867 tests with TZ=UTC, and the formula cell/editor UI suite passed 27 tests.
  • Latest focused engine/cell/renderer validation: 3 suites / 93 tests passed.
  • Regression proof: temporarily disabling code styling fails the new browser assertion at c (missing background and 4px corner radius). The renderer was restored byte-for-byte before the passing rerun.
  • Final pnpm lint (TypeScript and ESLint), BDD generation, and separate typed BDD-step lint/format checks passed.

Run the focused browser regression against the configured test server with:

pnpm exec bddgen test -c playwright.bdd.config.ts
pnpm exec playwright test -c playwright.bdd.config.ts --grep '@formula-conditional-styling' --project=chromium --workers=1

Feature Preview

Actual screenshots captured during the failing and passing Playwright runs using the supplied CSV.

Before — failing color assertion: 91, 95, and 100 are still painted in the default color.

Before fix: Playwright reproduction shows all conversion values in the default color

After — passing regression: the four rows above 90 (91, 95, 100, 91) are red. Both rows at exactly 90 retain the default color. This capture occurs before the scenario edits row 5 and verifies reload.

After fix: all 12 CSV rows match expected text and conditional colors

Checklist

  • Relevant documentation/comments included.
  • Tested in multiple browsers/operating systems (browser validation used Chromium on macOS).
  • Added and updated regression tests.
  • Included feature screenshots from actual test runs.
  • Verified formula evaluation, preview, caching, and live updates through the checks above.

@sourcery-ai

sourcery-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown

Sorry @appflowy, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 5 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR introduces structured styled text runs for formula values, propagates them through evaluation, formatting, caching, and cell state while preserving plain-text behavior for data operations, and renders the styling in formula cells and editor previews. It adds comprehensive unit, component, cache, and end-to-end regression coverage for conditional styling and live persistence.

Sequence diagram for conditional formula styling and rendering

sequenceDiagram
    actor User
    participant Editor as FormulaEditor
    participant Evaluator as evaluateFormulaCell
    participant Cache as FormulaResultCache
    participant Cell as FormulaCell
    participant Renderer as FormulaTextContent

    User->>Editor: paste conditional formula
    Editor->>Evaluator: evaluateFormulaCell
    Evaluator->>Evaluator: styleText
    Evaluator->>Cache: cache styled result
    Evaluator-->>Editor: text and runs
    Editor->>Renderer: render preview with runs
    User->>Cell: close editor
    Cell->>Cache: read evaluated result
    Cache-->>Cell: plain text and runs
    Cell->>Renderer: render formula cell with runs
    User->>Cell: change source values
    Cell->>Evaluator: evaluateFormulaCell
    Evaluator-->>Cell: updated runs
    Cell->>Renderer: render default or red text
Loading

Flow diagram for threshold-based formula styling

flowchart TD
    Inputs[Done and In progress values] --> Conversion[round conversion percentage]
    Conversion --> Threshold{Conversion > 90}
    Threshold -->|yes| Red[style formatted value red]
    Threshold -->|no| Default[formatted value with default color]
    Red --> Runs[structured text runs]
    Default --> Runs
    Runs --> Display[Formula cell and editor preview]
    Runs --> Plain[plain text for comparison sorting filtering export]
Loading

File-Level Changes

Change Details Files
Carries formula text styling as structured runs while retaining plain text semantics.
  • Added typed text runs and supported foreground/background colors and decorations.
  • Applied and selectively removed styles through style(), unstyle(), concatenation, formatting, joins, and repetition.
  • Updated coercion, formatting, work budgeting, and cache fingerprints/cloning to preserve runs safely and avoid mutation or unbounded growth.
  • Kept comparisons, sorting, filtering, copying, and export based on unstyled text.
src/application/database-yjs/fields/formula/values.ts
src/application/database-yjs/fields/formula/styled-text.ts
src/application/database-yjs/fields/formula/coerce.ts
src/application/database-yjs/fields/formula/evaluator.ts
src/application/database-yjs/fields/formula/functions/text.ts
src/application/database-yjs/fields/formula/format.ts
src/application/database-yjs/fields/formula/budget.ts
src/application/database-yjs/fields/formula/result-cache.ts
src/application/database-yjs/fields/formula/evaluate.ts
src/application/database-yjs/fields/formula/formula.type.ts
src/application/database-yjs/fields/formula/index.ts
Persists styled formula results through database cell selection and renders them in cells and formula previews.
  • Added optional runs to formula cell/result models and selector output.
  • Introduced shared rendering for inline font, decoration, color, background, and code styles using theme palettes.
  • Applied viewer-specific date/number formatting without losing nested text styling.
  • Rendered the same styled runs in the formula editor preview.
src/application/database-yjs/cell.type.ts
src/application/database-yjs/selector.ts
src/components/database/components/cell/formula/FormulaCell.tsx
src/components/database/components/cell/formula/FormulaTextContent.tsx
src/components/database/components/property/formula/FormulaEditor.tsx
Expanded automated coverage for styled formula evaluation, caching, rendering, and conditional UI behavior.
  • Added unit coverage for conditional thresholds, style composition/removal, nested formatting, repetition, work limits, and plain-text operations.
  • Added cache isolation and dependency-refresh tests.
  • Added FormulaCell styling coverage and a Chromium BDD scenario covering CSV setup, editor preview, live threshold transitions, and reload persistence.
  • Updated long-formula documentation assertions for applied styles.
src/application/database-yjs/fields/formula/__tests__/styling.test.ts
src/application/database-yjs/fields/formula/__tests__/format.test.ts
src/application/database-yjs/fields/formula/__tests__/result-cache.test.ts
src/application/database-yjs/fields/formula/__tests__/issue-9039.test.ts
src/components/database/components/cell/formula/FormulaCell.test.tsx
playwright/bdd/features/database/formula-conditional-styling.feature
playwright/bdd/steps/formula-conditional-styling.steps.ts
playwright/bdd/features/database/formula-long-notion-formulas.feature
playwright/fixtures/database/csv/notion_formula_conversion_test_data.csv

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

@appflowy
appflowy merged commit f4bb244 into main Oct 7, 2026
21 checks passed
@appflowy
appflowy deleted the codex/formula-conditional-style branch October 7, 2026 11:45
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.

1 participant