chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] 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
- [ ] 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
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
|
2020-12-30 07:31:20 +00:00
|
|
|
import {
|
|
|
|
|
ReduxActionTypes,
|
2021-08-03 08:06:48 +00:00
|
|
|
WidgetReduxActionTypes,
|
2022-04-12 10:50:01 +00:00
|
|
|
} from "@appsmith/constants/ReduxActionConstants";
|
2020-12-30 07:31:20 +00:00
|
|
|
import {
|
|
|
|
|
all,
|
2023-01-28 02:17:06 +00:00
|
|
|
call,
|
|
|
|
|
delay,
|
2020-12-30 07:31:20 +00:00
|
|
|
put,
|
|
|
|
|
select,
|
2022-01-25 13:56:52 +00:00
|
|
|
take,
|
2023-01-28 02:17:06 +00:00
|
|
|
takeLatest,
|
2020-12-30 07:31:20 +00:00
|
|
|
} from "redux-saga/effects";
|
|
|
|
|
import {
|
2023-05-02 09:52:05 +00:00
|
|
|
getFirstTimeUserOnboardingApplicationIds,
|
|
|
|
|
removeAllFirstTimeUserOnboardingApplicationIds,
|
|
|
|
|
removeFirstTimeUserOnboardingApplicationId,
|
|
|
|
|
setEnableStartSignposting,
|
2022-01-25 13:56:52 +00:00
|
|
|
setFirstTimeUserOnboardingApplicationId as storeFirstTimeUserOnboardingApplicationId,
|
|
|
|
|
setFirstTimeUserOnboardingIntroModalVisibility as storeFirstTimeUserOnboardingIntroModalVisibility,
|
|
|
|
|
} from "utils/storage";
|
|
|
|
|
|
|
|
|
|
import { getCurrentUser } from "selectors/usersSelectors";
|
|
|
|
|
import history from "utils/history";
|
|
|
|
|
import TourApp from "pages/Editor/GuidedTour/app.json";
|
|
|
|
|
|
2022-01-21 10:19:10 +00:00
|
|
|
import {
|
2022-01-25 13:56:52 +00:00
|
|
|
getHadReachedStep,
|
2022-06-15 15:37:41 +00:00
|
|
|
getOnboardingWorkspaces,
|
2022-01-25 13:56:52 +00:00
|
|
|
getQueryAction,
|
|
|
|
|
getTableWidget,
|
2022-01-21 10:19:10 +00:00
|
|
|
} from "selectors/onboardingSelectors";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] 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
- [ ] 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
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { Workspaces } from "@appsmith/constants/workspaceConstants";
|
2022-01-21 10:19:10 +00:00
|
|
|
import {
|
2023-05-02 09:52:05 +00:00
|
|
|
disableStartSignpostingAction,
|
2022-01-25 13:56:52 +00:00
|
|
|
enableGuidedTour,
|
|
|
|
|
focusWidgetProperty,
|
2022-09-02 13:15:48 +00:00
|
|
|
loadGuidedTour,
|
2023-05-02 09:52:05 +00:00
|
|
|
removeFirstTimeUserOnboardingApplicationId as removeFirstTimeUserOnboardingApplicationIdAction,
|
2022-01-25 13:56:52 +00:00
|
|
|
setCurrentStep,
|
|
|
|
|
toggleLoader,
|
|
|
|
|
} from "actions/onboardingActions";
|
2022-02-24 13:13:23 +00:00
|
|
|
import {
|
|
|
|
|
getCurrentApplicationId,
|
2022-03-15 13:12:29 +00:00
|
|
|
getIsEditorInitialized,
|
2022-02-24 13:13:23 +00:00
|
|
|
} from "selectors/editorSelectors";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] 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
- [ ] 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
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { WidgetProps } from "widgets/BaseWidget";
|
2022-01-25 13:56:52 +00:00
|
|
|
import { getNextWidgetName } from "./WidgetOperationUtils";
|
|
|
|
|
import WidgetFactory from "utils/WidgetFactory";
|
2022-01-21 10:19:10 +00:00
|
|
|
import { generateReactKey } from "utils/generators";
|
2022-01-25 13:56:52 +00:00
|
|
|
import { RenderModes } from "constants/WidgetConstants";
|
|
|
|
|
import log from "loglevel";
|
|
|
|
|
import { getDataTree } from "selectors/dataTreeSelectors";
|
|
|
|
|
import { getWidgets } from "./selectors";
|
2022-03-30 13:11:41 +00:00
|
|
|
import { clearActionResponse } from "actions/pluginActionActions";
|
2021-02-11 06:36:07 +00:00
|
|
|
import {
|
2022-01-25 13:56:52 +00:00
|
|
|
importApplication,
|
|
|
|
|
updateApplicationLayout,
|
2023-03-29 17:07:06 +00:00
|
|
|
} from "@appsmith/actions/applicationActions";
|
2022-01-25 13:56:52 +00:00
|
|
|
import { setPreviewModeAction } from "actions/editorActions";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] 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
- [ ] 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
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { FlattenedWidgetProps } from "widgets/constants";
|
|
|
|
|
import type { ActionData } from "reducers/entityReducers/actionsReducer";
|
2022-01-25 13:56:52 +00:00
|
|
|
import { batchUpdateMultipleWidgetProperties } from "actions/controlActions";
|
2022-07-27 13:59:43 +00:00
|
|
|
import {
|
|
|
|
|
setExplorerActiveAction,
|
|
|
|
|
setExplorerPinnedAction,
|
|
|
|
|
} from "actions/explorerActions";
|
2022-01-25 13:56:52 +00:00
|
|
|
import { selectWidgetInitAction } from "actions/widgetSelectionActions";
|
|
|
|
|
import { hideIndicator } from "pages/Editor/GuidedTour/utils";
|
|
|
|
|
import { updateWidgetName } from "actions/propertyPaneActions";
|
|
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] 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
- [ ] 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
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { DataTree } from "entities/DataTree/dataTreeFactory";
|
|
|
|
|
import type { CanvasWidgetsReduxState } from "reducers/entityReducers/canvasWidgetsReducer";
|
|
|
|
|
import type { User } from "constants/userConstants";
|
2022-03-25 10:43:26 +00:00
|
|
|
import { builderURL, queryEditorIdURL } from "RouteBuilder";
|
2022-02-24 13:13:23 +00:00
|
|
|
import { GuidedTourEntityNames } from "pages/Editor/GuidedTour/constants";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] 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
- [ ] 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
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { GuidedTourState } from "reducers/uiReducers/guidedTourReducer";
|
2022-09-02 13:15:48 +00:00
|
|
|
import { sessionStorage } from "utils/localStorage";
|
2022-10-13 20:13:44 +00:00
|
|
|
import store from "store";
|
2022-09-29 09:09:19 +00:00
|
|
|
import {
|
|
|
|
|
createMessage,
|
|
|
|
|
ONBOARDING_SKIPPED_FIRST_TIME_USER,
|
|
|
|
|
} from "@appsmith/constants/messages";
|
2023-01-28 02:17:06 +00:00
|
|
|
import { SelectionRequestType } from "sagas/WidgetSelectUtils";
|
2023-05-19 18:37:06 +00:00
|
|
|
import { toast } from "design-system";
|
2022-09-02 13:15:48 +00:00
|
|
|
|
|
|
|
|
const GUIDED_TOUR_STORAGE_KEY = "GUIDED_TOUR_STORAGE_KEY";
|
2021-02-11 06:36:07 +00:00
|
|
|
|
|
|
|
|
function* createApplication() {
|
2022-03-15 13:12:29 +00:00
|
|
|
// If we are starting onboarding from the editor wait for the editor to reset.
|
2022-06-21 13:57:34 +00:00
|
|
|
const isEditorInitialised: boolean = yield select(getIsEditorInitialized);
|
2022-06-15 15:37:41 +00:00
|
|
|
let userWorkspaces: Workspaces[] = yield select(getOnboardingWorkspaces);
|
2022-03-15 13:12:29 +00:00
|
|
|
if (isEditorInitialised) {
|
|
|
|
|
yield take(ReduxActionTypes.RESET_EDITOR_SUCCESS);
|
2022-03-16 14:38:50 +00:00
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
// If we haven't fetched the workspace list yet we wait for it to complete
|
|
|
|
|
// as we need an workspace where we create an application
|
|
|
|
|
if (!userWorkspaces.length) {
|
|
|
|
|
yield take(ReduxActionTypes.FETCH_USER_APPLICATIONS_WORKSPACES_SUCCESS);
|
2022-03-16 14:38:50 +00:00
|
|
|
}
|
2022-03-15 13:12:29 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
userWorkspaces = yield select(getOnboardingWorkspaces);
|
2022-06-21 13:57:34 +00:00
|
|
|
const currentUser: User | undefined = yield select(getCurrentUser);
|
|
|
|
|
// @ts-expect-error: currentUser can be undefined
|
2022-06-15 15:37:41 +00:00
|
|
|
const currentWorkspaceId = currentUser.currentWorkspaceId;
|
|
|
|
|
let workspace;
|
|
|
|
|
if (!currentWorkspaceId) {
|
|
|
|
|
workspace = userWorkspaces[0];
|
2021-02-11 06:36:07 +00:00
|
|
|
} else {
|
2022-06-15 15:37:41 +00:00
|
|
|
const filteredWorkspaces = userWorkspaces.filter(
|
|
|
|
|
(workspace: any) => workspace.workspace.id === currentWorkspaceId,
|
2021-02-11 06:36:07 +00:00
|
|
|
);
|
2022-06-15 15:37:41 +00:00
|
|
|
workspace = filteredWorkspaces[0];
|
2021-02-11 06:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
if (workspace) {
|
2022-01-25 13:56:52 +00:00
|
|
|
const appFileObject = new File([JSON.stringify(TourApp)], "app.json", {
|
|
|
|
|
type: "application/json",
|
2021-03-01 09:51:23 +00:00
|
|
|
});
|
2022-01-25 13:56:52 +00:00
|
|
|
yield put(enableGuidedTour(true));
|
|
|
|
|
yield put(
|
|
|
|
|
importApplication({
|
2022-06-15 15:37:41 +00:00
|
|
|
workspaceId: workspace.workspace.id,
|
2022-01-25 13:56:52 +00:00
|
|
|
applicationFile: appFileObject,
|
|
|
|
|
}),
|
|
|
|
|
);
|
2021-03-01 09:51:23 +00:00
|
|
|
}
|
2021-02-11 06:36:07 +00:00
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
yield put(setPreviewModeAction(true));
|
|
|
|
|
}
|
2021-02-11 06:36:07 +00:00
|
|
|
|
2022-09-02 13:15:48 +00:00
|
|
|
function* syncGuidedTourStateSaga() {
|
|
|
|
|
const applicationId: string = yield select(getCurrentApplicationId);
|
|
|
|
|
const guidedTourState: GuidedTourState = yield select(
|
|
|
|
|
(state) => state.ui.guidedTour,
|
|
|
|
|
);
|
|
|
|
|
yield call(
|
|
|
|
|
sessionStorage.setItem,
|
|
|
|
|
GUIDED_TOUR_STORAGE_KEY,
|
|
|
|
|
JSON.stringify({ applicationId, guidedTourState }),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* loadGuidedTourInitSaga() {
|
|
|
|
|
const applicationId: string = yield select(getCurrentApplicationId);
|
|
|
|
|
const guidedTourState: undefined | string = yield call(
|
|
|
|
|
sessionStorage.getItem,
|
|
|
|
|
GUIDED_TOUR_STORAGE_KEY,
|
|
|
|
|
);
|
|
|
|
|
if (guidedTourState) {
|
|
|
|
|
const parsedGuidedTourState: {
|
|
|
|
|
applicationId: string;
|
|
|
|
|
guidedTourState: GuidedTourState;
|
|
|
|
|
} = JSON.parse(guidedTourState);
|
|
|
|
|
|
|
|
|
|
if (applicationId === parsedGuidedTourState.applicationId) {
|
|
|
|
|
yield put(loadGuidedTour(parsedGuidedTourState.guidedTourState));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
function* setCurrentStepSaga(action: ReduxAction<number>) {
|
2022-06-21 13:57:34 +00:00
|
|
|
const hadReachedStep: number = yield select(getHadReachedStep);
|
2022-01-25 13:56:52 +00:00
|
|
|
// Log only once when we reach that step
|
|
|
|
|
if (action.payload > hadReachedStep) {
|
|
|
|
|
AnalyticsUtil.logEvent("GUIDED_TOUR_REACHED_STEP", {
|
|
|
|
|
step: action.payload,
|
2021-06-24 09:12:12 +00:00
|
|
|
});
|
2022-01-25 13:56:52 +00:00
|
|
|
}
|
2021-06-24 09:12:12 +00:00
|
|
|
|
2022-09-02 13:15:48 +00:00
|
|
|
yield call(syncGuidedTourStateSaga);
|
2022-01-25 13:56:52 +00:00
|
|
|
yield put(setCurrentStep(action.payload));
|
|
|
|
|
}
|
2021-06-24 09:12:12 +00:00
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
function* setUpTourAppSaga() {
|
|
|
|
|
yield put(setPreviewModeAction(false));
|
|
|
|
|
// Delete the container widget
|
|
|
|
|
const widgets: { [widgetId: string]: FlattenedWidgetProps } = yield select(
|
|
|
|
|
getWidgets,
|
|
|
|
|
);
|
|
|
|
|
const containerWidget = Object.values(widgets).find(
|
|
|
|
|
(widget) => widget.type === "CONTAINER_WIDGET",
|
|
|
|
|
);
|
|
|
|
|
yield put({
|
|
|
|
|
type: WidgetReduxActionTypes.WIDGET_DELETE,
|
|
|
|
|
payload: {
|
|
|
|
|
widgetId: containerWidget?.widgetId,
|
|
|
|
|
parentId: containerWidget?.parentId,
|
|
|
|
|
disallowUndo: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
2021-06-24 09:12:12 +00:00
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
yield delay(500);
|
2022-06-21 13:57:34 +00:00
|
|
|
// @ts-expect-error: No type declared for getTableWidgetSelector.
|
2022-01-25 13:56:52 +00:00
|
|
|
const tableWidget = yield select(getTableWidget);
|
|
|
|
|
yield put(
|
|
|
|
|
batchUpdateMultipleWidgetProperties([
|
|
|
|
|
{
|
|
|
|
|
widgetId: tableWidget.widgetId,
|
|
|
|
|
updates: {
|
|
|
|
|
modify: {
|
|
|
|
|
tableData: "",
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-02-11 06:36:07 +00:00
|
|
|
},
|
2022-01-25 13:56:52 +00:00
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
// Update getCustomers query body
|
|
|
|
|
const query: ActionData | undefined = yield select(getQueryAction);
|
|
|
|
|
yield put(clearActionResponse(query?.config.id ?? ""));
|
2022-03-25 10:43:26 +00:00
|
|
|
const applicationId: string = yield select(getCurrentApplicationId);
|
2022-01-25 13:56:52 +00:00
|
|
|
yield put(
|
|
|
|
|
updateApplicationLayout(applicationId || "", {
|
|
|
|
|
appLayout: {
|
|
|
|
|
type: "DESKTOP",
|
2021-02-11 06:36:07 +00:00
|
|
|
},
|
2022-01-25 13:56:52 +00:00
|
|
|
}),
|
|
|
|
|
);
|
2022-07-11 04:06:29 +00:00
|
|
|
if (!query) return;
|
|
|
|
|
history.push(
|
|
|
|
|
queryEditorIdURL({
|
|
|
|
|
pageId: query.config.pageId,
|
|
|
|
|
queryId: query.config.id,
|
|
|
|
|
}),
|
|
|
|
|
);
|
2022-10-17 15:16:38 +00:00
|
|
|
// Hide the explorer initialy
|
|
|
|
|
yield put(setExplorerPinnedAction(false));
|
|
|
|
|
yield put(setExplorerActiveAction(false));
|
|
|
|
|
yield put(toggleLoader(false));
|
2022-01-25 13:56:52 +00:00
|
|
|
}
|
2021-02-11 06:36:07 +00:00
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
function* addOnboardingWidget(action: ReduxAction<Partial<WidgetProps>>) {
|
|
|
|
|
const widgetConfig = action.payload;
|
2021-02-11 06:36:07 +00:00
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
if (!widgetConfig.type) return;
|
2021-02-11 06:36:07 +00:00
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
const defaultConfig = WidgetFactory.widgetConfigMap.get(widgetConfig.type);
|
2021-02-11 06:36:07 +00:00
|
|
|
|
2022-03-25 10:43:26 +00:00
|
|
|
const evalTree: DataTree = yield select(getDataTree);
|
2022-06-21 13:57:34 +00:00
|
|
|
const widgets: CanvasWidgetsReduxState = yield select(getWidgets);
|
2021-02-11 06:36:07 +00:00
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
const widgetName = getNextWidgetName(widgets, widgetConfig.type, evalTree, {
|
|
|
|
|
prefix: widgetConfig.widgetName,
|
|
|
|
|
});
|
2021-02-11 06:36:07 +00:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const newWidget = {
|
|
|
|
|
newWidgetId: generateReactKey(),
|
|
|
|
|
widgetId: "0",
|
|
|
|
|
parentId: "0",
|
|
|
|
|
renderMode: RenderModes.CANVAS,
|
|
|
|
|
isLoading: false,
|
2022-01-25 13:56:52 +00:00
|
|
|
...defaultConfig,
|
|
|
|
|
widgetName,
|
2021-02-11 06:36:07 +00:00
|
|
|
...widgetConfig,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
yield put({
|
2021-08-03 08:06:48 +00:00
|
|
|
type: WidgetReduxActionTypes.WIDGET_ADD_CHILD,
|
2021-02-11 06:36:07 +00:00
|
|
|
payload: newWidget,
|
|
|
|
|
});
|
|
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
// Wait for widget names to be updated
|
|
|
|
|
// Updating widget names here as widget blueprints don't take widget names
|
|
|
|
|
yield take(ReduxActionTypes.SAVE_PAGE_SUCCESS);
|
|
|
|
|
const widgets: { [widgetId: string]: FlattenedWidgetProps } = yield select(
|
|
|
|
|
getWidgets,
|
2021-02-11 06:36:07 +00:00
|
|
|
);
|
|
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
const nameInput = Object.values(widgets).find(
|
|
|
|
|
(widget) => widget.widgetName === "Input1",
|
|
|
|
|
);
|
|
|
|
|
const emailInput = Object.values(widgets).find(
|
|
|
|
|
(widget) => widget.widgetName === "Input2",
|
|
|
|
|
);
|
|
|
|
|
const countryInput = Object.values(widgets).find(
|
|
|
|
|
(widget) => widget.widgetName === "Input3",
|
|
|
|
|
);
|
|
|
|
|
const imageWidget = Object.values(widgets).find(
|
|
|
|
|
(widget) => widget.widgetName === "Image1",
|
|
|
|
|
);
|
2021-02-11 06:36:07 +00:00
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
if (nameInput && emailInput && countryInput && imageWidget) {
|
2022-04-29 10:09:16 +00:00
|
|
|
yield put(
|
|
|
|
|
updateWidgetName(nameInput.widgetId, GuidedTourEntityNames.NAME_INPUT),
|
|
|
|
|
);
|
2022-01-25 13:56:52 +00:00
|
|
|
yield take(ReduxActionTypes.FETCH_PAGE_DSL_SUCCESS);
|
2022-04-29 10:09:16 +00:00
|
|
|
yield put(
|
|
|
|
|
updateWidgetName(
|
|
|
|
|
emailInput.widgetId,
|
|
|
|
|
GuidedTourEntityNames.EMAIL_INPUT,
|
|
|
|
|
),
|
|
|
|
|
);
|
2022-01-25 13:56:52 +00:00
|
|
|
yield take(ReduxActionTypes.FETCH_PAGE_DSL_SUCCESS);
|
2022-04-29 10:09:16 +00:00
|
|
|
yield put(
|
|
|
|
|
updateWidgetName(
|
|
|
|
|
countryInput.widgetId,
|
|
|
|
|
GuidedTourEntityNames.COUNTRY_INPUT,
|
|
|
|
|
),
|
|
|
|
|
);
|
2022-01-25 13:56:52 +00:00
|
|
|
yield take(ReduxActionTypes.FETCH_PAGE_DSL_SUCCESS);
|
2022-04-29 10:09:16 +00:00
|
|
|
yield put(
|
|
|
|
|
updateWidgetName(
|
|
|
|
|
imageWidget.widgetId,
|
|
|
|
|
GuidedTourEntityNames.DISPLAY_IMAGE,
|
|
|
|
|
),
|
|
|
|
|
);
|
2021-02-11 06:36:07 +00:00
|
|
|
}
|
2022-01-25 13:56:52 +00:00
|
|
|
} catch (error) {
|
|
|
|
|
log.error(error);
|
2021-02-11 06:36:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
// Update button widget text
|
|
|
|
|
function* updateWidgetTextSaga() {
|
|
|
|
|
const widgets: { [widgetId: string]: FlattenedWidgetProps } = yield select(
|
|
|
|
|
getWidgets,
|
|
|
|
|
);
|
|
|
|
|
const buttonWidget = Object.values(widgets).find(
|
|
|
|
|
(widget) => widget.type === "BUTTON_WIDGET",
|
|
|
|
|
);
|
|
|
|
|
if (buttonWidget) {
|
2021-02-11 06:36:07 +00:00
|
|
|
yield put(
|
2022-01-25 13:56:52 +00:00
|
|
|
batchUpdateMultipleWidgetProperties([
|
|
|
|
|
{
|
|
|
|
|
widgetId: buttonWidget.widgetId,
|
|
|
|
|
updates: {
|
|
|
|
|
modify: {
|
|
|
|
|
text: "Click to Update",
|
|
|
|
|
rightColumn: buttonWidget.leftColumn + 24,
|
|
|
|
|
bottomRow: buttonWidget.topRow + 5,
|
2022-02-24 13:13:23 +00:00
|
|
|
widgetName: GuidedTourEntityNames.BUTTON_WIDGET,
|
2022-01-25 13:56:52 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
]),
|
2021-02-11 06:36:07 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
function* focusWidgetPropertySaga(action: ReduxAction<string>) {
|
|
|
|
|
const input: HTMLElement | null = document.querySelector(
|
|
|
|
|
`[data-guided-tour-iid=${action.payload}] .CodeEditorTarget textarea`,
|
|
|
|
|
);
|
|
|
|
|
input?.focus();
|
|
|
|
|
}
|
2021-02-11 06:36:07 +00:00
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
function* endGuidedTourSaga(action: ReduxAction<boolean>) {
|
|
|
|
|
if (!action.payload) {
|
|
|
|
|
yield call(hideIndicator);
|
2022-09-02 13:15:48 +00:00
|
|
|
yield call(sessionStorage.removeItem, GUIDED_TOUR_STORAGE_KEY);
|
2022-01-25 13:56:52 +00:00
|
|
|
}
|
2021-02-11 06:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
function* selectWidgetSaga(
|
|
|
|
|
action: ReduxAction<{ widgetName: string; propertyName?: string }>,
|
|
|
|
|
) {
|
|
|
|
|
const widgets: { [widgetId: string]: FlattenedWidgetProps } = yield select(
|
|
|
|
|
getWidgets,
|
|
|
|
|
);
|
|
|
|
|
const widget = Object.values(widgets).find((widget) => {
|
|
|
|
|
return widget.widgetName === action.payload.widgetName;
|
|
|
|
|
});
|
2021-02-11 06:36:07 +00:00
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
if (widget) {
|
2023-01-28 02:17:06 +00:00
|
|
|
yield put(
|
|
|
|
|
selectWidgetInitAction(SelectionRequestType.One, [widget.widgetId]),
|
|
|
|
|
);
|
2022-01-25 13:56:52 +00:00
|
|
|
// Delay to wait for the fields to render
|
|
|
|
|
yield delay(1000);
|
|
|
|
|
// If the propertyName exist then we focus the respective input field as well
|
|
|
|
|
if (action.payload.propertyName)
|
|
|
|
|
yield put(focusWidgetProperty(action.payload.propertyName));
|
2021-02-11 06:36:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
// Signposting sagas
|
2021-09-13 07:22:51 +00:00
|
|
|
function* setFirstTimeUserOnboardingApplicationId(action: ReduxAction<string>) {
|
|
|
|
|
yield storeFirstTimeUserOnboardingApplicationId(action.payload);
|
2023-05-02 09:52:05 +00:00
|
|
|
|
|
|
|
|
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),
|
|
|
|
|
});
|
2021-09-13 07:22:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* setFirstTimeUserOnboardingIntroModalVisibility(
|
|
|
|
|
action: ReduxAction<boolean>,
|
|
|
|
|
) {
|
|
|
|
|
yield storeFirstTimeUserOnboardingIntroModalVisibility(action.payload);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* endFirstTimeUserOnboardingSaga() {
|
2022-03-25 10:43:26 +00:00
|
|
|
const firstTimeUserExperienceAppId: string = yield select(
|
2023-05-02 09:52:05 +00:00
|
|
|
getCurrentApplicationId,
|
|
|
|
|
);
|
|
|
|
|
yield put(
|
|
|
|
|
removeFirstTimeUserOnboardingApplicationIdAction(
|
|
|
|
|
firstTimeUserExperienceAppId,
|
|
|
|
|
),
|
2021-09-13 07:22:51 +00:00
|
|
|
);
|
2023-05-19 18:37:06 +00:00
|
|
|
toast.show(createMessage(ONBOARDING_SKIPPED_FIRST_TIME_USER), {
|
|
|
|
|
kind: "success",
|
|
|
|
|
action: {
|
|
|
|
|
text: "undo",
|
|
|
|
|
effect: () => {
|
|
|
|
|
store.dispatch({
|
|
|
|
|
type: ReduxActionTypes.UNDO_END_FIRST_TIME_USER_ONBOARDING,
|
|
|
|
|
payload: firstTimeUserExperienceAppId,
|
|
|
|
|
});
|
|
|
|
|
},
|
2021-09-13 07:22:51 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* undoEndFirstTimeUserOnboardingSaga(action: ReduxAction<string>) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.SET_FIRST_TIME_USER_ONBOARDING_APPLICATION_ID,
|
|
|
|
|
payload: action.payload,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 05:36:17 +00:00
|
|
|
function* firstTimeUserOnboardingInitSaga(
|
|
|
|
|
action: ReduxAction<{ applicationId: string; pageId: string }>,
|
|
|
|
|
) {
|
2023-05-02 09:52:05 +00:00
|
|
|
yield call(setEnableStartSignposting, true);
|
2021-10-21 05:36:17 +00:00
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.SET_FIRST_TIME_USER_ONBOARDING_APPLICATION_ID,
|
|
|
|
|
payload: action.payload.applicationId,
|
|
|
|
|
});
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.SET_SHOW_FIRST_TIME_USER_ONBOARDING_MODAL,
|
|
|
|
|
payload: true,
|
|
|
|
|
});
|
|
|
|
|
history.replace(
|
2022-03-25 10:43:26 +00:00
|
|
|
builderURL({
|
2021-10-21 05:36:17 +00:00
|
|
|
pageId: action.payload.pageId,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-02 09:52:05 +00:00
|
|
|
function* setFirstTimeUserOnboardingCompleteSaga(action: ReduxAction<boolean>) {
|
|
|
|
|
if (action.payload) {
|
|
|
|
|
yield put(disableStartSignpostingAction());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* disableStartFirstTimeUserOnboardingSaga() {
|
|
|
|
|
yield call(removeAllFirstTimeUserOnboardingApplicationIds);
|
|
|
|
|
yield call(setEnableStartSignposting, false);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
export default function* onboardingActionSagas() {
|
2020-12-30 07:31:20 +00:00
|
|
|
yield all([
|
2021-02-11 06:36:07 +00:00
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.ONBOARDING_CREATE_APPLICATION,
|
|
|
|
|
createApplication,
|
|
|
|
|
),
|
2022-01-25 13:56:52 +00:00
|
|
|
takeLatest(ReduxActionTypes.SET_UP_TOUR_APP, setUpTourAppSaga),
|
|
|
|
|
takeLatest(ReduxActionTypes.GUIDED_TOUR_ADD_WIDGET, addOnboardingWidget),
|
|
|
|
|
takeLatest(ReduxActionTypes.SET_CURRENT_STEP_INIT, setCurrentStepSaga),
|
|
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.UPDATE_BUTTON_WIDGET_TEXT,
|
|
|
|
|
updateWidgetTextSaga,
|
|
|
|
|
),
|
|
|
|
|
takeLatest(ReduxActionTypes.ENABLE_GUIDED_TOUR, endGuidedTourSaga),
|
|
|
|
|
takeLatest(ReduxActionTypes.GUIDED_TOUR_FOCUS_WIDGET, selectWidgetSaga),
|
|
|
|
|
takeLatest(ReduxActionTypes.FOCUS_WIDGET_PROPERTY, focusWidgetPropertySaga),
|
2022-09-02 13:15:48 +00:00
|
|
|
takeLatest(ReduxActionTypes.LOAD_GUIDED_TOUR_INIT, loadGuidedTourInitSaga),
|
2021-09-13 07:22:51 +00:00
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.SET_FIRST_TIME_USER_ONBOARDING_APPLICATION_ID,
|
|
|
|
|
setFirstTimeUserOnboardingApplicationId,
|
|
|
|
|
),
|
2023-05-02 09:52:05 +00:00
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.REMOVE_FIRST_TIME_USER_ONBOARDING_APPLICATION_ID,
|
|
|
|
|
removeFirstTimeUserOnboardingApplicationIdSaga,
|
|
|
|
|
),
|
2021-09-13 07:22:51 +00:00
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.SET_SHOW_FIRST_TIME_USER_ONBOARDING_MODAL,
|
|
|
|
|
setFirstTimeUserOnboardingIntroModalVisibility,
|
|
|
|
|
),
|
|
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.END_FIRST_TIME_USER_ONBOARDING,
|
|
|
|
|
endFirstTimeUserOnboardingSaga,
|
|
|
|
|
),
|
|
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.UNDO_END_FIRST_TIME_USER_ONBOARDING,
|
|
|
|
|
undoEndFirstTimeUserOnboardingSaga,
|
|
|
|
|
),
|
2021-10-21 05:36:17 +00:00
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.FIRST_TIME_USER_ONBOARDING_INIT,
|
|
|
|
|
firstTimeUserOnboardingInitSaga,
|
|
|
|
|
),
|
2023-05-02 09:52:05 +00:00
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.SET_FIRST_TIME_USER_ONBOARDING_COMPLETE,
|
|
|
|
|
setFirstTimeUserOnboardingCompleteSaga,
|
|
|
|
|
),
|
|
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.DISABLE_START_SIGNPOSTING,
|
|
|
|
|
disableStartFirstTimeUserOnboardingSaga,
|
|
|
|
|
),
|
2020-12-30 07:31:20 +00:00
|
|
|
]);
|
|
|
|
|
}
|