In order to unify package names, we decided to use `@appsmith` prefix as a marker to indicate that packages belong to our codebase and that these packages are developed internally. So that we can use this prefix, we need to rename the alias of the same name. But since `@appsmith` is currently being used as an alias for `ee` folder, we have to rename the alias as the first step. Related discussion https://theappsmith.slack.com/archives/CPG2ZTXEY/p1722516279126329 EE PR — https://github.com/appsmithorg/appsmith-ee/pull/4801 ## 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/10267368821> > Commit: 2b00af2d257e4d4304db0a80072afef7513de6be > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10267368821&attempt=2" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Tue, 06 Aug 2024 14:24:22 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No
106 lines
3.3 KiB
TypeScript
106 lines
3.3 KiB
TypeScript
import { call, put, select } from "redux-saga/effects";
|
|
import { getCurrentPageId, getPageList } from "selectors/editorSelectors";
|
|
import _ from "lodash";
|
|
import { ReduxActionTypes, type Page } from "ee/constants/ReduxActionConstants";
|
|
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
|
|
import { getAppMode } from "ee/selectors/applicationSelectors";
|
|
import { APP_MODE } from "entities/App";
|
|
import { getQueryStringfromObject } from "ee/entities/URLRedirect/URLAssembly";
|
|
import history from "utils/history";
|
|
import { setDataUrl } from "ee/sagas/PageSagas";
|
|
import AppsmithConsole from "utils/AppsmithConsole";
|
|
import { builderURL, viewerURL } from "ee/RouteBuilder";
|
|
import { TriggerFailureError } from "./errorUtils";
|
|
import { isValidURL, matchesURLPattern } from "utils/URLUtils";
|
|
import type { TNavigateToDescription } from "workers/Evaluation/fns/navigateTo";
|
|
import { NavigationTargetType } from "workers/Evaluation/fns/navigateTo";
|
|
|
|
export enum NavigationTargetType_Dep {
|
|
SAME_WINDOW = "SAME_WINDOW",
|
|
NEW_WINDOW = "NEW_WINDOW",
|
|
}
|
|
|
|
const isValidPageName = (
|
|
pageNameOrUrl: string,
|
|
pageList: Page[],
|
|
): Page | undefined => {
|
|
return _.find(pageList, (page: Page) => page.pageName === pageNameOrUrl);
|
|
};
|
|
|
|
export default function* navigateActionSaga(action: TNavigateToDescription) {
|
|
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 path =
|
|
appMode === APP_MODE.EDIT
|
|
? builderURL({
|
|
basePageId: page.basePageId,
|
|
params,
|
|
})
|
|
: viewerURL({
|
|
basePageId: page.basePageId,
|
|
params,
|
|
});
|
|
|
|
if (target === NavigationTargetType.SAME_WINDOW) {
|
|
history.push(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({
|
|
text: `navigateTo('${page.pageName}') was triggered`,
|
|
state: {
|
|
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,
|
|
});
|
|
}
|
|
}
|