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: Incorrect updation of selctedRowIndex when primary column is set. #36393

Merged

Conversation

rahulbarwal
Copy link
Contributor

@rahulbarwal rahulbarwal commented Sep 18, 2024

Description

Problem statement

  1. Table should have a primary column set.
  2. The table should be filtered(via search or client side filters)
  3. there should be a selectedRow in table
    a. One way to ensure is add a text widget and bind it to table's selectedRowIndex property.

If you now run a query that updates the data behind the table: the selectedRow is updated to (seemingly) random row and selectedRowIndex is updated as well

Rootcause
We have a mechanism of preserving selectedRow when data updates happen.
Underlying logic gets the previous selected row and tries to find it in the new data using the primary key.

  • If it finds it, it updates the selectedRowIndex to the __original_index__ of the found row i.e. its position in the original data before any filters were applied.

Solution
We update the selectedRowIndex to the index in the new filtered data.

How to test

  1. Create a table with a primary key
  2. Add a text widget and bind it to table's selectedRowIndex property
  3. Filter the table
  4. Click on a row to select it
  5. Run a query that updates the data behind the table
  6. Assert that the selected row is the same and that the selectedRowIndex is updated to the new index

Fixes #36080
or
Fixes Issue URL

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.Table, @tag.Binding, @tag.Sanity"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10953679202
Commit: 1a2d644
Cypress dashboard.
Tags: @tag.Table, @tag.Binding, @tag.Sanity
Spec:


Fri, 20 Sep 2024 06:30:08 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

Summary by CodeRabbit

  • Improvements

    • Enhanced the efficiency of the TableWidgetV2 by streamlining the method for retrieving the index of selected rows.
    • Improved code readability and maintainability without altering the overall functionality.
  • New Features

    • Introduced new test cases to validate filtering and searching functionalities within the Table Widget V2.
    • Added a JSON configuration for a data-driven table interface, supporting sorting, filtering, and dynamic data binding.
    • Introduced fixture data for testing, allowing for comprehensive validation of table behavior under various conditions.
    • Added a JavaScript object containing employee data to facilitate filtering and display in the table.

…ed to select row using original index, simple index will suffice.
@rahulbarwal rahulbarwal self-assigned this Sep 18, 2024
Copy link
Contributor

coderabbitai bot commented Sep 18, 2024

Walkthrough

The pull request introduces a modification to the getOriginalRowIndex function in the utilities.ts file of the TableWidgetV2 component. The update replaces the previous method of locating a selected row in the tableData array using the find method with a more efficient approach that employs the findIndex method. This change simplifies the code while maintaining the original functionality of returning the index of the row based on the primary key.

Changes

File Path Change Summary
app/client/src/widgets/TableWidgetV2/widget/utilities.ts Modified the getOriginalRowIndex function to replace the find method with findIndex, simplifying the logic and enhancing readability.
app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_FilteredTableData_spec.ts Enhanced tests for filtering and searching functionality in the Table Widget V2.
app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_filteredTableData_spec/Fixture.ts Added fixture data for testing purposes, including employee objects and a method for data manipulation.
app/client/cypress/fixtures/tableV2FilteringWithPrimaryColumn.json Added JSON configuration for a table widget, defining its properties and behaviors.
app/client/cypress/fixtures/tableV2FilteringWithPrimaryColumnJSObjectWidthData.ts Introduced a JavaScript object containing employee data for testing and demonstration purposes.

Assessment against linked issues

Objective Addressed Explanation
Ensure selectedRowIndex does not update unnecessarily on data reload (36080)

Possibly related PRs

Suggested labels

Enhancement, Table Widget, Test

In the code where rows reside,
A change was made, a smoother ride.
From find to findIndex, swift and bright,
The logic now shines, a clearer sight.
With fewer lines, the code does gleam,
Efficiency reigns, like a coder's dream! 🌟


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 High This issue blocks a user from building or impacts a lot of users Needs Triaging Needs attention from maintainers to triage Production Table Widget V2 Issues related to Table Widget V2 Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets labels Sep 18, 2024
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@rahulbarwal rahulbarwal marked this pull request as draft September 18, 2024 09:39
Copy link

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

Copy link

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

Copy link

🔴 There's new test files in JS, please port to TS and re-trigger Cypress tests:

  1. app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_filteredTableData_spec/Fixture.js
  2. app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_filteredTableData_spec/TableV2_FilteredTableData_spec.js

