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

fix: datasource name not reflecting in schema pane #37131

Merged
merged 3 commits into from
Oct 31, 2024

Conversation

albinAppsmith
Copy link
Collaborator

@albinAppsmith albinAppsmith commented Oct 30, 2024

Description

Renaming the datasource was not getting updated in schema tab. This is caused because of the use of unpublished action object.

Fixes #37118

Automation

/ok-to-test tags="@tag.Sanity"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11591002654
Commit: 2f3b111
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Wed, 30 Oct 2024 17:09:22 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced a new selector for improved datasource retrieval in the Query Debugger.
  • Improvements

    • Enhanced the way datasource information is accessed, streamlining the process for the Schema component.
    • Updated test configuration to include a mock structure for testing datasource functionality.

Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

Walkthrough

The changes introduce a new selector, getDatasource, to retrieve datasource information based on the current action configuration's datasource ID. This selector is integrated into the QueryDebuggerTabs component, replacing direct access to the datasource name with a more structured approach using the useSelector hook. The modifications streamline the data flow while maintaining existing functionality in the component.

Changes

File Path Change Summary
app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx Added getDatasource selector to retrieve datasource information, replacing direct access with useSelector.
app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.test.tsx Added list: [] to datasources in mock store for testing purposes.

Assessment against linked issues

Objective Addressed Explanation
Update the datasource name in the bottom pane (#37118)

Possibly related PRs

Suggested reviewers

  • ApekshaBhosale
  • ayushpahwa
  • hetunandu

🎉 In the realm of code, a new path we pave,
With getDatasource, our data we save.
No more direct calls, just a selector's embrace,
In QueryDebuggerTabs, we find our place.
A smoother flow, like a dance in the night,
Our datasource shines, oh what 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 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.

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 Bug Something isn't working IDE Navigation Issues/feature requests related to IDE navigation, and context switching IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage Production labels Oct 30, 2024
@albinAppsmith albinAppsmith added the ok-to-test Required label for CI label Oct 30, 2024
@albinAppsmith
Copy link
Collaborator Author

/build-deploy-preview skip-test=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11589444561.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 37131.
recreate: .

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 (1)
app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx (1)

101-104: Consider adding loading state for datasource name

The current implementation might show an empty string briefly while the datasource is being fetched. Consider showing a loading state.

-datasourceName={datasource?.name || ""}
+datasourceName={datasource?.name || datasource === undefined ? "Loading..." : ""}

Also applies to: 260-260

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e7e3d5e and 40c4991.

📒 Files selected for processing (1)
  • app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx (3 hunks)
🔇 Additional comments (3)
app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx (3)

24-24: LGTM: Clean import addition

The new selector import is properly grouped with related entity selectors.


101-104: LGTM: Proper selector implementation

The selector usage correctly handles the optional chaining for datasource ID, maintaining null safety.


260-260: Verify error handling for undefined datasource name

The fallback to empty string is good, but we should verify the UI behavior when datasource name is undefined.

✅ Verification successful

Fallback handling for undefined datasource name is consistent across codebase

The current implementation using datasource?.name || "" is consistent with other similar usages across the codebase, appearing in multiple components including DataSourceEditor and PluginActionResponse. This pattern represents a standard approach for handling undefined datasource names in the application.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for Schema component usage to verify consistent handling of undefined names
ast-grep --pattern 'Schema $$$datasourceName={$_}$$$'

Length of output: 55


Script:

#!/bin/bash
# Let's check the component usage and error handling patterns
rg -U "datasourceName.*undefined|datasourceName.*\|\|" -A 2

# Also check the component definition to understand expected props
ast-grep --pattern 'interface $_ {
  $$$
  datasourceName$_
  $$$
}'

# Look for similar patterns of handling undefined datasource names
rg "datasource\?\.name.*\|\|" -A 2

Length of output: 1713

hetunandu
hetunandu previously approved these changes Oct 30, 2024
Copy link

Deploy-Preview-URL: https://ce-37131.dp.appsmith.com

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 (1)
app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx (1)

Line range hint 101-260: Consider memoizing the datasource selector

The datasource selector result could be memoized to prevent unnecessary re-renders.

+ const memoizedGetDatasource = useCallback(
+   (state) => getDatasource(state, currentActionConfig?.datasource?.id ?? ""),
+   [currentActionConfig?.datasource?.id]
+ );
- const datasource = useSelector((state) =>
-   getDatasource(state, currentActionConfig?.datasource?.id ?? ""),
- );
+ const datasource = useSelector(memoizedGetDatasource);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e7e3d5e and 40c4991.

