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 { ReactNode } from "react";
|
|
|
|
|
import React, { useCallback, useEffect, useState } from "react";
|
2023-05-19 18:37:06 +00:00
|
|
|
import styled, { useTheme, css } from "styled-components";
|
2022-11-28 08:13:17 +00:00
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
2022-03-17 10:28:54 +00:00
|
|
|
import {
|
|
|
|
|
importApplication,
|
2022-06-15 15:37:41 +00:00
|
|
|
setWorkspaceIdForImport,
|
2023-03-29 17:07:06 +00:00
|
|
|
} from "@appsmith/actions/applicationActions";
|
2022-03-17 10:28:54 +00:00
|
|
|
import {
|
|
|
|
|
createMessage,
|
|
|
|
|
IMPORT_APP_FROM_FILE_MESSAGE,
|
|
|
|
|
IMPORT_APP_FROM_FILE_TITLE,
|
|
|
|
|
IMPORT_APP_FROM_GIT_MESSAGE,
|
|
|
|
|
IMPORT_APP_FROM_GIT_TITLE,
|
|
|
|
|
IMPORT_APPLICATION_MODAL_LABEL,
|
|
|
|
|
IMPORT_APPLICATION_MODAL_TITLE,
|
2022-05-17 06:56:34 +00:00
|
|
|
UPLOADING_APPLICATION,
|
|
|
|
|
UPLOADING_JSON,
|
2022-03-17 10:28:54 +00:00
|
|
|
} from "@appsmith/constants/messages";
|
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 { SetProgress } from "design-system-old";
|
2023-05-19 18:37:06 +00:00
|
|
|
import { FilePickerV2, FileType } from "design-system-old";
|
2022-03-17 10:28:54 +00:00
|
|
|
import { setIsGitSyncModalOpen } from "actions/gitSyncActions";
|
|
|
|
|
import { GitSyncModalTab } from "entities/GitSync";
|
2023-03-29 17:07:06 +00:00
|
|
|
import { getIsImportingApplication } from "@appsmith/selectors/applicationSelectors";
|
2022-04-12 10:50:01 +00:00
|
|
|
import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants";
|
2022-05-17 06:56:34 +00:00
|
|
|
import Statusbar from "pages/Editor/gitSync/components/Statusbar";
|
2022-05-19 06:46:38 +00:00
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag
### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { Theme } from "constants/DefaultTheme";
|
2023-05-19 18:37:06 +00:00
|
|
|
import { Icon, Modal, ModalContent, ModalHeader, Text } from "design-system";
|
2021-06-03 06:18:08 +00:00
|
|
|
|
2022-03-17 10:28:54 +00:00
|
|
|
const TextWrapper = styled.div`
|
|
|
|
|
padding: 0;
|
2023-05-19 18:37:06 +00:00
|
|
|
margin-bottom: var(--ads-v2-spaces-7);
|
2022-03-17 10:28:54 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const Row = styled.div`
|
2021-06-03 06:18:08 +00:00
|
|
|
display: flex;
|
2022-03-17 10:28:54 +00:00
|
|
|
padding: 0;
|
|
|
|
|
margin: 0;
|
2023-05-19 18:37:06 +00:00
|
|
|
justify-content: center;
|
|
|
|
|
gap: 16px;
|
2021-06-03 06:18:08 +00:00
|
|
|
`;
|
|
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
const CardStyles = css`
|
2022-03-17 10:28:54 +00:00
|
|
|
height: 200px;
|
2023-05-19 18:37:06 +00:00
|
|
|
border: 1px solid var(--ads-v2-color-border);
|
|
|
|
|
border-radius: var(--ads-v2-border-radius);
|
2021-06-03 06:18:08 +00:00
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
2022-03-17 10:28:54 +00:00
|
|
|
flex-direction: column;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
|
|
&:hover {
|
2023-05-19 18:37:06 +00:00
|
|
|
background: var(--ads-v2-color-bg-subtle);
|
2022-03-17 10:28:54 +00:00
|
|
|
}
|
2023-05-19 18:37:06 +00:00
|
|
|
`;
|
2022-03-17 10:28:54 +00:00
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
const FileImportCard = styled.div<{ fillCardWidth: boolean }>`
|
|
|
|
|
${CardStyles}
|
|
|
|
|
width: ${(props) => (props.fillCardWidth ? "100%" : "320px")};
|
2022-03-17 10:28:54 +00:00
|
|
|
& > div {
|
|
|
|
|
background: transparent none;
|
2023-05-19 18:37:06 +00:00
|
|
|
border: none;
|
2022-03-17 10:28:54 +00:00
|
|
|
|
|
|
|
|
.upload-form-container {
|
|
|
|
|
padding-top: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.button-wrapper {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
justify-content: flex-start;
|
|
|
|
|
|
|
|
|
|
.cs-icon {
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
width: ${(props) => props.theme.spaces[12] + 2}px;
|
|
|
|
|
height: ${(props) => props.theme.spaces[12] + 2}px;
|
2023-05-19 18:37:06 +00:00
|
|
|
background: var(--ads-v2-color-bg-muted);
|
2022-03-17 10:28:54 +00:00
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
margin-top: 35px;
|
|
|
|
|
margin-bottom: 32px;
|
2023-05-19 18:37:06 +00:00
|
|
|
color: var(--ads-v2-color-fg) !important;
|
2022-03-17 10:28:54 +00:00
|
|
|
|
|
|
|
|
svg {
|
|
|
|
|
width: ${(props) => props.theme.iconSizes.XL}px;
|
|
|
|
|
height: ${(props) => props.theme.iconSizes.XL}px;
|
|
|
|
|
|
|
|
|
|
path {
|
2023-05-19 18:37:06 +00:00
|
|
|
color: var(--ads-v2-color-fg) !important;
|
2022-03-17 10:28:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.cs-text {
|
|
|
|
|
max-width: 220px;
|
|
|
|
|
text-align: center;
|
|
|
|
|
margin-top: 0;
|
|
|
|
|
font-size: ${(props) => props.theme.typography.p1.fontSize}px;
|
|
|
|
|
|
|
|
|
|
&.drag-drop-text {
|
2023-05-19 18:37:06 +00:00
|
|
|
color: var(--ads-v2-color-fg);
|
2022-03-17 10:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&.drag-drop-description {
|
2023-05-19 18:37:06 +00:00
|
|
|
color: var(--ads-v2-color-fg-muted);
|
2022-03-17 10:28:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const CardWrapper = styled.div`
|
2023-05-19 18:37:06 +00:00
|
|
|
${CardStyles}
|
2022-03-17 10:28:54 +00:00
|
|
|
width: 320px;
|
2023-05-19 18:37:06 +00:00
|
|
|
.ads-v2-icon {
|
2022-03-17 10:28:54 +00:00
|
|
|
border-radius: 50%;
|
|
|
|
|
width: 32px;
|
|
|
|
|
height: 32px;
|
2023-05-19 18:37:06 +00:00
|
|
|
background: var(--ads-v2-color-bg-muted);
|
2022-03-17 10:28:54 +00:00
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
margin-top: 35px;
|
|
|
|
|
margin-bottom: 32px;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
.ads-v2-text {
|
2022-03-17 10:28:54 +00:00
|
|
|
max-width: 250px;
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
2023-05-19 18:37:06 +00:00
|
|
|
|
|
|
|
|
.ads-v2-text:last-child {
|
|
|
|
|
color: var(--ads-v2-color-fg-muted);
|
|
|
|
|
}
|
2021-06-03 06:18:08 +00:00
|
|
|
`;
|
|
|
|
|
|
2022-05-17 06:56:34 +00:00
|
|
|
const StatusbarWrapper = styled.div`
|
|
|
|
|
width: 252px;
|
2023-05-29 05:40:41 +00:00
|
|
|
height: 240px;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
2022-05-17 06:56:34 +00:00
|
|
|
.cs-icon {
|
|
|
|
|
margin: auto;
|
2023-05-19 18:37:06 +00:00
|
|
|
border-radius: var(--ads-v2-border-radius-circle);
|
2022-05-17 06:56:34 +00:00
|
|
|
width: 32px;
|
|
|
|
|
height: 32px;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
margin-bottom: 8px;
|
2022-05-19 15:02:35 +00:00
|
|
|
background: var(--appsmith-color-black-200);
|
2022-05-17 06:56:34 +00:00
|
|
|
svg {
|
|
|
|
|
width: 20px;
|
|
|
|
|
height: 20px;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-19 18:37:06 +00:00
|
|
|
.ads-v2-text.importing-app-name {
|
2022-05-17 06:56:34 +00:00
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2022-03-17 10:28:54 +00:00
|
|
|
function GitImportCard(props: { children?: ReactNode; handler?: () => void }) {
|
|
|
|
|
const theme = useTheme() as Theme;
|
|
|
|
|
const onClick = useCallback(() => {
|
2022-05-19 06:46:38 +00:00
|
|
|
AnalyticsUtil.logEvent("GS_IMPORT_VIA_GIT_CARD_CLICK");
|
2022-03-17 10:28:54 +00:00
|
|
|
props.handler && props.handler();
|
|
|
|
|
}, []);
|
|
|
|
|
const message = createMessage(IMPORT_APP_FROM_GIT_MESSAGE);
|
|
|
|
|
const title = createMessage(IMPORT_APP_FROM_GIT_TITLE);
|
|
|
|
|
return (
|
|
|
|
|
<CardWrapper onClick={onClick}>
|
2023-05-19 18:37:06 +00:00
|
|
|
<Icon name={"fork"} size="md" />
|
|
|
|
|
<Text kind="body-m" style={{ marginBottom: theme.spaces[4] }}>
|
2022-03-17 10:28:54 +00:00
|
|
|
{title}
|
|
|
|
|
</Text>
|
2023-05-19 18:37:06 +00:00
|
|
|
<Text kind="body-m">{message}</Text>
|
2022-03-17 10:28:54 +00:00
|
|
|
{props.children}
|
|
|
|
|
</CardWrapper>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 07:35:24 +00:00
|
|
|
interface ImportApplicationModalProps {
|
2022-06-15 15:37:41 +00:00
|
|
|
workspaceId?: string;
|
2021-06-03 06:18:08 +00:00
|
|
|
isModalOpen?: boolean;
|
|
|
|
|
onClose?: () => void;
|
2023-05-01 13:29:26 +00:00
|
|
|
appId?: string;
|
|
|
|
|
toApp?: boolean;
|
2023-10-11 07:35:24 +00:00
|
|
|
}
|
2021-06-03 06:18:08 +00:00
|
|
|
|
|
|
|
|
function ImportApplicationModal(props: ImportApplicationModalProps) {
|
2023-05-01 13:29:26 +00:00
|
|
|
const { appId, isModalOpen, onClose, toApp = false, workspaceId } = props;
|
2021-06-03 06:18:08 +00:00
|
|
|
const [appFileToBeUploaded, setAppFileToBeUploaded] = useState<{
|
|
|
|
|
file: File;
|
|
|
|
|
setProgress: SetProgress;
|
|
|
|
|
} | null>(null);
|
2022-03-17 10:28:54 +00:00
|
|
|
|
2021-06-03 06:18:08 +00:00
|
|
|
const dispatch = useDispatch();
|
2022-03-17 10:28:54 +00:00
|
|
|
const onGitImport = useCallback(() => {
|
|
|
|
|
onClose && onClose();
|
|
|
|
|
dispatch({
|
|
|
|
|
type: ReduxActionTypes.GIT_INFO_INIT,
|
|
|
|
|
});
|
2022-06-15 15:37:41 +00:00
|
|
|
dispatch(setWorkspaceIdForImport(workspaceId));
|
2021-06-03 06:18:08 +00:00
|
|
|
|
2022-03-17 10:28:54 +00:00
|
|
|
dispatch(
|
|
|
|
|
setIsGitSyncModalOpen({
|
|
|
|
|
isOpen: true,
|
|
|
|
|
tab: GitSyncModalTab.GIT_CONNECTION,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// dispatch(setIsReconnectingDatasourcesModalOpen({ isOpen: true }));
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const importingApplication = useSelector(getIsImportingApplication);
|
2021-06-03 06:18:08 +00:00
|
|
|
|
|
|
|
|
const FileUploader = useCallback(
|
|
|
|
|
async (file: File, setProgress: SetProgress) => {
|
|
|
|
|
if (!!file) {
|
|
|
|
|
setAppFileToBeUploaded({
|
|
|
|
|
file,
|
|
|
|
|
setProgress,
|
|
|
|
|
});
|
2022-03-17 10:28:54 +00:00
|
|
|
dispatch(
|
|
|
|
|
importApplication({
|
2023-05-01 13:29:26 +00:00
|
|
|
appId: appId as string,
|
2022-06-15 15:37:41 +00:00
|
|
|
workspaceId: workspaceId as string,
|
2022-03-17 10:28:54 +00:00
|
|
|
applicationFile: file,
|
|
|
|
|
}),
|
|
|
|
|
);
|
2021-06-03 06:18:08 +00:00
|
|
|
} else {
|
|
|
|
|
setAppFileToBeUploaded(null);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[],
|
|
|
|
|
);
|
|
|
|
|
|
2022-03-17 10:28:54 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
// finished of importing application
|
|
|
|
|
if (appFileToBeUploaded && !importingApplication) {
|
|
|
|
|
setAppFileToBeUploaded(null);
|
2022-05-17 06:56:34 +00:00
|
|
|
onClose && onClose();
|
2022-03-17 10:28:54 +00:00
|
|
|
// should open "Add credential" modal
|
2021-06-03 06:18:08 +00:00
|
|
|
}
|
2022-03-17 10:28:54 +00:00
|
|
|
}, [appFileToBeUploaded, importingApplication]);
|
2021-06-03 06:18:08 +00:00
|
|
|
|
|
|
|
|
const onRemoveFile = useCallback(() => setAppFileToBeUploaded(null), []);
|
2022-04-07 17:57:32 +00:00
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
const handleModalClose = (open: boolean) => {
|
|
|
|
|
if (!open) {
|
|
|
|
|
onClose && onClose();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-03 06:18:08 +00:00
|
|
|
return (
|
2023-05-19 18:37:06 +00:00
|
|
|
<Modal onOpenChange={handleModalClose} open={isModalOpen}>
|
|
|
|
|
<ModalContent
|
|
|
|
|
className={"t--import-application-modal"}
|
2023-05-29 05:40:41 +00:00
|
|
|
style={{
|
|
|
|
|
width: importingApplication ? "40vw" : "fit-content",
|
|
|
|
|
minWidth: "30vw",
|
|
|
|
|
}}
|
2023-05-19 18:37:06 +00:00
|
|
|
>
|
|
|
|
|
<ModalHeader>
|
|
|
|
|
{createMessage(IMPORT_APPLICATION_MODAL_TITLE)}
|
|
|
|
|
</ModalHeader>
|
|
|
|
|
<TextWrapper>
|
|
|
|
|
<Text kind="body-m">
|
|
|
|
|
{toApp
|
|
|
|
|
? null
|
|
|
|
|
: createMessage(
|
|
|
|
|
importingApplication
|
|
|
|
|
? UPLOADING_JSON
|
|
|
|
|
: IMPORT_APPLICATION_MODAL_LABEL,
|
|
|
|
|
)}
|
|
|
|
|
</Text>
|
|
|
|
|
</TextWrapper>
|
|
|
|
|
{!importingApplication && (
|
|
|
|
|
<Row>
|
|
|
|
|
<FileImportCard
|
|
|
|
|
className="t--import-json-card"
|
|
|
|
|
fillCardWidth={toApp}
|
|
|
|
|
>
|
|
|
|
|
<FilePickerV2
|
|
|
|
|
containerClickable
|
|
|
|
|
description={createMessage(IMPORT_APP_FROM_FILE_MESSAGE)}
|
|
|
|
|
fileType={FileType.JSON}
|
|
|
|
|
fileUploader={FileUploader}
|
|
|
|
|
iconFillColor={"var(--ads-v2-color-fg)"}
|
|
|
|
|
onFileRemoved={onRemoveFile}
|
|
|
|
|
title={createMessage(IMPORT_APP_FROM_FILE_TITLE)}
|
|
|
|
|
uploadIcon="file-line"
|
|
|
|
|
/>
|
|
|
|
|
</FileImportCard>
|
|
|
|
|
{!toApp && <GitImportCard handler={onGitImport} />}
|
|
|
|
|
</Row>
|
|
|
|
|
)}
|
|
|
|
|
{importingApplication && (
|
|
|
|
|
<Row className="t-import-app-progress-wrapper">
|
|
|
|
|
<StatusbarWrapper className="t--importing-app-statusbar">
|
|
|
|
|
<Icon name="file-line" size="md" />
|
|
|
|
|
<Text className="importing-app-name" kind="body-m">
|
|
|
|
|
{appFileToBeUploaded?.file?.name || "filename.json"}
|
|
|
|
|
</Text>
|
|
|
|
|
<Statusbar
|
|
|
|
|
completed={!importingApplication}
|
|
|
|
|
message={createMessage(UPLOADING_APPLICATION)}
|
|
|
|
|
period={4}
|
|
|
|
|
/>
|
|
|
|
|
</StatusbarWrapper>
|
|
|
|
|
</Row>
|
|
|
|
|
)}
|
|
|
|
|
</ModalContent>
|
|
|
|
|
</Modal>
|
2021-06-03 06:18:08 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ImportApplicationModal;
|