Skip to content

Conversation

@MohitAgrawal16
Copy link
Collaborator

@MohitAgrawal16 MohitAgrawal16 commented Aug 4, 2025

Fixes: #1628

Here we can solve it by two ways:

1.Either keep the source defined primary key and cursor field always checked.
2. or clear all keys when changing to non-incremental and when again changed to incremental, update primary key and cursor field according to source defined.

I had pushed commits with 1st approach.

Summary by CodeRabbit

  • Bug Fixes
    • Preserves source-defined cursor fields and primary keys when disabling incremental sync, avoiding unintended clears.
    • Stops automatically clearing primary keys when changing destination sync mode away from append+dedupe, reducing unexpected configuration loss.
    • No changes to public APIs or exported interfaces.

@coderabbitai
Copy link

coderabbitai bot commented Aug 4, 2025

Walkthrough

The setStreamIncr logic in src/components/Connections/CreateConnectionForm.tsx was changed to only clear a stream's cursorField or primaryKey when disabling incremental sync if those fields are not source-defined. Additionally, setDestinationSyncMode no longer clears primaryKey when changing away from append_dedup.

Changes

Cohort / File(s) Change Summary
Incremental sync and primary key handling
src/components/Connections/CreateConnectionForm.tsx
Preserve source-defined cursorField and primaryKey when disabling incremental sync; stop clearing primaryKey in setDestinationSyncMode.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CreateConnectionForm
    participant Stream

    User->>CreateConnectionForm: Toggle incremental sync OFF
    CreateConnectionForm->>Stream: Inspect stream.cursorFieldConfig.sourceDefinedCursor
    alt sourceDefinedCursor == true
        CreateConnectionForm->>Stream: Keep cursorField
    else
        CreateConnectionForm->>Stream: Clear cursorField
    end
    CreateConnectionForm->>Stream: Inspect stream.primaryKeyConfig.sourceDefinedPrimaryKey
    alt sourceDefinedPrimaryKey == true
        CreateConnectionForm->>Stream: Keep primaryKey
    else
        CreateConnectionForm->>Stream: Clear primaryKey
    end

    User->>CreateConnectionForm: Change destination sync mode away from append_dedup
    CreateConnectionForm->>Stream: Update destinationSyncMode (do not modify primaryKey)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Fix issue where primary key cannot be selected after toggling incremental sync mode in create connection (#1628)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bug/primary_key_selection

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@MohitAgrawal16
Copy link
Collaborator Author

Since when source defined is true, we can't select any other keys as primary key.

So now The simple solution is to clear primary keys and cursor if it is not source defined, otherwise it will remain as it is.

@himanshudube97
Copy link
Member

@MohitAgrawal16
This doesn't work if I change to Append from Append/Dedup and then reselect Append/Dedup - here you can't select the primary key - issue persists.

@MohitAgrawal16
Copy link
Collaborator Author

@MohitAgrawal16 This doesn't work if I change to Append from Append/Dedup and then reselect Append/Dedup - here you can't select the primary key - issue persists.

Ok....I will check and fix it.

@codecov
Copy link

codecov bot commented Aug 14, 2025

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@5395304). Learn more about missing BASE report.
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
...rc/components/Connections/CreateConnectionForm.tsx 0.00% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1631   +/-   ##
=======================================
  Coverage        ?   75.96%           
=======================================
  Files           ?      102           
  Lines           ?     7773           
  Branches        ?     1875           
=======================================
  Hits            ?     5905           
  Misses          ?     1836           
  Partials        ?       32           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
src/components/Connections/CreateConnectionForm.tsx (1)

158-164: Primary key options for source-defined streams should come from the stream, not from config

Using el.config.primaryKey to populate options can leave the Primary Key menu empty (especially in “create” flows), which matches the reported “cannot select primary key” behavior after mode toggles. For source-defined PKs, derive options from el.stream.sourceDefinedPrimaryKey and prefer persisted config only to initialize the current selection.

Apply this diff to fix the options source and keep behavior consistent for both create and edit:

