PromucFlow_constructor/app/client/src/sagas/OnboardingSagas.ts
Ilia d6f249b42d
chore: add blank line eslint rule (#36369)
## 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>
2024-09-18 19:35:28 +03:00

225 lines
6.6 KiB
TypeScript

import type { ReduxAction } from "ee/constants/ReduxActionConstants";
import { ReduxActionTypes } from "ee/constants/ReduxActionConstants";
import {
all,
call,
delay,
put,
select,
take,
takeLatest,
} from "redux-saga/effects";
import {
getFirstTimeUserOnboardingApplicationIds,
getFirstTimeUserOnboardingTelemetryCalloutIsAlreadyShown,
removeAllFirstTimeUserOnboardingApplicationIds,
removeFirstTimeUserOnboardingApplicationId,
setEnableStartSignposting,
setFirstTimeUserOnboardingApplicationId as storeFirstTimeUserOnboardingApplicationId,
setFirstTimeUserOnboardingIntroModalVisibility as storeFirstTimeUserOnboardingIntroModalVisibility,
} from "utils/storage";
import { getCurrentUser } from "selectors/usersSelectors";
import history from "utils/history";
import { getSignpostingStepStateByStep } from "selectors/onboardingSelectors";
import {
disableStartSignpostingAction,
removeFirstTimeUserOnboardingApplicationId as removeFirstTimeUserOnboardingApplicationIdAction,
setSignpostingOverlay,
showSignpostingTooltip,
signpostingStepUpdate,
} from "actions/onboardingActions";
import {
getCurrentApplicationId,
getIsEditorInitialized,
} from "selectors/editorSelectors";
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
import type { User } from "constants/userConstants";
import { builderURL } from "ee/RouteBuilder";
import type { SIGNPOSTING_STEP } from "pages/Editor/FirstTimeUserOnboarding/Utils";
import type { StepState } from "reducers/uiReducers/onBoardingReducer";
import { isUndefined } from "lodash";
import { isAirgapped } from "ee/utils/airgapHelpers";
import { SIGNPOSTING_ANALYTICS_STEP_NAME } from "pages/Editor/FirstTimeUserOnboarding/constants";
// Signposting sagas
function* setFirstTimeUserOnboardingApplicationId(action: ReduxAction<string>) {
yield storeFirstTimeUserOnboardingApplicationId(action.payload);
const applicationIds: string[] =
yield getFirstTimeUserOnboardingApplicationIds();
yield put({
type: ReduxActionTypes.SET_FIRST_TIME_USER_ONBOARDING_APPLICATION_IDS,
payload: [...applicationIds, ...action.payload],
});
}
function* removeFirstTimeUserOnboardingApplicationIdSaga(
action: ReduxAction<string>,
) {
yield call(removeFirstTimeUserOnboardingApplicationId, action.payload);
const applicationIds: string[] =
yield getFirstTimeUserOnboardingApplicationIds();
yield put({
type: ReduxActionTypes.SET_FIRST_TIME_USER_ONBOARDING_APPLICATION_IDS,
payload: applicationIds.filter((id) => id !== action.payload),
});
}
function* setFirstTimeUserOnboardingIntroModalVisibility(
action: ReduxAction<boolean>,
) {
yield storeFirstTimeUserOnboardingIntroModalVisibility(action.payload);
}
function* endFirstTimeUserOnboardingSaga() {
const firstTimeUserExperienceAppId: string = yield select(
getCurrentApplicationId,
);
yield put(
removeFirstTimeUserOnboardingApplicationIdAction(
firstTimeUserExperienceAppId,
),
);
}
function* firstTimeUserOnboardingInitSaga(
action: ReduxAction<{
applicationId: string;
basePageId: string;
suffix?: string;
}>,
) {
yield call(setEnableStartSignposting, true);
yield put({
type: ReduxActionTypes.SET_FIRST_TIME_USER_ONBOARDING_APPLICATION_ID,
payload: action.payload.applicationId,
});
history.replace(
builderURL({
basePageId: action.payload.basePageId,
suffix: action.payload.suffix || "",
}),
);
const isEditorInitialised: boolean = yield select(getIsEditorInitialized);
if (!isEditorInitialised) {
yield take(ReduxActionTypes.INITIALIZE_EDITOR_SUCCESS);
}
let showOverlay = true;
// We don't want to show the signposting overlay when we intend to show the
// telemetry callout
const currentUser: User | undefined = yield select(getCurrentUser);
if (currentUser?.isSuperUser && !isAirgapped()) {
const isAnonymousDataPopupAlreadyOpen: unknown = yield call(
getFirstTimeUserOnboardingTelemetryCalloutIsAlreadyShown,
);
if (!isAnonymousDataPopupAlreadyOpen) {
showOverlay = false;
}
}
yield put(setSignpostingOverlay(showOverlay));
// Show the modal once the editor is loaded. The delay is to grab user attention back once the editor
yield delay(1000);
yield put({
type: ReduxActionTypes.SET_SHOW_FIRST_TIME_USER_ONBOARDING_MODAL,
payload: true,
});
AnalyticsUtil.logEvent("SIGNPOSTING_MODAL_FIRST_TIME_OPEN");
}
function* setFirstTimeUserOnboardingCompleteSaga(action: ReduxAction<boolean>) {
if (action.payload) {
yield put(disableStartSignpostingAction());
}
}
function* disableStartFirstTimeUserOnboardingSaga() {
yield call(removeAllFirstTimeUserOnboardingApplicationIds);
yield call(setEnableStartSignposting, false);
}
function* setSignpostingStepStateSaga(
action: ReduxAction<{ step: SIGNPOSTING_STEP; completed: boolean }>,
) {
const { completed, step } = action.payload;
const stepState: StepState | undefined = yield select(
getSignpostingStepStateByStep,
step,
);
// No changes to update so we ignore
if (stepState && stepState.completed === completed) return;
const readProps = completed
? {
read: false,
}
: {};
yield put(
signpostingStepUpdate({
...action.payload,
...readProps,
}),
);
// Show tooltip when a step is completed
if (!isUndefined(readProps.read) && !readProps.read) {
// Show tooltip after a small delay to not be abrupt
yield delay(1000);
AnalyticsUtil.logEvent("SIGNPOSTING_STEP_COMPLETE", {
step_name: SIGNPOSTING_ANALYTICS_STEP_NAME[step],
});
yield put(showSignpostingTooltip(true));
}
}
export default function* onboardingActionSagas() {
yield all([
takeLatest(
ReduxActionTypes.SET_FIRST_TIME_USER_ONBOARDING_APPLICATION_ID,
setFirstTimeUserOnboardingApplicationId,
),
takeLatest(
ReduxActionTypes.REMOVE_FIRST_TIME_USER_ONBOARDING_APPLICATION_ID,
removeFirstTimeUserOnboardingApplicationIdSaga,
),
takeLatest(
ReduxActionTypes.SET_SHOW_FIRST_TIME_USER_ONBOARDING_MODAL,
setFirstTimeUserOnboardingIntroModalVisibility,
),
takeLatest(
ReduxActionTypes.END_FIRST_TIME_USER_ONBOARDING,
endFirstTimeUserOnboardingSaga,
),
takeLatest(
ReduxActionTypes.FIRST_TIME_USER_ONBOARDING_INIT,
firstTimeUserOnboardingInitSaga,
),
takeLatest(
ReduxActionTypes.SET_FIRST_TIME_USER_ONBOARDING_COMPLETE,
setFirstTimeUserOnboardingCompleteSaga,
),
takeLatest(
ReduxActionTypes.DISABLE_START_SIGNPOSTING,
disableStartFirstTimeUserOnboardingSaga,
),
takeLatest(
ReduxActionTypes.SIGNPOSTING_STEP_UPDATE_INIT,
setSignpostingStepStateSaga,
),
]);
}