PromucFlow_constructor/app/client/src/pages/Applications/ImportApplicationModal.tsx
Tanvi Bhakta 4fca7da51d
fix: ads-v2 fixes (#23543)
## Description

Notion Issues: 

1. Issues with link component:
https://www.notion.so/appsmith/f353d8c6bd664f79ad858a42010cdfc8?v=f04cde23f6424aeb9d5a6e389cd172bd&p=4121a76714cb49f2ba76d20fbeab9766&pm=s
2. GraphQL code editor heading color:
https://www.notion.so/appsmith/f353d8c6bd664f79ad858a42010cdfc8?v=f04cde23f6424aeb9d5a6e389cd172bd&p=82bbeaa2749642268eada28fcf5ec6a6&pm=s
3. tooltip on long JS Object names:
https://www.notion.so/appsmith/f353d8c6bd664f79ad858a42010cdfc8?v=f04cde23f6424aeb9d5a6e389cd172bd&p=353552b086de45329390bd4dfae98ee4&pm=s
4. Multiple scroll bars on response tab:
https://www.notion.so/appsmith/f353d8c6bd664f79ad858a42010cdfc8?v=f04cde23f6424aeb9d5a6e389cd172bd&p=111515d90ec5447687b1b573d64bd6eb&pm=s
5. Save and delete buttons:
https://www.notion.so/appsmith/f353d8c6bd664f79ad858a42010cdfc8?v=f04cde23f6424aeb9d5a6e389cd172bd&p=1ac1fed293994b51b4c31bc44dd2d736&pm=s
6. Js Objects always on tooltip:
https://www.notion.so/appsmith/f353d8c6bd664f79ad858a42010cdfc8?v=f04cde23f6424aeb9d5a6e389cd172bd&p=59f3e5b452d24ab9aa05e9fdd169113f&pm=s
7. Error message alignment:
https://www.notion.so/appsmith/f353d8c6bd664f79ad858a42010cdfc8?v=f04cde23f6424aeb9d5a6e389cd172bd&p=a6f2cc4e79994b77894c0293d50be3b9&pm=s
8. Max width of field on Admin settings page:
https://www.notion.so/appsmith/Text-boxes-too-small-in-Auth-Pages-ef2d0fb97f8247848113f9a419e3da09?pvs=4


Other issues:
1. Added data testid for branch create spinner.
7. Fix: branch name button have a fixed width even if text length is
small.


#### Type of change
- Bug fix (non-breaking change which fixes an issue)


## Testing
>
#### How Has This Been Tested?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [ ] Manual
- [ ] Jest
- [ ] Cypress
>
>
#### 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
- [ ] 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
- [ ] 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:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed

---------

Co-authored-by: Parthvi Goswami <parthvigoswami@Parthvis-MacBook-Pro.local>
Co-authored-by: akash-codemonk <67054171+akash-codemonk@users.noreply.github.com>
Co-authored-by: Preet Sidhu <preetsidhu.bits@gmail.com>
Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com>
Co-authored-by: rahulramesha <rahul@appsmith.com>
Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
Co-authored-by: Vijetha-Kaja <vijetha@appsmith.com>
Co-authored-by: Apple <nandan@thinkify.io>
Co-authored-by: Arsalan Yaldram <arsalanyaldram0211@outlook.com>
Co-authored-by: albinAppsmith <87797149+albinAppsmith@users.noreply.github.com>
Co-authored-by: Aswath K <aswath.sana@gmail.com>
Co-authored-by: Ankita Kinger <ankita@appsmith.com>
Co-authored-by: Aman Agarwal <aman@appsmith.com>
Co-authored-by: Sangeeth Sivan <74818788+berzerkeer@users.noreply.github.com>
Co-authored-by: Saroj <43822041+sarojsarab@users.noreply.github.com>
Co-authored-by: Aishwarya-U-R <91450662+Aishwarya-U-R@users.noreply.github.com>
Co-authored-by: Parthvi <80334441+Parthvi12@users.noreply.github.com>
Co-authored-by: Vijetha-Kaja <119562824+Vijetha-Kaja@users.noreply.github.com>
Co-authored-by: Ayush Pahwa <ayushpahwa96@gmail.com>
Co-authored-by: Rohit Agarwal <rohit_agarwal@live.in>
2023-05-29 13:40:41 +08:00

323 lines
8.6 KiB
TypeScript

import type { ReactNode } from "react";
import React, { useCallback, useEffect, useState } from "react";
import styled, { useTheme, css } from "styled-components";
import { useDispatch, useSelector } from "react-redux";
import {
importApplication,
setWorkspaceIdForImport,
} from "@appsmith/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,
UPLOADING_APPLICATION,
UPLOADING_JSON,
} from "@appsmith/constants/messages";
import type { SetProgress } from "design-system-old";
import { FilePickerV2, FileType } from "design-system-old";
import { setIsGitSyncModalOpen } from "actions/gitSyncActions";
import { GitSyncModalTab } from "entities/GitSync";
import { getIsImportingApplication } from "@appsmith/selectors/applicationSelectors";
import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants";
import Statusbar from "pages/Editor/gitSync/components/Statusbar";
import AnalyticsUtil from "utils/AnalyticsUtil";
import type { Theme } from "constants/DefaultTheme";
import { Icon, Modal, ModalContent, ModalHeader, Text } from "design-system";
const TextWrapper = styled.div`
padding: 0;
margin-bottom: var(--ads-v2-spaces-7);
`;
const Row = styled.div`
display: flex;
padding: 0;
margin: 0;
justify-content: center;
gap: 16px;
`;
const CardStyles = css`
height: 200px;
border: 1px solid var(--ads-v2-color-border);
border-radius: var(--ads-v2-border-radius);
display: flex;
align-items: center;
flex-direction: column;
cursor: pointer;
position: relative;
&:hover {
background: var(--ads-v2-color-bg-subtle);
}
`;
const FileImportCard = styled.div<{ fillCardWidth: boolean }>`
${CardStyles}
width: ${(props) => (props.fillCardWidth ? "100%" : "320px")};
& > div {
background: transparent none;
border: 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: var(--ads-v2-color-bg-muted);
display: flex;
justify-content: center;
margin-top: 35px;
margin-bottom: 32px;
color: var(--ads-v2-color-fg) !important;
svg {
width: ${(props) => props.theme.iconSizes.XL}px;
height: ${(props) => props.theme.iconSizes.XL}px;
path {
color: var(--ads-v2-color-fg) !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: var(--ads-v2-color-fg);
}
&.drag-drop-description {
color: var(--ads-v2-color-fg-muted);
}
}
}
}
`;
const CardWrapper = styled.div`
${CardStyles}
width: 320px;
.ads-v2-icon {
border-radius: 50%;
width: 32px;
height: 32px;
background: var(--ads-v2-color-bg-muted);
display: flex;
justify-content: center;
margin-top: 35px;
margin-bottom: 32px;
}
.ads-v2-text {
max-width: 250px;
text-align: center;
}
.ads-v2-text:last-child {
color: var(--ads-v2-color-fg-muted);
}
`;
const StatusbarWrapper = styled.div`
width: 252px;
height: 240px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.cs-icon {
margin: auto;
border-radius: var(--ads-v2-border-radius-circle);
width: 32px;
height: 32px;
display: flex;
justify-content: center;
margin-bottom: 8px;
background: var(--appsmith-color-black-200);
svg {
width: 20px;
height: 20px;
}
}
.ads-v2-text.importing-app-name {
display: flex;
justify-content: center;
}
`;
function GitImportCard(props: { children?: ReactNode; handler?: () => void }) {
const theme = useTheme() as Theme;
const onClick = useCallback(() => {
AnalyticsUtil.logEvent("GS_IMPORT_VIA_GIT_CARD_CLICK");
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 name={"fork"} size="md" />
<Text kind="body-m" style={{ marginBottom: theme.spaces[4] }}>
{title}
</Text>
<Text kind="body-m">{message}</Text>
{props.children}
</CardWrapper>
);
}
type ImportApplicationModalProps = {
workspaceId?: string;
isModalOpen?: boolean;
onClose?: () => void;
appId?: string;
toApp?: boolean;
};
function ImportApplicationModal(props: ImportApplicationModalProps) {
const { appId, isModalOpen, onClose, toApp = false, workspaceId } = props;
const [appFileToBeUploaded, setAppFileToBeUploaded] = useState<{
file: File;
setProgress: SetProgress;
} | null>(null);
const dispatch = useDispatch();
const onGitImport = useCallback(() => {
onClose && onClose();
dispatch({
type: ReduxActionTypes.GIT_INFO_INIT,
});
dispatch(setWorkspaceIdForImport(workspaceId));
dispatch(
setIsGitSyncModalOpen({
isOpen: true,
tab: GitSyncModalTab.GIT_CONNECTION,
}),
);
// dispatch(setIsReconnectingDatasourcesModalOpen({ isOpen: true }));
}, []);
const importingApplication = useSelector(getIsImportingApplication);
const FileUploader = useCallback(
async (file: File, setProgress: SetProgress) => {
if (!!file) {
setAppFileToBeUploaded({
file,
setProgress,
});
dispatch(
importApplication({
appId: appId as string,
workspaceId: workspaceId as string,
applicationFile: file,
}),
);
} else {
setAppFileToBeUploaded(null);
}
},
[],
);
useEffect(() => {
// finished of importing application
if (appFileToBeUploaded && !importingApplication) {
setAppFileToBeUploaded(null);
onClose && onClose();
// should open "Add credential" modal
}
}, [appFileToBeUploaded, importingApplication]);
const onRemoveFile = useCallback(() => setAppFileToBeUploaded(null), []);
const handleModalClose = (open: boolean) => {
if (!open) {
onClose && onClose();
}
};
return (
<Modal onOpenChange={handleModalClose} open={isModalOpen}>
<ModalContent
className={"t--import-application-modal"}
style={{
width: importingApplication ? "40vw" : "fit-content",
minWidth: "30vw",
}}
>
<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>
);
}
export default ImportApplicationModal;