2023-05-19 18:37:06 +00:00
|
|
|
import React, { useState, useMemo, useEffect } from "react";
|
2022-11-28 08:13:17 +00:00
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
2023-03-29 17:07:06 +00:00
|
|
|
import {
|
|
|
|
|
getUserApplicationsWorkspaces,
|
|
|
|
|
getIsFetchingApplications,
|
|
|
|
|
} from "@appsmith/selectors/applicationSelectors";
|
2022-12-01 06:30:50 +00:00
|
|
|
import { hasCreateNewAppPermission } from "@appsmith/utils/permissionHelpers";
|
2022-04-12 10:50:01 +00:00
|
|
|
import { ReduxActionTypes } from "@appsmith/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 { AppState } from "@appsmith/reducers";
|
feat: import changes batch 2 (#15722)
* Remove treedropdown from ads
* Change Treedropdown imports
* Remove Notification Banner, change imports
* Remove Toggle from ads
* Change toggle imports
* explicitly declare function argument types
* Remove Menu from ads
* Change menu imports
* Remove Spinner from ads
* Change spinner imports
* Remove Radio, import changes
* test: updated flaky test under default meta (#15707)
* updated flaky test
* Updated tests
* updated tests
* updated the tests
* updated tests
* Update constants.ts
* add more typecasting
* Remove ListSegmentHeader, import changes
* Remove TagInputComponent, import changes
* Remove Switch, import changes
* Remove SearchInput, change imports
* Rename TagInputComponent to TagInput
* Remove ProgressiveImage, import changes
* import changes for SearchVariant
* Remove menu divider, import changes
* Remove TableDropdown, import changes
* Remove Switcher
* Remove StatusBar, import changes
* Remove showcase carousel
* Remove RectangularSwitcher, import change
* Add types to TableDropdown's args
* Remove MultiSwitch, import change
* Remove GifPlayerComponent, import change
* Remove DraggableList, import change
* Remove DisplayImageUpload, import change
* Remove DatePickerComponent, import change
* Remove CopyToClipBoard, import change
* Remove ColorSelector, import change
* Remove TabItemBackgroundFill, NumberedStep, ColorPickerComponent
* GifPlayerComponent -> GifPlayer
* change named import
* Remove FormFieldError, change imports
* Update to new version of Tree Dropdown
* Fix issue with ads/index.ts
* Test file fix
* Fix issue with merge?!?!??
* update design system to 1.0.18
* Bump ds version
* bump ds version
* bump ds version
Co-authored-by: NandanAnantharamu <67676905+NandanAnantharamu@users.noreply.github.com>
Co-authored-by: Albin <albin@appsmith.com>
2022-09-02 08:38:17 +00:00
|
|
|
import {
|
|
|
|
|
Button,
|
2023-05-19 18:37:06 +00:00
|
|
|
Modal,
|
|
|
|
|
ModalContent,
|
|
|
|
|
ModalHeader,
|
feat: import changes batch 2 (#15722)
* Remove treedropdown from ads
* Change Treedropdown imports
* Remove Notification Banner, change imports
* Remove Toggle from ads
* Change toggle imports
* explicitly declare function argument types
* Remove Menu from ads
* Change menu imports
* Remove Spinner from ads
* Change spinner imports
* Remove Radio, import changes
* test: updated flaky test under default meta (#15707)
* updated flaky test
* Updated tests
* updated tests
* updated the tests
* updated tests
* Update constants.ts
* add more typecasting
* Remove ListSegmentHeader, import changes
* Remove TagInputComponent, import changes
* Remove Switch, import changes
* Remove SearchInput, change imports
* Rename TagInputComponent to TagInput
* Remove ProgressiveImage, import changes
* import changes for SearchVariant
* Remove menu divider, import changes
* Remove TableDropdown, import changes
* Remove Switcher
* Remove StatusBar, import changes
* Remove showcase carousel
* Remove RectangularSwitcher, import change
* Add types to TableDropdown's args
* Remove MultiSwitch, import change
* Remove GifPlayerComponent, import change
* Remove DraggableList, import change
* Remove DisplayImageUpload, import change
* Remove DatePickerComponent, import change
* Remove CopyToClipBoard, import change
* Remove ColorSelector, import change
* Remove TabItemBackgroundFill, NumberedStep, ColorPickerComponent
* GifPlayerComponent -> GifPlayer
* change named import
* Remove FormFieldError, change imports
* Update to new version of Tree Dropdown
* Fix issue with ads/index.ts
* Test file fix
* Fix issue with merge?!?!??
* update design system to 1.0.18
* Bump ds version
* bump ds version
* bump ds version
Co-authored-by: NandanAnantharamu <67676905+NandanAnantharamu@users.noreply.github.com>
Co-authored-by: Albin <albin@appsmith.com>
2022-09-02 08:38:17 +00:00
|
|
|
Spinner,
|
2023-05-19 18:37:06 +00:00
|
|
|
Select,
|
|
|
|
|
Option,
|
|
|
|
|
} from "design-system";
|
|
|
|
|
import { ButtonWrapper, SpinnerWrapper } from "./ForkModalStyles";
|
2022-03-10 14:39:05 +00:00
|
|
|
import {
|
|
|
|
|
CANCEL,
|
|
|
|
|
createMessage,
|
|
|
|
|
FORK,
|
|
|
|
|
FORK_APP_MODAL_EMPTY_TITLE,
|
|
|
|
|
FORK_APP_MODAL_LOADING_TITLE,
|
|
|
|
|
FORK_APP_MODAL_SUCCESS_TITLE,
|
|
|
|
|
} from "@appsmith/constants/messages";
|
2023-03-29 17:07:06 +00:00
|
|
|
import { getAllApplications } from "@appsmith/actions/applicationActions";
|
2021-03-10 07:08:20 +00:00
|
|
|
|
2023-10-11 07:35:24 +00:00
|
|
|
interface ForkApplicationModalProps {
|
2021-05-04 06:04:23 +00:00
|
|
|
applicationId: string;
|
|
|
|
|
// if a trigger is passed
|
|
|
|
|
// it renders that component
|
|
|
|
|
trigger?: React.ReactNode;
|
|
|
|
|
isModalOpen?: boolean;
|
2023-09-26 02:08:05 +00:00
|
|
|
handleOpen?: () => void;
|
|
|
|
|
handleClose?: () => void;
|
2023-05-30 09:24:38 +00:00
|
|
|
isInEditMode?: boolean;
|
2023-10-11 07:35:24 +00:00
|
|
|
}
|
2021-03-12 07:44:16 +00:00
|
|
|
|
2021-05-04 06:04:23 +00:00
|
|
|
function ForkApplicationModal(props: ForkApplicationModalProps) {
|
2023-09-26 02:08:05 +00:00
|
|
|
const { handleClose, handleOpen, isModalOpen } = props;
|
2022-06-15 15:37:41 +00:00
|
|
|
const [workspace, selectWorkspace] = useState<{
|
2022-03-10 14:39:05 +00:00
|
|
|
label: string;
|
|
|
|
|
value: string;
|
|
|
|
|
}>({ label: "", value: "" });
|
2021-03-10 07:08:20 +00:00
|
|
|
const dispatch = useDispatch();
|
2022-06-15 15:37:41 +00:00
|
|
|
const userWorkspaces = useSelector(getUserApplicationsWorkspaces);
|
2021-03-12 07:44:16 +00:00
|
|
|
const forkingApplication = useSelector(
|
|
|
|
|
(state: AppState) => state.ui.applications.forkingApplication,
|
|
|
|
|
);
|
2021-05-04 06:04:23 +00:00
|
|
|
|
|
|
|
|
const isFetchingApplications = useSelector(getIsFetchingApplications);
|
2023-05-19 18:37:06 +00:00
|
|
|
|
2023-05-30 09:24:38 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
// This effect makes sure that no if <ForkApplicationModel />
|
|
|
|
|
// is getting controlled from outside, then we always load workspaces
|
|
|
|
|
if (isModalOpen) {
|
2023-09-26 02:08:05 +00:00
|
|
|
getApplicationsListAndOpenModal();
|
2023-05-30 09:24:38 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}, [isModalOpen]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
// when we fork from within the appeditor, fork modal remains open
|
|
|
|
|
// even on the landing page of "Forked" app, this closes it
|
2023-09-26 02:08:05 +00:00
|
|
|
const url = new URL(window.location.href);
|
2023-05-30 09:24:38 +00:00
|
|
|
const shouldCloseForcibly =
|
2023-09-26 02:08:05 +00:00
|
|
|
!forkingApplication &&
|
|
|
|
|
isModalOpen &&
|
|
|
|
|
handleClose &&
|
|
|
|
|
!url.searchParams.has("fork");
|
|
|
|
|
|
|
|
|
|
if (shouldCloseForcibly) {
|
|
|
|
|
handleClose();
|
|
|
|
|
}
|
2023-05-30 09:24:38 +00:00
|
|
|
}, [forkingApplication]);
|
|
|
|
|
|
2021-03-10 07:08:20 +00:00
|
|
|
const forkApplication = () => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: ReduxActionTypes.FORK_APPLICATION_INIT,
|
|
|
|
|
payload: {
|
|
|
|
|
applicationId: props.applicationId,
|
2022-06-15 15:37:41 +00:00
|
|
|
workspaceId: workspace?.value,
|
2023-05-30 09:24:38 +00:00
|
|
|
editMode: props.isInEditMode,
|
2021-03-10 07:08:20 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
const workspaceList = useMemo(() => {
|
|
|
|
|
const filteredUserWorkspaces = userWorkspaces.filter((item) => {
|
2022-12-01 06:30:50 +00:00
|
|
|
const permitted = hasCreateNewAppPermission(
|
2022-06-15 15:37:41 +00:00
|
|
|
item.workspace.userPermissions ?? [],
|
2021-03-10 07:08:20 +00:00
|
|
|
);
|
|
|
|
|
return permitted;
|
|
|
|
|
});
|
|
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
if (filteredUserWorkspaces.length) {
|
|
|
|
|
selectWorkspace({
|
|
|
|
|
label: filteredUserWorkspaces[0].workspace.name,
|
|
|
|
|
value: filteredUserWorkspaces[0].workspace.id,
|
2022-03-10 14:39:05 +00:00
|
|
|
});
|
2021-03-10 07:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
return filteredUserWorkspaces.map((workspace) => {
|
2021-03-10 07:08:20 +00:00
|
|
|
return {
|
2022-06-15 15:37:41 +00:00
|
|
|
label: workspace.workspace.name,
|
|
|
|
|
value: workspace.workspace.id,
|
2021-03-10 07:08:20 +00:00
|
|
|
};
|
|
|
|
|
});
|
2022-06-15 15:37:41 +00:00
|
|
|
}, [userWorkspaces]);
|
2021-03-10 07:08:20 +00:00
|
|
|
|
2022-03-10 14:39:05 +00:00
|
|
|
const modalHeading = isFetchingApplications
|
|
|
|
|
? createMessage(FORK_APP_MODAL_LOADING_TITLE)
|
2022-06-15 15:37:41 +00:00
|
|
|
: !workspaceList.length
|
2022-03-10 14:39:05 +00:00
|
|
|
? createMessage(FORK_APP_MODAL_EMPTY_TITLE)
|
|
|
|
|
: createMessage(FORK_APP_MODAL_SUCCESS_TITLE);
|
|
|
|
|
|
2023-09-26 02:08:05 +00:00
|
|
|
const getApplicationsListAndOpenModal = () => {
|
2023-05-30 09:24:38 +00:00
|
|
|
!workspaceList.length && dispatch(getAllApplications());
|
2023-09-26 02:08:05 +00:00
|
|
|
handleOpen && handleOpen();
|
2023-05-19 18:37:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleOnOpenChange = (isOpen: boolean) => {
|
|
|
|
|
if (isOpen) {
|
2023-09-26 02:08:05 +00:00
|
|
|
getApplicationsListAndOpenModal();
|
2023-05-19 18:37:06 +00:00
|
|
|
} else {
|
2023-09-26 02:08:05 +00:00
|
|
|
handleClose && handleClose();
|
2023-01-23 09:58:45 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-10 07:08:20 +00:00
|
|
|
return (
|
2023-09-26 02:08:05 +00:00
|
|
|
<Modal onOpenChange={handleOnOpenChange} open={isModalOpen}>
|
2023-05-19 18:37:06 +00:00
|
|
|
<ModalContent className={"fork-modal"} style={{ width: "640px" }}>
|
|
|
|
|
<ModalHeader>{modalHeading}</ModalHeader>
|
|
|
|
|
{isFetchingApplications ? (
|
|
|
|
|
<SpinnerWrapper>
|
|
|
|
|
<Spinner size="lg" />
|
|
|
|
|
</SpinnerWrapper>
|
|
|
|
|
) : (
|
|
|
|
|
!!workspaceList.length && (
|
|
|
|
|
<>
|
|
|
|
|
<Select
|
|
|
|
|
dropdownMatchSelectWidth
|
2023-05-29 05:40:41 +00:00
|
|
|
getPopupContainer={(triggerNode) => triggerNode.parentNode}
|
2023-05-19 18:37:06 +00:00
|
|
|
onSelect={(_, dropdownOption) =>
|
|
|
|
|
// ignoring this because rc-select label and value types are not compatible
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
selectWorkspace(dropdownOption)
|
|
|
|
|
}
|
|
|
|
|
value={workspace.value}
|
|
|
|
|
>
|
|
|
|
|
{workspaceList.map((option) => (
|
|
|
|
|
<Option key={option.value} value={option.value}>
|
|
|
|
|
{option.label}
|
|
|
|
|
</Option>
|
|
|
|
|
))}
|
|
|
|
|
</Select>
|
2022-03-10 14:39:05 +00:00
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
<ButtonWrapper>
|
|
|
|
|
<Button
|
|
|
|
|
isDisabled={forkingApplication}
|
|
|
|
|
kind="secondary"
|
|
|
|
|
onClick={() => {
|
2023-09-26 02:08:05 +00:00
|
|
|
handleClose && handleClose();
|
2023-05-19 18:37:06 +00:00
|
|
|
}}
|
|
|
|
|
size="md"
|
|
|
|
|
>
|
|
|
|
|
{createMessage(CANCEL)}
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
className="t--fork-app-to-workspace-button"
|
|
|
|
|
isLoading={forkingApplication}
|
|
|
|
|
onClick={forkApplication}
|
|
|
|
|
size="md"
|
|
|
|
|
>
|
|
|
|
|
{createMessage(FORK)}
|
|
|
|
|
</Button>
|
|
|
|
|
</ButtonWrapper>
|
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
)}
|
|
|
|
|
</ModalContent>
|
|
|
|
|
</Modal>
|
2021-03-10 07:08:20 +00:00
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2021-03-10 07:08:20 +00:00
|
|
|
|
|
|
|
|
export default ForkApplicationModal;
|