Skip to content
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

Sync dataset name with datasource in add remote view #8245

Merged
merged 7 commits into from
Nov 29, 2024

Conversation

MichaelBuessemeyer
Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer commented Nov 28, 2024

URL of deployed dev instance (used for testing):

  • https://___.webknossos.xyz

Steps to test:

  • try adding a remote dataset
  • enter a DS name
  • submitting should work
  • when checking the advanced settings tab before submitting id.name should be in sync with the dataset name input field of the simple settings view

Issues:


(Please delete unneeded items, merge only when none are left open)

Copy link
Contributor

coderabbitai bot commented Nov 28, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request focus on the DatasetAddRemoteView and DatasetSettingsDataTab components, enhancing the synchronization of data source fields and error handling mechanisms. A new boolean parameter has been added to the syncDataSourceFields function, which modifies its behavior for dataset name synchronization between simple and advanced modes. Additionally, error handling has been improved to ensure operations only proceed with valid datastores, enhancing user feedback during dataset addition.

Changes

File Path Change Summary
frontend/javascripts/admin/dataset/dataset_add_remote_view.tsx Updated syncDataSourceFields call to include a new boolean parameter for mode switching. Enhanced error handling in handleStoreDataset. Modified onSuccesfulExplore to check for form errors.
frontend/javascripts/dashboard/dataset/dataset_settings_data_tab.tsx Added syncDatasetName parameter to syncDataSourceFields, allowing dataset name synchronization. Updated type casting for dataSourceFromAdvancedTab.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • daniel-wer

Poem

🐇 In fields of data, we hop and play,
With names that sync in a clever way.
Errors now caught, like carrots in sight,
Our dataset's journey feels just right!
So let’s add a view, with joy and cheer,
For every hop brings us closer, my dear! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 13eb34b and 4e51269.

📒 Files selected for processing (1)
  • CHANGELOG.unreleased.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.unreleased.md

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 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: 1

🧹 Outside diff range and nitpick comments (3)
frontend/javascripts/dashboard/dataset/dataset_settings_data_tab.tsx (2)

42-43: Consider adding JSDoc documentation

