2023-06-15 05:26:42 +00:00
|
|
|
import {
|
|
|
|
|
FORK_THIS_TEMPLATE,
|
|
|
|
|
GO_BACK,
|
|
|
|
|
createMessage,
|
|
|
|
|
} from "@appsmith/constants/messages";
|
2023-10-12 05:31:22 +00:00
|
|
|
import { templateIdUrl } from "@appsmith/RouteBuilder";
|
2023-06-15 05:26:42 +00:00
|
|
|
import { Button, Link, Text } from "design-system";
|
|
|
|
|
import { useQuery } from "pages/Editor/utils";
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { useSelector } from "react-redux";
|
|
|
|
|
import {
|
|
|
|
|
getActiveTemplateSelector,
|
|
|
|
|
getForkableWorkspaces,
|
2023-11-09 04:19:02 +00:00
|
|
|
isImportingTemplateToAppSelector,
|
2023-06-15 05:26:42 +00:00
|
|
|
} from "selectors/templatesSelectors";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import history from "utils/history";
|
|
|
|
|
import ForkTemplate from "./ForkTemplate";
|
|
|
|
|
|
|
|
|
|
const HeaderWrapper = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const Title = styled(Text)`
|
|
|
|
|
display: inline-block;
|
|
|
|
|
color: var(--ads-v2-color-fg-emphasis-plus);
|
|
|
|
|
`;
|
|
|
|
|
|
2023-10-11 07:35:24 +00:00
|
|
|
interface Props {
|
2023-06-15 05:26:42 +00:00
|
|
|
templateId: string;
|
2023-11-09 04:19:02 +00:00
|
|
|
onClickUseTemplate?: (id: string) => void;
|
|
|
|
|
showBack: boolean;
|
2023-10-11 07:35:24 +00:00
|
|
|
}
|
2023-06-15 05:26:42 +00:00
|
|
|
const SHOW_FORK_MODAL_PARAM = "showForkTemplateModal";
|
|
|
|
|
|
2023-11-09 04:19:02 +00:00
|
|
|
function TemplateViewHeader({
|
|
|
|
|
onClickUseTemplate,
|
|
|
|
|
showBack,
|
|
|
|
|
templateId,
|
|
|
|
|
}: Props) {
|
2023-06-15 05:26:42 +00:00
|
|
|
const currentTemplate = useSelector(getActiveTemplateSelector);
|
|
|
|
|
const query = useQuery();
|
|
|
|
|
const workspaceList = useSelector(getForkableWorkspaces);
|
2023-11-09 04:19:02 +00:00
|
|
|
const isImportingTemplateToApp = useSelector(
|
|
|
|
|
isImportingTemplateToAppSelector,
|
|
|
|
|
);
|
2023-06-15 05:26:42 +00:00
|
|
|
const goBack = () => {
|
|
|
|
|
history.goBack();
|
|
|
|
|
};
|
|
|
|
|
const onForkModalClose = () => {
|
|
|
|
|
history.replace(`${templateIdUrl({ id: templateId })}`);
|
|
|
|
|
};
|
|
|
|
|
const onForkButtonTrigger = () => {
|
2023-11-09 04:19:02 +00:00
|
|
|
if (onClickUseTemplate) {
|
|
|
|
|
onClickUseTemplate(templateId);
|
|
|
|
|
} else {
|
|
|
|
|
history.replace(
|
|
|
|
|
`${templateIdUrl({ id: templateId })}?${SHOW_FORK_MODAL_PARAM}=true`,
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-06-15 05:26:42 +00:00
|
|
|
};
|
|
|
|
|
return (
|
|
|
|
|
<HeaderWrapper>
|
2023-11-09 04:19:02 +00:00
|
|
|
{showBack && (
|
|
|
|
|
<Link
|
|
|
|
|
data-testid="t--template-view-goback"
|
|
|
|
|
onClick={goBack}
|
|
|
|
|
startIcon="arrow-left-line"
|
|
|
|
|
>
|
|
|
|
|
{createMessage(GO_BACK)}
|
|
|
|
|
</Link>
|
|
|
|
|
)}
|
2023-06-15 05:26:42 +00:00
|
|
|
<Title kind="heading-l" renderAs="h1">
|
|
|
|
|
{currentTemplate?.title}
|
|
|
|
|
</Title>
|
|
|
|
|
<section>
|
|
|
|
|
{!!workspaceList.length && (
|
|
|
|
|
<ForkTemplate
|
|
|
|
|
onClose={onForkModalClose}
|
|
|
|
|
showForkModal={!!query.get(SHOW_FORK_MODAL_PARAM)}
|
|
|
|
|
templateId={templateId}
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
className="template-fork-button"
|
|
|
|
|
data-testid="template-fork-button"
|
2023-11-09 04:19:02 +00:00
|
|
|
isLoading={onClickUseTemplate && isImportingTemplateToApp}
|
2023-06-15 05:26:42 +00:00
|
|
|
onClick={onForkButtonTrigger}
|
|
|
|
|
size="md"
|
|
|
|
|
startIcon="fork-2"
|
|
|
|
|
>
|
|
|
|
|
{createMessage(FORK_THIS_TEMPLATE)}
|
|
|
|
|
</Button>
|
|
|
|
|
</ForkTemplate>
|
|
|
|
|
)}
|
|
|
|
|
</section>
|
|
|
|
|
</HeaderWrapper>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default TemplateViewHeader;
|