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

feat: Add currentPage, workspace, application name to appsmith context #38114

Merged
merged 7 commits into from
Dec 23, 2024

Conversation

rishabhrathod01
Copy link
Contributor

@rishabhrathod01 rishabhrathod01 commented Dec 11, 2024

Description

Add currentPageName, AppName and workspace name to appsmith context object

Fixes #38046

Automation

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

🔍 Cypress test results

Tip

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


Mon, 23 Dec 2024 09:14:06 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced AppsmithEntity interface with new properties: currentPageName, workspaceName, and appName.
    • Updated getUnevaluatedDataTree selector to accept additional parameters, providing more contextual information about the current application state.
    • Introduced a new internal selector to retrieve the current page's name.
  • Bug Fixes

    • Adjusted expected hint text in autocomplete tests for JavaScript objects to align with updated behavior.

Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Walkthrough

The pull request introduces new properties to the AppsmithEntity interface in the data tree types, specifically adding currentPageName, workspaceName, and appName. These properties enhance the context of the application state by providing direct access to relevant identifiers. The changes are implemented in both the type definitions and the data tree selector to support retrieving and populating these new contextual properties.

Changes

File Change Summary
app/client/src/ce/entities/DataTree/types.ts Added currentPageName, workspaceName, and appName as string properties to AppsmithEntity interface
app/client/src/selectors/dataTreeSelectors.ts Updated getUnevaluatedDataTree selector to accept and incorporate new workspace, application, and page name parameters; added getCurrentPageName selector
app/client/cypress/e2e/Regression/ClientSide/Autocomplete/JS_AC1_spec.ts Updated expected hint text in autocomplete tests for JavaScript objects

Assessment against linked issues

Objective Addressed Explanation
Add currentPageName
Add workspaceName
Add appName
Enable scripting without hardcoding page names

Possibly related PRs

  • chore: Added pg branch #36086: The changes in the main PR regarding the AppsmithEntity interface and the new properties added are related to the modifications in dataTreeSelectors.ts, where the getUnevaluatedDataTree selector has been updated to include parameters that correspond to the new properties in the AppsmithEntity interface.
  • fix: New query button does not show up issue fixed #36766: This PR introduces tests for the useEditorType hook, which may indirectly relate to the changes in the main PR as they both involve the structure and behavior of entities within the application, although the connection is less direct.
  • test: partial import export areas covered #37661: The tests added in this PR for partial import/export functionality may relate to the new properties in the AppsmithEntity interface, as they could involve the handling of entities during import/export operations.
  • chore: add packagePullStatus to consolidated API #38179: The addition of packagePullStatus to the consolidated API may relate to the overall structure and management of entities within the application, which is a broader context that includes the changes made in the main PR.
  • chore: converted isNewEntity lookup to use a set  #38264: The changes to the isNewEntity function and its performance improvements may relate to how entities are evaluated and managed in the application, which aligns with the modifications made to the AppsmithEntity interface in the main PR.

Suggested labels

IDE Product, Task

Suggested reviewers

  • ApekshaBhosale
  • sagar-qa007
  • hetunandu

Poem

Code flows like a river bright,
Context blooms with newfound might,
Names of page and workspace clear,
Appsmith's power now draws near! 🌟
Developers dance with glee today! 🎉

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 Enhancement New feature or request Javascript Product Issues related to users writing javascript in appsmith JS Evaluation Issues related to JS evaluation on the platform Query & JS Pod Issues related to the query & JS Pod labels Dec 11, 2024
@sneha122 sneha122 added the ok-to-test Required label for CI label Dec 16, 2024
@sneha122 sneha122 marked this pull request as ready for review December 16, 2024 18:23
@sneha122
Copy link
Contributor

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12358867744.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 38114.
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

🧹 Nitpick comments (1)
app/client/src/selectors/dataTreeSelectors.ts (1)

168-168: Remove development comment

This commented code appears to be a development leftover and should be removed.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 996a30b and 96c4be9.

📒 Files selected for processing (2)
  • app/client/src/ce/entities/DataTree/types.ts (1 hunks)
  • app/client/src/selectors/dataTreeSelectors.ts (3 hunks)
🔇 Additional comments (4)
app/client/src/selectors/dataTreeSelectors.ts (3)

44-46: LGTM! New imports are properly organized

The new imports for current application, workspace, and page name are correctly added and logically grouped with other selector imports.


143-156: LGTM! Selector signature updated correctly

The getUnevaluatedDataTree selector has been properly extended to include the new context parameters.


176-178: ⚠️ Potential issue

Fix getCurrentPageName parameter usage

There's a bug in the property assignment. The getCurrentPageName parameter is being used directly instead of its value.

Apply this fix:

-  currentPageName: getCurrentPageName,
+  currentPageName: getCurrentPageName,
   workspaceName: currentWorkspace.name,
   appName: currentApplication?.name,

Likely invalid or redundant comment.

app/client/src/ce/entities/DataTree/types.ts (1)

192-194: LGTM! AppsmithEntity interface properly extended

The new properties are correctly typed and align with the requirements to enhance the appsmith context.

