PromucFlow_constructor/app/client/src/ce/sagas/NavigationSagas.ts
Ankita Kinger ae05e93ec9
chore: Removing feature flag for app level invites (#22650)
## Description

Removing feature flag for app-level invites. Also, updating import
statements to use `@appsmith/..` instead of `ce/..`

Fixes [#22657](https://github.com/appsmithorg/appsmith/issues/22657)

## Type of change
- Chore (housekeeping or task changes that don't impact user perception)


## How Has This Been Tested?
- Manual
- Jest
- Cypress

## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
2023-04-26 12:48:16 +05:30

103 lines
3.7 KiB
TypeScript

import { fork, put, select } from "redux-saga/effects";
import type { RouteChangeActionPayload } from "actions/focusHistoryActions";
import { FocusEntity, identifyEntityFromPath } from "navigation/FocusEntity";
import log from "loglevel";
import AnalyticsUtil from "utils/AnalyticsUtil";
import { getRecentEntityIds } from "selectors/globalSearchSelectors";
import type { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
import { getCurrentThemeDetails } from "selectors/themeSelectors";
import type { BackgroundTheme } from "sagas/ThemeSaga";
import { changeAppBackground } from "sagas/ThemeSaga";
import { updateRecentEntitySaga } from "sagas/GlobalSearchSagas";
import { isEditorPath } from "@appsmith/pages/Editor/Explorer/helpers";
import {
setLastSelectedWidget,
setSelectedWidgets,
} from "actions/widgetSelectionActions";
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
import { contextSwitchingSaga } from "sagas/ContextSwitchingSaga";
import { getSafeCrash } from "selectors/errorSelectors";
import { flushErrors } from "actions/errorActions";
import type { NavigationMethod } from "utils/history";
let previousPath: string;
export function* handleRouteChange(
action: ReduxAction<RouteChangeActionPayload>,
) {
const { pathname, state } = action.payload.location;
try {
yield fork(clearErrors);
const isAnEditorPath = isEditorPath(pathname);
// handled only on edit mode
if (isAnEditorPath) {
yield fork(logNavigationAnalytics, action.payload);
yield fork(contextSwitchingSaga, pathname, previousPath, state);
yield fork(appBackgroundHandler);
const entityInfo = identifyEntityFromPath(pathname);
yield fork(updateRecentEntitySaga, entityInfo);
yield fork(setSelectedWidgetsSaga, state?.invokedBy);
}
} catch (e) {
log.error("Error in focus change", e);
} finally {
previousPath = pathname;
}
}
function* appBackgroundHandler() {
const currentTheme: BackgroundTheme = yield select(getCurrentThemeDetails);
changeAppBackground(currentTheme);
}
/**
* When an error occurs, we take over the whole router and keep it the error
* state till the errors are flushed. By default, we will flush out the
* error state when a CTA on the page is clicked but in case the
* user navigates via the browser buttons, this will ensure
* the errors are flushed
* */
function* clearErrors() {
const isCrashed: boolean = yield select(getSafeCrash);
if (isCrashed) {
yield put(flushErrors());
}
}
function* logNavigationAnalytics(payload: RouteChangeActionPayload) {
const {
location: { pathname, state },
} = payload;
const recentEntityIds: Array<string> = yield select(getRecentEntityIds);
const currentEntity = identifyEntityFromPath(pathname);
const previousEntity = identifyEntityFromPath(previousPath);
const isRecent = recentEntityIds.some(
(entityId) => entityId === currentEntity.id,
);
AnalyticsUtil.logEvent("ROUTE_CHANGE", {
toPath: pathname,
fromPath: previousPath || undefined,
navigationMethod: state?.invokedBy,
isRecent,
recentLength: recentEntityIds.length,
toType: currentEntity.entity,
fromType: previousEntity.entity,
});
}
function* setSelectedWidgetsSaga(invokedBy?: NavigationMethod) {
const pathname = window.location.pathname;
const entityInfo = identifyEntityFromPath(pathname);
let widgets: string[] = [];
let lastSelectedWidget = MAIN_CONTAINER_WIDGET_ID;
if (entityInfo.entity === FocusEntity.PROPERTY_PANE) {
widgets = entityInfo.id.split(",");
if (widgets.length) {
lastSelectedWidget = widgets[widgets.length - 1];
}
}
yield put(setSelectedWidgets(widgets, invokedBy));
yield put(setLastSelectedWidget(lastSelectedWidget));
}