Skip to content

Commit

Permalink
feat: Add currentPage, workspace, application name to appsmith context (
Browse files Browse the repository at this point in the history
#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” <“[email protected]”>
  • Loading branch information
rishabhrathod01 and “sneha122” authored Dec 23, 2024
1 parent dcb27d2 commit 8a16903
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ describe("Autocomplete tests", { tags: ["@tag.JS", "@tag.Binding"] }, () => {
)
.type(".");

agHelper.GetNAssertElementText(locators._hints, "geolocation");
agHelper.GetNAssertElementText(locators._hints, "appName");
});
});

Expand All @@ -313,6 +313,6 @@ describe("Autocomplete tests", { tags: ["@tag.JS", "@tag.Binding"] }, () => {
.type("{downArrow}{leftArrow}{leftArrow}");

agHelper.TypeText(locators._codeMirrorTextArea, ".");
agHelper.GetNAssertElementText(locators._hints, "geolocation");
agHelper.GetNAssertElementText(locators._hints, "appName");
});
});
3 changes: 3 additions & 0 deletions app/client/src/ce/entities/DataTree/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ export interface AppsmithEntity extends Omit<AppDataState, "store"> {
ENTITY_TYPE: typeof ENTITY_TYPE.APPSMITH;
store: Record<string, unknown>;
theme: AppTheme["properties"];
currentPageName: string;
workspaceName: string;
appName: string;
}

export interface DataTreeSeed {
Expand Down
30 changes: 29 additions & 1 deletion app/client/src/selectors/dataTreeSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ import {
getCurrentWorkflowActions,
getCurrentWorkflowJSActions,
} from "ee/selectors/workflowSelectors";
import { getCurrentApplication } from "ee/selectors/applicationSelectors";
import { getCurrentAppWorkspace } from "ee/selectors/selectedWorkspaceSelectors";
import type { PageListReduxState } from "reducers/entityReducers/pageListReducer";

export const getLoadingEntities = (state: AppState) =>
state.evaluations.loadingEntities;
Expand Down Expand Up @@ -130,14 +133,36 @@ const getMetaWidgetsFromUnevaluatedDataTree = createSelector(
DataTreeFactory.metaWidgets(metaWidgets, widgetsMeta, loadingEntities),
);

// * This is only for internal use to avoid cyclic dependency issue
const getPageListState = (state: AppState) => state.entities.pageList;
const getCurrentPageName = createSelector(
getPageListState,
(pageList: PageListReduxState) =>
pageList.pages.find((page) => page.pageId === pageList.currentPageId)
?.pageName,
);

export const getUnevaluatedDataTree = createSelector(
getActionsFromUnevaluatedDataTree,
getJSActionsFromUnevaluatedDataTree,
getWidgetsFromUnevaluatedDataTree,
getMetaWidgetsFromUnevaluatedDataTree,
getAppData,
getSelectedAppThemeProperties,
(actions, jsActions, widgets, metaWidgets, appData, theme) => {
getCurrentAppWorkspace,
getCurrentApplication,
getCurrentPageName,
(
actions,
jsActions,
widgets,
metaWidgets,
appData,
theme,
currentWorkspace,
currentApplication,
getCurrentPageName,
) => {
let dataTree: UnEvalTree = {
...actions.dataTree,
...jsActions.dataTree,
Expand All @@ -155,6 +180,9 @@ export const getUnevaluatedDataTree = createSelector(
// taking precedence in case the key is the same
store: appData.store,
theme,
currentPageName: getCurrentPageName,
workspaceName: currentWorkspace.name,
appName: currentApplication?.name,
} as AppsmithEntity;
(dataTree.appsmith as AppsmithEntity).ENTITY_TYPE = ENTITY_TYPE.APPSMITH;
dataTree = { ...dataTree, ...metaWidgets.dataTree };
Expand Down

0 comments on commit 8a16903

Please sign in to comment.