Skip to content

feat(client): open new page on creation from layers panel#825

Closed
Paulson-Robert wants to merge 2 commits intodevfrom
283-Open-newPage-onCreation-from-layersPanel
Closed

feat(client): open new page on creation from layers panel#825
Paulson-Robert wants to merge 2 commits intodevfrom
283-Open-newPage-onCreation-from-layersPanel

Conversation

@Paulson-Robert
Copy link
Copy Markdown
Contributor

Description

Changes Made

How to Test

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

Notes

@Paulson-Robert Paulson-Robert self-assigned this Apr 11, 2025
@Paulson-Robert Paulson-Robert requested a review from a team as a code owner April 11, 2025 14:28
@github-actions
Copy link
Copy Markdown

@CodiumAI-Agent /describe

@QodoAI-Agent
Copy link
Copy Markdown

Title

feat(client): open new page on creation from layers panel


User description

Description

Changes Made

How to Test

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

Notes


PR Type

Enhancement


Description

  • Update block generation to handle page blocks.

  • Refactor page add function to async for proper selection.

  • Standardize object key quoting for consistency.


Changes walkthrough 📝

Relevant files
Enhancement
state.store.ts
Refactor block generation with page id check.                       

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

  • Standardize key quoting.
  • Return block id when widget is page.
  • Minor refactor in block generation.
  • +4/-4     
    LayersPanel.tsx
    Refactor asynchronous page addition.                                         

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

  • Convert page add to async method.
  • Handle new page id and trigger selection.
  • Log error for invalid page id.
  • +9/-2     

    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 /review

    @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

    Logic Consistency

    Review the updated parent assignment logic in the block generation method to ensure that the new conditional check behaves as intended.

    if (!json["parent"] && parent) {
        block.parent = parent;
    }
    Error Handling

    Validate that the asynchronous handling of new page creation properly manages error cases and provides robust feedback to the user.

    const handlePageAdd = async () => {
        const newPageId = await state.dispatch({
            message: ActionMessages.ADD_BLOCK,
            payload: {
                json: PAGE_BLOCK,
            },
        });
        if (typeof newPageId === 'string') {
            console.log('newPageId', newPageId);
            const block = state.blocks[newPageId];
            handlePageSelection(block);
        } else {
            console.error('Invalid newPageId:', newPageId);
        }

    @QodoAI-Agent
    Copy link
    Copy Markdown

    QodoAI-Agent commented Apr 11, 2025

    PR Code Suggestions ✨

    Latest suggestions up to c255dde

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Validate block existence

    Add a validation to ensure block exists before calling handlePageSelection to avoid
    potential runtime errors.

    packages/client/src/components/blocks-workspace/panels/LayersPanel.tsx [938-944]

     if (typeof newPageId === 'string') {
         console.log('newPageId', newPageId);
         const block = state.blocks[newPageId];
    -    handlePageSelection(block);
    +    if (block) {
    +        handlePageSelection(block);
    +    } else {
    +        console.error('Block not found for newPageId:', newPageId);
    +    }
     } else {
         console.error('Invalid newPageId:', newPageId);
     }
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion adds a critical error handling check by verifying block exists before calling handlePageSelection, improving robustness without being overly complex.

    Medium

    Previous suggestions

    Suggestions up to commit d129427
    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Handle async errors

    Wrap the asynchronous block creation and dispatch logic in a try-catch block to
    properly handle potential promise rejections.

    packages/client/src/components/blocks-workspace/panels/LayersPanel.tsx [931-945]

     const handlePageAdd = async () => {
    -    const newPageId = await state.dispatch({
    -        message: ActionMessages.ADD_BLOCK,
    -        payload: {
    -            json: PAGE_BLOCK,
    -        },
    -    });
    -    ...
    +    try {
    +        const newPageId = await state.dispatch({
    +            message: ActionMessages.ADD_BLOCK,
    +            payload: {
    +                json: PAGE_BLOCK,
    +            },
    +        });
    +        if (typeof newPageId === 'string') {
    +            const block = state.blocks[newPageId];
    +            if (block) {
    +                handlePageSelection(block);
    +            } else {
    +                console.error('Block not found for newPageId:', newPageId);
    +            }
    +        } else {
    +            console.error('Invalid newPageId:', newPageId);
    +        }
    +    } catch (error) {
    +        console.error('Error dispatching ADD_BLOCK:', error);
    +    }
     };
    Suggestion importance[1-10]: 7

    __

    Why: By wrapping the asynchronous dispatch and block creation logic in a try-catch block, this suggestion improves error handling and overall robustness, addressing potential runtime exceptions.

    Medium
    Validate block existence

    Verify that the block exists in state.blocks before calling handlePageSelection to
    ensure safe execution.

    packages/client/src/components/blocks-workspace/panels/LayersPanel.tsx [938-944]

     if (typeof newPageId === 'string') {
    -    console.log('newPageId', newPageId);
         const block = state.blocks[newPageId];
    -    handlePageSelection(block);
    +    if (block) {
    +        handlePageSelection(block);
    +    } else {
    +        console.error('Block not found for newPageId:', newPageId);
    +    }
     } else {
         console.error('Invalid newPageId:', newPageId);
     }
    Suggestion importance[1-10]: 5

    __

    Why: The suggestion adds a defensive check to ensure the block exists before proceeding with handlePageSelection, which improves safety without introducing major changes.

    Low

    @johbaxter
    Copy link
    Copy Markdown
    Contributor

    Closed with #895

    Ty Paulson

    @johbaxter johbaxter closed this Apr 15, 2025
    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.

    Open new page upon creation from the Layers panel

    3 participants