2020-06-17 10:19:56 +00:00
|
|
|
import { all, takeEvery, call, put, select } from "redux-saga/effects";
|
2024-08-06 14:52:22 +00:00
|
|
|
import type { ReduxAction } from "ee/constants/ReduxActionConstants";
|
2020-04-29 11:58:02 +00:00
|
|
|
import {
|
|
|
|
|
ReduxActionTypes,
|
|
|
|
|
ReduxActionErrorTypes,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/constants/ReduxActionConstants";
|
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 { DefaultPlugin, PluginFormPayload } from "api/PluginApi";
|
|
|
|
|
import PluginsApi from "api/PluginApi";
|
2019-11-29 05:22:49 +00:00
|
|
|
import { validateResponse } from "sagas/ErrorSagas";
|
2024-08-06 14:52:22 +00:00
|
|
|
import { getCurrentWorkspaceId } from "ee/selectors/selectedWorkspaceSelectors";
|
2021-03-30 05:29:03 +00:00
|
|
|
import {
|
2022-12-08 03:36:35 +00:00
|
|
|
getActions,
|
2021-03-30 05:29:03 +00:00
|
|
|
getDatasources,
|
|
|
|
|
getPlugin,
|
|
|
|
|
getPluginForm,
|
|
|
|
|
getPlugins,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/selectors/entitiesSelector";
|
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 { Datasource } from "entities/Datasource";
|
|
|
|
|
import type { Plugin } from "api/PluginApi";
|
2021-03-30 05:29:03 +00:00
|
|
|
import {
|
|
|
|
|
fetchPluginFormConfigsSuccess,
|
|
|
|
|
fetchPluginFormConfigSuccess,
|
2021-07-29 08:13:10 +00:00
|
|
|
fetchPluginFormConfigError,
|
2021-03-30 05:29:03 +00:00
|
|
|
} from "actions/pluginActions";
|
|
|
|
|
import {
|
2021-04-26 05:41:32 +00:00
|
|
|
defaultActionDependenciesConfig,
|
2021-03-30 05:29:03 +00:00
|
|
|
defaultActionEditorConfigs,
|
|
|
|
|
defaultActionSettings,
|
2022-03-30 13:11:25 +00:00
|
|
|
defaultDatasourceFormButtonConfig,
|
2021-03-30 05:29:03 +00:00
|
|
|
} from "constants/AppsmithActionConstants/ActionConstants";
|
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 { ApiResponse } from "api/ApiResponses";
|
2021-03-30 05:29:03 +00:00
|
|
|
import PluginApi from "api/PluginApi";
|
|
|
|
|
import log from "loglevel";
|
2024-01-16 14:49:08 +00:00
|
|
|
import {
|
|
|
|
|
getAppsmithAIPlugin,
|
|
|
|
|
getGraphQLPlugin,
|
|
|
|
|
PluginType,
|
|
|
|
|
} from "entities/Action";
|
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 {
|
2021-08-26 05:37:07 +00:00
|
|
|
FormEditorConfigs,
|
|
|
|
|
FormSettingsConfigs,
|
|
|
|
|
FormDependencyConfigs,
|
2022-03-30 13:11:25 +00:00
|
|
|
FormDatasourceButtonConfigs,
|
2021-08-26 05:37:07 +00:00
|
|
|
} from "utils/DynamicBindingUtils";
|
2024-08-06 14:52:22 +00:00
|
|
|
import type { ActionDataState } from "ee/reducers/entityReducers/actionsReducer";
|
2024-01-24 06:44:16 +00:00
|
|
|
import { getFromServerWhenNoPrefetchedResult } from "./helper";
|
2019-11-29 05:22:49 +00:00
|
|
|
|
2022-03-17 10:28:54 +00:00
|
|
|
function* fetchPluginsSaga(
|
2024-01-24 06:44:16 +00:00
|
|
|
action: ReduxAction<
|
|
|
|
|
{ workspaceId?: string; plugins?: ApiResponse<Plugin[]> } | undefined
|
|
|
|
|
>,
|
2022-03-17 10:28:54 +00:00
|
|
|
) {
|
2019-11-29 05:22:49 +00:00
|
|
|
try {
|
2024-01-24 06:44:16 +00:00
|
|
|
const plugins = action.payload?.plugins;
|
2022-06-21 13:57:34 +00:00
|
|
|
let workspaceId: string = yield select(getCurrentWorkspaceId);
|
2022-06-15 15:37:41 +00:00
|
|
|
if (action.payload?.workspaceId) workspaceId = action.payload?.workspaceId;
|
2022-03-03 10:56:53 +00:00
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
if (!workspaceId) {
|
2022-07-20 11:54:16 +00:00
|
|
|
throw Error("Workspace id does not exist");
|
2020-08-26 13:22:10 +00:00
|
|
|
}
|
2022-06-21 13:57:34 +00:00
|
|
|
const pluginsResponse: ApiResponse<Plugin[]> = yield call(
|
2024-01-24 06:44:16 +00:00
|
|
|
getFromServerWhenNoPrefetchedResult,
|
|
|
|
|
plugins,
|
|
|
|
|
() => call(PluginsApi.fetchPlugins, workspaceId),
|
2022-06-21 13:57:34 +00:00
|
|
|
);
|
2024-01-24 06:44:16 +00:00
|
|
|
|
2022-06-21 13:57:34 +00:00
|
|
|
const isValid: boolean = yield validateResponse(pluginsResponse);
|
2019-11-29 05:22:49 +00:00
|
|
|
if (isValid) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.FETCH_PLUGINS_SUCCESS,
|
|
|
|
|
payload: pluginsResponse.data,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
2020-06-04 13:49:22 +00:00
|
|
|
type: ReduxActionErrorTypes.FETCH_PLUGINS_ERROR,
|
2019-11-29 05:22:49 +00:00
|
|
|
payload: { error },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-24 06:44:16 +00:00
|
|
|
function* fetchPluginFormConfigsSaga(action?: {
|
|
|
|
|
payload?: { pluginFormConfigs?: ApiResponse<PluginFormPayload[]> };
|
|
|
|
|
}) {
|
|
|
|
|
const pluginFormConfigs = action?.payload?.pluginFormConfigs;
|
2020-04-29 09:23:23 +00:00
|
|
|
try {
|
2021-03-30 05:29:03 +00:00
|
|
|
const datasources: Datasource[] = yield select(getDatasources);
|
|
|
|
|
const plugins: Plugin[] = yield select(getPlugins);
|
2022-06-15 15:37:41 +00:00
|
|
|
// Add plugins of all the datasources of their workspace
|
2021-04-02 09:47:37 +00:00
|
|
|
const pluginIdFormsToFetch = new Set(
|
2021-03-30 05:29:03 +00:00
|
|
|
datasources.map((datasource) => datasource.pluginId),
|
2020-04-29 09:23:23 +00:00
|
|
|
);
|
2022-09-09 15:59:47 +00:00
|
|
|
// Add the api plugin id by default as API, JS, Graphql can exists without datasource
|
2021-04-02 09:47:37 +00:00
|
|
|
const apiPlugin = plugins.find((plugin) => plugin.type === PluginType.API);
|
2021-09-08 17:32:22 +00:00
|
|
|
const jsPlugin = plugins.find((plugin) => plugin.type === PluginType.JS);
|
2022-09-09 15:59:47 +00:00
|
|
|
const graphqlPlugin = getGraphQLPlugin(plugins);
|
2024-01-16 14:49:08 +00:00
|
|
|
const appsmithAIPlugin = getAppsmithAIPlugin(plugins);
|
2021-04-02 09:47:37 +00:00
|
|
|
if (apiPlugin) {
|
|
|
|
|
pluginIdFormsToFetch.add(apiPlugin.id);
|
|
|
|
|
}
|
2022-09-09 15:59:47 +00:00
|
|
|
|
|
|
|
|
if (graphqlPlugin) {
|
|
|
|
|
pluginIdFormsToFetch.add(graphqlPlugin.id);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-16 14:49:08 +00:00
|
|
|
if (appsmithAIPlugin) {
|
|
|
|
|
pluginIdFormsToFetch.add(appsmithAIPlugin.id);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-08 03:36:35 +00:00
|
|
|
const actions: ActionDataState = yield select(getActions);
|
|
|
|
|
const actionPluginIds = actions.map((action) => action.config.pluginId);
|
|
|
|
|
for (const pluginId of actionPluginIds) {
|
|
|
|
|
pluginIdFormsToFetch.add(pluginId);
|
|
|
|
|
}
|
2024-01-24 06:44:16 +00:00
|
|
|
const pluginCalls = [...pluginIdFormsToFetch].map((id) =>
|
|
|
|
|
call(
|
|
|
|
|
getFromServerWhenNoPrefetchedResult,
|
|
|
|
|
// Set the data if it exists in the prefetched data
|
|
|
|
|
// This is to avoid making a call to the server for the data
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2024-01-24 06:44:16 +00:00
|
|
|
pluginFormConfigs?.data?.[id as any]
|
|
|
|
|
? {
|
|
|
|
|
...pluginFormConfigs,
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2024-01-24 06:44:16 +00:00
|
|
|
data: pluginFormConfigs?.data?.[id as any],
|
|
|
|
|
}
|
|
|
|
|
: undefined,
|
|
|
|
|
// If the data does not exist in the prefetched data, make a call to the server
|
|
|
|
|
() => call(PluginsApi.fetchFormConfig, id),
|
2024-01-16 04:46:48 +00:00
|
|
|
),
|
2022-03-25 10:43:26 +00:00
|
|
|
);
|
2023-10-19 10:27:39 +00:00
|
|
|
|
2024-01-24 06:44:16 +00:00
|
|
|
const pluginFormResponses: ApiResponse<PluginFormPayload>[] =
|
|
|
|
|
yield all(pluginCalls);
|
|
|
|
|
|
|
|
|
|
const pluginFormData: PluginFormPayload[] = [];
|
|
|
|
|
|
2023-10-19 10:27:39 +00:00
|
|
|
for (let i = 0; i < pluginFormResponses.length; i++) {
|
|
|
|
|
const response = pluginFormResponses[i];
|
2021-03-30 05:29:03 +00:00
|
|
|
yield validateResponse(response);
|
|
|
|
|
pluginFormData.push(response.data);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-08 17:32:22 +00:00
|
|
|
if (jsPlugin) {
|
|
|
|
|
pluginIdFormsToFetch.add(jsPlugin.id);
|
|
|
|
|
}
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2021-03-30 05:29:03 +00:00
|
|
|
const formConfigs: Record<string, any[]> = {};
|
2021-08-26 05:37:07 +00:00
|
|
|
const editorConfigs: FormEditorConfigs = {};
|
|
|
|
|
const settingConfigs: FormSettingsConfigs = {};
|
|
|
|
|
const dependencies: FormDependencyConfigs = {};
|
2022-03-30 13:11:25 +00:00
|
|
|
const datasourceFormButtonConfigs: FormDatasourceButtonConfigs = {};
|
2021-03-30 05:29:03 +00:00
|
|
|
|
2021-04-02 09:47:37 +00:00
|
|
|
Array.from(pluginIdFormsToFetch).forEach((pluginId, index) => {
|
2021-03-30 05:29:03 +00:00
|
|
|
const plugin = plugins.find((plugin) => plugin.id === pluginId);
|
2021-09-08 17:32:22 +00:00
|
|
|
if (plugin && plugin.type === PluginType.JS) {
|
2021-03-30 05:29:03 +00:00
|
|
|
settingConfigs[pluginId] = defaultActionSettings[plugin.type];
|
2021-09-08 17:32:22 +00:00
|
|
|
editorConfigs[pluginId] = defaultActionEditorConfigs[plugin.type];
|
|
|
|
|
formConfigs[pluginId] = [];
|
2021-04-26 05:41:32 +00:00
|
|
|
dependencies[pluginId] = defaultActionDependenciesConfig[plugin.type];
|
|
|
|
|
} else {
|
2021-09-08 17:32:22 +00:00
|
|
|
// Datasource form always use server's copy
|
2023-10-16 06:10:55 +00:00
|
|
|
if (!!pluginFormData[index]) {
|
|
|
|
|
formConfigs[pluginId] = pluginFormData[index].form;
|
|
|
|
|
// Action editor form if not available use default
|
|
|
|
|
if (plugin && !pluginFormData[index].editor) {
|
|
|
|
|
editorConfigs[pluginId] = defaultActionEditorConfigs[plugin.type];
|
|
|
|
|
} else {
|
|
|
|
|
editorConfigs[pluginId] = pluginFormData[index].editor;
|
|
|
|
|
}
|
|
|
|
|
// Action settings form if not available use default
|
|
|
|
|
if (plugin && !pluginFormData[index].setting) {
|
|
|
|
|
settingConfigs[pluginId] = defaultActionSettings[plugin.type];
|
|
|
|
|
} else {
|
|
|
|
|
settingConfigs[pluginId] = pluginFormData[index].setting;
|
|
|
|
|
}
|
|
|
|
|
// Action dependencies config if not available use default
|
|
|
|
|
if (plugin && !pluginFormData[index].dependencies) {
|
|
|
|
|
dependencies[pluginId] =
|
|
|
|
|
defaultActionDependenciesConfig[plugin.type];
|
|
|
|
|
} else {
|
|
|
|
|
dependencies[pluginId] = pluginFormData[index].dependencies;
|
|
|
|
|
}
|
|
|
|
|
// Datasource form buttons config if not available use default
|
|
|
|
|
if (plugin && !pluginFormData[index].formButton) {
|
|
|
|
|
datasourceFormButtonConfigs[pluginId] =
|
|
|
|
|
defaultDatasourceFormButtonConfig[plugin.type];
|
|
|
|
|
} else {
|
|
|
|
|
datasourceFormButtonConfigs[pluginId] =
|
|
|
|
|
pluginFormData[index].formButton;
|
|
|
|
|
}
|
2022-03-30 13:11:25 +00:00
|
|
|
}
|
2021-04-26 05:41:32 +00:00
|
|
|
}
|
2021-03-30 05:29:03 +00:00
|
|
|
});
|
2023-10-16 06:10:55 +00:00
|
|
|
|
2021-03-30 05:29:03 +00:00
|
|
|
yield put(
|
|
|
|
|
fetchPluginFormConfigsSuccess({
|
|
|
|
|
formConfigs,
|
|
|
|
|
editorConfigs,
|
|
|
|
|
settingConfigs,
|
2021-04-26 05:41:32 +00:00
|
|
|
dependencies,
|
2022-03-30 13:11:25 +00:00
|
|
|
datasourceFormButtonConfigs,
|
2021-03-30 05:29:03 +00:00
|
|
|
}),
|
|
|
|
|
);
|
2020-04-29 09:23:23 +00:00
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
2021-03-30 05:29:03 +00:00
|
|
|
type: ReduxActionErrorTypes.FETCH_PLUGIN_FORM_CONFIGS_ERROR,
|
2020-04-29 09:23:23 +00:00
|
|
|
payload: { error },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-30 05:29:03 +00:00
|
|
|
export function* checkAndGetPluginFormConfigsSaga(pluginId: string) {
|
2020-10-20 09:00:02 +00:00
|
|
|
try {
|
2021-03-30 05:29:03 +00:00
|
|
|
const plugin: Plugin = yield select(getPlugin, pluginId);
|
2022-06-21 13:57:34 +00:00
|
|
|
const formConfig: Record<string, unknown> = yield select(
|
|
|
|
|
getPluginForm,
|
|
|
|
|
pluginId,
|
|
|
|
|
);
|
2021-03-30 05:29:03 +00:00
|
|
|
if (!formConfig) {
|
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
|
|
|
const formConfigResponse: ApiResponse<PluginFormPayload> =
|
|
|
|
|
yield PluginApi.fetchFormConfig(pluginId);
|
2021-03-30 05:29:03 +00:00
|
|
|
yield validateResponse(formConfigResponse);
|
|
|
|
|
if (!formConfigResponse.data.setting) {
|
|
|
|
|
formConfigResponse.data.setting = defaultActionSettings[plugin.type];
|
|
|
|
|
}
|
|
|
|
|
if (!formConfigResponse.data.editor) {
|
|
|
|
|
formConfigResponse.data.editor =
|
|
|
|
|
defaultActionEditorConfigs[plugin.type];
|
2020-10-20 09:00:02 +00:00
|
|
|
}
|
2021-04-26 05:41:32 +00:00
|
|
|
if (!formConfigResponse.data.dependencies) {
|
|
|
|
|
formConfigResponse.data.dependencies =
|
|
|
|
|
defaultActionDependenciesConfig[plugin.type];
|
|
|
|
|
}
|
2022-03-30 13:11:25 +00:00
|
|
|
if (!formConfigResponse.data.formButton) {
|
|
|
|
|
formConfigResponse.data.formButton =
|
|
|
|
|
defaultDatasourceFormButtonConfig[plugin.type];
|
|
|
|
|
}
|
2021-03-30 05:29:03 +00:00
|
|
|
yield put(
|
|
|
|
|
fetchPluginFormConfigSuccess({
|
|
|
|
|
id: pluginId,
|
|
|
|
|
...formConfigResponse.data,
|
|
|
|
|
}),
|
|
|
|
|
);
|
2020-10-20 09:00:02 +00:00
|
|
|
}
|
2021-03-30 05:29:03 +00:00
|
|
|
} catch (e) {
|
|
|
|
|
log.error("Failed to get plugin form");
|
2021-07-29 08:13:10 +00:00
|
|
|
yield put(
|
|
|
|
|
fetchPluginFormConfigError({
|
|
|
|
|
id: pluginId,
|
|
|
|
|
}),
|
|
|
|
|
);
|
2020-10-20 09:00:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 07:35:24 +00:00
|
|
|
interface GetPluginFormConfigParams {
|
|
|
|
|
id: string;
|
|
|
|
|
type: string;
|
|
|
|
|
}
|
2021-07-29 08:13:10 +00:00
|
|
|
|
|
|
|
|
function* getPluginFormConfig({ id }: GetPluginFormConfigParams) {
|
|
|
|
|
yield call(checkAndGetPluginFormConfigsSaga, id);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-03 10:56:53 +00:00
|
|
|
function* getDefaultPluginsSaga() {
|
|
|
|
|
try {
|
2022-06-21 13:57:34 +00:00
|
|
|
const response: ApiResponse<DefaultPlugin> = yield call(
|
|
|
|
|
PluginsApi.fetchDefaultPlugins,
|
|
|
|
|
);
|
|
|
|
|
const isValid: boolean = yield validateResponse(response);
|
2022-03-03 10:56:53 +00:00
|
|
|
if (isValid) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.GET_DEFAULT_PLUGINS_SUCCESS,
|
|
|
|
|
payload: response.data,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.GET_DEFAULT_PLUGINS_ERROR,
|
|
|
|
|
payload: {
|
|
|
|
|
error,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-29 05:22:49 +00:00
|
|
|
function* root() {
|
|
|
|
|
yield all([
|
|
|
|
|
takeEvery(ReduxActionTypes.FETCH_PLUGINS_REQUEST, fetchPluginsSaga),
|
2020-10-20 09:00:02 +00:00
|
|
|
takeEvery(
|
2021-03-30 05:29:03 +00:00
|
|
|
ReduxActionTypes.FETCH_PLUGIN_FORM_CONFIGS_REQUEST,
|
|
|
|
|
fetchPluginFormConfigsSaga,
|
2020-10-20 09:00:02 +00:00
|
|
|
),
|
2021-07-29 08:13:10 +00:00
|
|
|
takeEvery(
|
|
|
|
|
ReduxActionTypes.GET_PLUGIN_FORM_CONFIG_INIT,
|
|
|
|
|
getPluginFormConfig,
|
|
|
|
|
),
|
2022-03-03 10:56:53 +00:00
|
|
|
takeEvery(
|
|
|
|
|
ReduxActionTypes.GET_DEFAULT_PLUGINS_REQUEST,
|
|
|
|
|
getDefaultPluginsSaga,
|
|
|
|
|
),
|
2019-11-29 05:22:49 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default root;
|