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";
|
2022-03-17 10:28:54 +00:00
|
|
|
import styled, { useTheme } 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,
|
2022-03-17 10:28:54 +00:00
|
|
|
} from "actions/applicationActions";
|
|
|
|
|
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";
|
|
|
|
|
import { Colors } from "constants/Colors";
|
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";
|
2022-10-10 03:54:41 +00:00
|
|
|
import {
|
|
|
|
|
DialogComponent as Dialog,
|
2022-10-13 20:13:44 +00:00
|
|
|
FilePickerV2,
|
2022-11-01 16:47:45 +00:00
|
|
|
FileType,
|
2022-10-10 03:54:41 +00:00
|
|
|
Icon,
|
|
|
|
|
IconSize,
|
|
|
|
|
Text,
|
|
|
|
|
TextType,
|
2023-01-23 03:50:47 +00:00
|
|
|
} from "design-system-old";
|
2022-03-17 10:28:54 +00:00
|
|
|
import { setIsGitSyncModalOpen } from "actions/gitSyncActions";
|
|
|
|
|
import { GitSyncModalTab } from "entities/GitSync";
|
|
|
|
|
import { getIsImportingApplication } from "selectors/applicationSelectors";
|
2022-04-12 10:50:01 +00:00
|
|
|
import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants";
|
2022-03-17 10:28:54 +00:00
|
|
|
import { Classes } from "@blueprintjs/core";
|
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";
|
2021-06-03 06:18:08 +00:00
|
|
|
|
2022-03-17 10:28:54 +00:00
|
|
|
const StyledDialog = styled(Dialog)`
|
|
|
|
|
&& .${Classes.DIALOG_HEADER} {
|
|
|
|
|
min-height: unset;
|
|
|
|
|
|
|
|
|
|
& .${Classes.DIALOG_CLOSE_BUTTON} {
|
|
|
|
|
margin-top: -2px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
& .${Classes.ICON} {
|
|
|
|
|
&:hover {
|
|
|
|
|
& svg path {
|
|
|
|
|
fill: ${Colors.GREY_800};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
& svg {
|
|
|
|
|
margin-right: ${(props) => props.theme.spaces[3]}px;
|
|
|
|
|
|
|
|
|
|
& path {
|
|
|
|
|
fill: ${Colors.GREY_7};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&& .${Classes.DIALOG_BODY} {
|
|
|
|
|
padding: 0;
|
|
|
|
|
margin-bottom: 0;
|
|
|
|
|
margin-top: 8px;
|
|
|
|
|
}
|
2021-06-03 06:18:08 +00:00
|
|
|
`;
|
|
|
|
|
|
2022-03-17 10:28:54 +00:00
|
|
|
const TextWrapper = styled.div`
|
|
|
|
|
padding: 0;
|
|
|
|
|
margin-bottom: ${(props) => props.theme.spaces[12] + 4}px;
|
|
|
|
|
margin-top: ${(props) => props.theme.spaces[11]}px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
justify-content: space-between;
|
2022-05-17 06:56:34 +00:00
|
|
|
&.t-import-app-progress-wrapper {
|
|
|
|
|
justify-content: center;
|
|
|
|
|
}
|
2021-06-03 06:18:08 +00:00
|
|
|
`;
|
|
|
|
|
|
2022-11-01 16:47:45 +00:00
|
|
|
const FileImportCard = styled.div`
|
|
|
|
|
width: 320px;
|
2022-03-17 10:28:54 +00:00
|
|
|
height: 200px;
|
|
|
|
|
border: 1px solid ${Colors.GREY_4};
|
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 {
|
|
|
|
|
background: ${Colors.GREY_4};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
& > div {
|
|
|
|
|
background: transparent none;
|
|
|
|
|
|
|
|
|
|
.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;
|
|
|
|
|
background: ${Colors.GREY_4};
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
margin-top: 35px;
|
|
|
|
|
margin-bottom: 32px;
|
|
|
|
|
color: ${Colors.GREY_800} !important;
|
|
|
|
|
|
|
|
|
|
svg {
|
|
|
|
|
width: ${(props) => props.theme.iconSizes.XL}px;
|
|
|
|
|
height: ${(props) => props.theme.iconSizes.XL}px;
|
|
|
|
|
|
|
|
|
|
path {
|
|
|
|
|
color: ${Colors.GREY_800} !important;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.cs-text {
|
|
|
|
|
max-width: 220px;
|
|
|
|
|
text-align: center;
|
|
|
|
|
margin-top: 0;
|
|
|
|
|
font-size: ${(props) => props.theme.typography.p1.fontSize}px;
|
|
|
|
|
|
|
|
|
|
&.drag-drop-text {
|
|
|
|
|
color: ${Colors.OXFORD_BLUE};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&.drag-drop-description {
|
|
|
|
|
color: ${Colors.GREY_800};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const CardWrapper = styled.div`
|
|
|
|
|
width: 320px;
|
|
|
|
|
height: 200px;
|
|
|
|
|
border: 1px solid ${Colors.GREY_4};
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
background: ${Colors.GREY_4};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.cs-icon {
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
width: 32px;
|
|
|
|
|
height: 32px;
|
|
|
|
|
background: ${Colors.GREY_4};
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
margin-top: 35px;
|
|
|
|
|
margin-bottom: 32px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.cs-text {
|
|
|
|
|
max-width: 250px;
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
2021-06-03 06:18:08 +00:00
|
|
|
`;
|
|
|
|
|
|
2022-05-17 06:56:34 +00:00
|
|
|
const StatusbarWrapper = styled.div`
|
|
|
|
|
width: 252px;
|
|
|
|
|
height: 199px;
|
|
|
|
|
.cs-icon {
|
|
|
|
|
margin: auto;
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.cs-text.importing-app-name {
|
|
|
|
|
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}>
|
|
|
|
|
<Icon fillColor={Colors.GREY_800} name={"fork"} size={IconSize.XL} />
|
|
|
|
|
<Text
|
|
|
|
|
color={Colors.OXFORD_BLUE}
|
|
|
|
|
style={{ marginBottom: theme.spaces[4] }}
|
|
|
|
|
type={TextType.P1}
|
|
|
|
|
>
|
|
|
|
|
{title}
|
|
|
|
|
</Text>
|
|
|
|
|
<Text color={Colors.GREY_800} type={TextType.P1}>
|
|
|
|
|
{message}
|
|
|
|
|
</Text>
|
|
|
|
|
{props.children}
|
|
|
|
|
</CardWrapper>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-03 06:18:08 +00:00
|
|
|
type ImportApplicationModalProps = {
|
2022-06-15 15:37:41 +00:00
|
|
|
workspaceId?: string;
|
2021-06-03 06:18:08 +00:00
|
|
|
isModalOpen?: boolean;
|
|
|
|
|
onClose?: () => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function ImportApplicationModal(props: ImportApplicationModalProps) {
|
2022-06-15 15:37:41 +00:00
|
|
|
const { isModalOpen, onClose, 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({
|
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
|
|
|
|
2021-06-03 06:18:08 +00:00
|
|
|
return (
|
|
|
|
|
<StyledDialog
|
|
|
|
|
canOutsideClickClose
|
|
|
|
|
className={"t--import-application-modal"}
|
2022-03-17 10:28:54 +00:00
|
|
|
headerIcon={{
|
|
|
|
|
name: "right-arrow",
|
|
|
|
|
bgColor: Colors.GEYSER_LIGHT,
|
|
|
|
|
}}
|
2021-06-03 06:18:08 +00:00
|
|
|
isOpen={isModalOpen}
|
|
|
|
|
maxHeight={"540px"}
|
|
|
|
|
setModalClose={onClose}
|
2022-03-17 10:28:54 +00:00
|
|
|
title={createMessage(IMPORT_APPLICATION_MODAL_TITLE)}
|
|
|
|
|
width="710px"
|
2021-06-03 06:18:08 +00:00
|
|
|
>
|
2022-03-17 10:28:54 +00:00
|
|
|
<TextWrapper>
|
|
|
|
|
<Text color={Colors.COD_GRAY} type={TextType.P1}>
|
2022-05-17 06:56:34 +00:00
|
|
|
{createMessage(
|
|
|
|
|
importingApplication
|
|
|
|
|
? UPLOADING_JSON
|
|
|
|
|
: IMPORT_APPLICATION_MODAL_LABEL,
|
|
|
|
|
)}
|
2022-03-17 10:28:54 +00:00
|
|
|
</Text>
|
|
|
|
|
</TextWrapper>
|
2022-05-17 06:56:34 +00:00
|
|
|
{!importingApplication && (
|
|
|
|
|
<Row>
|
2022-11-01 16:47:45 +00:00
|
|
|
<FileImportCard className="t--import-json-card">
|
2022-05-17 06:56:34 +00:00
|
|
|
<FilePickerV2
|
|
|
|
|
containerClickable
|
|
|
|
|
description={createMessage(IMPORT_APP_FROM_FILE_MESSAGE)}
|
|
|
|
|
fileType={FileType.JSON}
|
|
|
|
|
fileUploader={FileUploader}
|
|
|
|
|
iconFillColor={Colors.GREY_800}
|
|
|
|
|
onFileRemoved={onRemoveFile}
|
|
|
|
|
title={createMessage(IMPORT_APP_FROM_FILE_TITLE)}
|
|
|
|
|
uploadIcon="file-line"
|
|
|
|
|
/>
|
|
|
|
|
</FileImportCard>
|
2022-11-01 16:47:45 +00:00
|
|
|
<GitImportCard handler={onGitImport} />
|
2022-05-17 06:56:34 +00:00
|
|
|
</Row>
|
|
|
|
|
)}
|
|
|
|
|
{importingApplication && (
|
|
|
|
|
<Row className="t-import-app-progress-wrapper">
|
|
|
|
|
<StatusbarWrapper className="t--importing-app-statusbar">
|
|
|
|
|
<Icon fillColor={Colors.GREY_800} name="file-line" />
|
|
|
|
|
<Text className="importing-app-name" type={TextType.P2}>
|
2022-05-19 15:02:35 +00:00
|
|
|
{appFileToBeUploaded?.file?.name || "filename.json"}
|
2022-05-17 06:56:34 +00:00
|
|
|
</Text>
|
|
|
|
|
<Statusbar
|
|
|
|
|
completed={!importingApplication}
|
|
|
|
|
message={createMessage(UPLOADING_APPLICATION)}
|
|
|
|
|
period={4}
|
|
|
|
|
/>
|
|
|
|
|
</StatusbarWrapper>
|
|
|
|
|
</Row>
|
|
|
|
|
)}
|
2021-06-03 06:18:08 +00:00
|
|
|
</StyledDialog>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ImportApplicationModal;
|