Copy link

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

Copy link

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 1, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

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

🧹 Nitpick comments (3)
app/client/src/selectors/dataTreeSelectors.ts (3)

136-143: Consider improving edge case handling and documentation

While the implementation is functional, consider:

  1. Adding a default value when no matching page is found
  2. Expanding the internal use comment to explain the cyclic dependency issue
 // * This is only for internal use to avoid cyclic dependency issue
+ // * Used internally by getUnevaluatedDataTree to avoid circular dependencies
+ // * between page and data tree selectors
 const getPageListState = (state: AppState) => state.entities.pageList;
 const getCurrentPageName = createSelector(
   getPageListState,
   (pageList: PageListReduxState) =>
     pageList.pages.find((page) => page.pageId === pageList.currentPageId)
-      ?.pageName,
+      ?.pageName ?? "Unknown Page",
 );

177-177: Remove development comment

The commented code appears to be a development leftover and should be removed.

- // const { currentPageName, workspaceName, appName } = someObj;

Line range hint 152-187: Improve parameter naming and null safety

A few suggestions for improvement:

  1. Rename the getCurrentPageName parameter to avoid confusion with the selector
  2. Add null checks for workspace name for consistency
   getCurrentApplication,
   getCurrentPageName,
   (
     actions,
     jsActions,
     widgets,
     metaWidgets,
     appData,
     theme,
     currentWorkspace,
     currentApplication,
-    getCurrentPageName,
+    currentPageName,
   ) => {
     // ...
     dataTree.appsmith = {
       ...appData,
       store: appData.store,
       theme,
-      currentPageName: getCurrentPageName,
+      currentPageName,
-      workspaceName: currentWorkspace.name,
+      workspaceName: currentWorkspace?.name ?? "Unknown Workspace",
       appName: currentApplication?.name,
     } as AppsmithEntity;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cca4e2b and 6c39e11.

📒 Files selected for processing (1)
  • app/client/src/selectors/dataTreeSelectors.ts (3 hunks)
🔇 Additional comments (2)
app/client/src/selectors/dataTreeSelectors.ts (2)

44-46: LGTM!

The new imports are properly organized and necessary for the enhanced appsmith context functionality.


185-187: Verify appsmith context usage

Let's verify that all consumers of the appsmith context are prepared for these new properties.

✅ Verification successful

Let me search for actual usages and type definitions of these properties to verify their impact on the codebase.


Let me try a broader search to find any references to these properties and their related selectors.


Changes to appsmith context properties are properly handled

Based on the codebase analysis:

  • The properties currentPageName, workspaceName, and appName are properly defined in the AppsmithEntity interface
  • These properties are used consistently across the application for analytics, page navigation, and UI display
  • The changes are additive and existing consumers are already prepared for these properties
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of appsmith context properties
rg -l "appsmith\.(currentPageName|workspaceName|appName)" 

# Search for type checks or property access
ast-grep --pattern 'appsmith.$_' 

Length of output: 86392


Script:

#!/bin/bash
# Search for usages of appsmith context properties in TypeScript files
rg -t ts "appsmith\.(currentPageName|workspaceName|appName)" -A 2 -B 2

# Search for type definitions of appsmith context
ast-grep --pattern 'interface $_Context {
  $$$
  currentPageName?: $_
  workspaceName?: $_
  appName?: $_
  $$$
}'

Length of output: 190


Script:

#!/bin/bash
# Search for any references to these properties in the codebase
rg -g '*.{ts,tsx,js,jsx}' "currentPageName|workspaceName|appName" -A 2 -B 2

# Search for type definitions or interfaces that might contain these properties
ast-grep --pattern 'type $_ = {
  $$$
  currentPageName: $_
  $$$
}'

# Look for any usage of these properties in selectors
rg -g '*.ts' "getCurrentPageName|getWorkspaceName|getAppName" -A 2 -B 2

Length of output: 73160

@sneha122
Copy link
Contributor

/build-deploy-preview skip-tests=true

Copy link

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

@sneha122 sneha122 requested review from AmanAgarwal041 and removed request for ApekshaBhosale and sneha122 December 17, 2024 06:51
Copy link

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

AmanAgarwal041
AmanAgarwal041 previously approved these changes Dec 17, 2024
@sneha122 sneha122 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Dec 19, 2024
Copy link

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 1, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

Copy link

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 1, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

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

🧹 Nitpick comments (1)
app/client/src/selectors/dataTreeSelectors.ts (1)

137-138: Enhance the internal comment

The current comment could be more descriptive about why this selector needs to be internal.

-// * This is only for internal use to avoid cyclic dependency issue
+// Internal selector to prevent cyclic dependency between page and datatree modules
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8acdb47 and b6a7de6.

📒 Files selected for processing (2)
  • app/client/src/ce/entities/DataTree/types.ts (1 hunks)
  • app/client/src/selectors/dataTreeSelectors.ts (3 hunks)
🔇 Additional comments (2)
app/client/src/ce/entities/DataTree/types.ts (1)

