Skip to content

feat: Modify the data source #1502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: release/v2.7.x
Choose a base branch
from

Conversation

xuanlid
Copy link
Contributor

@xuanlid xuanlid commented Jul 4, 2025

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

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Improved form validation with clearer error handling and automatic tab switching during the data source save process.
    • Enhanced user feedback by switching to relevant tabs when validation errors occur.
    • Automatically clears validation states when editing a data source.
    • Enabled tab switching to the "field" tab when editing records from the settings view.
  • Refactor

    • Streamlined validation and save logic for a more consistent user experience.

Copy link
Contributor

coderabbitai bot commented Jul 4, 2025

Walkthrough

The changes refactor form validation and tab-switching logic in the data source management components. The main form's save function is now asynchronous, performing sequential validations and switching tabs upon errors. Utility functions for accessing form and grid components were added, and tab change handling was modularized and exposed for event-driven UI updates.

Changes

File(s) Change Summary
DataSourceForm.vue Refactored save to async with sequential awaited validations, tab switching on error, and improved state handling. Added activeTabChange function and utility imports.
DataSourceList.vue Imported getServiceForm; cleared validation state when opening the edit form.
DataSourceSettingRecordList.vue Moved grid ref to module level; exported getRecordGrid() function.
DataSourceSettings.vue Added and exposed changeTab() method; now switches to 'field' tab on record list edit event.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DataSourceForm
    participant ServiceForm
    participant RecordGrid
    participant ParentComponent

    User->>DataSourceForm: Click Save
    DataSourceForm->>ServiceForm: validate()
    alt Validation fails
        ServiceForm-->>DataSourceForm: Error
        DataSourceForm->>DataSourceForm: Switch tab to 'remote'
        DataSourceForm-->>User: Show validation error
    else Validation succeeds
        DataSourceForm->>DataSourceForm: Validate data source name
        alt Name invalid
            DataSourceForm->>DataSourceForm: Switch tab to 'field'
            DataSourceForm-->>User: Show name error
        else Name valid
            DataSourceForm->>RecordGrid: fullValidate()
            alt Grid validation fails
                RecordGrid-->>DataSourceForm: Error
                DataSourceForm->>DataSourceForm: Switch tab to 'record'
                DataSourceForm-->>User: Show grid error
            else Grid valid
                DataSourceForm->>DataSourceForm: Save record, update/add data source
                DataSourceForm->>DataSourceForm: Clear state
                DataSourceForm->>ParentComponent: Emit 'save' event, close form
            end
        end
    end
Loading

Poem

🐇
A hop, a skip, a validation leap,
Tabs now switch when errors creep.
Async saves with careful checks,
Forms and grids in tidy specs.
Rabbits cheer for code so neat—
Bugs beware, you face defeat!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dcc9b80 and 6f30c7f.

