## Description Rename `design-system` package to `@appsmith/ads` ## Automation /ok-to-test tags="@tag.All" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/10319507327> > Commit: 65d9664dd75b750496458a6e1652e0da858e1fc6 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10319507327&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Fri, 09 Aug 2024 13:47:50 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No
123 lines
3.3 KiB
TypeScript
123 lines
3.3 KiB
TypeScript
import { templateIdUrl } from "ee/RouteBuilder";
|
|
import {
|
|
FORK_THIS_TEMPLATE,
|
|
FORK_THIS_TEMPLATE_BUILDING_BLOCK,
|
|
GO_BACK,
|
|
createMessage,
|
|
} from "ee/constants/messages";
|
|
import { Button, Link, Text } from "@appsmith/ads";
|
|
import { useQuery } from "pages/Editor/utils";
|
|
import React from "react";
|
|
import { useSelector } from "react-redux";
|
|
import {
|
|
getActiveTemplateSelector,
|
|
getForkableWorkspaces,
|
|
isImportingTemplateSelector,
|
|
isImportingTemplateToAppSelector,
|
|
} from "selectors/templatesSelectors";
|
|
import styled from "styled-components";
|
|
import history from "utils/history";
|
|
import ForkTemplate from "./ForkTemplate";
|
|
import { TEMPLATE_BUILDING_BLOCKS_FILTER_FUNCTION_VALUE } from "./constants";
|
|
|
|
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);
|
|
`;
|
|
|
|
interface Props {
|
|
handleBackPress?: () => void;
|
|
templateId: string;
|
|
onClickUseTemplate?: (id: string) => void;
|
|
showBack: boolean;
|
|
}
|
|
const SHOW_FORK_MODAL_PARAM = "showForkTemplateModal";
|
|
|
|
function TemplateViewHeader({
|
|
handleBackPress,
|
|
onClickUseTemplate,
|
|
showBack,
|
|
templateId,
|
|
}: Props) {
|
|
const currentTemplate = useSelector(getActiveTemplateSelector);
|
|
const query = useQuery();
|
|
const workspaceList = useSelector(getForkableWorkspaces);
|
|
const isImportingTemplateToApp = useSelector(
|
|
isImportingTemplateToAppSelector,
|
|
);
|
|
const isImportingTemplate = useSelector(isImportingTemplateSelector);
|
|
const goBack = () => {
|
|
if (handleBackPress) {
|
|
handleBackPress();
|
|
} else {
|
|
history.goBack();
|
|
}
|
|
};
|
|
const onForkModalClose = () => {
|
|
history.replace(`${templateIdUrl({ id: templateId })}`);
|
|
};
|
|
const onForkButtonTrigger = () => {
|
|
if (onClickUseTemplate) {
|
|
onClickUseTemplate(templateId);
|
|
} else {
|
|
history.replace(
|
|
`${templateIdUrl({ id: templateId })}?${SHOW_FORK_MODAL_PARAM}=true`,
|
|
);
|
|
}
|
|
};
|
|
|
|
const FORK_BUTTON_TEXT = currentTemplate?.functions.includes(
|
|
TEMPLATE_BUILDING_BLOCKS_FILTER_FUNCTION_VALUE,
|
|
)
|
|
? FORK_THIS_TEMPLATE_BUILDING_BLOCK
|
|
: FORK_THIS_TEMPLATE;
|
|
|
|
return (
|
|
<HeaderWrapper>
|
|
{showBack && (
|
|
<Link
|
|
data-testid="t--template-view-goback"
|
|
onClick={goBack}
|
|
startIcon="arrow-left-line"
|
|
>
|
|
{createMessage(GO_BACK)}
|
|
</Link>
|
|
)}
|
|
<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"
|
|
isLoading={
|
|
onClickUseTemplate &&
|
|
(isImportingTemplateToApp || isImportingTemplate)
|
|
}
|
|
onClick={onForkButtonTrigger}
|
|
size="md"
|
|
startIcon="fork-2"
|
|
>
|
|
{createMessage(FORK_BUTTON_TEXT)}
|
|
</Button>
|
|
</ForkTemplate>
|
|
)}
|
|
</section>
|
|
</HeaderWrapper>
|
|
);
|
|
}
|
|
|
|
export default TemplateViewHeader;
|