## Description - Making sure to trigger evaluation after navigateTo on same page to make sure we update the `appsmith.URL.queryParams` - Update the cypress test to check queryParams update on same page Fixes https://github.com/appsmithorg/appsmith/issues/26831 ## Steps to test 1. Add a button widget 2. Add a `navigateTo` action on click event of button 3. NavigateTo should have params as below and should navigate to same page ```js {{ { key: "aff", key2: "dsfs" } }} ``` 4. Add a text widget with binding `{{appsmith.URL.queryParams}}` 5. Make sure that the text widget updates once the button is clicked ## Automation /ok-to-test tags="@tag.JS" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!IMPORTANT] > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/8598783804> > Commit: `634477b53582ae5392eb26dde1a1fcd434f55883` > Cypress dashboard url: <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=8598783804&attempt=2" target="_blank">Click here!</a> > All cypress tests have passed 🎉🎉🎉 <!-- end of auto-generated comment: Cypress test results --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for setting URL data through Redux actions for enhanced state management. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
109 lines
3.3 KiB
TypeScript
109 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 "@appsmith/constants/ReduxActionConstants";
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
|
import { getAppMode } from "@appsmith/selectors/applicationSelectors";
|
|
import { APP_MODE } from "entities/App";
|
|
import { getQueryStringfromObject } from "@appsmith/entities/URLRedirect/URLAssembly";
|
|
import history from "utils/history";
|
|
import { setDataUrl } from "@appsmith/sagas/PageSagas";
|
|
import AppsmithConsole from "utils/AppsmithConsole";
|
|
import { builderURL, viewerURL } from "@appsmith/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({
|
|
pageId: page.pageId,
|
|
params,
|
|
})
|
|
: viewerURL({
|
|
pageId: page.pageId,
|
|
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,
|
|
});
|
|
}
|
|
}
|