Skip to content

automate variable creation notebook, cell, block#1002

Merged
johbaxter merged 2 commits intodevfrom
1001-automatically-create-variables-for-input-blocks-notebooks-and-cells
Apr 29, 2025
Merged

automate variable creation notebook, cell, block#1002
johbaxter merged 2 commits intodevfrom
1001-automatically-create-variables-for-input-blocks-notebooks-and-cells

Conversation

@johbaxter
Copy link
Copy Markdown
Contributor

…block

Description

Changes Made

How to Test

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

Notes

@johbaxter johbaxter requested a review from a team as a code owner April 28, 2025 20:20
@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

automate variable creation notebook, cell, block


User description

…block

Description

Changes Made

How to Test

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

Notes


PR Type

Enhancement, Bug fix


Description

Automate variable creation for new queries and cells
Auto-add variables for input blocks on addition
Standardize "Notebook Id" error messages
Ensure variables created after duplicating blocks


Changes walkthrough 📝

Relevant files
Enhancement
state.store.ts
Automate variable creation for queries and cells                 

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

  • Dispatch ADD_VARIABLE after creating new query
  • Iterate query cells, dispatch ADD_VARIABLE per cell
  • +28/-0   
    AddBlocksMenuCard.tsx
    Auto-add variables for input blocks                                           

    packages/client/src/components/designer/AddBlocksMenuCard.tsx

  • Import INPUT_BLOCK_TYPES constant
  • Dispatch ADD_VARIABLE for input blocks
  • +15/-1   
    DeleteDuplicateMask.tsx
    Auto-add variables on duplicating input blocks                     

    packages/client/src/components/designer/DeleteDuplicateMask.tsx

  • Import INPUT_BLOCK_TYPES constant
  • Dispatch ADD_VARIABLE on block duplication
  • +21/-1   
    NotebookAddCell.tsx
    Auto-add variable on new notebook cell                                     

    packages/client/src/components/notebook/NotebookAddCell.tsx

    • Dispatch ADD_VARIABLE after creating new notebook cell
    +11/-0   
    Bug fix
    NewQueryOverlay.tsx
    Standardize Notebook Id error messages                                     

    packages/client/src/components/notebook/NewQueryOverlay.tsx

    • Rename error messages to "Notebook Id"
    +2/-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 /improve

    @QodoAI-Agent
    Copy link
    Copy Markdown

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

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

    Missing Flags

    The ADD_VARIABLE dispatch for cell variables omits explicit isInput or isOutput flags, which may lead to default behavior and inconsistent variable states.

    // Automate variable creation for notebook and new cell
    this.dispatch({
        message: ActionMessages.ADD_VARIABLE,
        payload: {
            id: queryId,
            type: "query",
            to: queryId,
            isOutput: true
        }
    })
    Duplicated Logic

    The logic for dispatching ADD_VARIABLE for input blocks is duplicated across components; consider extracting into a shared helper to ensure consistency and maintainability.

    // TODO: REFACTOR
    // Add variables for all blocks that are inputs from user
    if (INPUT_BLOCK_TYPES.indexOf(item.json.widget) > -1) {
        state.dispatch({
            message: ActionMessages.ADD_VARIABLE,
            payload: {
                id: id,
                type: 'block',
                to: id,
                isInput: true,
            },
        });
    }
    Dispatch Ordering

    The ADD_VARIABLE dispatch occurs immediately after NEW_CELL without verifying the new cell creation succeeded; if the NEW_CELL dispatch fails or returns an unexpected id, the variable creation may fail or be orphaned.

    state.dispatch({
        message: ActionMessages.ADD_VARIABLE,
        payload: {
            id: `${query.id}--${newCellId}`,
            type: 'cell',
            to: query.id,
            cellId: newCellId,
        },
    });

    @QodoAI-Agent
    Copy link
    Copy Markdown

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Await variable dispatch before selection

    Await the ADD_VARIABLE dispatch before invoking selectCell to ensure the variable is
    created and avoid race conditions.

    packages/client/src/components/notebook/NotebookAddCell.tsx [217-227]

    -state.dispatch({
    +await state.dispatch({
         message: ActionMessages.ADD_VARIABLE,
         payload: {
             id: `${query.id}--${newCellId}`,
             type: 'cell',
             to: query.id,
             cellId: newCellId,
         },
     });
     notebook.selectCell(query.id, newCellId);
    Suggestion importance[1-10]: 6

    __

    Why: Adding await before state.dispatch ensures the variable is created before calling notebook.selectCell, reducing the risk of race conditions when updating the UI.

    Low
    General
    Destructure entries and catch dispatch errors

    Destructure the entries array for clearer intent and safer indexing, and wrap the
    dispatch call in try/catch to prevent errors from interrupting store initialization.

    libs/renderer/src/store/state/state.store.ts [1316-1328]

    -Object.entries(this._store.queries[queryId].cells).forEach((c) => {
    +Object.entries(this._store.queries[queryId].cells).forEach(([cId, cell]) => {
         // Automate variable creation for notebook and new cell
    -    const cId = c[0]
    -    this.dispatch({
    -        message: ActionMessages.ADD_VARIABLE,
    -        payload: {
    -            id: `${queryId}--${cId}`,
    -            type: "cell",
    -            to: queryId,
    -            cellId: cId
    -        }
    -    })
    -})
    +    try {
    +        this.dispatch({
    +            message: ActionMessages.ADD_VARIABLE,
    +            payload: {
    +                id: `${queryId}--${cId}`,
    +                type: "cell",
    +                to: queryId,
    +                cellId: cId
    +            }
    +        });
    +    } catch (err) {
    +        console.error('Variable creation failed for cell', cId, err);
    +    }
    +});
    Suggestion importance[1-10]: 5

    __

    Why: Destructuring [cId, cell] improves readability over indexing into c, and adding a try/catch around this.dispatch helps prevent a single failed variable creation from breaking the entire store initialization.

    Low
    Use includes instead of indexOf

    Replace the indexOf check with includes for readability and intention clarity.

    packages/client/src/components/designer/AddBlocksMenuCard.tsx [187-196]

    -if (INPUT_BLOCK_TYPES.indexOf(item.json.widget) > -1) {
    +if (INPUT_BLOCK_TYPES.includes(item.json.widget)) {
         state.dispatch({
             message: ActionMessages.ADD_VARIABLE,
             payload: {
                 id: id,
                 type: 'block',
                 to: id,
                 isInput: true,
             },
         });
     }
    Suggestion importance[1-10]: 4

    __

    Why: Switching from INPUT_BLOCK_TYPES.indexOf(...) > -1 to INPUT_BLOCK_TYPES.includes(...) is a straightforward readability improvement with no behavioral change.

    Low

    @johbaxter johbaxter merged commit 0f41f81 into dev Apr 29, 2025
    3 checks passed
    @johbaxter johbaxter deleted the 1001-automatically-create-variables-for-input-blocks-notebooks-and-cells branch April 29, 2025 16:27
    @github-actions
    Copy link
    Copy Markdown

    @CodiumAI-Agent /update_changelog

    @QodoAI-Agent
    Copy link
    Copy Markdown

    Changelog updates: 🔄

    2025-04-29 [*][https://github.com//pull/1002]

    Added

    • Automate variable creation for notebooks, cells, and input blocks

    Changed

    • Streamline variable creation logic in the renderer

    Fixed

    • Handle missing query or cell cases in input settings

    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.

    Automatically create variables for input blocks, notebooks, and cells

    2 participants