193-196: LGTM! Properties added to AppsmithEntity interface

The new properties are well-typed and follow the existing naming conventions.

app/client/src/selectors/dataTreeSelectors.ts (1)

153-167: LGTM! Selector signature updated correctly

The new parameters are properly added and destructured in the selector.

Comment on lines 186 to 189
currentPageName: getCurrentPageName,
workspaceName: currentWorkspace.name,
appName: currentApplication?.name,
currentEnvName: currentEnvironmentName,
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

Add null checks for workspace and environment properties

While currentApplication?.name uses optional chaining, currentWorkspace.name and currentEnvironmentName are accessed directly. Consider adding null checks for consistency and safety.

-      currentPageName: getCurrentPageName,
-      workspaceName: currentWorkspace.name,
-      appName: currentApplication?.name,
-      currentEnvName: currentEnvironmentName,
+      currentPageName: getCurrentPageName ?? "",
+      workspaceName: currentWorkspace?.name ?? "",
+      appName: currentApplication?.name ?? "",
+      currentEnvName: currentEnvironmentName ?? "",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
currentPageName: getCurrentPageName,
workspaceName: currentWorkspace.name,
appName: currentApplication?.name,
currentEnvName: currentEnvironmentName,
currentPageName: getCurrentPageName ?? "",
workspaceName: currentWorkspace?.name ?? "",
appName: currentApplication?.name ?? "",
currentEnvName: currentEnvironmentName ?? "",

@sneha122
Copy link
Contributor

/build-deploy-preview skip-tests=true

Copy link

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

Copy link

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

AmanAgarwal041
AmanAgarwal041 previously approved these changes Dec 23, 2024
Copy link

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 1, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

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 comments (1)
app/client/cypress/e2e/Regression/ClientSide/Autocomplete/JS_AC1_spec.ts (1)

Line range hint 273-273: Replace XPath usage with data- attribute or a custom locator*
According to the guidelines, avoid using XPath and prefer data-* attributes for reliable and maintainable selectors.

Example minimal fix:

-cy.xpath(documentInputSelector)
+cy.get("[data-cy=document-input]")
🧹 Nitpick comments (1)
app/client/cypress/e2e/Regression/ClientSide/Autocomplete/JS_AC1_spec.ts (1)

Line range hint 269-272: Avoid using cy.wait for fixed time intervals
Using cy.wait(200) introduces flakiness and can slow down tests. It's best to wait on a specific event or condition instead.

A possible approach is to wait on an element state:

cy.get(selector).should("be.visible")

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b6a7de6 and eec4292.

📒 Files selected for processing (3)
  • app/client/cypress/e2e/Regression/ClientSide/Autocomplete/JS_AC1_spec.ts (2 hunks)
  • app/client/src/ce/entities/DataTree/types.ts (1 hunks)
  • app/client/src/selectors/dataTreeSelectors.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/client/src/ce/entities/DataTree/types.ts
  • app/client/src/selectors/dataTreeSelectors.ts
🧰 Additional context used
📓 Path-based instructions (1)
app/client/cypress/e2e/Regression/ClientSide/Autocomplete/JS_AC1_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.
🔇 Additional comments (2)
app/client/cypress/e2e/Regression/ClientSide/Autocomplete/JS_AC1_spec.ts (2)

301-301: Recognition of new property 'appName'
This check aligns with the new property added to the appsmith context. The assertion confirms the autocomplete suggestion for "appName".


316-316: Correct validation for 'appName' hint
Verifying "appName" appears again ensures consistency in multiple binding scenarios. Looks good.

@sneha122
Copy link
Contributor

/build-deploy-preview skip-tests=true

Copy link

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

Copy link

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

@sneha122 sneha122 merged commit 8a16903 into release Dec 23, 2024
44 checks passed
@sneha122 sneha122 deleted the feat/addInfoToAppsmithContext branch December 23, 2024 11:03
NandanAnantharamu pushed a commit that referenced this pull request Dec 27, 2024
#38114)

## Description

Add currentPageName, AppName and workspace name to appsmith context
object

Fixes #38046

## Automation

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

### 🔍 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/12462985063>
> Commit: eec4292
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12462985063&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.JS`
> Spec:
> <hr>Mon, 23 Dec 2024 09:14:06 UTC
<!-- end of auto-generated comment: Cypress test results  -->


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


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

- **New Features**
- Enhanced `AppsmithEntity` interface with new properties:
`currentPageName`, `workspaceName`, and `appName`.
- Updated `getUnevaluatedDataTree` selector to accept additional
parameters, providing more contextual information about the current
application state.
- Introduced a new internal selector to retrieve the current page's
name.

- **Bug Fixes**
- Adjusted expected hint text in autocomplete tests for JavaScript
objects to align with updated behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: “sneha122” <“sneha@appsmith.com”>
This was referenced Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Javascript Product Issues related to users writing javascript in appsmith JS Evaluation Issues related to JS evaluation on the platform ok-to-test Required label for CI Query & JS Pod Issues related to the query & JS Pod
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Add currentPageName, workspaceName and appName to appsmith context object
3 participants