-      if (primaryKeyObj.sourceDefinedPrimaryKey) {
-        stream.primaryKey = el.config.primaryKey.flat();
-        primaryKeyObj.primaryKeyOptions = el.config.primaryKey.flat();
-      } else {
+      if (primaryKeyObj.sourceDefinedPrimaryKey) {
+        const sdpk = (el.stream.sourceDefinedPrimaryKey || []).flat();
+        // Prefer persisted config if available (edit), otherwise use source-defined defaults.
+        stream.primaryKey =
+          (el.config.primaryKey && el.config.primaryKey.length > 0)
+            ? el.config.primaryKey.flat()
+            : sdpk;
+        primaryKeyObj.primaryKeyOptions = sdpk;
+      } else {
🧹 Nitpick comments (2)
src/components/Connections/CreateConnectionForm.tsx (2)

485-505: Align bulk toggle semantics with per-stream toggle for cursor/PK resets

handleIncrementalAllStreams does not mirror the new conditional reset semantics you added in setStreamIncr. Today, turning OFF incremental for all streams leaves user-defined cursor/PK values intact, while turning it off for a single stream clears them. This inconsistency can confuse users and cause the “Incremental All” switch availability to differ based on which control they used.

Apply this diff to conditionally clear user-defined values when turning incremental OFF in bulk:

   const sourceStreamsSlice: Array<SourceStream> = sourceStreams.map((stream: SourceStream) => {
@@
-    return {
-      ...stream,
-      syncMode: checked ? 'incremental' : 'full_refresh',
-      destinationSyncMode: destinationMode,
-    };
+    const nextCursorField =
+      !checked && !stream.cursorFieldConfig.sourceDefinedCursor ? '' : stream.cursorField;
+    const nextPrimaryKey =
+      !checked && !stream.primaryKeyConfig.sourceDefinedPrimaryKey ? [] : stream.primaryKey;
+
+    return {
+      ...stream,
+      syncMode: checked ? 'incremental' : 'full_refresh',
+      destinationSyncMode: destinationMode,
+      cursorField: nextCursorField,
+      primaryKey: nextPrimaryKey,
+    };
   });

41-44: Typo: rename PrimayKeyConfig to PrimaryKeyConfig

Minor but worthwhile cleanup to avoid confusion and improve readability.

-type PrimayKeyConfig = {
+type PrimaryKeyConfig = {
   sourceDefinedPrimaryKey: boolean;
   primaryKeyOptions: string[];
 };
@@
-  primaryKeyConfig: PrimayKeyConfig;
+  primaryKeyConfig: PrimaryKeyConfig;

Also applies to: 60-60

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f488523 and 4b86307.

📒 Files selected for processing (1)
  • src/components/Connections/CreateConnectionForm.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Ishankoradia
PR: DalgoT4D/webapp#1623
File: src/components/Connections/Connections.tsx:816-853
Timestamp: 2025-08-03T14:08:39.068Z
Learning: In src/components/Connections/StreamSelectionDialog.tsx, the confirm button is disabled until at least one stream is selected, preventing users from proceeding with an empty stream selection. This UI validation makes server-side validation for empty selectedStreamsForClear array redundant in the clearSelectedStreams function.
📚 Learning: 2025-08-03T14:08:39.068Z
Learnt from: Ishankoradia
PR: DalgoT4D/webapp#1623
File: src/components/Connections/Connections.tsx:816-853
Timestamp: 2025-08-03T14:08:39.068Z
Learning: In src/components/Connections/StreamSelectionDialog.tsx, the confirm button is disabled until at least one stream is selected, preventing users from proceeding with an empty stream selection. This UI validation makes server-side validation for empty selectedStreamsForClear array redundant in the clearSelectedStreams function.

Applied to files:

  • src/components/Connections/CreateConnectionForm.tsx
🔇 Additional comments (1)
src/components/Connections/CreateConnectionForm.tsx (1)

441-442: Re-verify the Append ↔ Append/Dedup toggle UX; primary key selectability depends on multiple gates

Even after not clearing primaryKey in setDestinationSyncMode, the Primary Key control is disabled unless ALL conditions are true: stream selected, supports incremental, syncMode is incremental, and destinationSyncMode is append_dedup. Also, if options are empty (see source-defined fix above), the user still can’t select anything.

Please validate manually:

  • Start with a stream in incremental mode.
  • Toggle Destination between Append and Append/Dedup.
  • Ensure when in Append/Dedup, the Primary Key menu is enabled and populated (for non source-defined PKs).
  • For source-defined PKs, verify the selected keys remain visible and the checkboxes are disabled (by design).

If you still see a disabled or empty menu in Append/Dedup for non source-defined PKs, the options source fix (proposed above) is likely the missing piece.

Also applies to: 708-714, 745-785

Comment on lines +423 to +431
if (!stream.cursorFieldConfig.sourceDefinedCursor) {
// Reset to empty cursor field if not source-defined
stream.cursorField = '';
}

if (!stream.primaryKeyConfig.sourceDefinedPrimaryKey) {
// Reset primary key to empty array if not source-defined
stream.primaryKey = [];
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid mutating React state objects in-place; compute next values and update immutably

Directly mutating stream before calling updateThisStreamTo_ risks subtle bugs and stale renders. Compute the next values and pass them in a single immutable update.

Apply this diff to make the update atomic and immutable:

-    if (!checked) {
-      if (!stream.cursorFieldConfig.sourceDefinedCursor) {
-        // Reset to empty cursor field if not source-defined
-        stream.cursorField = '';
-      }
-
-      if (!stream.primaryKeyConfig.sourceDefinedPrimaryKey) {
-        // Reset primary key to empty array if not source-defined
-        stream.primaryKey = [];
-      }
-    }
-
-    updateThisStreamTo_(stream, {
-      ...stream,
-      syncMode: checked ? 'incremental' : 'full_refresh',
-      destinationSyncMode: destinationMode,
-    });
+    const nextCursorField =
+      !checked && !stream.cursorFieldConfig.sourceDefinedCursor ? '' : stream.cursorField;
+    const nextPrimaryKey =
+      !checked && !stream.primaryKeyConfig.sourceDefinedPrimaryKey ? [] : stream.primaryKey;
+
+    updateThisStreamTo_(stream, {
+      ...stream,
+      syncMode: checked ? 'incremental' : 'full_refresh',
+      destinationSyncMode: destinationMode,
+      cursorField: nextCursorField,
+      primaryKey: nextPrimaryKey,
+    });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!stream.cursorFieldConfig.sourceDefinedCursor) {
// Reset to empty cursor field if not source-defined
stream.cursorField = '';
}
if (!stream.primaryKeyConfig.sourceDefinedPrimaryKey) {
// Reset primary key to empty array if not source-defined
stream.primaryKey = [];
}
const nextCursorField =
!checked && !stream.cursorFieldConfig.sourceDefinedCursor ? '' : stream.cursorField;
const nextPrimaryKey =
!checked && !stream.primaryKeyConfig.sourceDefinedPrimaryKey ? [] : stream.primaryKey;
updateThisStreamTo_(stream, {
...stream,
syncMode: checked ? 'incremental' : 'full_refresh',
destinationSyncMode: destinationMode,
cursorField: nextCursorField,
primaryKey: nextPrimaryKey,
});
🤖 Prompt for AI Agents
In src/components/Connections/CreateConnectionForm.tsx around lines 423 to 431,
avoid mutating the stream object in-place; instead compute the next stream
object immutably and call updateThisStreamTo_ once with that object. Concretely,
build a newStream = { ...stream, cursorField:
stream.cursorFieldConfig.sourceDefinedCursor ? stream.cursorField : '',
primaryKey: stream.primaryKeyConfig.sourceDefinedPrimaryKey ? stream.primaryKey
: [] } (ensuring any nested objects are spread as needed) and pass newStream to
updateThisStreamTo_ so the update is atomic and no in-place mutation occurs.

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.

Issue with selecting the primary key in create connection.

2 participants