2023-04-26 07:18:16 +00:00
|
|
|
import {
|
|
|
|
|
createMessage,
|
|
|
|
|
SELECT_ALL_WIDGETS_MSG,
|
|
|
|
|
} from "@appsmith/constants/messages";
|
2023-03-04 07:25:54 +00:00
|
|
|
import {
|
|
|
|
|
ReduxActionErrorTypes,
|
|
|
|
|
ReduxActionTypes,
|
2023-04-26 07:18:16 +00:00
|
|
|
} from "@appsmith/constants/ReduxActionConstants";
|
2023-03-04 07:25:54 +00:00
|
|
|
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
|
|
|
|
|
import { uniq } from "lodash";
|
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 {
|
2023-01-28 02:17:06 +00:00
|
|
|
CanvasWidgetsReduxState,
|
|
|
|
|
FlattenedWidgetProps,
|
|
|
|
|
} from "reducers/entityReducers/canvasWidgetsReducer";
|
|
|
|
|
import { call, put, select } from "redux-saga/effects";
|
|
|
|
|
import {
|
|
|
|
|
getWidgetImmediateChildren,
|
|
|
|
|
getWidgetMetaProps,
|
|
|
|
|
getWidgets,
|
|
|
|
|
} from "sagas/selectors";
|
|
|
|
|
import { getWidgetChildrenIds } from "sagas/WidgetOperationUtils";
|
2023-03-04 07:25:54 +00:00
|
|
|
import { getLastSelectedWidget, getSelectedWidgets } from "selectors/ui";
|
2023-09-06 12:15:04 +00:00
|
|
|
import WidgetFactory from "WidgetProvider/factory";
|
2023-05-19 18:37:06 +00:00
|
|
|
import { toast } from "design-system";
|
2023-09-06 12:15:04 +00:00
|
|
|
import { checkIsDropTarget } from "WidgetProvider/factory/helpers";
|
2023-01-28 02:17:06 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Selection types that are possible for widget select
|
|
|
|
|
*
|
|
|
|
|
* It is currently used for widget selection,
|
|
|
|
|
* but can be used for other types of selections like tabs
|
|
|
|
|
*/
|
|
|
|
|
export enum SelectionRequestType {
|
|
|
|
|
/** Remove all selections, reset last selected widget to the main container */
|
|
|
|
|
Empty = "Empty",
|
|
|
|
|
/** Replace the existing selection with a new single selection.
|
|
|
|
|
* The new selection will be the last selected widget */
|
|
|
|
|
One = "One",
|
|
|
|
|
/** Replace the existing selection with a new selection of multiple widgets.
|
|
|
|
|
* The new selection's first widget becomes the last selected widget
|
|
|
|
|
* */
|
|
|
|
|
Multiple = "Multiple",
|
|
|
|
|
/** Adds or removes a widget selection. Similar to CMD/Ctrl selections,
|
|
|
|
|
* if the payload exits in the selection, it will be removed.
|
|
|
|
|
* If the payload is new, it will be added.*/
|
|
|
|
|
PushPop = "PushPop",
|
|
|
|
|
/** Selects all widgets in the last selected canvas */
|
|
|
|
|
All = "All",
|
|
|
|
|
/** Add selection like shift select where the widgets between two selections
|
|
|
|
|
* are also selected. Widget order is taken from children order of the canvas */
|
|
|
|
|
ShiftSelect = "ShiftSelect",
|
|
|
|
|
/**
|
|
|
|
|
* Unselect specific widgets */
|
|
|
|
|
Unselect = "Unselect",
|
2023-02-21 13:38:16 +00:00
|
|
|
/** Skip checks and just try to select. Page ID can be supplied to select a
|
|
|
|
|
* widget on another page */
|
|
|
|
|
UnsafeSelect = "UnsafeSelect",
|
2023-01-28 02:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type SelectionPayload = string[];
|
|
|
|
|
|
2023-02-21 13:38:16 +00:00
|
|
|
export type SetSelectionResult = string[] | undefined;
|
2023-01-28 02:17:06 +00:00
|
|
|
|
|
|
|
|
// Main container cannot be a selection, dont honour this request
|
|
|
|
|
export const isInvalidSelectionRequest = (id: unknown) =>
|
|
|
|
|
typeof id !== "string" || id === MAIN_CONTAINER_WIDGET_ID;
|
|
|
|
|
|
|
|
|
|
export class WidgetSelectionError extends Error {
|
|
|
|
|
request?: SelectionPayload;
|
|
|
|
|
type?: SelectionRequestType;
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
message: string,
|
|
|
|
|
request?: SelectionPayload,
|
|
|
|
|
type?: SelectionRequestType,
|
|
|
|
|
) {
|
|
|
|
|
super(message);
|
|
|
|
|
this.request = request;
|
|
|
|
|
this.type = type;
|
|
|
|
|
this.name = "WidgetSelectionError";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const deselectAll = (request: SelectionPayload): SetSelectionResult => {
|
|
|
|
|
if (request.length > 0) {
|
|
|
|
|
throw new WidgetSelectionError(
|
|
|
|
|
"Wrong payload supplied",
|
|
|
|
|
request,
|
|
|
|
|
SelectionRequestType.Empty,
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-02-21 13:38:16 +00:00
|
|
|
return [];
|
2023-01-28 02:17:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const selectOneWidget = (
|
|
|
|
|
request: SelectionPayload,
|
|
|
|
|
): SetSelectionResult => {
|
|
|
|
|
if (request.length !== 1) {
|
|
|
|
|
throw new WidgetSelectionError(
|
|
|
|
|
"Wrong payload supplied",
|
|
|
|
|
request,
|
|
|
|
|
SelectionRequestType.One,
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-02-21 13:38:16 +00:00
|
|
|
return request;
|
2023-01-28 02:17:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const selectMultipleWidgets = (
|
|
|
|
|
request: SelectionPayload,
|
|
|
|
|
allWidgets: CanvasWidgetsReduxState,
|
|
|
|
|
): SetSelectionResult => {
|
|
|
|
|
const parentToMatch = allWidgets[request[0]]?.parentId;
|
|
|
|
|
const areSiblings = request.every((each) => {
|
|
|
|
|
return allWidgets[each]?.parentId === parentToMatch;
|
|
|
|
|
});
|
|
|
|
|
if (!areSiblings) return;
|
2023-02-21 13:38:16 +00:00
|
|
|
return request;
|
2023-01-28 02:17:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const shiftSelectWidgets = (
|
|
|
|
|
request: SelectionPayload,
|
|
|
|
|
siblingWidgets: string[],
|
|
|
|
|
currentlySelectedWidgets: string[],
|
|
|
|
|
lastSelectedWidget: string,
|
|
|
|
|
): SetSelectionResult => {
|
|
|
|
|
const selectedWidgetIndex = siblingWidgets.indexOf(request[0]);
|
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 siblingIndexOfLastSelectedWidget =
|
|
|
|
|
siblingWidgets.indexOf(lastSelectedWidget);
|
2023-01-28 02:17:06 +00:00
|
|
|
if (siblingIndexOfLastSelectedWidget === -1) {
|
2023-02-21 13:38:16 +00:00
|
|
|
return request;
|
2023-01-28 02:17:06 +00:00
|
|
|
}
|
|
|
|
|
if (currentlySelectedWidgets.includes(request[0])) {
|
2023-02-21 13:38:16 +00:00
|
|
|
return currentlySelectedWidgets.filter((w) => request[0] !== w);
|
2023-01-28 02:17:06 +00:00
|
|
|
}
|
2023-02-21 13:38:16 +00:00
|
|
|
let widgets: string[] = [...currentlySelectedWidgets, ...request];
|
2023-01-28 02:17:06 +00:00
|
|
|
const start =
|
|
|
|
|
siblingIndexOfLastSelectedWidget < selectedWidgetIndex
|
|
|
|
|
? siblingIndexOfLastSelectedWidget
|
|
|
|
|
: selectedWidgetIndex;
|
|
|
|
|
const end =
|
|
|
|
|
siblingIndexOfLastSelectedWidget < selectedWidgetIndex
|
|
|
|
|
? selectedWidgetIndex
|
|
|
|
|
: siblingIndexOfLastSelectedWidget;
|
|
|
|
|
const unSelectedSiblings = siblingWidgets.slice(start, end + 1);
|
|
|
|
|
if (unSelectedSiblings && unSelectedSiblings.length) {
|
|
|
|
|
widgets = widgets.concat(...unSelectedSiblings);
|
|
|
|
|
}
|
2023-02-21 13:38:16 +00:00
|
|
|
return uniq(widgets);
|
2023-01-28 02:17:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const pushPopWidgetSelection = (
|
|
|
|
|
request: SelectionPayload,
|
|
|
|
|
currentlySelectedWidgets: string[],
|
|
|
|
|
siblingWidgets: string[],
|
|
|
|
|
): SetSelectionResult => {
|
|
|
|
|
const widgetId = request[0];
|
|
|
|
|
const alreadySelected = currentlySelectedWidgets.includes(widgetId);
|
|
|
|
|
|
|
|
|
|
if (alreadySelected) {
|
2023-02-21 13:38:16 +00:00
|
|
|
return currentlySelectedWidgets.filter((each) => each !== widgetId);
|
2023-01-28 02:17:06 +00:00
|
|
|
} else if (!!widgetId) {
|
2023-02-21 13:38:16 +00:00
|
|
|
return [...currentlySelectedWidgets, widgetId].filter((w) =>
|
2023-01-28 02:17:06 +00:00
|
|
|
siblingWidgets.includes(w),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const unselectWidget = (
|
|
|
|
|
request: SelectionPayload,
|
|
|
|
|
currentlySelectedWidgets: string[],
|
|
|
|
|
): SetSelectionResult => {
|
2023-02-21 13:38:16 +00:00
|
|
|
return currentlySelectedWidgets.filter((w) => !request.includes(w));
|
2023-01-28 02:17:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const WidgetTypes = WidgetFactory.widgetTypes;
|
|
|
|
|
|
|
|
|
|
function* getDroppingCanvasOfWidget(widgetLastSelected: FlattenedWidgetProps) {
|
|
|
|
|
if (checkIsDropTarget(widgetLastSelected.type)) {
|
|
|
|
|
const canvasWidgets: CanvasWidgetsReduxState = yield select(getWidgets);
|
|
|
|
|
const childWidgets: string[] = yield select(
|
|
|
|
|
getWidgetImmediateChildren,
|
|
|
|
|
widgetLastSelected.widgetId,
|
|
|
|
|
);
|
|
|
|
|
const firstCanvas = childWidgets.find((each) => {
|
|
|
|
|
const widget = canvasWidgets[each];
|
|
|
|
|
return widget.type === WidgetTypes.CANVAS_WIDGET;
|
|
|
|
|
});
|
|
|
|
|
if (widgetLastSelected.type === WidgetTypes.TABS_WIDGET) {
|
|
|
|
|
const tabMetaProps: Record<string, unknown> = yield select(
|
|
|
|
|
getWidgetMetaProps,
|
2023-02-14 16:07:31 +00:00
|
|
|
widgetLastSelected,
|
2023-01-28 02:17:06 +00:00
|
|
|
);
|
|
|
|
|
return tabMetaProps.selectedTabWidgetId;
|
|
|
|
|
}
|
|
|
|
|
if (firstCanvas) {
|
|
|
|
|
return firstCanvas;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return widgetLastSelected.parentId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* getLastSelectedCanvas() {
|
|
|
|
|
const lastSelectedWidget: string = yield select(getLastSelectedWidget);
|
2023-03-04 07:25:54 +00:00
|
|
|
const selectedWidgets: string[] = yield select(getSelectedWidgets);
|
|
|
|
|
const areMultipleWidgetsSelected: boolean = selectedWidgets.length > 1;
|
2023-01-28 02:17:06 +00:00
|
|
|
const canvasWidgets: CanvasWidgetsReduxState = yield select(getWidgets);
|
|
|
|
|
const widgetLastSelected =
|
|
|
|
|
lastSelectedWidget && canvasWidgets[lastSelectedWidget];
|
|
|
|
|
if (widgetLastSelected) {
|
2023-03-04 07:25:54 +00:00
|
|
|
if (areMultipleWidgetsSelected) {
|
|
|
|
|
return widgetLastSelected.parentId || MAIN_CONTAINER_WIDGET_ID;
|
|
|
|
|
}
|
|
|
|
|
if (!areMultipleWidgetsSelected) {
|
|
|
|
|
const canvasToSelect: string = yield call(
|
|
|
|
|
getDroppingCanvasOfWidget,
|
|
|
|
|
widgetLastSelected,
|
|
|
|
|
);
|
|
|
|
|
return canvasToSelect ? canvasToSelect : MAIN_CONTAINER_WIDGET_ID;
|
|
|
|
|
}
|
2023-01-28 02:17:06 +00:00
|
|
|
}
|
2023-03-04 07:25:54 +00:00
|
|
|
|
2023-01-28 02:17:06 +00:00
|
|
|
return MAIN_CONTAINER_WIDGET_ID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// used for List widget cases
|
|
|
|
|
const isChildOfDropDisabledCanvas = (
|
|
|
|
|
canvasWidgets: CanvasWidgetsReduxState,
|
|
|
|
|
widgetId: string,
|
|
|
|
|
) => {
|
|
|
|
|
const widget = canvasWidgets[widgetId];
|
|
|
|
|
const parentId = widget.parentId || MAIN_CONTAINER_WIDGET_ID;
|
|
|
|
|
const parent = canvasWidgets[parentId];
|
|
|
|
|
return !!parent?.dropDisabled;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function* getAllSelectableChildren() {
|
|
|
|
|
const lastSelectedWidget: string = yield select(getLastSelectedWidget);
|
|
|
|
|
const canvasWidgets: CanvasWidgetsReduxState = yield select(getWidgets);
|
|
|
|
|
const widgetLastSelected = canvasWidgets[lastSelectedWidget];
|
|
|
|
|
const canvasId: string = yield call(getLastSelectedCanvas);
|
|
|
|
|
let allChildren: string[];
|
|
|
|
|
const selectGrandChildren: boolean = lastSelectedWidget
|
|
|
|
|
? widgetLastSelected && widgetLastSelected.type === WidgetTypes.LIST_WIDGET
|
|
|
|
|
: false;
|
|
|
|
|
if (selectGrandChildren) {
|
|
|
|
|
allChildren = yield call(
|
|
|
|
|
getWidgetChildrenIds,
|
|
|
|
|
canvasWidgets,
|
|
|
|
|
lastSelectedWidget,
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
allChildren = yield select(getWidgetImmediateChildren, canvasId);
|
|
|
|
|
}
|
|
|
|
|
if (allChildren && allChildren.length) {
|
|
|
|
|
return allChildren.filter((each) => {
|
|
|
|
|
const isCanvasWidget =
|
|
|
|
|
each &&
|
|
|
|
|
canvasWidgets[each] &&
|
|
|
|
|
canvasWidgets[each].type === WidgetTypes.CANVAS_WIDGET;
|
|
|
|
|
const isImmovableWidget = isChildOfDropDisabledCanvas(
|
|
|
|
|
canvasWidgets,
|
|
|
|
|
each,
|
|
|
|
|
);
|
|
|
|
|
return !(isCanvasWidget || isImmovableWidget);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function assertParentId(parentId: unknown): asserts parentId is string {
|
|
|
|
|
if (!parentId || typeof parentId !== "string") {
|
|
|
|
|
throw new WidgetSelectionError("Could not find a parent for the widget");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-10 07:25:14 +00:00
|
|
|
export function getWidgetAncestry(
|
|
|
|
|
widgetId: string | undefined,
|
2023-01-28 02:17:06 +00:00
|
|
|
allWidgets: CanvasWidgetsReduxState,
|
|
|
|
|
) {
|
|
|
|
|
// Fill up the ancestry of widget
|
|
|
|
|
// The following is computed to be used in the entity explorer
|
|
|
|
|
// Every time a widget is selected, we need to expand widget entities
|
|
|
|
|
// in the entity explorer so that the selected widget is visible
|
2023-04-10 07:25:14 +00:00
|
|
|
// It is also used for finding the selected widget ancestry so that we can
|
|
|
|
|
// show widgets that could be invisible in the current state like widgets inside
|
|
|
|
|
// hidden tabs
|
2023-01-28 02:17:06 +00:00
|
|
|
const widgetAncestry: string[] = [];
|
2023-04-10 07:25:14 +00:00
|
|
|
let ancestorWidgetId = widgetId;
|
2023-01-28 02:17:06 +00:00
|
|
|
while (ancestorWidgetId) {
|
|
|
|
|
widgetAncestry.push(ancestorWidgetId);
|
|
|
|
|
if (allWidgets[ancestorWidgetId] && allWidgets[ancestorWidgetId].parentId) {
|
|
|
|
|
const parentId = allWidgets[ancestorWidgetId].parentId;
|
|
|
|
|
assertParentId(parentId);
|
|
|
|
|
ancestorWidgetId = parentId;
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-10 07:25:14 +00:00
|
|
|
return widgetAncestry;
|
2023-01-28 02:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function* selectAllWidgetsInCanvasSaga() {
|
|
|
|
|
try {
|
|
|
|
|
const canvasWidgets: CanvasWidgetsReduxState = yield select(getWidgets);
|
|
|
|
|
const allSelectableChildren: string[] = yield call(
|
|
|
|
|
getAllSelectableChildren,
|
|
|
|
|
);
|
|
|
|
|
if (allSelectableChildren && allSelectableChildren.length) {
|
|
|
|
|
const isAnyModalSelected = allSelectableChildren.some((each) => {
|
|
|
|
|
return (
|
|
|
|
|
each &&
|
|
|
|
|
canvasWidgets[each] &&
|
|
|
|
|
canvasWidgets[each].type === WidgetFactory.widgetTypes.MODAL_WIDGET
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
if (isAnyModalSelected) {
|
2023-05-19 18:37:06 +00:00
|
|
|
toast.show(createMessage(SELECT_ALL_WIDGETS_MSG), {
|
|
|
|
|
kind: "info",
|
2023-01-28 02:17:06 +00:00
|
|
|
});
|
|
|
|
|
}
|
2023-02-21 13:38:16 +00:00
|
|
|
return allSelectableChildren;
|
2023-01-28 02:17:06 +00:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.WIDGET_SELECTION_ERROR,
|
|
|
|
|
payload: {
|
|
|
|
|
action: ReduxActionTypes.SELECT_WIDGET_INIT,
|
|
|
|
|
error,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|