PromucFlow_constructor/app/client/src/pages/Applications/ImportApplicationModal.tsx

119 lines
3.2 KiB
TypeScript
Raw Normal View History

Feature/import applications (#4483) * Added export option to app menu. TODO: call api to download app file * Added checkbox component and removed unused code * Added import app without filepicker. Opens modal * added ability to fetch the exported app * can download exported application as a json file * Updated the file picker component to accept other file formats * WIP import app * Added functionality to import application json file * minor fixes * Made the file type prop mandatory for file picker * added a test suite for export app * Test added to check if on import application click, it open a modal * added a dummy application file for cypress testing * Added end to end integration test suite to verify import app feature * added test to verify the export api status and download file. * added a linked btn to carry exporting. - according to latest BE changes * Removed old redux and saga mechanism for app export * updated cypress test to validate new flow * fixed minor linting errors * updated test case title * updated the test cases for import/export app feat * review changes * added prop to facilitate delayed upload * added new application file to fixtures. Minor fix to take care of loading state. * Removed export app modal. Added one click action, to download the file. * Updated File picker to work with all other files acc to the design. * Updated the import modal * updated the import application test * Added remove upload tooltip * updated the icons for import/export actions * removed unused logs * added hard coded feature flag to hide/show import export feature Co-authored-by: Pranav Kanade <pranav@appsmith.com>
2021-06-03 06:18:08 +00:00
import React, { useCallback, useState } from "react";
import styled from "styled-components";
import Button, { Size } from "components/ads/Button";
import { StyledDialog } from "./ForkModalStyles";
import { useSelector } from "store";
import { AppState } from "reducers";
import FilePicker, { SetProgress, FileType } from "components/ads/FilePicker";
import { useDispatch } from "react-redux";
import { importApplication } from "actions/applicationActions";
import { Toaster } from "components/ads/Toast";
import { Variant } from "components/ads/common";
import { IMPORT_APPLICATION_MODAL_TITLE } from "constants/messages";
const ImportButton = styled(Button)<{ disabled?: boolean }>`
height: 30px;
width: 81px;
pointer-events: ${(props) => (!!props.disabled ? "none" : "auto")};
`;
const ButtonWrapper = styled.div`
display: flex;
justify-content: center;
2021-09-20 05:36:54 +00:00
margin-top: ${(props) => props.theme.spaces[6]}px;
Feature/import applications (#4483) * Added export option to app menu. TODO: call api to download app file * Added checkbox component and removed unused code * Added import app without filepicker. Opens modal * added ability to fetch the exported app * can download exported application as a json file * Updated the file picker component to accept other file formats * WIP import app * Added functionality to import application json file * minor fixes * Made the file type prop mandatory for file picker * added a test suite for export app * Test added to check if on import application click, it open a modal * added a dummy application file for cypress testing * Added end to end integration test suite to verify import app feature * added test to verify the export api status and download file. * added a linked btn to carry exporting. - according to latest BE changes * Removed old redux and saga mechanism for app export * updated cypress test to validate new flow * fixed minor linting errors * updated test case title * updated the test cases for import/export app feat * review changes * added prop to facilitate delayed upload * added new application file to fixtures. Minor fix to take care of loading state. * Removed export app modal. Added one click action, to download the file. * Updated File picker to work with all other files acc to the design. * Updated the import modal * updated the import application test * Added remove upload tooltip * updated the icons for import/export actions * removed unused logs * added hard coded feature flag to hide/show import export feature Co-authored-by: Pranav Kanade <pranav@appsmith.com>
2021-06-03 06:18:08 +00:00
`;
const FilePickerWrapper = styled.div`
width: 100%;
display: flex;
align-items: center;
justify-content: center;
`;
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);
const dispatch = useDispatch();
const importingApplication = useSelector(
(state: AppState) => state.ui.applications.importingApplication,
);
const FileUploader = useCallback(
async (file: File, setProgress: SetProgress) => {
if (!!file) {
setAppFileToBeUploaded({
file,
setProgress,
});
} else {
setAppFileToBeUploaded(null);
}
},
[],
);
const onImportApplication = useCallback(() => {
if (!appFileToBeUploaded) {
Toaster.show({
text: "Please choose a valid application file!",
variant: Variant.danger,
});
return;
}
const { file } = appFileToBeUploaded || {};
dispatch(
importApplication({
orgId: organizationId as string,
applicationFile: file,
}),
);
}, [appFileToBeUploaded, organizationId]);
const onRemoveFile = useCallback(() => setAppFileToBeUploaded(null), []);
return (
<StyledDialog
canOutsideClickClose
className={"t--import-application-modal"}
isOpen={isModalOpen}
maxHeight={"540px"}
setModalClose={onClose}
title={IMPORT_APPLICATION_MODAL_TITLE()}
>
<FilePickerWrapper>
<FilePicker
delayedUpload
fileType={FileType.JSON}
fileUploader={FileUploader}
onFileRemoved={onRemoveFile}
/>
</FilePickerWrapper>
<ButtonWrapper>
<ImportButton
// category={ButtonCategory.tertiary}
cypressSelector={"t--org-import-app-button"}
disabled={!appFileToBeUploaded}
isLoading={importingApplication}
onClick={onImportApplication}
size={Size.large}
text={"IMPORT"}
/>
</ButtonWrapper>
</StyledDialog>
);
}
export default ImportApplicationModal;