* Refactor toast to be passed the dispatch hook externally * Add comments explaining dilemma * use store.dispatch instead of a hook * use alpha version * Change imports * Refactor DebugButton out * update release * fix issue with incorrectly merged package.lock * fix syntax of alpha version * bump ds vesion * copy lock from release * update lock to have alpha * make changes * delete Toast * DS package version updated * import change from release * use new alpha version * update ds version * update ds version * chore: migrate editable text and friends (#17285) * Delete empty components * use alpha for ds * Deleted EditableTextSubComponent, import changes * Delete EditableText, import changes * use ds alpha 10 * Delete EditableTextWrapper.tsx * update ds to use next minor version * use new alpha * fix issue with merge Co-authored-by: Albin <albin@appsmith.com> * chore: migrate file picker v2 (#17308) * use alpha ds * Delete FilePickerV2, import changes * Delete FilePicker, change imports * update alpha version * chore: move copy url form into setting components (#17322) * move CopyUrlForm to src/pages/settings/formgroup * update ds version to use next minor release * feat: Migrate table component to design system (#17329) * feat: Migrate table component to design system * removed commented code in ads index file * fix: table no data hover effect removed Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> * feat: Banner message component migrated to design system (#17327) * feat: Banner image component migrated to design system * Version update for design system package * design system version updated Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> * feat: Tabs component migrated to design system (#17321) * feat: Tabs component migrated to design system * design system package version updated * Update app/client/src/components/editorComponents/form/FormDialogComponent.tsx * Update app/client/src/pages/Editor/PropertyPane/PropertyPaneTab.tsx * Tab component expand issue fix Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> Co-authored-by: Albin <albin@appsmith.com> Co-authored-by: albinAppsmith <87797149+albinAppsmith@users.noreply.github.com>
122 lines
3.2 KiB
TypeScript
122 lines
3.2 KiB
TypeScript
import React, { useCallback, useState } from "react";
|
|
import styled from "styled-components";
|
|
import {
|
|
Button,
|
|
FilePickerV2,
|
|
FileType,
|
|
SetProgress,
|
|
Size,
|
|
} from "design-system";
|
|
import { StyledDialog } from "./ForkModalStyles";
|
|
import { useSelector } from "store";
|
|
import { useDispatch } from "react-redux";
|
|
import { importApplication } from "actions/applicationActions";
|
|
import { Toaster } from "design-system";
|
|
import { Variant } from "components/ads/common";
|
|
import { IMPORT_APPLICATION_MODAL_TITLE } from "@appsmith/constants/messages";
|
|
import { getIsImportingApplication } from "selectors/applicationSelectors";
|
|
|
|
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;
|
|
margin-top: ${(props) => props.theme.spaces[6]}px;
|
|
`;
|
|
|
|
const FilePickerWrapper = styled.div`
|
|
width: 100%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
`;
|
|
|
|
type ImportApplicationModalProps = {
|
|
// import?: (file: any) => void;
|
|
workspaceId?: string;
|
|
isModalOpen?: boolean;
|
|
onClose?: () => void;
|
|
};
|
|
|
|
function ImportApplicationModal(props: ImportApplicationModalProps) {
|
|
const { isModalOpen, onClose, workspaceId } = props;
|
|
const [appFileToBeUploaded, setAppFileToBeUploaded] = useState<{
|
|
file: File;
|
|
setProgress: SetProgress;
|
|
} | null>(null);
|
|
const dispatch = useDispatch();
|
|
|
|
const importingApplication = useSelector(getIsImportingApplication);
|
|
|
|
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({
|
|
workspaceId: workspaceId as string,
|
|
applicationFile: file,
|
|
}),
|
|
);
|
|
}, [appFileToBeUploaded, workspaceId]);
|
|
|
|
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>
|
|
<FilePickerV2
|
|
delayedUpload
|
|
fileType={FileType.JSON}
|
|
fileUploader={FileUploader}
|
|
onFileRemoved={onRemoveFile}
|
|
/>
|
|
</FilePickerWrapper>
|
|
<ButtonWrapper>
|
|
<ImportButton
|
|
// category={ButtonCategory.tertiary}
|
|
cypressSelector={"t--workspace-import-app-button"}
|
|
disabled={!appFileToBeUploaded}
|
|
isLoading={importingApplication}
|
|
onClick={onImportApplication}
|
|
size={Size.large}
|
|
text={"IMPORT"}
|
|
/>
|
|
</ButtonWrapper>
|
|
</StyledDialog>
|
|
);
|
|
}
|
|
|
|
export default ImportApplicationModal;
|