Skip to content

Add sequencing to new layers (pages & blocks)#1498

Merged
johbaxter merged 6 commits intodevfrom
1396-add-sequencing-to-new-layers
Jul 18, 2025
Merged

Add sequencing to new layers (pages & blocks)#1498
johbaxter merged 6 commits intodevfrom
1396-add-sequencing-to-new-layers

Conversation

@Vishal24-Kanini
Copy link
Copy Markdown
Contributor

Description

This PR implements the feature, when user add new layers like pages they should count up numerically based on when they are added.
This PR also implements the feature, when user add new blocks they should count up numerically based on when they are added to the page.

Changes Made

  • Added sequencing to the pages, when add a new page, sequencing starts from page--1, page--2, page--3, page--4, and so on.
  • Added sequencing to the blocks also when user add new blocks they should count up numerically based on when they are added to the page.
  • Sequencing of blocks also starts from block--1, block--2, block--3, even across the multiple pages the count will goes on continuously.
  • User can save the app and came again to add new page or a new block, count will where it left.
  • Confirmed and put the check that page sequencing should not mix with block sequencing.
image

How to Test

  1. Steps to reproduce/test the behavior
  2. Expected outcomes

@Vishal24-Kanini Vishal24-Kanini self-assigned this Jul 11, 2025
@Vishal24-Kanini Vishal24-Kanini requested a review from a team as a code owner July 11, 2025 07:01
@Vishal24-Kanini Vishal24-Kanini linked an issue Jul 11, 2025 that may be closed by this pull request
4 tasks
@github-actions
Copy link
Copy Markdown

@CodiumAI-Agent /describe

@github-actions
Copy link
Copy Markdown

@CodiumAI-Agent /review

@QodoAI-Agent
Copy link
Copy Markdown

Title

Add sequencing to new layers (pages & blocks)


User description

Description

This PR implements the feature, when user add new layers like pages they should count up numerically based on when they are added.
This PR also implements the feature, when user add new blocks they should count up numerically based on when they are added to the page.

Changes Made

  • Added sequencing to the pages, when add a new page, sequencing starts from page--1, page--2, page--3, page--4, and so on.
  • Added sequencing to the blocks also when user add new blocks they should count up numerically based on when they are added to the page.
  • Sequencing of blocks also starts from block--1, block--2, block--3, even across the multiple pages the count will goes on continuously.
  • User can save the app and came again to add new page or a new block, count will where it left.
  • Confirmed and put the check that page sequencing should not mix with block sequencing.
image

How to Test

  1. Steps to reproduce/test the behavior
  2. Expected outcomes

PR Type

Enhancement


Description

  • Add sequential numbering for page IDs

  • Assign globally unique block numbers

  • Replace random IDs with deterministic sequences

  • Remove debug log and clean up formatting


Changes diagram

flowchart LR
  A["ADD_BLOCK action"] --> B["StateStore.generateBlock"]
  B -- "widget == 'page'" --> C["Compute next page--N"]
  B -- "widget != 'page'" --> D["Compute next widget--N"]
  C --> E["Return page--N ID"]
  D --> E["Return widget--N ID"]
Loading

Changes walkthrough 📝

Relevant files
Enhancement
state.store.ts
Implement sequential ID generation                                             

libs/renderer/src/store/state/state.store.ts

  • Replace random ID generation with sequences
  • Add page sequential numbering logic
  • Add global block numbering across pages
  • Keep page and block sequences separate
  • +34/-1   
    Formatting
    LayersPanel.tsx
    Remove debug log                                                                                 

    packages/client/src/components/blocks-workspace/panels/LayersPanel.tsx

  • Removed debug console.log for newPageId
  • Simplify error path unchanged
  • +0/-1     
    Help.tsx
    Fix component return indentation                                                 

    packages/client/src/components/help/Help.tsx

  • Fix indentation of return statement
  • Remove extra leading whitespace
  • +1/-1     
    EngineLayout.tsx
    Clean up layout formatting                                                             

    packages/client/src/pages/engine/EngineLayout.tsx

  • Remove stray blank line before StyledContent
  • Clean up layout file formatting
  • +0/-1     

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @github-actions
    Copy link
    Copy Markdown

    @CodiumAI-Agent /improve

    @QodoAI-Agent
    Copy link
    Copy Markdown

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    ID Collision

    Generating IDs by scanning existing blocks can lead to race conditions and duplicate IDs if two pages or blocks are added concurrently. Consider centralizing sequencing logic or using an atomic counter to avoid conflicts.

    let id: string;
    if (json.widget === "page") {
        // Find all page blocks and their numbers
        const usedPageNumbers = new Set<number>();
        Object.keys(this._store.blocks).forEach(blockId => {
            const match = blockId.match(/^page--(\d+)$/);
            if (match) {
                usedPageNumbers.add(Number(match[1]));
            }
        });
        // Find the lowest available page number
        let pageNum = 2; // Start from 2 to avoid conflicts with the default page
        while (usedPageNumbers.has(pageNum)) {
            pageNum++;
        }
        id = `page--${pageNum}`;
    } else if (json.widget !== "page") {
    Performance

    Iterating over the entire blocks store on every new block/page creation may become costly as the number of blocks grows. Consider maintaining a cached next-sequence value or incremental tracker.

        // Find all page blocks and their numbers
        const usedPageNumbers = new Set<number>();
        Object.keys(this._store.blocks).forEach(blockId => {
            const match = blockId.match(/^page--(\d+)$/);
            if (match) {
                usedPageNumbers.add(Number(match[1]));
            }
        });
        // Find the lowest available page number
        let pageNum = 2; // Start from 2 to avoid conflicts with the default page
        while (usedPageNumbers.has(pageNum)) {
            pageNum++;
        }
        id = `page--${pageNum}`;
    } else if (json.widget !== "page") {
        // Global sequencing: find all block numbers used, regardless of page and widget type
        const usedBlockNumbers = new Set<number>();
        Object.values(this._store.blocks).forEach(block => {
            if (block.widget !== "page") {
                const match = block.id.match(/^.+--(\d+)$/);
                if (match) {
                    usedBlockNumbers.add(Number(match[1]));
                }
            }
        });
        // Find the lowest available block number
        let blockNum = 1;
        while (usedBlockNumbers.has(blockNum)) {
            blockNum++;
        }
        id = `${json.widget}--${blockNum}`;

    @QodoAI-Agent
    Copy link
    Copy Markdown

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    private generateBlock = (json: BlockJSON, parent?: Block["parent"]) => {
    // generate a new id
    const id = `${json.widget}--${Math.floor(Math.random() * 10000)}`;
    let id: string;
    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.

    Overall i think we can split this logic out into its own private function.

    With this we should probably be a bit more optimal, and not do a loop through blocks and rather do a check.

    Will put this in the next commit

    @johbaxter johbaxter merged commit 0a0c6df into dev Jul 18, 2025
    3 checks passed
    @johbaxter johbaxter deleted the 1396-add-sequencing-to-new-layers branch July 18, 2025 17:47
    @github-actions
    Copy link
    Copy Markdown

    @CodiumAI-Agent /update_changelog

    @QodoAI-Agent
    Copy link
    Copy Markdown

    Changelog updates: 🔄

    2025-07-18 *

    Added

    • Numeric sequencing for pages when adding new pages.
    • Numeric sequencing for blocks when adding new blocks, with counts persisting across sessions and pages.

    to commit the new content to the CHANGELOG.md file, please type:
    '/update_changelog --pr_update_changelog.push_changelog_changes=true'

    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.

    Add sequencing to new layers

    3 participants