2024-10-25 09:00:34 +00:00
|
|
|
import type { ActionData } from "ee/reducers/entityReducers/actionsReducer";
|
|
|
|
|
import {
|
|
|
|
|
BlueprintOperationActionTypes,
|
|
|
|
|
type WidgetBlueprint,
|
|
|
|
|
} from "WidgetProvider/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 { FlattenedWidgetProps } from "reducers/entityReducers/canvasWidgetsReducer";
|
|
|
|
|
import type { WidgetProps } from "widgets/BaseWidget";
|
2020-03-06 09:45:21 +00:00
|
|
|
import { generateReactKey } from "utils/generators";
|
2023-04-07 13:51:35 +00:00
|
|
|
import { call, select } from "redux-saga/effects";
|
2021-03-04 05:24:47 +00:00
|
|
|
import { get } from "lodash";
|
2023-09-06 12:15:04 +00:00
|
|
|
import WidgetFactory from "WidgetProvider/factory";
|
2021-04-23 05:43:13 +00:00
|
|
|
|
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 { WidgetType } from "constants/WidgetConstants";
|
|
|
|
|
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
|
2023-09-06 12:15:04 +00:00
|
|
|
import { BlueprintOperationTypes } from "WidgetProvider/constants";
|
2021-11-05 05:49:19 +00:00
|
|
|
import * as log from "loglevel";
|
2024-08-09 14:20:29 +00:00
|
|
|
import { toast } from "@appsmith/ads";
|
2023-10-19 20:27:40 +00:00
|
|
|
import type { LayoutSystemTypes } from "layoutSystems/types";
|
|
|
|
|
import { getLayoutSystemType } from "selectors/layoutSystemSelectors";
|
2024-10-25 09:00:34 +00:00
|
|
|
import type { Action, PluginPackageName } from "../entities/Action";
|
2025-01-07 06:21:08 +00:00
|
|
|
import { createOrUpdateDataSourceWithAction } from "../ee/sagas/DatasourcesSagas";
|
2020-03-06 09:45:21 +00:00
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
function buildView(view: WidgetBlueprint["view"], widgetId: string) {
|
|
|
|
|
const children = [];
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2020-09-16 10:28:01 +00:00
|
|
|
if (view) {
|
|
|
|
|
for (const template of view) {
|
|
|
|
|
//TODO(abhinav): Can we keep rows and size mandatory?
|
|
|
|
|
try {
|
|
|
|
|
children.push({
|
|
|
|
|
widgetId,
|
|
|
|
|
type: template.type,
|
|
|
|
|
leftColumn: template.position.left || 0,
|
|
|
|
|
topRow: template.position.top || 0,
|
|
|
|
|
columns: template.size && template.size.cols,
|
|
|
|
|
rows: template.size && template.size.rows,
|
|
|
|
|
newWidgetId: generateReactKey(),
|
|
|
|
|
props: template.props,
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
2021-11-05 05:49:19 +00:00
|
|
|
log.error(e);
|
2020-09-16 10:28:01 +00:00
|
|
|
}
|
2020-03-06 09:45:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-16 10:28:01 +00:00
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
return children;
|
2020-03-06 09:45:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function* buildWidgetBlueprint(
|
|
|
|
|
blueprint: WidgetBlueprint,
|
|
|
|
|
widgetId: string,
|
|
|
|
|
) {
|
2022-06-21 13:57:34 +00:00
|
|
|
const widgetProps: Record<string, unknown> = yield call(
|
|
|
|
|
buildView,
|
|
|
|
|
blueprint.view,
|
|
|
|
|
widgetId,
|
|
|
|
|
);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
return widgetProps;
|
2020-03-06 09:45:21 +00:00
|
|
|
}
|
2020-04-14 05:35:16 +00:00
|
|
|
|
2023-10-11 07:35:24 +00:00
|
|
|
export interface UpdatePropertyArgs {
|
2020-04-14 05:35:16 +00:00
|
|
|
widgetId: string;
|
|
|
|
|
propertyName: string;
|
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
|
2020-04-14 05:35:16 +00:00
|
|
|
propertyValue: any;
|
2023-10-11 07:35:24 +00:00
|
|
|
}
|
2024-10-25 09:00:34 +00:00
|
|
|
export type BlueprintOperationAddActionFn = (
|
|
|
|
|
widget: WidgetProps & { children?: WidgetProps[] },
|
|
|
|
|
) => Generator;
|
2020-04-14 05:35:16 +00:00
|
|
|
export type BlueprintOperationModifyPropsFn = (
|
|
|
|
|
widget: WidgetProps & { children?: WidgetProps[] },
|
2021-04-23 05:43:13 +00:00
|
|
|
widgets: { [widgetId: string]: FlattenedWidgetProps },
|
2020-04-14 05:35:16 +00:00
|
|
|
parent?: WidgetProps,
|
2023-10-19 20:27:40 +00:00
|
|
|
layoutSystemType?: LayoutSystemTypes,
|
2024-10-25 09:00:34 +00:00
|
|
|
addActionResult?: ActionData,
|
2020-04-14 05:35:16 +00:00
|
|
|
) => UpdatePropertyArgs[] | undefined;
|
|
|
|
|
|
2021-04-23 05:43:13 +00:00
|
|
|
export interface ChildOperationFnResponse {
|
|
|
|
|
widgets: Record<string, FlattenedWidgetProps>;
|
|
|
|
|
message?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type BlueprintOperationChildOperationsFn = (
|
|
|
|
|
widgets: { [widgetId: string]: FlattenedWidgetProps },
|
|
|
|
|
widgetId: string,
|
|
|
|
|
parentId: string,
|
|
|
|
|
widgetPropertyMaps: {
|
|
|
|
|
defaultPropertyMap: Record<string, string>;
|
|
|
|
|
},
|
2023-10-19 20:27:40 +00:00
|
|
|
layoutSystemType: LayoutSystemTypes,
|
2021-04-23 05:43:13 +00:00
|
|
|
) => ChildOperationFnResponse;
|
|
|
|
|
|
2023-02-21 04:13:25 +00:00
|
|
|
export type BlueprintBeforeOperationsFn = (
|
|
|
|
|
widgets: { [widgetId: string]: FlattenedWidgetProps },
|
|
|
|
|
widgetId: string,
|
|
|
|
|
parentId: string,
|
2023-10-19 20:27:40 +00:00
|
|
|
layoutSystemType: LayoutSystemTypes,
|
2023-02-21 04:13:25 +00:00
|
|
|
) => void;
|
|
|
|
|
|
2020-04-14 05:35:16 +00:00
|
|
|
export type BlueprintOperationFunction =
|
|
|
|
|
| BlueprintOperationModifyPropsFn
|
2021-04-23 05:43:13 +00:00
|
|
|
| BlueprintOperationAddActionFn
|
2023-02-21 04:13:25 +00:00
|
|
|
| BlueprintOperationChildOperationsFn
|
|
|
|
|
| BlueprintBeforeOperationsFn;
|
2020-04-14 05:35:16 +00:00
|
|
|
|
|
|
|
|
export type BlueprintOperationType = keyof typeof BlueprintOperationTypes;
|
2024-10-25 09:00:34 +00:00
|
|
|
export type BlueprintOperationActionType =
|
|
|
|
|
keyof typeof BlueprintOperationActionTypes;
|
|
|
|
|
|
|
|
|
|
export interface BlueprintOperationActionPayload {
|
|
|
|
|
pluginPackageName: PluginPackageName;
|
|
|
|
|
actionConfig: Action;
|
|
|
|
|
datasourceName?: string;
|
|
|
|
|
}
|
2020-04-14 05:35:16 +00:00
|
|
|
|
2023-10-11 07:35:24 +00:00
|
|
|
export interface BlueprintOperation {
|
2020-04-14 05:35:16 +00:00
|
|
|
type: BlueprintOperationType;
|
|
|
|
|
fn: BlueprintOperationFunction;
|
2024-10-25 09:00:34 +00:00
|
|
|
actionType?: BlueprintOperationActionType;
|
|
|
|
|
payload?: BlueprintOperationActionPayload;
|
2023-10-11 07:35:24 +00:00
|
|
|
}
|
2020-04-14 05:35:16 +00:00
|
|
|
|
|
|
|
|
export function* executeWidgetBlueprintOperations(
|
|
|
|
|
operations: BlueprintOperation[],
|
|
|
|
|
widgets: { [widgetId: string]: FlattenedWidgetProps },
|
|
|
|
|
widgetId: string,
|
|
|
|
|
) {
|
2023-10-19 20:27:40 +00:00
|
|
|
const layoutSystemType: LayoutSystemTypes = yield select(getLayoutSystemType);
|
2024-10-25 09:00:34 +00:00
|
|
|
let addActionResult: ActionData = {} as ActionData;
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-10-25 09:00:34 +00:00
|
|
|
for (const operation of operations) {
|
2021-04-23 05:43:13 +00:00
|
|
|
const widget: WidgetProps & { children?: string[] | WidgetProps[] } = {
|
|
|
|
|
...widgets[widgetId],
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-14 05:35:16 +00:00
|
|
|
switch (operation.type) {
|
2024-10-25 09:00:34 +00:00
|
|
|
case BlueprintOperationTypes.ADD_ACTION:
|
|
|
|
|
addActionResult =
|
|
|
|
|
yield executeWidgetBlueprintAddActionOperations(operation);
|
|
|
|
|
|
|
|
|
|
break;
|
2020-04-14 05:35:16 +00:00
|
|
|
case BlueprintOperationTypes.MODIFY_PROPS:
|
|
|
|
|
if (widget.children && widget.children.length > 0) {
|
|
|
|
|
widget.children = (widget.children as string[]).map(
|
|
|
|
|
(childId: string) => widgets[childId],
|
|
|
|
|
) as WidgetProps[];
|
|
|
|
|
}
|
2024-09-18 16:35:28 +00:00
|
|
|
|
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 updatePropertyPayloads: UpdatePropertyArgs[] | undefined = (
|
|
|
|
|
operation.fn as BlueprintOperationModifyPropsFn
|
|
|
|
|
)(
|
2020-04-14 05:35:16 +00:00
|
|
|
widget as WidgetProps & { children?: WidgetProps[] },
|
2021-04-23 05:43:13 +00:00
|
|
|
widgets,
|
2021-03-04 05:24:47 +00:00
|
|
|
get(widgets, widget.parentId || "", undefined),
|
2023-10-19 20:27:40 +00:00
|
|
|
layoutSystemType,
|
2024-10-25 09:00:34 +00:00
|
|
|
addActionResult,
|
2020-04-14 05:35:16 +00:00
|
|
|
);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2020-04-14 05:35:16 +00:00
|
|
|
updatePropertyPayloads &&
|
|
|
|
|
updatePropertyPayloads.forEach((params: UpdatePropertyArgs) => {
|
|
|
|
|
widgets[params.widgetId][params.propertyName] =
|
|
|
|
|
params.propertyValue;
|
|
|
|
|
});
|
2021-04-23 05:43:13 +00:00
|
|
|
break;
|
2020-04-14 05:35:16 +00:00
|
|
|
}
|
2024-10-25 09:00:34 +00:00
|
|
|
}
|
2021-04-23 05:43:13 +00:00
|
|
|
|
2022-06-21 13:57:34 +00:00
|
|
|
const result: { [widgetId: string]: FlattenedWidgetProps } = yield widgets;
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2022-06-21 13:57:34 +00:00
|
|
|
return result;
|
2020-04-14 05:35:16 +00:00
|
|
|
}
|
2024-10-25 09:00:34 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* this saga executes the blueprint add action operation
|
|
|
|
|
* @param operation
|
|
|
|
|
*/
|
|
|
|
|
function* executeWidgetBlueprintAddActionOperations(
|
|
|
|
|
operation: BlueprintOperation,
|
|
|
|
|
) {
|
|
|
|
|
switch (operation.actionType) {
|
|
|
|
|
case BlueprintOperationActionTypes.CREATE_OR_UPDATE_DATASOURCE_WITH_ACTION:
|
|
|
|
|
if (
|
|
|
|
|
!operation.payload?.pluginPackageName ||
|
|
|
|
|
!operation.payload?.actionConfig
|
|
|
|
|
)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const { actionConfig, datasourceName, pluginPackageName } =
|
|
|
|
|
operation.payload;
|
|
|
|
|
|
|
|
|
|
// TODO Add the event to the watcher to avoid importing it and the associated cyclic dependencies.
|
|
|
|
|
// https://github.com/appsmithorg/appsmith-ee/pull/5368#discussion_r1804419760
|
|
|
|
|
const createdAction: ActionData =
|
|
|
|
|
yield createOrUpdateDataSourceWithAction(
|
|
|
|
|
pluginPackageName,
|
|
|
|
|
actionConfig,
|
|
|
|
|
datasourceName,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return createdAction;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-23 05:43:13 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* this saga executes the blueprint child operation
|
|
|
|
|
*
|
|
|
|
|
* @param parent
|
|
|
|
|
* @param newWidgetId
|
|
|
|
|
* @param widgets
|
|
|
|
|
*
|
|
|
|
|
* @returns { [widgetId: string]: FlattenedWidgetProps }
|
|
|
|
|
*/
|
|
|
|
|
export function* executeWidgetBlueprintChildOperations(
|
|
|
|
|
operation: BlueprintOperation,
|
|
|
|
|
canvasWidgets: { [widgetId: string]: FlattenedWidgetProps },
|
2022-12-17 20:03:35 +00:00
|
|
|
widgetIds: string[],
|
2021-04-23 05:43:13 +00:00
|
|
|
parentId: string,
|
|
|
|
|
) {
|
|
|
|
|
// TODO(abhinav): Special handling for child operaionts
|
|
|
|
|
// This needs to be deprecated soon
|
|
|
|
|
|
2022-12-17 20:03:35 +00:00
|
|
|
let widgets = canvasWidgets,
|
|
|
|
|
message;
|
2023-10-19 20:27:40 +00:00
|
|
|
const layoutSystemType: LayoutSystemTypes = yield select(getLayoutSystemType);
|
2022-12-17 20:03:35 +00:00
|
|
|
|
|
|
|
|
for (const widgetId of widgetIds) {
|
|
|
|
|
// Get the default properties map of the current widget
|
|
|
|
|
// The operation can handle things based on this map
|
|
|
|
|
// Little abstraction leak, but will be deprecated soon
|
|
|
|
|
const widgetPropertyMaps = {
|
|
|
|
|
defaultPropertyMap: WidgetFactory.getWidgetDefaultPropertiesMap(
|
|
|
|
|
canvasWidgets[widgetId].type as WidgetType,
|
|
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let currMessage;
|
|
|
|
|
|
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
|
|
|
({ message: currMessage, widgets } = (
|
|
|
|
|
operation.fn as BlueprintOperationChildOperationsFn
|
2023-10-19 20:27:40 +00:00
|
|
|
)(widgets, widgetId, parentId, widgetPropertyMaps, layoutSystemType));
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2022-12-17 20:03:35 +00:00
|
|
|
//set message if one of the widget has any message to show
|
|
|
|
|
if (currMessage) message = currMessage;
|
|
|
|
|
}
|
2021-04-23 05:43:13 +00:00
|
|
|
|
|
|
|
|
// If something odd happens show the message related to the odd scenario
|
|
|
|
|
if (message) {
|
2023-05-19 18:37:06 +00:00
|
|
|
toast.show(message, {
|
|
|
|
|
kind: "info",
|
2021-04-23 05:43:13 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Flow returns to the usual from here.
|
|
|
|
|
return widgets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* this saga traverse the tree till we get
|
|
|
|
|
* to MAIN_CONTAINER_WIDGET_ID while travesring, if we find
|
|
|
|
|
* any widget which has CHILD_OPERATION, we will call the fn in it
|
|
|
|
|
*
|
|
|
|
|
* @param parent
|
|
|
|
|
* @param newWidgetId
|
|
|
|
|
* @param widgets
|
|
|
|
|
*
|
|
|
|
|
* @returns { [widgetId: string]: FlattenedWidgetProps }
|
|
|
|
|
*/
|
|
|
|
|
export function* traverseTreeAndExecuteBlueprintChildOperations(
|
|
|
|
|
parent: FlattenedWidgetProps,
|
2022-12-17 20:03:35 +00:00
|
|
|
newWidgetIds: string[],
|
2021-04-23 05:43:13 +00:00
|
|
|
widgets: { [widgetId: string]: FlattenedWidgetProps },
|
|
|
|
|
) {
|
|
|
|
|
let root = parent;
|
|
|
|
|
|
|
|
|
|
while (root.parentId && root.widgetId !== MAIN_CONTAINER_WIDGET_ID) {
|
2021-09-09 15:10:22 +00:00
|
|
|
const parentConfig = WidgetFactory.widgetConfigMap.get(root.type);
|
2021-04-23 05:43:13 +00:00
|
|
|
|
|
|
|
|
// find the blueprint with type CHILD_OPERATIONS
|
|
|
|
|
const blueprintChildOperation = get(
|
|
|
|
|
parentConfig,
|
|
|
|
|
"blueprint.operations",
|
|
|
|
|
[],
|
|
|
|
|
).find(
|
|
|
|
|
(operation: BlueprintOperation) =>
|
|
|
|
|
operation.type === BlueprintOperationTypes.CHILD_OPERATIONS,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// if there is blueprint operation with CHILD_OPERATION type, call the fn in it
|
|
|
|
|
if (blueprintChildOperation) {
|
|
|
|
|
const updatedWidgets:
|
|
|
|
|
| { [widgetId: string]: FlattenedWidgetProps }
|
|
|
|
|
| undefined = yield call(
|
|
|
|
|
executeWidgetBlueprintChildOperations,
|
|
|
|
|
blueprintChildOperation,
|
|
|
|
|
widgets,
|
2022-12-17 20:03:35 +00:00
|
|
|
newWidgetIds,
|
2021-04-23 05:43:13 +00:00
|
|
|
root.widgetId,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (updatedWidgets) {
|
|
|
|
|
widgets = updatedWidgets;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
root = widgets[root.parentId];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return widgets;
|
|
|
|
|
}
|
2023-02-21 04:13:25 +00:00
|
|
|
|
2023-10-11 07:35:24 +00:00
|
|
|
interface ExecuteWidgetBlueprintBeforeOperationsParams {
|
2023-02-21 04:13:25 +00:00
|
|
|
parentId: string;
|
|
|
|
|
widgetId: string;
|
|
|
|
|
widgets: { [widgetId: string]: FlattenedWidgetProps };
|
|
|
|
|
widgetType: WidgetType;
|
2023-10-11 07:35:24 +00:00
|
|
|
}
|
2023-02-21 04:13:25 +00:00
|
|
|
|
|
|
|
|
export function* executeWidgetBlueprintBeforeOperations(
|
|
|
|
|
blueprintOperation: Extract<
|
|
|
|
|
BlueprintOperationTypes,
|
|
|
|
|
| BlueprintOperationTypes.BEFORE_ADD
|
|
|
|
|
| BlueprintOperationTypes.BEFORE_DROP
|
|
|
|
|
| BlueprintOperationTypes.BEFORE_PASTE
|
2023-04-07 13:51:35 +00:00
|
|
|
| BlueprintOperationTypes.UPDATE_CREATE_PARAMS_BEFORE_ADD
|
2023-02-21 04:13:25 +00:00
|
|
|
>,
|
|
|
|
|
params: ExecuteWidgetBlueprintBeforeOperationsParams,
|
|
|
|
|
) {
|
|
|
|
|
const { parentId, widgetId, widgets, widgetType } = params;
|
2023-10-19 20:27:40 +00:00
|
|
|
const layoutSystemType: LayoutSystemTypes = yield select(getLayoutSystemType);
|
2023-02-21 04:13:25 +00:00
|
|
|
const blueprintOperations: BlueprintOperation[] =
|
|
|
|
|
WidgetFactory.widgetConfigMap.get(widgetType)?.blueprint?.operations ?? [];
|
|
|
|
|
|
|
|
|
|
const beforeAddOperation = blueprintOperations.find(
|
|
|
|
|
(operation) => operation.type === blueprintOperation,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (beforeAddOperation)
|
2023-04-07 13:51:35 +00:00
|
|
|
return (beforeAddOperation.fn as BlueprintBeforeOperationsFn)(
|
2023-02-21 04:13:25 +00:00
|
|
|
widgets,
|
|
|
|
|
widgetId,
|
|
|
|
|
parentId,
|
2023-10-19 20:27:40 +00:00
|
|
|
layoutSystemType,
|
2023-02-21 04:13:25 +00:00
|
|
|
);
|
|
|
|
|
}
|