While the parameter name is self-explanatory, adding JSDoc documentation would help explain the purpose and impact of this parameter to other developers.

 export const syncDataSourceFields = (
   form: FormInstance,
   syncTargetTabKey: "simple" | "advanced",
+  /** When true, synchronizes the dataset name between simple and advanced views */
   syncDatasetName = false,
 ): void => {

59-69: LGTM: Advanced to simple sync implementation

The implementation includes proper type casting and null safety checks. For consistency with the rest of the codebase, consider using optional chaining syntax.

-    if (syncDatasetName && dataSourceFromAdvancedTab?.id?.name) {
+    if (syncDatasetName && dataSourceFromAdvancedTab?.id?.name != null) {
frontend/javascripts/admin/dataset/dataset_add_remote_view.tsx (1)

Line range hint 503-503: Ensure consistent usage of syncDataSourceFields

The syncDataSourceFields is called with different parameter counts in different places:

  • Line 379: syncDataSourceFields(form, activeEditMode, true)
  • Line 503: syncDataSourceFields(form, dataSourceEditMode === "simple" ? "advanced" : "simple")
  • Line 592: syncDataSourceFields(form, dataSourceEditMode === "simple" ? "advanced" : "simple")

For consistent behavior, consider adding the syncDatasetName parameter to all calls:

- syncDataSourceFields(form, dataSourceEditMode === "simple" ? "advanced" : "simple");
+ syncDataSourceFields(form, dataSourceEditMode === "simple" ? "advanced" : "simple", true);

Also applies to: 592-592

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7206862 and e8afa5e.

📒 Files selected for processing (2)
  • frontend/javascripts/admin/dataset/dataset_add_remote_view.tsx (1 hunks)
  • frontend/javascripts/dashboard/dataset/dataset_settings_data_tab.tsx (2 hunks)
🔇 Additional comments (3)
frontend/javascripts/dashboard/dataset/dataset_settings_data_tab.tsx (2)

36-36: LGTM: Type import addition

The ArbitraryObject type import enhances type safety for the data source object handling.


Line range hint 42-69: Verify bidirectional sync behavior

Please ensure that the bidirectional synchronization works as expected in the following scenarios:

  1. When switching from simple to advanced mode
  2. When switching from advanced to simple mode
  3. When the dataset name is empty
  4. When the datasource JSON is invalid
frontend/javascripts/admin/dataset/dataset_add_remote_view.tsx (1)

379-379: LGTM! Verify function signature in DatasetSettingsDataTab

The addition of true parameter to syncDataSourceFields correctly implements the dataset name synchronization between simple and advanced modes.

Let's verify the function signature update in the imported module:

✅ Verification successful

Function signature verified - Change is correct

The syncDataSourceFields function in dataset_settings_data_tab.tsx has the correct signature with an optional syncDatasetName parameter:

export const syncDataSourceFields = (
  form: FormInstance,
  syncTargetTabKey: "simple" | "advanced",
  syncDatasetName = false,
): void

The addition of true as the third argument in dataset_add_remote_view.tsx correctly enables dataset name synchronization, matching the function's signature and the PR's objective.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the updated function signature of syncDataSourceFields
# Expected: Should find the updated function signature with syncDatasetName parameter

ast-grep --pattern 'export function syncDataSourceFields(form: FormInstance, syncTargetTabKey: "simple" | "advanced"$_)'

Length of output: 122


Script:

#!/bin/bash
# Let's try a broader search to locate the function definition
rg -l "syncDataSourceFields" --type ts --type tsx

# Then examine the content of any matching files
rg "syncDataSourceFields" -A 5 --type ts --type tsx

Length of output: 157


Script:

#!/bin/bash
# Search for the function without file type restrictions since tsx might not be recognized
rg "syncDataSourceFields" -A 5

Length of output: 6213

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 and nitpick comments (2)
frontend/javascripts/dashboard/dataset/dataset_settings_data_tab.tsx (2)

36-45: LGTM! Consider moving the comment closer to the parameter.

The type import and optional parameter addition look good. The comments clearly explain the parameter's purpose and usage context.

Consider moving the comments closer to the parameter declaration for better readability:

export const syncDataSourceFields = (
  form: FormInstance,
  syncTargetTabKey: "simple" | "advanced",
-  // Syncing the dataset name is optional as this is needed for the add remote view, but not for the edit view.
-  // In the edit view, the datasource.id fields should never be changed and the backend will automatically ignore all changes to the id field.
-  syncDatasetName = false,
+  syncDatasetName = false, // Optional: needed for add remote view, not for edit view where datasource.id changes are ignored by backend
): void => {

54-74: LGTM! Consider enhancing type safety.

The implementation correctly handles bidirectional synchronization with proper null safety checks.

Consider using TypeScript's nullish coalescing operator for more concise null safety:

if (syncTargetTabKey === "advanced") {
  const dataSourceFromSimpleTab = form.getFieldValue("dataSource");
  if (syncDatasetName) {
-    if (dataSourceFromSimpleTab.id == null) {
-      dataSourceFromSimpleTab.id = {};
-    }
+    dataSourceFromSimpleTab.id ??= {};
    dataSourceFromSimpleTab.id.name = form.getFieldValue(["dataset", "name"]);
  }
  form.setFieldsValue({
    dataSourceJson: jsonStringify(dataSourceFromSimpleTab),
  });
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9739183 and 09a7486.

📒 Files selected for processing (1)
  • frontend/javascripts/dashboard/dataset/dataset_settings_data_tab.tsx (2 hunks)
🔇 Additional comments (1)
frontend/javascripts/dashboard/dataset/dataset_settings_data_tab.tsx (1)

54-59: Previous null safety concern has been addressed.

The implementation now includes proper null safety checks for dataSourceFromSimpleTab.id, addressing the concern raised in the previous review.

Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

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

code looks alright, but testing didn't work for me. in my case I did not switch to the advanced tab. I think in that case the synchronization is not triggered? at least, I got this error: toast.tsx:215 The datasource config could not be stored. Error: The dataset name must not be empty.. only after switching to the tab, the import worked.

Copy link
Contributor Author

@MichaelBuessemeyer MichaelBuessemeyer left a comment

Choose a reason for hiding this comment

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

Thanks for noticing 🙏 . Should be better now

form.validateFields();
};

async function handleStoreDataset() {
// Sync simple with advanced and get newest datasourceJson
syncDataSourceFields(form, dataSourceEditMode === "simple" ? "advanced" : "simple");
syncDataSourceFields(form, dataSourceEditMode === "simple" ? "advanced" : "simple", true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed a few occurrences of syncDataSourceFields 🙈, this one here being the most important.

@@ -47,12 +51,25 @@ export const syncDataSourceFields = (
if (syncTargetTabKey === "advanced") {
// Copy from simple to advanced: update json
const dataSourceFromSimpleTab = form.getFieldValue("dataSource");
if (syncDatasetName && dataSourceFromSimpleTab) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The && dataSourceFromSimpleTab was added as syncDataSourceFields is called before the first exploration request is sent to the backend. In this case dataSourceFromSimpleTab==undefined and thus I guarded this assignment below as else the code would silently crash.

Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

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

great! works now 👍

@MichaelBuessemeyer MichaelBuessemeyer enabled auto-merge (squash) November 29, 2024 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants