2022-03-17 10:28:54 +00:00
|
|
|
import React, { ReactNode, useCallback, useEffect, useState } from "react";
|
|
|
|
|
import styled, { useTheme } from "styled-components";
|
2021-06-03 06:18:08 +00:00
|
|
|
import { useSelector } from "store";
|
2022-03-17 10:28:54 +00:00
|
|
|
import { FileType, SetProgress } from "components/ads/FilePicker";
|
2021-06-03 06:18:08 +00:00
|
|
|
import { useDispatch } from "react-redux";
|
2022-03-17 10:28:54 +00:00
|
|
|
import {
|
|
|
|
|
importApplication,
|
|
|
|
|
setOrgIdForImport,
|
|
|
|
|
} 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,
|
|
|
|
|
} from "@appsmith/constants/messages";
|
2021-10-04 15:34:37 +00:00
|
|
|
import FilePickerV2 from "components/ads/FilePickerV2";
|
2022-03-17 10:28:54 +00:00
|
|
|
import { Colors } from "constants/Colors";
|
|
|
|
|
import Text, { TextType } from "components/ads/Text";
|
|
|
|
|
import Icon, { IconSize } from "components/ads/Icon";
|
|
|
|
|
import { Theme } from "constants/DefaultTheme";
|
|
|
|
|
import { setIsGitSyncModalOpen } from "actions/gitSyncActions";
|
|
|
|
|
import { GitSyncModalTab } from "entities/GitSync";
|
|
|
|
|
import { getIsImportingApplication } from "selectors/applicationSelectors";
|
|
|
|
|
import { ReduxActionTypes } from "constants/ReduxActionConstants";
|
|
|
|
|
import Dialog from "../../components/ads/DialogComponent";
|
|
|
|
|
import { Classes } from "@blueprintjs/core";
|
|
|
|
|
import getFeatureFlags from "../../utils/featureFlags";
|
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;
|
2021-06-03 06:18:08 +00:00
|
|
|
`;
|
|
|
|
|
|
2022-03-17 10:28:54 +00:00
|
|
|
const FileImportCard = styled.div`
|
|
|
|
|
width: 320px;
|
|
|
|
|
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-03-17 10:28:54 +00:00
|
|
|
function GitImportCard(props: { children?: ReactNode; handler?: () => void }) {
|
|
|
|
|
const theme = useTheme() as Theme;
|
|
|
|
|
const onClick = useCallback(() => {
|
|
|
|
|
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 = {
|
|
|
|
|
// import?: (file: any) => void;
|
|
|
|
|
organizationId?: string;
|
|
|
|
|
isModalOpen?: boolean;
|
|
|
|
|
onClose?: () => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function ImportApplicationModal(props: ImportApplicationModalProps) {
|
|
|
|
|
const { isModalOpen, onClose, organizationId } = props;
|
|
|
|
|
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,
|
|
|
|
|
});
|
|
|
|
|
dispatch(setOrgIdForImport(organizationId));
|
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({
|
|
|
|
|
orgId: organizationId as string,
|
|
|
|
|
applicationFile: file,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
onClose && onClose();
|
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);
|
|
|
|
|
// 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-03-17 10:28:54 +00:00
|
|
|
const isGitImportFeatureEnabled = getFeatureFlags().GIT_IMPORT;
|
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}>
|
|
|
|
|
{createMessage(IMPORT_APPLICATION_MODAL_LABEL)}
|
|
|
|
|
</Text>
|
|
|
|
|
</TextWrapper>
|
|
|
|
|
<Row>
|
|
|
|
|
<FileImportCard className="t--import-json-card">
|
|
|
|
|
<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>
|
|
|
|
|
{isGitImportFeatureEnabled && <GitImportCard handler={onGitImport} />}
|
|
|
|
|
</Row>
|
2021-06-03 06:18:08 +00:00
|
|
|
</StyledDialog>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ImportApplicationModal;
|