Skip to content

Fixed create new optimistic#16257

Merged
charlesBochet merged 2 commits intomainfrom
fix/create-new-records-optimistic
Dec 2, 2025
Merged

Fixed create new optimistic#16257
charlesBochet merged 2 commits intomainfrom
fix/create-new-records-optimistic

Conversation

@lucasbordeau
Copy link
Copy Markdown
Contributor

This PR fixes create new optimistic on boards, which was broken due to a recent refactor of the query system for boards in : #16063

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Dec 2, 2025

Greptile Overview

Greptile Summary

This PR fixes the broken optimistic create functionality for boards by centralizing the logic in useCreateNewIndexRecord. Previously, after the refactor in #16063, the board column header had duplicate logic that wasn't properly handling the optimistic state updates for grouped records.

Key changes:

  • Moved optimistic group state management from RecordBoardColumnHeader into useCreateNewIndexRecord hook
  • The hook now checks for recordIndexGroupFieldMetadataItem and updates the appropriate group's record IDs
  • Supports both 'first' and 'last' position insertion for records
  • Renamed CreateNewTableRecordNoSelectionRecordAction to CreateNewIndexRecordNoSelectionRecordAction to reflect its broader use (tables and boards)

The fix ensures that when creating a new record in a board column, the record appears immediately in the correct column through optimistic updates, matching the table view behavior.

Confidence Score: 5/5

  • This PR is safe to merge with no identified issues
  • The fix properly centralizes optimistic update logic that was broken by a previous refactor. The implementation correctly handles grouped record state updates, properly checks for the group field metadata, and maintains the same functionality that worked before. No edge cases or potential issues identified.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/twenty-front/src/modules/object-record/record-table/hooks/useCreateNewIndexRecord.ts 5/5 Centralized optimistic update logic for creating records in both table and board views, handling group-by state updates correctly
packages/twenty-front/src/modules/object-record/record-board/record-board-column/components/RecordBoardColumnHeader.tsx 5/5 Simplified by removing duplicate optimistic update logic, now delegates to centralized useCreateNewIndexRecord hook

Sequence Diagram

sequenceDiagram
    participant User
    participant RecordBoardColumnHeader
    participant useCreateNewIndexRecord
    participant useCreateOneRecord
    participant Apollo Cache
    participant Backend API
    participant Recoil State

    User->>RecordBoardColumnHeader: Click "+" button
    RecordBoardColumnHeader->>useCreateNewIndexRecord: createNewIndexRecord({position: 'first', [selectField]: columnValue})
    
    useCreateNewIndexRecord->>useCreateOneRecord: createOneRecord(recordInput)
    useCreateOneRecord->>Apollo Cache: Create optimistic record
    useCreateOneRecord->>Backend API: Mutation: createRecord
    
    useCreateOneRecord-->>useCreateNewIndexRecord: Return created record
    
    alt recordIndexGroupFieldMetadataItem exists
        useCreateNewIndexRecord->>useCreateNewIndexRecord: Find matching recordGroup by field value
        alt recordGroup found
            useCreateNewIndexRecord->>Recoil State: Get current recordIds for group
            alt position === 'first'
                useCreateNewIndexRecord->>Recoil State: Set [newRecordId, ...currentIds]
            else position !== 'first'
                useCreateNewIndexRecord->>Recoil State: Set [...currentIds, newRecordId]
            end
        end
    end
    
    useCreateNewIndexRecord->>Recoil State: upsertRecordsInStore([createdRecord])
    
    alt Open in side panel
        useCreateNewIndexRecord->>useCreateNewIndexRecord: openRecordInCommandMenu()
        useCreateNewIndexRecord->>useCreateNewIndexRecord: openRecordTitleCell()
    else Navigate to record page
        useCreateNewIndexRecord->>User: Navigate to RecordShowPage
    end
    
    Backend API-->>Apollo Cache: Return actual record data
    Apollo Cache->>Recoil State: Update with server response
    RecordBoardColumnHeader->>User: Show new record in column
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 2, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:57509

This environment will automatically shut down when the PR is closed or after 5 hours.

@charlesBochet charlesBochet merged commit 21c023c into main Dec 2, 2025
63 checks passed
@charlesBochet charlesBochet deleted the fix/create-new-records-optimistic branch December 2, 2025 15:37
@twenty-eng-sync
Copy link
Copy Markdown

Hey @lucasbordeau! After you've done the QA of your Pull Request, you can mark it as done here. Thank you!

NotYen pushed a commit to NotYen/twenty-ym that referenced this pull request Dec 4, 2025
This PR fixes create new optimistic on boards, which was broken due to a
recent refactor of the query system for boards in : twentyhq#16063
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