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: widget icon in Connect To options in oneclick binding menu #36703

Merged
merged 6 commits into from
Oct 7, 2024

Conversation

rahulbarwal
Copy link
Contributor

@rahulbarwal rahulbarwal commented Oct 4, 2024

Description

This pull request fixes the issue with the widget icon not displaying correctly in the Connect To options.
The useConnectToOptions function now correctly retrieves the widget config for the current widget and uses the iconSVG property from the config to display the widget icon.

Fixes #Issue Number
or
Fixes #36353

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

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

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11208692370
Commit: 80a6355
Cypress dashboard.
Tags: @tag.All
Spec:


Mon, 07 Oct 2024 09:25:24 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced datasource selection validation by ensuring images associated with queried items are present and valid.
    • Improved icon retrieval for connectable widgets in the dropdown, allowing for more accurate icon displays based on widget types.
  • Bug Fixes

    • Fixed icon rendering issues in dropdown options to ensure the correct icons are displayed.

Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

Walkthrough

The changes in this pull request involve enhancements to the ChooseAndAssertForm method in the OneClickBinding class, adding functionality to validate the presence of images in a dropdown menu after selecting a datasource. Additionally, modifications to the useConnectToOptions and useDropdown hooks introduce a new iconSVG variable to improve icon retrieval for widgets. These updates maintain the overall structure and functionality of the existing methods while integrating new validation and icon handling features.

Changes

File Change Summary
app/client/cypress/e2e/Regression/ClientSide/OneClickBinding/spec_utility.ts Modified ChooseAndAssertForm to validate image presence in dropdown menu items.
app/client/src/components/editorComponents/WidgetQueryGeneratorForm/CommonControls/DatasourceDropdown/useSource/useConnectToOptions.tsx Introduced iconSVG variable for improved widget icon retrieval in useConnectToOptions hook.
app/client/src/components/editorComponents/WidgetQueryGeneratorForm/WidgetSpecificControls/OtherFields/Field/Dropdown/useDropdown.tsx Added iconSVG variable for icon handling in dropdown options within useDropdown hook.

Possibly related PRs

Suggested labels

Enhancement

Suggested reviewers

  • sagar-qa007
  • ApekshaBhosale
  • rishabhrathod01

Poem

In the land of code where widgets play,
Icons now shine in a brighter way.
Dropdowns and forms, all set to cheer,
With images bright, the path is clear!
Validation's strong, the icons align,
A dance of logic, oh how divine! 🎉


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.

@rahulbarwal rahulbarwal self-assigned this Oct 4, 2024
@github-actions github-actions bot added Bug Something isn't working Community Reported issues reported by community members Low An issue that is neither critical nor breaks a user flow Needs Triaging Needs attention from maintainers to triage One-click Binding Issues related to the One click binding epic Production Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets labels Oct 4, 2024
@rahulbarwal rahulbarwal removed Bug Something isn't working Widgets Product This label groups issues related to widgets Low An issue that is neither critical nor breaks a user flow Production Community Reported issues reported by community members Needs Triaging Needs attention from maintainers to triage One-click Binding Issues related to the One click binding epic labels Oct 4, 2024
@github-actions github-actions bot added Bug Something isn't working Community Reported issues reported by community members Low An issue that is neither critical nor breaks a user flow Needs Triaging Needs attention from maintainers to triage One-click Binding Issues related to the One click binding epic Production Widgets Product This label groups issues related to widgets labels Oct 4, 2024
@rahulbarwal rahulbarwal changed the title Fix widget icon in Connect To options fix: widget icon in Connect To options in oneclick binding menu Oct 4, 2024
@rahulbarwal rahulbarwal added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Oct 4, 2024
@rahulbarwal rahulbarwal marked this pull request as ready for review October 7, 2024 04:29
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 (1)
app/client/cypress/e2e/Regression/ClientSide/OneClickBinding/spec_utility.ts (1)

Line range hint 1-105: Let's review our overall approach and make some improvements!

Class, you've done a good job with the structure of this file, but there are a few areas where we can make it even better:

  1. In the expandLoadMoreOptions function, we're using cy.get('body'). This is a bit too broad. Can anyone suggest a more specific selector we could use?

  2. Throughout the file, let's make sure we're using data-* attributes for our selectors wherever possible. This will make our tests more resilient to changes in the UI.

  3. We should consider creating more custom commands or helper functions for common operations. This will make our tests more readable and maintainable.

Here's an example of how we could improve the expandLoadMoreOptions function:

export function expandLoadMoreOptions() {
  agHelper.GetElement(oneClickBindingLocator.loadMoreContainer).then(($container) => {
    const loadMoreButtons = $container.find(oneClickBindingLocator.loadMore);
    if (loadMoreButtons.length > 0) {
      loadMoreButtons.each((index, button) => {
        agHelper.GetNClick(oneClickBindingLocator.loadMore, index);
      });
    }
  });
}

Remember, writing good tests is like writing a good essay. We want to be clear, specific, and organized!

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e495422 and 80a6355.

📒 Files selected for processing (3)
  • app/client/cypress/e2e/Regression/ClientSide/OneClickBinding/spec_utility.ts (1 hunks)
  • app/client/src/components/editorComponents/WidgetQueryGeneratorForm/CommonControls/DatasourceDropdown/useSource/useConnectToOptions.tsx (2 hunks)
  • app/client/src/components/editorComponents/WidgetQueryGeneratorForm/WidgetSpecificControls/OtherFields/Field/Dropdown/useDropdown.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/client/cypress/e2e/Regression/ClientSide/OneClickBinding/spec_utility.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
