2022-03-03 10:56:53 +00:00
|
|
|
import React, { ReactNode, useState } from "react";
|
2022-10-10 03:54:41 +00:00
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
Category,
|
|
|
|
|
DialogComponent as Dialog,
|
|
|
|
|
Dropdown,
|
|
|
|
|
Size,
|
|
|
|
|
} from "design-system";
|
2022-03-03 10:56:53 +00:00
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
|
|
import { noop } from "lodash";
|
|
|
|
|
import {
|
2022-06-15 15:37:41 +00:00
|
|
|
getForkableWorkspaces,
|
2022-03-03 10:56:53 +00:00
|
|
|
isImportingTemplateSelector,
|
|
|
|
|
} from "selectors/templatesSelectors";
|
|
|
|
|
import styled from "styled-components";
|
2022-06-15 15:37:41 +00:00
|
|
|
import { importTemplateToWorkspace } from "actions/templateActions";
|
2022-03-03 10:56:53 +00:00
|
|
|
import {
|
|
|
|
|
CANCEL,
|
|
|
|
|
CHOOSE_WHERE_TO_FORK,
|
|
|
|
|
createMessage,
|
|
|
|
|
FORK_TEMPLATE,
|
2022-06-15 15:37:41 +00:00
|
|
|
SELECT_WORKSPACE,
|
2022-03-03 10:56:53 +00:00
|
|
|
} from "@appsmith/constants/messages";
|
|
|
|
|
import { Colors } from "constants/Colors";
|
|
|
|
|
import { Classes } from "@blueprintjs/core";
|
|
|
|
|
|
|
|
|
|
const ButtonsWrapper = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
margin-top: ${(props) => props.theme.spaces[11]}px;
|
|
|
|
|
gap: ${(props) => props.theme.spaces[4]}px;
|
|
|
|
|
justify-content: flex-end;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const StyledDialog = styled(Dialog)`
|
|
|
|
|
&& {
|
|
|
|
|
.${Classes.DIALOG_CLOSE_BUTTON} {
|
|
|
|
|
svg {
|
|
|
|
|
width: 29px;
|
|
|
|
|
height: 29px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
interface ForkTemplateProps {
|
|
|
|
|
children: ReactNode;
|
|
|
|
|
showForkModal: boolean;
|
|
|
|
|
onClose: (e?: React.MouseEvent<HTMLElement>) => void;
|
|
|
|
|
templateId: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ForkTemplate({
|
|
|
|
|
children,
|
|
|
|
|
onClose,
|
|
|
|
|
showForkModal,
|
|
|
|
|
templateId,
|
|
|
|
|
}: ForkTemplateProps) {
|
2022-06-15 15:37:41 +00:00
|
|
|
const workspaceList = useSelector(getForkableWorkspaces);
|
|
|
|
|
const [selectedWorkspace, setSelectedWorkspace] = useState(workspaceList[0]);
|
2022-03-03 10:56:53 +00:00
|
|
|
const isImportingTemplate = useSelector(isImportingTemplateSelector);
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
const onFork = () => {
|
2022-06-15 15:37:41 +00:00
|
|
|
dispatch(importTemplateToWorkspace(templateId, selectedWorkspace.value));
|
2022-03-03 10:56:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2022-09-30 13:41:04 +00:00
|
|
|
<>
|
|
|
|
|
{children}
|
|
|
|
|
<StyledDialog
|
|
|
|
|
canOutsideClickClose={!isImportingTemplate}
|
|
|
|
|
headerIcon={{ name: "fork-2", bgColor: Colors.GEYSER_LIGHT }}
|
|
|
|
|
isOpen={showForkModal}
|
|
|
|
|
onClose={isImportingTemplate ? noop : onClose}
|
|
|
|
|
title={createMessage(CHOOSE_WHERE_TO_FORK)}
|
|
|
|
|
>
|
|
|
|
|
<Dropdown
|
|
|
|
|
boundary="viewport"
|
|
|
|
|
dropdownMaxHeight={"200px"}
|
|
|
|
|
fillOptions
|
|
|
|
|
onSelect={(
|
|
|
|
|
_value: any,
|
|
|
|
|
dropdownOption: React.SetStateAction<{
|
|
|
|
|
label: string;
|
|
|
|
|
value: string;
|
|
|
|
|
}>,
|
|
|
|
|
) => setSelectedWorkspace(dropdownOption)}
|
|
|
|
|
options={workspaceList}
|
|
|
|
|
placeholder={createMessage(SELECT_WORKSPACE)}
|
|
|
|
|
selected={selectedWorkspace}
|
|
|
|
|
showLabelOnly
|
|
|
|
|
width={"100%"}
|
2022-03-03 10:56:53 +00:00
|
|
|
/>
|
2022-09-30 13:41:04 +00:00
|
|
|
<ButtonsWrapper>
|
|
|
|
|
<Button
|
|
|
|
|
category={Category.tertiary}
|
|
|
|
|
disabled={isImportingTemplate}
|
|
|
|
|
onClick={onClose}
|
|
|
|
|
size={Size.large}
|
|
|
|
|
tag="button"
|
|
|
|
|
text={createMessage(CANCEL)}
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
className="t--fork-template-button"
|
|
|
|
|
isLoading={isImportingTemplate}
|
|
|
|
|
onClick={onFork}
|
|
|
|
|
size={Size.large}
|
|
|
|
|
tag="button"
|
|
|
|
|
text={createMessage(FORK_TEMPLATE)}
|
|
|
|
|
/>
|
|
|
|
|
</ButtonsWrapper>
|
|
|
|
|
</StyledDialog>
|
|
|
|
|
</>
|
2022-03-03 10:56:53 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ForkTemplate;
|