## Description Added ESLint rule to force blank lines between statements. Fixes #`Issue Number` _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 --> > [!CAUTION] > 🔴 🔴 🔴 Some tests have failed. > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/10924926728> > Commit: 34f57714a1575ee04e94e03cbcaf95e57a96c86c > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10924926728&attempt=1&selectiontype=test&testsstatus=failed&specsstatus=fail" target="_blank">Cypress dashboard</a>. > Tags: @tag.All > Spec: > The following are new failures, please fix them before merging the PR: <ol> > <li>cypress/e2e/Regression/ClientSide/Anvil/AnvilModal_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilButtonWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilCheckboxGroupWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilCurrencyInputWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilIconButtonWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilInlineButtonWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilInputWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilParagraphWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilPhoneInputWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilStatsWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilSwitchGroupWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilSwitchWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilTableWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilToolbarButtonWidgetSnapshot_spec.ts > <li>cypress/e2e/Regression/ClientSide/Anvil/Widgets/AnvilZoneSectionWidgetSnapshot_spec.ts</ol> > <a href="https://internal.appsmith.com/app/cypress-dashboard/identified-flaky-tests-65890b3c81d7400d08fa9ee3?branch=master" target="_blank">List of identified flaky tests</a>. > <hr>Wed, 18 Sep 2024 16:33:36 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No --------- Co-authored-by: Valera Melnikov <valera@appsmith.com>
111 lines
3.3 KiB
TypeScript
111 lines
3.3 KiB
TypeScript
import { call, put, select } from "redux-saga/effects";
|
|
import { getCurrentPageId, getPageList } from "selectors/editorSelectors";
|
|
import _ from "lodash";
|
|
import { ReduxActionTypes } from "ee/constants/ReduxActionConstants";
|
|
import type { Page } from "entities/Page";
|
|
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,
|
|
});
|
|
}
|
|
}
|