🔇 Additional comments (3)
app/client/cypress/e2e/Regression/ClientSide/OneClickBinding/spec_utility.ts (1)

33-33: ⚠️ Potential issue

Let's replace this hardcoded sleep with a more reliable waiting mechanism!

Class, can anyone tell me why using agHelper.Sleep(3000) might not be the best approach here? That's right! It's because it can make our tests flaky and slow.

Instead, let's use Cypress's built-in waiting mechanisms. Here's how we can improve this:

// Replace this line
agHelper.Sleep(3000); //for tables to populate for CI runs

// With something like this
agHelper.WaitUntil(() => {
  return cy.get(oneClickBindingLocator.tableOrSpreadsheetDropdown).should('be.visible');
}, 'Wait for tables to populate');

This way, we're waiting for a specific condition to be met rather than an arbitrary amount of time. It's like waiting for the bell to ring instead of looking at the clock every few seconds!

⛔ Skipped due to learnings
Learnt from: sagar-qa007
PR: appsmithorg/appsmith#35412
File: app/client/cypress/e2e/Regression/ClientSide/OneClickBinding/TableWidget/mysql_spec.ts:99-99
Timestamp: 2024-08-06T05:59:19.000Z
Learning: In Cypress tests within the `app/client/cypress` directory, avoid using `agHelper.Sleep`, `this.Sleep`, and other related sleep functions to prevent non-deterministic behaviors and ensure tests are more reliable and maintainable. Instead, use Cypress methods like `cy.get()`, `cy.contains()`, and `cy.intercept()` to wait for specific conditions.
app/client/src/components/editorComponents/WidgetQueryGeneratorForm/WidgetSpecificControls/OtherFields/Field/Dropdown/useDropdown.tsx (1)

84-86: Well done, class! Let's review the improvements in our icon handling.

Students, pay attention to the new iconSVG variable. It's like having a backup plan for our widget icons. First, we try to get the icon from our widget factory - think of it as our icon library. If that doesn't work, we use the widget's own icon. This way, we always have an icon to show!

On line 92, we're using this new iconSVG in our dropdown options. It's like updating our class roster to always have a picture for each student, even if they forgot their school photo!

This change makes our code more robust and ensures we always have an icon to display. Great job!

Also applies to: 92-92

app/client/src/components/editorComponents/WidgetQueryGeneratorForm/CommonControls/DatasourceDropdown/useSource/useConnectToOptions.tsx (1)

243-245: Class, let's examine this excellent improvement in our code!

Dear students, I'm pleased to see this enhancement in our widgetOptions useMemo hook. The introduction of the iconSVG variable is a smart move that ensures we always have the correct icon for our widgets. Let's break it down:

  1. We first try to fetch the icon from the widget configuration.
  2. If that's not available, we fall back to the current widget's iconSVG.
  3. This icon is then used in the DatasourceImage component.

This change demonstrates good coding practices by providing a fallback mechanism and improving the reliability of our UI. Well done!

Also applies to: 256-256

Comment on lines +15 to +30
agHelper.GetElement("[role='menu']").then(($menu) => {
if (
$menu.find(oneClickBindingLocator.datasourceQuerySelector()).length > 0
) {
cy.wrap($menu)
.find(oneClickBindingLocator.datasourceQuerySelector())
.should("have.length.greaterThan", 0)
.each(($item) => {
cy.wrap($item)
.find("img")
.should(($img) => {
expect($img).to.have.attr("src").and.not.be.empty;
});
});
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Class, let's review this new code block and make some improvements!

While the addition of image validation for datasource items is a good step, there are a few areas where we can enhance our code:

  1. Instead of using cy.wrap directly, let's create a custom command or helper method for better maintainability and reusability.

  2. We should avoid using hardcoded waits like agHelper.Sleep(3000). Instead, let's use Cypress's built-in waiting mechanisms or create custom waiting functions.

  3. This method is becoming quite long. Consider breaking it down into smaller, more focused methods for better readability and maintainability.

Here's an example of how we could refactor this part:

private assertDatasourceImages() {
  return agHelper.GetElement("[role='menu']").then(($menu) => {
    if ($menu.find(oneClickBindingLocator.datasourceQuerySelector()).length > 0) {
      cy.wrap($menu)
        .find(oneClickBindingLocator.datasourceQuerySelector())
        .should("have.length.greaterThan", 0)
        .each(($item) => {
          cy.wrap($item)
            .find("img")
            .should("have.attr", "src")
            .and("not.be.empty");
        });
    }
  });
}

Then, in the ChooseAndAssertForm method:

this.assertDatasourceImages();

Remember, class, breaking down complex methods into smaller, more focused ones is like solving a big problem by tackling smaller parts one at a time. It makes our code easier to understand and maintain!

@vsvamsi1
Copy link
Contributor

vsvamsi1 commented Oct 7, 2024

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Oct 7, 2024

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

Copy link

github-actions bot commented Oct 7, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Community Reported issues reported by community members Low An issue that is neither critical nor breaks a user flow Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI One-click Binding Issues related to the One click binding epic Production Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets
Projects
None yet
4 participants