Skip to content

Commit edb0cab

Browse files
authored
preview disabled tabs (#4235)
1 parent 233683c commit edb0cab

File tree

8 files changed

+152
-47
lines changed

8 files changed

+152
-47
lines changed

dashboard/src/assets/lock.svg

Lines changed: 3 additions & 0 deletions
Loading

dashboard/src/main/home/Home.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,7 @@ const Home: React.FC<Props> = (props) => {
580580
path={"/project-settings"}
581581
render={() => <GuardedProjectSettings />}
582582
/>
583-
{currentProject?.validate_apply_v2 &&
584-
currentProject.preview_envs_enabled ? (
583+
{currentProject?.validate_apply_v2 && (
585584
<>
586585
<Route exact path="/preview-environments/configure">
587586
<SetupApp />
@@ -602,7 +601,7 @@ const Home: React.FC<Props> = (props) => {
602601
<PreviewEnvs />
603602
</Route>
604603
</>
605-
) : null}
604+
)}
606605
<Route path={"*"} render={() => <LaunchWrapper />} />
607606
</Switch>
608607
</ViewWrapper>

dashboard/src/main/home/cluster-dashboard/preview-environments/v2/PreviewEnvs.tsx

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from "react";
1+
import React, { useState, useContext } from "react";
22
import styled from "styled-components";
33
import { match } from "ts-pattern";
44

@@ -12,17 +12,22 @@ import PullRequestIcon from "assets/pull_request_icon.svg";
1212
import DashboardHeader from "../../DashboardHeader";
1313
import { ConfigurableAppList } from "./ConfigurableAppList";
1414
import PreviewEnvGrid from "./PreviewEnvGrid";
15+
import { Context } from "shared/Context";
16+
import ClusterProvisioningPlaceholder from "components/ClusterProvisioningPlaceholder";
17+
import DashboardPlaceholder from "components/porter/DashboardPlaceholder";
18+
import Text from "components/porter/Text";
1519

1620
const tabs = ["environments", "config"] as const;
1721
export type ValidTab = (typeof tabs)[number];
1822

1923
const PreviewEnvs: React.FC = () => {
24+
const { currentProject, currentCluster } = useContext(Context);
2025
const [tab, setTab] = useState<ValidTab>("environments");
2126

2227
const { deploymentTargetList, isDeploymentTargetListLoading } =
2328
useDeploymentTargetList({ preview: true });
2429

25-
const renderContents = (): JSX.Element => {
30+
const renderTab = (): JSX.Element => {
2631
if (isDeploymentTargetListLoading) {
2732
return <Loading offset="-150px" />;
2833
}
@@ -38,30 +43,69 @@ const PreviewEnvs: React.FC = () => {
3843
.exhaustive();
3944
};
4045

46+
const renderContents = (): JSX.Element => {
47+
if (currentCluster?.status === "UPDATING_UNAVAILABLE") {
48+
return <ClusterProvisioningPlaceholder />;
49+
}
50+
51+
if (currentProject?.sandbox_enabled) {
52+
return (
53+
<DashboardPlaceholder>
54+
<Text size={16}>Preview apps are not enabled for sandbox users</Text>
55+
<Spacer y={0.5} />
56+
57+
<Text color={"helper"}>
58+
Eject to your own cloud account to enable preview apps.
59+
</Text>
60+
</DashboardPlaceholder>
61+
);
62+
}
63+
64+
if (!currentProject?.db_enabled) {
65+
return (
66+
<DashboardPlaceholder>
67+
<Text size={16}>Preview apps are not enabled for this project</Text>
68+
<Spacer y={0.5} />
69+
70+
<Text color={"helper"}>
71+
Reach out to [email protected] to enable preview apps on your project.
72+
</Text>
73+
</DashboardPlaceholder>
74+
);
75+
}
76+
77+
return (
78+
<>
79+
<TabSelector
80+
noBuffer
81+
options={[
82+
{ label: "Existing Previews", value: "environments" },
83+
{ label: "Preview Templates", value: "config" },
84+
]}
85+
currentTab={tab}
86+
setCurrentTab={(tab: string) => {
87+
if (tab === "environments") {
88+
setTab("environments");
89+
return;
90+
}
91+
setTab("config");
92+
}}
93+
/>
94+
<Spacer y={1} />
95+
{renderTab()}
96+
</>
97+
)
98+
}
99+
41100
return (
42101
<StyledAppDashboard>
43102
<DashboardHeader
44103
image={PullRequestIcon}
45-
title="Preview Apps"
104+
title="Preview apps"
105+
capitalize={false}
46106
description="Preview apps are created for each pull request. They are automatically deleted when the pull request is closed."
47107
disableLineBreak
48108
/>
49-
<TabSelector
50-
noBuffer
51-
options={[
52-
{ label: "Existing Previews", value: "environments" },
53-
{ label: "Preview Templates", value: "config" },
54-
]}
55-
currentTab={tab}
56-
setCurrentTab={(tab: string) => {
57-
if (tab === "environments") {
58-
setTab("environments");
59-
return;
60-
}
61-
setTab("config");
62-
}}
63-
/>
64-
<Spacer y={1} />
65109
{renderContents()}
66110
<Spacer y={5} />
67111
</StyledAppDashboard>

dashboard/src/main/home/compliance-dashboard/ComplianceDashboard.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { ConfigSelectors } from "./ConfigSelectors";
1414
import { ProfileHeader } from "./ProfileHeader";
1515
import { SOC2CostConsent } from "./SOC2CostConsent";
1616
import { VendorChecksList } from "./VendorChecksList";
17+
import DashboardPlaceholder from "components/porter/DashboardPlaceholder";
18+
import Text from "components/porter/Text";
1719

1820
const ComplianceDashboard: React.FC = () => {
1921
const { currentProject, currentCluster } = useContext(Context);
@@ -38,6 +40,24 @@ const ComplianceDashboard: React.FC = () => {
3840
/>
3941
{currentCluster?.status === "UPDATING_UNAVAILABLE" ? (
4042
<ClusterProvisioningPlaceholder />
43+
) : currentProject?.sandbox_enabled ? (
44+
<DashboardPlaceholder>
45+
<Text size={16}>Compliance is not enabled for sandbox users</Text>
46+
<Spacer y={0.5} />
47+
48+
<Text color={"helper"}>
49+
Eject to your own cloud account to enable the Compliance dashboard.
50+
</Text>
51+
</DashboardPlaceholder>
52+
) : !currentProject?.soc2_controls_enabled ? (
53+
<DashboardPlaceholder>
54+
<Text size={16}>Compliance is not enabled for this project</Text>
55+
<Spacer y={0.5} />
56+
57+
<Text color={"helper"}>
58+
Reach out to [email protected] to enable the Compliance dashboard on your project.
59+
</Text>
60+
</DashboardPlaceholder>
4161
) : (
4262
<>
4363
<ConfigSelectors />

dashboard/src/main/home/database-dashboard/DatabaseDashboard.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { getDatastoreIcon, getEngineIcon } from "./icons";
3737
import EngineTag from "./tags/EngineTag";
3838

3939
const DatabaseDashboard: React.FC = () => {
40-
const { currentCluster } = useContext(Context);
40+
const { currentProject, currentCluster } = useContext(Context);
4141
const { clusters, isLoading: isLoadingClusters } = useClusterList();
4242

4343
const [searchValue, setSearchValue] = useState("");
@@ -111,6 +111,32 @@ const DatabaseDashboard: React.FC = () => {
111111
return <ClusterProvisioningPlaceholder />;
112112
}
113113

114+
if (currentProject?.sandbox_enabled) {
115+
return (
116+
<DashboardPlaceholder>
117+
<Text size={16}>Databases are not enabled for sandbox users</Text>
118+
<Spacer y={0.5} />
119+
120+
<Text color={"helper"}>
121+
Eject to your own cloud account to enable managed databases.
122+
</Text>
123+
</DashboardPlaceholder>
124+
);
125+
}
126+
127+
if (!currentProject?.db_enabled) {
128+
return (
129+
<DashboardPlaceholder>
130+
<Text size={16}>Databases are not enabled for this project</Text>
131+
<Spacer y={0.5} />
132+
133+
<Text color={"helper"}>
134+
Reach out to [email protected] to enable managed databases on your project.
135+
</Text>
136+
</DashboardPlaceholder>
137+
);
138+
}
139+
114140
if (datastores.length === 0) {
115141
return (
116142
<DashboardPlaceholder>

dashboard/src/main/home/sidebar/Sidebar.tsx

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import { withAuth, type WithAuthProps } from "shared/auth/AuthorizationHoc";
2727
import SidebarLink from "./SidebarLink";
2828
import { overrideInfraTabEnabled } from "utils/infrastructure";
2929
import ClusterListContainer from "./ClusterListContainer";
30+
import lock from "assets/lock.svg";
31+
import Image from "components/porter/Image";
3032

3133
type PropsType = RouteComponentProps &
3234
WithAuthProps & {
@@ -286,15 +288,19 @@ class Sidebar extends Component<PropsType, StateType> {
286288
<Img src={applications} />
287289
Applications
288290
</NavButton>
289-
{currentProject.db_enabled && (
290-
<NavButton
291-
path="/datastores"
292-
active={window.location.pathname.startsWith("/apps")}
293-
>
294-
<Img src={database} />
295-
Datastores
296-
</NavButton>
297-
)}
291+
<NavButton
292+
path="/datastores"
293+
active={window.location.pathname.startsWith("/apps")}
294+
>
295+
<Img src={database} />
296+
Datastores
297+
{(currentProject.sandbox_enabled || !currentProject.db_enabled) && (
298+
<Container row>
299+
<Spacer inline width="15px" />
300+
<Image size={15} src={lock} />
301+
</Container>
302+
)}
303+
</NavButton>
298304
<NavButton
299305
path="/addons"
300306
active={window.location.pathname.startsWith("/addons")}
@@ -325,21 +331,29 @@ class Sidebar extends Component<PropsType, StateType> {
325331
</NavButton>
326332
)}
327333

328-
{currentProject.preview_envs_enabled && (
329-
<NavButton path="/preview-environments">
330-
<Img src={pr_icon} />
331-
Preview apps
332-
</NavButton>
334+
<NavButton path="/preview-environments">
335+
<Img src={pr_icon} />
336+
Preview apps
337+
{(currentProject.sandbox_enabled || !currentProject.preview_envs_enabled) && (
338+
<Container row>
339+
<Spacer inline width="15px" />
340+
<Image size={15} src={lock} />
341+
</Container>
333342
)}
343+
</NavButton>
334344

335-
{currentProject?.soc2_controls_enabled && (
336-
<NavButton
337-
path="/compliance"
338-
>
339-
<Img src={compliance} />
340-
Compliance
341-
</NavButton>
342-
)}
345+
<NavButton
346+
path="/compliance"
347+
>
348+
<Img src={compliance} />
349+
Compliance
350+
{(currentProject.sandbox_enabled || !currentProject.soc2_controls_enabled) && (
351+
<Container row>
352+
<Spacer inline width="15px" />
353+
<Image size={15} src={lock} />
354+
</Container>
355+
)}
356+
</NavButton>
343357

344358
{this.props.isAuthorized("integrations", "", [
345359
"get",

dashboard/src/shared/types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ export type ProjectType = {
333333
validate_apply_v2: boolean;
334334
managed_deployment_targets_enabled: boolean;
335335
aws_ack_auth_enabled: boolean;
336+
sandbox_enabled: boolean;
336337
roles: Array<{
337338
id: number;
338339
kind: string;

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,8 +1523,6 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
15231523
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
15241524
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15251525
github.com/polyfloyd/go-errorlint v0.0.0-20210722154253-910bb7978349/go.mod h1:wi9BfjxjF/bwiZ701TzmfKu6UKC357IOAtNr0Td0Lvw=
1526-
github.com/porter-dev/api-contracts v0.2.97 h1:JXxg/b0R8hL2IurJAnSakRRSHx4zT9ZQDCqe1gvR0Uc=
1527-
github.com/porter-dev/api-contracts v0.2.97/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
15281526
github.com/porter-dev/api-contracts v0.2.98 h1:bfOmR9SfspEDkO72TF+YewGKvIpW9ZhcC6Nzpt1I9EI=
15291527
github.com/porter-dev/api-contracts v0.2.98/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
15301528
github.com/porter-dev/switchboard v0.0.3 h1:dBuYkiVLa5Ce7059d6qTe9a1C2XEORFEanhbtV92R+M=

0 commit comments

Comments
 (0)