Skip to content

fix(site): fix tabs in the template layout #10334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use tabs on template layout
  • Loading branch information
BrunoQuaresma committed Oct 18, 2023
commit 57a8f597f53a7dbce3503ff2b0aede0f0e36cdf0
112 changes: 16 additions & 96 deletions site/src/pages/TemplatePage/TemplateLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { css } from "@emotion/css";
import { useTheme } from "@emotion/react";
import { createContext, type FC, Suspense, useContext } from "react";
import { useQuery } from "react-query";
import { NavLink, Outlet, useNavigate, useParams } from "react-router-dom";
import { Outlet, useNavigate, useParams } from "react-router-dom";
import type { AuthorizationRequest } from "api/typesGenerated";
import {
checkAuthorization,
Expand All @@ -11,10 +10,10 @@ import {
} from "api/api";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { Margins } from "components/Margins/Margins";
import { Stack } from "components/Stack/Stack";
import { Loader } from "components/Loader/Loader";
import { useOrganizationId } from "hooks/useOrganizationId";
import { TemplatePageHeader } from "./TemplatePageHeader";
import { TabLink, Tabs } from "components/Tabs/Tabs";

const templatePermissions = (
templateId: string,
Expand Down Expand Up @@ -85,34 +84,6 @@ export const TemplateLayout: FC<{ children?: JSX.Element }> = ({
return <Loader />;
}

const itemStyles = css`
text-decoration: none;
color: ${theme.palette.text.secondary};
font-size: 14;
display: block;
padding: ${theme.spacing(0, 2, 2)};

&:hover {
color: ${theme.palette.text.primary};
}
`;

const activeItemStyles = css`
${itemStyles}
color: ${theme.palette.text.primary};
position: relative;

&:before {
content: "";
left: 0;
bottom: 0;
height: 2;
width: 100%;
background: ${theme.palette.secondary.dark};
position: absolute;
}
`;

return (
<>
<TemplatePageHeader
Expand All @@ -124,71 +95,20 @@ export const TemplateLayout: FC<{ children?: JSX.Element }> = ({
}}
/>

<div
css={{
borderBottom: `1px solid ${theme.palette.divider}`,
marginBottom: theme.spacing(5),
}}
>
<Margins>
<Stack direction="row" spacing={0.25}>
<NavLink
end
to={`/templates/${templateName}`}
className={({ isActive }) =>
isActive ? activeItemStyles : itemStyles
}
>
Summary
</NavLink>
<NavLink
end
to={`/templates/${templateName}/docs`}
className={({ isActive }) =>
isActive ? activeItemStyles : itemStyles
}
>
Docs
</NavLink>
{data.permissions.canUpdateTemplate && (
<NavLink
to={`/templates/${templateName}/files`}
className={({ isActive }) =>
isActive ? activeItemStyles : itemStyles
}
>
Source Code
</NavLink>
)}
<NavLink
to={`/templates/${templateName}/versions`}
className={({ isActive }) =>
isActive ? activeItemStyles : itemStyles
}
>
Versions
</NavLink>
<NavLink
to={`/templates/${templateName}/embed`}
className={({ isActive }) =>
isActive ? activeItemStyles : itemStyles
}
>
Embed
</NavLink>
{shouldShowInsights && (
<NavLink
to={`/templates/${templateName}/insights`}
className={({ isActive }) =>
isActive ? activeItemStyles : itemStyles
}
>
Insights
</NavLink>
)}
</Stack>
</Margins>
</div>
<Tabs>
<TabLink end to={`/templates/${templateName}`}>
Summary
</TabLink>
<TabLink to={`/templates/${templateName}/docs`}>Docs</TabLink>
{data.permissions.canUpdateTemplate && (
<TabLink to={`/templates/${templateName}/files`}>Source Code</TabLink>
)}
<TabLink to={`/templates/${templateName}/versions`}>Versions</TabLink>
<TabLink to={`/templates/${templateName}/embed`}>Embed</TabLink>
{shouldShowInsights && (
<TabLink to={`/templates/${templateName}/insights`}>Insights</TabLink>
)}
</Tabs>

<Margins>
<TemplateLayoutContext.Provider value={data}>
Expand Down