-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: Tab navigation issue in multi page apps #38272
Conversation
WalkthroughThe pull request introduces optimizations to the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
/build-deploy-preview |
Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12426966500. |
There was a problem hiding this 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
🧹 Nitpick comments (1)
app/client/src/pages/Editor/IDE/EditorTabs/index.tsx (1)
89-95
: Good fix, with room for optimizationThe switch to useCallback with proper dependencies fixes the caching issue. However, consider optimizing further:
- const handleTabClick = useCallback( - (tab: EntityItem) => () => { - dispatch(setListViewActiveState(false)); - tabClickHandler(tab); - }, - [dispatch, tabClickHandler], - ); + const handleTabClick = useCallback( + (tab: EntityItem) => { + dispatch(setListViewActiveState(false)); + tabClickHandler(tab); + }, + [dispatch, tabClickHandler], + );Then update the onClick prop:
onClick={() => handleTabClick(tab)}This avoids creating a new closure for each tab while maintaining the same functionality.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/client/src/pages/Editor/IDE/EditorTabs/index.tsx
(2 hunks)
🔇 Additional comments (2)
app/client/src/pages/Editor/IDE/EditorTabs/index.tsx (2)
1-1
: LGTM: Clean import addition
The useCallback import is properly grouped with other React hooks.
89-95
: Verify similar patterns in the codebase
Let's check for similar patterns that might need the same fix.
✅ Verification successful
No issues found with the callback pattern
The code follows a consistent pattern across the codebase. The handleTabClick
implementation correctly:
- Uses
useCallback
with proper dependencies - Dispatches the list view state update
- Calls the
tabClickHandler
from the IDE hooks which handles navigation
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for other useEventCallback instances that might need similar fixes
rg "useEventCallback.*tabClickHandler" -A 3
# Search for other components using tabClickHandler
ast-grep --pattern 'const { $$$, tabClickHandler, $$$ } = use$_'
Length of output: 112
Script:
#!/bin/bash
# Search for tabClickHandler usage in the codebase
rg "tabClickHandler" -A 3
# Search for similar callback patterns with dispatch and state updates
ast-grep --pattern 'const $_ = useCallback(($$$) => () => {
dispatch($_);
$$$
}, $_)'
# Find where tabClickHandler is defined or passed as prop
ast-grep --pattern 'tabClickHandler: $_'
Length of output: 113019
Script:
#!/bin/bash
# Search for similar callback patterns in the codebase
ast-grep --pattern 'const $_ = useCallback(($$$) => {
dispatch($_);
$$$
}, $_)'
# Find where tabClickHandler is defined
ast-grep --pattern 'const tabClickHandler = useCallback(($$$) => {
$$$
}, $_)'
# Find other components using tabClickHandler
rg "tabClickHandler" -B 2 -A 2
Length of output: 59752
Deploy-Preview-URL: https://ce-38272.dp.appsmith.com |
fae4d47
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (2)
app/client/cypress/e2e/Regression/ClientSide/IDE/Tabs_Navigation_spec.ts (2)
79-88
: Strengthen assertions with multiple checksAdd additional assertions to verify the complete state after tab navigation.
cy.get("[data-testid='t--ide-tab-page2_js1']").click(); jsEditor.currentJSObjectName().then((jsObjName) => { expect(jsObjName).equal("Page2_JS1"); + // Add visibility check + cy.get("[data-testid='t--ide-tab-page2_js1']").should("have.class", "active"); + // Verify other tab is not active + cy.get("[data-testid='t--ide-tab-page2_js2']").should("not.have.class", "active"); });
19-148
: Consider improving test isolationWhile the test structure is good, consider:
- Adding cleanup in
afterEach
to ensure test isolation- Using API calls to set up and tear down test data
- Implementing proper error handling for setup failures
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/client/cypress/e2e/Regression/ClientSide/IDE/Tabs_Navigation_spec.ts
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/client/cypress/e2e/Regression/ClientSide/IDE/Tabs_Navigation_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.
before(() => { | ||
datasources.CreateDataSource("Mongo"); | ||
cy.renameDatasource(dsName); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Use API-based setup instead of UI interactions
Replace the UI-based datasource creation with API calls for better test reliability and performance.
- datasources.CreateDataSource("Mongo");
- cy.renameDatasource(dsName);
+ cy.request('POST', '/api/v1/datasources', {
+ name: dsName,
+ type: 'MongoDB',
+ // other required properties
+ });
Committable suggestion skipped: line range outside the PR's diff.
cy.get("[data-testid='t--ide-tab-page1_js1']").click(); | ||
|
||
jsEditor.currentJSObjectName().then((jsObjName) => { | ||
expect(jsObjName).equal("Page1_JS1"); | ||
}); | ||
|
||
cy.get("[data-testid='t--ide-tab-page1_js2']").click(); | ||
|
||
jsEditor.currentJSObjectName().then((jsObjName) => { | ||
expect(jsObjName).equal("Page1_JS2"); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Extract tab selectors into locator variables
Move selectors to locator variables for better maintainability and reuse.
+ const tabLocators = {
+ js1Tab: "[data-testid='t--ide-tab-page1_js1']",
+ js2Tab: "[data-testid='t--ide-tab-page1_js2']"
+ };
- cy.get("[data-testid='t--ide-tab-page1_js1']").click();
+ cy.get(tabLocators.js1Tab).click();
- cy.get("[data-testid='t--ide-tab-page1_js2']").click();
+ cy.get(tabLocators.js2Tab).click();
jsEditor.CreateJSObject("", { prettify: false, toRun: false }); | ||
jsEditor.RenameJSObjFromPane("Page1_JS2"); | ||
|
||
cy.get("[data-testid='t--ide-tab-page1_js1']").click(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please agHelper.GetNClick(reconnectDatasourceModal.SkipToAppBtn,0,true, ); here for click function. And do follow for all.
Kindly add locator as variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this 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 comments (1)
app/client/cypress/support/Pages/EditorNavigation.ts (1)
Line range hint
71-71
: Replace Sleep() calls with proper Cypress wait commands.Multiple methods use
_.AggregateHelper.Sleep()
which violates the coding guidelines. Consider replacing these with proper Cypress wait commands.Replace the sleep calls with appropriate wait conditions:
NavigateToWidget(name: string, clickOptions?: Partial<ClickOptions>, hierarchy: string[] = []) { AppSidebar.navigate(AppSidebarButton.Editor); PageLeftPane.switchSegment(PagePaneSegment.UI); hierarchy.forEach((level) => { PageLeftPane.expandCollapseItem(level); }); PageLeftPane.selectItem(name, clickOptions); - _.AggregateHelper.Sleep(); + cy.get('.t--entity-item.active').should('have.text', name); } NavigateToQuery(name: string) { AppSidebar.navigate(AppSidebarButton.Editor); PageLeftPane.switchSegment(PagePaneSegment.Queries); PageLeftPane.selectItem(name); - _.AggregateHelper.Sleep(); + cy.get('.t--entity-item.active').should('have.text', name); } NavigateToJSObject(name: string) { AppSidebar.navigate(AppSidebarButton.Editor); PageLeftPane.switchSegment(PagePaneSegment.JS); PageLeftPane.selectItem(name); - _.AggregateHelper.Sleep(); + cy.get('.t--entity-item.active').should('have.text', name); } NavigateToPage(name: string, networkCallAlias = false) { AppSidebar.navigate(AppSidebarButton.Editor); PageList.ShowList(); PageLeftPane.selectItem(name, { multiple: true, force: true }); - _.AggregateHelper.Sleep(); + cy.get('.t--entity-item.active').should('have.text', name); networkCallAlias && _.AssertHelper.AssertNetworkStatus("pageSnap"); }Also applies to: 84-84, 91-91, 98-98
🧹 Nitpick comments (1)
app/client/cypress/support/Pages/EditorNavigation.ts (1)
23-25
: Good implementation, consider adding input validation and documentation.The selector follows best practices by using data-testid. However, consider these improvements:
+/** + * Generates a data-testid selector for IDE tabs + * @param name - The name of the tab + * @returns A data-testid selector string + * @throws {Error} If name is empty or undefined + */ export const editorTabSelector = (name: string) => { + if (!name?.trim()) { + throw new Error('Tab name cannot be empty'); + } return `[data-testid='t--ide-tab-${name.toLowerCase()}']`; };
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
app/client/cypress/e2e/Regression/ClientSide/IDE/Tabs_Navigation_spec.ts
(1 hunks)app/client/cypress/support/Pages/EditorNavigation.ts
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- app/client/cypress/e2e/Regression/ClientSide/IDE/Tabs_Navigation_spec.ts
🧰 Additional context used
📓 Path-based instructions (1)
app/client/cypress/support/Pages/EditorNavigation.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.
Description
Fixes the caching in useEventCallback for tabClickHandler that was getting the old pageId
Fixes #38216
Automation
/ok-to-test tags="@tag.IDE"
🔍 Cypress test results
Tip
🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/12429634967
Commit: 3715ac2
Cypress dashboard.
Tags:
@tag.IDE
Spec:
Fri, 20 Dec 2024 10:53:24 UTC
Communication
Should the DevRel and Marketing teams inform users about this change?
Summary by CodeRabbit
New Features
editorTabSelector
for generating string selectors for IDE tabs.Bug Fixes
Chores