📒 Files selected for processing (1)
  • app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx (3 hunks)
🔇 Additional comments (3)
app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx (3)

24-24: LGTM: Clean import addition

The addition of getDatasource selector import aligns with the PR's objective to fix the datasource name update issue.


101-103: LGTM: Proper selector implementation

Good use of useSelector hook to fetch datasource information reactively. The optional chaining on the datasource ID provides proper null safety.


260-260: Verify error handling for undefined datasource name

While the optional chaining provides null safety, consider the UX when datasource name is undefined.

✅ Verification successful

The previous regex had issues. I've split the search pattern and added proper escaping. This will help us understand how datasource names are handled across the codebase and if there are any established patterns for handling undefined cases.


Let's try without file type restrictions since tsx isn't recognized. This should help us understand how datasource names are handled across the codebase.


I'll search for how the datasource name is used in the component and look for any error handling patterns around it.


Fallback handling for datasource name is appropriate

The code already implements proper error handling for undefined datasource name by using the nullish coalescing operator || to provide an empty string as fallback. This is a standard and safe approach, especially for display purposes in a debugger tab where an empty string is an acceptable fallback for missing datasource names.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there's any specific handling or display for undefined datasource names
rg -A 3 "datasourceName={|datasource.*name" --type tsx

Length of output: 188


Script:

#!/bin/bash
# Let's fix the regex and search for datasource name usage patterns
rg -A 3 "datasourceName=\{|datasource.*name" --type tsx

# Also search for any error handling or fallback patterns related to datasource
rg -B 2 -A 2 "datasource\?" --type tsx

Length of output: 154


Script:

#!/bin/bash
# Search for datasource name patterns in all files
rg -A 3 "datasourceName=\{|datasource.*name"

# Look for error handling patterns related to datasource
rg -B 2 -A 2 "datasource\?"

# Find the specific component file to understand the context better
fd "QueryDebuggerTabs.tsx"

Length of output: 547021


Script:

#!/bin/bash
# Let's check how datasource name is used in the component and if there's any error handling
ast-grep --pattern 'datasourceName={$_}'

# Also check for any error handling patterns around datasource name
rg -B 2 -A 2 'datasourceName.*\|\|.*""' --type ts

Length of output: 1292

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)
app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.test.tsx (2)

Line range hint 48-91: Add test coverage for datasource name display.

The current test only verifies text selection. Consider adding tests to verify the datasource name display functionality, which is the core issue being fixed in this PR.

it("should display the correct datasource name", () => {
  const mockDatasource = { id: "ds1", name: "TestDB" };
  const storeWithDatasource = {
    ...storeState,
    entities: {
      ...storeState.entities,
      datasources: {
        ...storeState.entities.datasources,
        list: [mockDatasource],
      },
    },
  };
  const store = mockStore(storeWithDatasource);
  
  const { getByText } = render(
    <Provider store={store}>
      <ThemeProvider theme={lightTheme}>
        <Router>
          <QueryDebuggerTabs
            actionName="Query1"
            actionSource={{
              id: "ID1",
              name: "Query1",
              type: ENTITY_TYPE.ACTION,
              datasource: mockDatasource.id,
            }}
            isRunning={false}
            onRunClick={() => {}}
          />
        </Router>
      </ThemeProvider>
    </Provider>
  );
  
  expect(getByText(mockDatasource.name)).toBeInTheDocument();
});

Line range hint 54-55: Clean up TODO comment and eslint disable.

Since we're modifying the file, we should address the TODO comment and properly type the store instead of using any.

-  // TODO: Fix this the next time the file is edited
-  // eslint-disable-next-line @typescript-eslint/no-explicit-any
-  let store: any;
+  let store: ReturnType<typeof mockStore>;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 40c4991 and 2f3b111.

📒 Files selected for processing (1)
  • app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.test.tsx (1 hunks)
🔇 Additional comments (1)
app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.test.tsx (1)

27-27: LGTM: Mock store structure updated correctly.

The addition of list: [] to datasources mock state aligns with the new selector requirements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working IDE Navigation Issues/feature requests related to IDE navigation, and context switching IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Production
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: The datasource name is not getting updated in the bottom pane
2 participants