## Description **TLDR:** Adds support for executing page unload actions during navigation in deployed mode, refactors related components, and improves action handling. <ins>Problem</ins> Page unload actions were not triggered during navigation in deployed mode, leading to incomplete workflows especially for cleanup. <ins>Root cause</ins> The application lacked integration for executing unload actions on page transitions, and related components did not properly handle navigation or action execution. <ins>Solution</ins> This PR handles the integration of page unload action execution during navigation in deployed mode. It introduces selectors for unload actions, refactors the MenuItem component for better navigation handling, and improves the PluginActionSaga for executing plugin actions. Unused parameters and functions are removed for clarity and maintainability. Fixes #40997 _or_ Fixes `Issue URL` > [!WARNING] > _If no issue exists, please create an issue first, and check with the maintainers if the issue is valid._ ## Automation /ok-to-test tags="@tag.All" ### 🔍 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/16021075820> > Commit: f09e3c44d379488e43aec6ab27228d7675f79415 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=16021075820&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Wed, 02 Jul 2025 10:21:00 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for actions that execute automatically when navigating away from a page. * Introduced new navigation logic and hooks for consistent page transitions within the app. * Added new menu and dropdown components for improved navigation UI. * **Bug Fixes** * Updated navigation item styling and active state detection for improved accuracy. * **Tests** * Added comprehensive tests for navigation sagas and page unload actions. * Added unit tests for navigation menu components. * **Chores** * Refactored and centralized navigation logic for maintainability. * Improved type safety and selector usage in navigation and action execution. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
141 lines
4.2 KiB
TypeScript
141 lines
4.2 KiB
TypeScript
import type { ReduxAction } from "actions/ReduxActionTypes";
|
|
import { ReduxActionTypes } from "ee/constants/ReduxActionConstants";
|
|
import { getQueryStringfromObject } from "ee/entities/URLRedirect/URLAssembly";
|
|
import { builderURL, viewerURL } from "ee/RouteBuilder";
|
|
import { setDataUrl } from "ee/sagas/PageSagas";
|
|
import { getAppMode } from "ee/selectors/applicationSelectors";
|
|
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
|
|
import { APP_MODE } from "entities/App";
|
|
import type { SourceEntity } from "entities/AppsmithConsole";
|
|
import type { Page } from "entities/Page";
|
|
import _ from "lodash";
|
|
import { call, put, select, take } from "redux-saga/effects";
|
|
import { getCurrentPageId, getPageList } from "selectors/editorSelectors";
|
|
import AppsmithConsole from "utils/AppsmithConsole";
|
|
import history, { type AppsmithLocationState } from "utils/history";
|
|
import { isValidURL, matchesURLPattern } from "utils/URLUtils";
|
|
import type { TNavigateToDescription } from "workers/Evaluation/fns/navigateTo";
|
|
import { NavigationTargetType } from "workers/Evaluation/fns/navigateTo";
|
|
import { TriggerFailureError } from "../errorUtils";
|
|
import type { NavigateToAnotherPagePayload } from "./types";
|
|
import type { LocationDescriptor, Path } from "history";
|
|
|
|
const isValidPageName = (
|
|
pageNameOrUrl: string,
|
|
pageList: Page[],
|
|
): Page | undefined => {
|
|
return _.find(pageList, (page: Page) => page.pageName === pageNameOrUrl);
|
|
};
|
|
|
|
export default function* navigateActionSaga(
|
|
action: TNavigateToDescription,
|
|
source?: SourceEntity,
|
|
) {
|
|
const { payload } = action;
|
|
const pageList: Page[] = yield select(getPageList);
|
|
const { pageNameOrUrl, params, target } = payload;
|
|
|
|
const page = isValidPageName(pageNameOrUrl, pageList);
|
|
|
|
if (page) {
|
|
const currentPageId: string = yield select(getCurrentPageId);
|
|
|
|
AnalyticsUtil.logEvent("NAVIGATE", {
|
|
pageName: pageNameOrUrl,
|
|
pageParams: params,
|
|
});
|
|
|
|
const appMode: APP_MODE = yield select(getAppMode);
|
|
const urlBuilder = appMode === APP_MODE.EDIT ? builderURL : viewerURL;
|
|
const path = urlBuilder({
|
|
basePageId: page.basePageId,
|
|
params,
|
|
});
|
|
|
|
if (target === NavigationTargetType.SAME_WINDOW) {
|
|
yield call(pushToHistory, path);
|
|
|
|
if (currentPageId === page.pageId) {
|
|
yield call(setDataUrl);
|
|
yield put({
|
|
type: ReduxActionTypes.TRIGGER_EVAL,
|
|
});
|
|
}
|
|
} else if (target === NavigationTargetType.NEW_WINDOW) {
|
|
window.open(path, "_blank");
|
|
}
|
|
|
|
AppsmithConsole.info({
|
|
source,
|
|
text: `navigateTo triggered`,
|
|
state: {
|
|
page,
|
|
params,
|
|
},
|
|
});
|
|
} else {
|
|
let url = pageNameOrUrl + getQueryStringfromObject(params);
|
|
|
|
if (!isValidURL(url)) {
|
|
const looksLikeURL = matchesURLPattern(url);
|
|
|
|
// Filter out cases like navigateTo("1");
|
|
if (!looksLikeURL)
|
|
throw new TriggerFailureError("Enter a valid URL or page name");
|
|
|
|
// Default to https protocol to support navigation to URLs like www.google.com
|
|
url = `https://${url}`;
|
|
|
|
if (!isValidURL(url))
|
|
throw new TriggerFailureError("Enter a valid URL or page name");
|
|
}
|
|
|
|
if (target === NavigationTargetType.SAME_WINDOW) {
|
|
window.location.assign(url);
|
|
} else if (target === NavigationTargetType.NEW_WINDOW) {
|
|
window.open(url, "_blank");
|
|
}
|
|
|
|
AppsmithConsole.info({
|
|
text: `navigateTo('${url}') was triggered`,
|
|
state: {
|
|
params,
|
|
},
|
|
});
|
|
AnalyticsUtil.logEvent("NAVIGATE", {
|
|
navUrl: pageNameOrUrl,
|
|
});
|
|
}
|
|
}
|
|
|
|
export function* navigateToAnyPageInApplication(
|
|
action: ReduxAction<NavigateToAnotherPagePayload>,
|
|
) {
|
|
yield call(pushToHistory, action.payload);
|
|
}
|
|
|
|
export function* pushToHistory(payload: NavigateToAnotherPagePayload | Path) {
|
|
yield put({
|
|
type: ReduxActionTypes.EXECUTE_PAGE_UNLOAD_ACTIONS,
|
|
});
|
|
|
|
yield take([
|
|
ReduxActionTypes.EXECUTE_PAGE_UNLOAD_ACTIONS_SUCCESS,
|
|
ReduxActionTypes.EXECUTE_PAGE_UNLOAD_ACTIONS_ERROR,
|
|
]);
|
|
|
|
if (typeof payload === "string") {
|
|
history.push(payload);
|
|
|
|
return;
|
|
}
|
|
|
|
const historyState: LocationDescriptor<AppsmithLocationState> = {
|
|
pathname: payload.pageURL,
|
|
search: payload.query,
|
|
state: payload.state,
|
|
};
|
|
|
|
history.push(historyState);
|
|
}
|