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
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 31 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 @@ -149,12 +174,17 @@ export const getUnevaluatedDataTree = createSelector(
...widgets.configTree,
};

// const { currentPageName, workspaceName, appName } = someObj;
sneha122 marked this conversation as resolved.
Show resolved Hide resolved

dataTree.appsmith = {
...appData,
// combine both persistent and transient state with the transient state
// 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
Loading