📒 Files selected for processing (1)
  • packages/plugins/datasource/src/DataSourceForm.vue (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/plugins/datasource/src/DataSourceForm.vue
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: push-check

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

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

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

@github-actions github-actions bot added enhancement New feature or request release merge to release/ branch, before release period labels Jul 4, 2025
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: 2

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

220-305: Refactor validation flow for better maintainability

The current implementation mixes callback-based validation (getDataSourceName().validate()) with async/await patterns, making the code harder to follow and maintain.

Consider refactoring to use consistent async/await patterns:

-    getDataSourceName().validate(async (valid) => {
-      if (valid) {
+    const isNameValid = await new Promise((resolve) => {
+      getDataSourceName().validate((valid) => resolve(valid))
+    })
+    
+    if (!isNameValid) {
+      activeTabChange('field')
+      message({ message: '请输入有效的数据源名称', status: 'error' })
+      return
+    }
+    
+    // Continue with the rest of the validation and save logic

This makes the flow more linear and easier to understand.

🧹 Nitpick comments (1)
packages/plugins/datasource/src/DataSourceForm.vue (1)

232-238: Consider validation error details

The record grid validation might fail for multiple reasons. Consider providing more specific error feedback to help users identify and fix issues.

 try {
   // await validate() 如果验证不通过会抛出异常,而不是返回 false
-  await getRecordGrid().fullValidate()
+  const validationResult = await getRecordGrid().fullValidate()
+  if (!validationResult) {
+    const errors = getRecordGrid().getValidationErrors()
+    // Log or display specific validation errors
+  }
 } catch (error) {
   activeTabChange('record')
-  throw new Error(`请先完成表格验证: ${error?.message || ''}`)
+  const errorDetails = error?.message || '数据验证失败'
+  throw new Error(`请先完成表格验证: ${errorDetails}`)
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4bd9faa and dcc9b80.

📒 Files selected for processing (4)
  • packages/plugins/datasource/src/DataSourceForm.vue (5 hunks)
  • packages/plugins/datasource/src/DataSourceList.vue (2 hunks)
  • packages/plugins/datasource/src/DataSourceSettingRecordList.vue (1 hunks)
  • packages/plugins/datasource/src/DataSourceSettings.vue (3 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: gene9831
PR: opentiny/tiny-engine#1041
File: packages/plugins/datasource/src/DataSourceList.vue:138-138
Timestamp: 2025-01-14T10:06:25.508Z
Learning: PR #1041 in opentiny/tiny-engine is specifically for reverting Prettier v3 formatting to v2, without any logical code changes or syntax improvements.
Learnt from: rhlin
PR: opentiny/tiny-engine#1011
File: packages/canvas/render/src/RenderMain.ts:82-88
Timestamp: 2025-01-14T08:50:50.226Z
Learning: For PR #1011, the focus is on resolving conflicts and migrating code, with architectural improvements deferred for future PRs.
Learnt from: rhlin
PR: opentiny/tiny-engine#1011
File: packages/canvas/container/src/components/CanvasMenu.vue:228-232
Timestamp: 2025-01-14T04:29:26.886Z
Learning: Error handling for page switching is centralized in the `switchPageWithConfirm` method of the page service, rather than being duplicated in UI handlers like menu actions.
packages/plugins/datasource/src/DataSourceList.vue (2)
Learnt from: gene9831
PR: opentiny/tiny-engine#1011
File: packages/configurator/src/router-select-configurator/RouterSelectConfigurator.vue:63-73
Timestamp: 2025-01-14T06:49:00.797Z
Learning: In the tiny-engine project, the SvgIcon component is globally registered and available throughout Vue components without requiring explicit imports.
Learnt from: gene9831
PR: opentiny/tiny-engine#1011
File: packages/configurator/src/router-select-configurator/RouterSelectConfigurator.vue:95-98
Timestamp: 2025-01-14T06:55:59.692Z
Learning: The tiny-select component from @opentiny/vue library ensures selected options are valid internally, requiring no additional validation in the change handler.
packages/plugins/datasource/src/DataSourceSettings.vue (1)
Learnt from: gene9831
PR: opentiny/tiny-engine#1011
File: packages/configurator/src/router-select-configurator/RouterSelectConfigurator.vue:95-98
Timestamp: 2025-01-14T06:55:59.692Z
Learning: The tiny-select component from @opentiny/vue library ensures selected options are valid internally, requiring no additional validation in the change handler.
packages/plugins/datasource/src/DataSourceForm.vue (4)
Learnt from: gene9831
PR: opentiny/tiny-engine#1011
File: packages/configurator/src/router-select-configurator/RouterSelectConfigurator.vue:63-73
Timestamp: 2025-01-14T06:49:00.797Z
Learning: In the tiny-engine project, the SvgIcon component is globally registered and available throughout Vue components without requiring explicit imports.
Learnt from: chilingling
PR: opentiny/tiny-engine#837
File: packages/vue-generator/src/plugins/genDependenciesPlugin.js:66-66
Timestamp: 2024-09-30T07:51:10.036Z
Learning: In the `tiny-engine` project, `@opentiny/tiny-engine-dsl-vue` refers to the current package itself, and importing types from it may cause circular dependencies.
Learnt from: gene9831
PR: opentiny/tiny-engine#1011
File: packages/configurator/src/router-select-configurator/RouterSelectConfigurator.vue:95-98
Timestamp: 2025-01-14T06:55:59.692Z
Learning: The tiny-select component from @opentiny/vue library ensures selected options are valid internally, requiring no additional validation in the change handler.
Learnt from: gene9831
PR: opentiny/tiny-engine#1011
File: packages/configurator/src/router-select-configurator/RouterSelectConfigurator.vue:63-73
Timestamp: 2025-01-14T06:49:00.797Z
Learning: In the tiny-engine project, the SvgIcon component is globally registered using `app.component('SvgIcon', SvgIcon)` in `packages/svgs/index.js`, making it available throughout Vue components without requiring explicit imports.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: push-check
🔇 Additional comments (3)
packages/plugins/datasource/src/DataSourceList.vue (1)

36-36: Good practice: Clear validation state on form open

Clearing validation errors when opening the data source form improves user experience by not showing stale validation messages. The optional chaining operator appropriately handles cases where the form might not be initialized yet.

Also applies to: 78-78

packages/plugins/datasource/src/DataSourceSettings.vue (1)

23-23: Clean implementation of tab switching on edit

The changeTab method and its integration with the edit event provide a smooth user experience by automatically switching to the relevant tab when editing records.

Also applies to: 97-99, 152-152

packages/plugins/datasource/src/DataSourceForm.vue (1)

275-275: Good addition: Clear remote config on save

Adding dataSourceState.remoteConfig = {} ensures that stale remote configuration doesn't persist after saving, preventing potential data inconsistencies.

Also applies to: 292-292

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request release merge to release/ branch, before release period
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant