Skip to content

fix: [Bug]: Data source module-configuration lost after creating data…#1124

Closed
1degrees wants to merge 3 commits intoopentiny:developfrom
1degrees:refactor/develop
Closed

fix: [Bug]: Data source module-configuration lost after creating data…#1124
1degrees wants to merge 3 commits intoopentiny:developfrom
1degrees:refactor/develop

Conversation

@1degrees
Copy link
Contributor

@1degrees 1degrees commented Feb 14, 2025

… source

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

1、创建数据源后,设置远程数据字段,保存后数据丢失
2、Bugfix before
image

3、Bugfix after
image

What is the current behavior?

Issue Number: #1020

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features
    • Enhanced the remote data source save operation for quicker and more reliable data synchronization.
    • Improved handling of dynamic data to ensure stability when saving edits.

@github-actions github-actions bot added bug Something isn't working refactor-main labels Feb 14, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 14, 2025

Walkthrough

This pull request updates the remote saving workflow for the data source form. The changes modify the DataSourceForm.vue to call a new remote save function (saveRemoteHandle) instead of closing the panel. In parallel, DataSourceRemotePanel.vue introduces a reactive variable and watcher to trigger the saveRemote process automatically upon changes. Additionally, safe access to nested properties using optional chaining is implemented in the save logic.

Changes

File(s) Summary
packages/plugins/datasource/src/DataSourceForm.vue Updated import to include saveRemoteHandle; replaced closeRemotePanel() with saveRemoteHandle() in the save method; added optional chaining for columns.
packages/plugins/datasource/src/DataSourceRemotePanel.vue Added a reactive variable saveWatch and watcher; introduced saveRemoteHandle that increments saveWatch to trigger saveRemote() synchronously.

Sequence Diagram(s)

sequenceDiagram
    participant DSForm as DataSourceForm.vue
    participant DSRemote as DataSourceRemotePanel.vue

    DSForm->>DSRemote: Call saveRemoteHandle() on save
    DSRemote->>DSRemote: Increment saveWatch (reactivity trigger)
    DSRemote->>DSRemote: Watcher detects change in saveWatch
    DSRemote->>DSRemote: Execute saveRemote() to save data
Loading

Possibly related PRs

Suggested labels

ready_for_review

Suggested reviewers

  • hexqi
  • chilingling

Poem

I’m a rabbit with a hop so light,
Updating code to make it right.
With remote saves now in full swing,
saveRemoteHandle does its thing.
Bugs beware, the code's a delight! 🐇🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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.

Copy link
Contributor

@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: 0

🔭 Outside diff range comments (1)
packages/plugins/datasource/src/DataSourceForm.vue (1)

185-224: ⚠️ Potential issue

Add consistent error handling for update operation.

The error handling is inconsistent between update and add operations. The add operation has proper error handling with a catch block, but the update operation doesn't handle potential errors.

Add error handling for the update operation:

 requestUpdateDataSource(state.dataSource.id, {
   name: state.dataSource.name,
   data: Object.assign(state.dataSource.data, { columns, ...dataSourceState.remoteConfig })
-}).then(() => {
+})
+.then(() => {
   requestGenerateDataSource(getAppId())
   // 修改dataSource成功
   useNotify({
     title: '数据源修改成功',
     type: 'success'
   })
   emit('save')
   dataSourceState.dataSourceColumn = {}
   dataSourceState.dataSourceColumnCopies = {}
+})
+.catch((error) => {
+  message({ message: `数据源修改失败:${error?.message || ''}`, status: 'error' })
 })
🧹 Nitpick comments (2)
packages/plugins/datasource/src/DataSourceForm.vue (1)

175-183: Good use of optional chaining, consider additional null checks.

The optional chaining operator prevents errors when accessing nested properties. Consider adding a null check for the array before mapping:

-const columns = state.dataSource.data?.columns?.map(({ name, title, type, format, field }) => {
+const columns = (state.dataSource.data?.columns || [])?.map(({ name, title, type, format, field }) => {
packages/plugins/datasource/src/DataSourceRemotePanel.vue (1)

81-85: LGTM! Consider adding documentation for the save mechanism.

The reactive save mechanism using saveWatch and saveRemoteHandle effectively addresses the data loss issue. The synchronous watcher ensures immediate execution of the save operation.

Add JSDoc comments to explain the save mechanism:

+/**
+ * Reactive reference to trigger remote save operations.
+ * Incrementing this value triggers the save operation synchronously.
+ */
 const saveWatch = ref(0);

+/**
+ * Triggers a remote save operation by incrementing the saveWatch value.
+ * This function is exported and used by DataSourceForm to ensure
+ * remote data is saved before the main form submission.
+ */
 export const saveRemoteHandle = () => {
   saveWatch.value += 1;
 }

Also applies to: 181-181

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 66068fb and 0d484fb.

📒 Files selected for processing (2)
  • packages/plugins/datasource/src/DataSourceForm.vue (2 hunks)
  • packages/plugins/datasource/src/DataSourceRemotePanel.vue (2 hunks)
🔇 Additional comments (1)
packages/plugins/datasource/src/DataSourceForm.vue (1)

36-36: LGTM! The changes align with PR objectives.

The addition of saveRemoteHandle and its invocation before form submission ensures that remote data source configuration is properly saved, addressing the data loss issue.

Also applies to: 172-173

@1degrees 1degrees closed this by deleting the head repository Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant