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: Use unique id instead of indices as keys for DraggableList #13553

Merged
merged 12 commits into from
May 9, 2022

Conversation

berzerkeer
Copy link
Contributor

@berzerkeer berzerkeer commented May 4, 2022

Description

Reordering page list and then renaming a page won't update the targeted page's name due to key mismatch. We were using index as key for the DraggableList component. So changed the list to take unique page ids for the list items keys.

Fixes #9991

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Go to any application, create 3 pages, swap 2nd and 3rd page's order. Now rename the 3rd page, it works as expected. Previously, it was renaming the 2nd page instead of the 3rd page.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Test coverage results 🧪

⚪ Total coverage has not changed
// Code coverage diff between base branch:release and head branch: fix/pages-list-rename-bug 
Status File % Stmts % Branch % Funcs % Lines
🔴 app/client/src/pages/Editor/PagesEditor/index.tsx 46.81 (-1.02) 42.86 (-17.14) 0 (0) 47.83 (-1.06)

@welcome
Copy link

welcome bot commented May 4, 2022

Welcome to the Appsmith community! Thank you for your first pull request and making this project better. 🤗

@vercel
Copy link

vercel bot commented May 4, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
appsmith ✅ Ready (Inspect) Visit Preview May 9, 2022 at 8:15AM (UTC)

@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 Page Management Issues related to configuring pages Platform Pod potential-duplicate This label marks issues that are potential duplicates of already open issues Release Admin Settings Issues in admin settings pages Team Managers Pod Issues that team managers care about for the security and efficiency of their teams UI Builders Pod Issues that UI Builders face using appsmith labels May 4, 2022
@github-actions
Copy link

github-actions bot commented May 4, 2022

Unable to find test scripts. Please add necessary tests to the PR.

@berzerkeer
Copy link
Contributor Author

/ok-to-test sha=bd269b3

@github-actions
Copy link

github-actions bot commented May 4, 2022

Tests running at: https://github.com/appsmithorg/appsmith/actions/runs/2269201210.
Workflow: Appsmith External Integration Test Workflow.
Commit: bd269b3.
PR: 13553.

@berzerkeer
Copy link
Contributor Author

/ok-to-test sha=102dbcf

@github-actions
Copy link

github-actions bot commented May 5, 2022

Tests running at: https://github.com/appsmithorg/appsmith/actions/runs/2275567570.
Workflow: Appsmith External Integration Test Workflow.
Commit: 102dbcf.
PR: 13553.

@@ -235,8 +235,8 @@ function DraggableList(props: any) {
{springs.map(({ scale, y, zIndex }, i) => (
<animated.div
{...bind(i)}
data-rbd-draggable-id={items[i].id}
key={i}
data-rbd-draggable-id={items[i].pageId}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure this change won't break the cypress tests? Just check and confirm once.

Copy link
Contributor

@ankitakinger ankitakinger left a comment

Choose a reason for hiding this comment

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

This may lead to bugs at other places as pageId is not being passed at all places. Since this is a bug in just one file app/client/src/pages/Editor/PagesEditor/index.tsx you can use something similar here as file app/client/src/components/propertyControls/FieldConfigurationControl.tsx line no. 226 and have send id as well as pageId with both being equal to pageId itself:

const draggableComponentColumns = pages.map(
      ({ identifier, isCustomField, isVisible, label }, index) => ({
        id: identifier,
        index,
        isCustomField,
        isVisible,
        label,
      }),
    );

@berzerkeer
Copy link
Contributor Author

This may lead to bugs at other places as pageId is not being passed at all places. Since this is a bug in just one file app/client/src/pages/Editor/PagesEditor/index.tsx you can use something similar here as file app/client/src/components/propertyControls/FieldConfigurationControl.tsx line no. 226 and have send id as well as pageId with both being equal to pageId itself:

const draggableComponentColumns = pages.map(
      ({ identifier, isCustomField, isVisible, label }, index) => ({
        id: identifier,
        index,
        isCustomField,
        isVisible,
        label,
      }),
    );

Thanks @ankitakinger , I have made those changes you suggested. Please review.

Copy link
Contributor

@ankitakinger ankitakinger left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions
Copy link

github-actions bot commented May 6, 2022

UI Performance test run logs and artifacts: https://github.com/appsmithorg/appsmith/actions/runs/2269201210.
Commit: bd269b3.
Results:

Click to view performance test results

Run 1 Run 2 Run 3 Run 4 Run 5 Median Mean SD.Sample SD.Population
SELECT_WIDGET_MENU_OPEN
scripting 1604.86 1785.58 1635.67 1581.46 1600.23 1604.86 1641.56 5.05 4.51
painting 8.36 16.01 10.4 14.51 6.87 10.4 11.23 34.91 31.26
rendering 533.96 754.86 601.68 530.94 528.89 533.96 590.07 16.45 14.71
SELECT_WIDGET_SELECT_OPTION
scripting 266.71 332.58 245.15 250.22 281.74 266.71 275.28 12.76 11.41
painting 10.82 6.1 7.49 6.61 2.83 6.61 6.77 42.39 37.96
rendering 18.36 21.89 19.01 17.14 18.44 18.44 18.97 9.33 8.33

1 similar comment
@github-actions
Copy link

github-actions bot commented May 6, 2022

UI Performance test run logs and artifacts: https://github.com/appsmithorg/appsmith/actions/runs/2269201210.
Commit: bd269b3.
Results:

Click to view performance test results

Run 1 Run 2 Run 3 Run 4 Run 5 Median Mean SD.Sample SD.Population
SELECT_WIDGET_MENU_OPEN
scripting 1604.86 1785.58 1635.67 1581.46 1600.23 1604.86 1641.56 5.05 4.51
painting 8.36 16.01 10.4 14.51 6.87 10.4 11.23 34.91 31.26
rendering 533.96 754.86 601.68 530.94 528.89 533.96 590.07 16.45 14.71
SELECT_WIDGET_SELECT_OPTION
scripting 266.71 332.58 245.15 250.22 281.74 266.71 275.28 12.76 11.41
painting 10.82 6.1 7.49 6.61 2.83 6.61 6.77 42.39 37.96
rendering 18.36 21.89 19.01 17.14 18.44 18.44 18.97 9.33 8.33

@berzerkeer
Copy link
Contributor Author

/ok-to-test sha=308da3e

@github-actions
Copy link

github-actions bot commented May 9, 2022

Tests running at: https://github.com/appsmithorg/appsmith/actions/runs/2293121983.
Workflow: Appsmith External Integration Test Workflow.
Commit: 308da3e.
PR: 13553.

@github-actions
Copy link

github-actions bot commented May 9, 2022

UI Performance test run logs and artifacts: https://github.com/appsmithorg/appsmith/actions/runs/2293121983.
Commit: 308da3e.
Results:

Click to view performance test results

Run 1 Run 2 Run 3 Run 4 Run 5 Median Mean SD.Sample SD.Population
SELECT_WIDGET_MENU_OPEN
scripting 1996.45 1983.42 2051.16 2036.01 2075.96 2036.01 2028.6 1.89 1.69
painting 18.39 19.67 18.56 14.78 10.8 18.39 16.44 22.20 19.83
rendering 681.78 687.05 704.06 698.11 691.03 691.03 692.41 1.28 1.14
SELECT_WIDGET_SELECT_OPTION
scripting 295.96 305.2 443.04 331.53 316.99 316.99 338.54 17.70 15.83
painting 6.94 4.71 8.39 5.17 9.02 6.94 6.85 27.74 24.82
rendering 21.42 20.68 21.68 23.48 21.35 21.42 21.72 4.83 4.33

1 similar comment
@github-actions
Copy link

github-actions bot commented May 9, 2022

UI Performance test run logs and artifacts: https://github.com/appsmithorg/appsmith/actions/runs/2293121983.
Commit: 308da3e.
Results:

Click to view performance test results

Run 1 Run 2 Run 3 Run 4 Run 5 Median Mean SD.Sample SD.Population
SELECT_WIDGET_MENU_OPEN
scripting 1996.45 1983.42 2051.16 2036.01 2075.96 2036.01 2028.6 1.89 1.69
painting 18.39 19.67 18.56 14.78 10.8 18.39 16.44 22.20 19.83
rendering 681.78 687.05 704.06 698.11 691.03 691.03 692.41 1.28 1.14
SELECT_WIDGET_SELECT_OPTION
scripting 295.96 305.2 443.04 331.53 316.99 316.99 338.54 17.70 15.83
painting 6.94 4.71 8.39 5.17 9.02 6.94 6.85 27.74 24.82
rendering 21.42 20.68 21.68 23.48 21.35 21.42 21.72 4.83 4.33

@berzerkeer berzerkeer merged commit d5845e9 into release May 9, 2022
@berzerkeer berzerkeer deleted the fix/pages-list-rename-bug branch May 9, 2022 10:22
@rahulramesha
Copy link
Contributor

rahulramesha commented May 9, 2022

@berzerkeer @ankitakinger I actually had another PR in the pipeline for this on a different (duplicate) issue #12758.
Use of items[i].id should have been the best way to solve this but since the component DraggableList is used in a lot more places this breaks few of them, eg, Table Widget's primaryColumns in property Pane. Most of them don't seem to have reliable unique ids. here is a reference to my PR #13448.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin Settings Issues in admin settings pages Bug Something isn't working High This issue blocks a user from building or impacts a lot of users Page Management Issues related to configuring pages potential-duplicate This label marks issues that are potential duplicates of already open issues Release Team Managers Pod Issues that team managers care about for the security and efficiency of their teams UI Builders Pod Issues that UI Builders face using appsmith
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]-[48000]:The other page name changes by default when users change any one page name
3 participants