@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

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

Copy link

🔴 There's new test files in JS, please port to TS and re-trigger Cypress tests:

  1. app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_filteredTableData_spec/Fixture.js
  2. app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_filteredTableData_spec/TableV2_FilteredTableData_spec.js

@rahulbarwal rahulbarwal added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Sep 19, 2024
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: 4

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 69b58b5 and 1f7a16b.

Files selected for processing (2)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_FilteredTableData_spec.ts (1 hunks)
  • app/client/cypress/fixtures/tableV2FilteringWithPrimaryColumnJSObjectWidthData.ts (1 hunks)
Additional context used
Path-based instructions (2)
app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_FilteredTableData_spec.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.
app/client/cypress/fixtures/tableV2FilteringWithPrimaryColumnJSObjectWidthData.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 not posted (1)
app/client/cypress/fixtures/tableV2FilteringWithPrimaryColumnJSObjectWidthData.ts (1)

1-84: Great work on creating this test data fixture! 👍

Class, let's take a closer look at the tableDataJSObject constant. This JavaScript object contains an array of employee records, which will be very useful for testing the filtering and display functionality of a table component.

Each employee record follows a consistent structure, with properties like employeeId, name, department, position, location, and salary. This well-organized data will make it easy to validate the behavior of the table when filtering based on the primary column.

Having a diverse set of test data, covering various departments and locations, is essential for thorough testing. With these ten employee records, you'll be able to simulate different scenarios and ensure that the table component handles them correctly.

Remember, using realistic test data is crucial for catching edge cases and ensuring a robust user experience. Keep up the excellent work in creating comprehensive test fixtures like this one!

@rahulbarwal rahulbarwal added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Sep 20, 2024
…o fix-36080/selectedRowIndex-getting-updated-unnecessarily
@rahulbarwal rahulbarwal merged commit 6507f90 into release Sep 20, 2024
42 checks passed
@rahulbarwal rahulbarwal deleted the fix-36080/selectedRowIndex-getting-updated-unnecessarily branch September 20, 2024 06:55
Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Sep 26, 2024
appsmithorg#36393)

## Description
<ins> Problem statement </ins>
1. Table should have a primary column set.
2. The table should be filtered(via search or client side filters)
3. there should be a selectedRow in table
a. One way to ensure is add a text widget and bind it to table's
`selectedRowIndex` property.

If you now run a query that updates the data behind the table: the
`selectedRow` is updated to (seemingly) random row and selectedRowIndex
is updated as well

<ins> Rootcause </ins>
We have a mechanism of preserving `selectedRow` when data updates
happen.
Underlying logic gets the previous selected row and tries to find it in
the new data using the primary key.
* If it finds it, it updates the selectedRowIndex to the
`__original_index__` of the found row i.e. its position in the original
data before any filters were applied.

<ins> Solution </ins>
We update the selectedRowIndex to the index in the new filtered data.

<ins> How to test </ins>
1. Create a table with a primary key
2. Add a text widget and bind it to table's `selectedRowIndex` property
3. Filter the table
4. Click on a row to select it
5. Run a query that updates the data behind the table
6. Assert that the selected row is the same and that the
selectedRowIndex is updated to the new index


Fixes appsmithorg#36080
_or_  
Fixes `Issue URL`
> [!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.Table, @tag.Binding, @tag.Sanity"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10953679202>
> Commit: 1a2d644
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10953679202&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Table, @tag.Binding, @tag.Sanity`
> Spec:
> <hr>Fri, 20 Sep 2024 06:30:08 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **Improvements**
- Enhanced the efficiency of the TableWidgetV2 by streamlining the
method for retrieving the index of selected rows.
- Improved code readability and maintainability without altering the
overall functionality.

- **New Features**
- Introduced new test cases to validate filtering and searching
functionalities within the Table Widget V2.
- Added a JSON configuration for a data-driven table interface,
supporting sorting, filtering, and dynamic data binding.
- Introduced fixture data for testing, allowing for comprehensive
validation of table behavior under various conditions.
- Added a JavaScript object containing employee data to facilitate
filtering and display in the table.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working High This issue blocks a user from building or impacts a lot of users Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Production Table Widget V2 Issues related to Table Widget V2 Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: selectedRowIndex getting updated unnecessarily on data reload.
3 participants