Skip to content
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

init view #395

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"use client";

import type React from "react";
import { useState } from "react";
import { useParams, usePathname, useRouter } from "next/navigation";

import { Tabs, TabsList, TabsTrigger } from "@ctrlplane/ui/tabs";

import { urls } from "~/app/urls";

export const EnvironmentTabs: React.FC = () => {
const { workspaceSlug, systemSlug, environmentId } = useParams<{
workspaceSlug: string;
systemSlug: string;
environmentId: string;
}>();

const environmentUrls = urls
.workspace(workspaceSlug)
.system(systemSlug)
.environment(environmentId);
const baseUrl = environmentUrls.baseUrl();
const overviewUrl = environmentUrls.overview();
const deploymentsUrl = environmentUrls.deployments();
const resourcesUrl = environmentUrls.resources();
const policiesUrl = environmentUrls.policies();

const pathname = usePathname();
const getInitialTab = () => {
if (pathname === policiesUrl) return "policies";
if (pathname === resourcesUrl) return "resources";
if (pathname === deploymentsUrl) return "deployments";
if (pathname === baseUrl) return "overview";
return "overview";
};

const [activeTab, setActiveTab] = useState(getInitialTab());

const router = useRouter();

const onTabChange = (value: string) => {
if (value === "overview") router.push(overviewUrl);
if (value === "deployments") router.push(deploymentsUrl);
if (value === "resources") router.push(resourcesUrl);
if (value === "policies") router.push(policiesUrl);
setActiveTab(value);
};

return (
<Tabs value={activeTab} onValueChange={onTabChange} className="w-full">
<TabsList className="mb-4">
<TabsTrigger value="overview">Overview</TabsTrigger>
<TabsTrigger value="deployments">Deployments</TabsTrigger>
<TabsTrigger value="resources">Resources</TabsTrigger>
<TabsTrigger value="policies">Policies</TabsTrigger>
</TabsList>
</Tabs>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { DeploymentsCard } from "~/app/[workspaceSlug]/(app)/_components/deployments/Card";

export default async function DeploymentsPage(props: {
params: Promise<{ environmentId: string }>;
}) {
const { environmentId } = await props.params;

return (
<div className="container m-8 mx-auto">
<DeploymentsCard environmentId={environmentId} />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { redirect } from "next/navigation";

export default function PoliciesPage(props: {
params: {
workspaceSlug: string;
systemSlug: string;
environmentId: string;
};
}) {
return redirect(
`/${props.params.workspaceSlug}/systems/${props.params.systemSlug}/environments/${props.params.environmentId}/policies/approval`,
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { notFound } from "next/navigation";

import { api } from "~/trpc/server";
import { EditFilterForm } from "./EditFilterForm";

export default async function ResourcesPage(props: {
params: Promise<{ workspaceSlug: string; environmentId: string }>;
}) {
const params = await props.params;
const workspace = await api.workspace.bySlug(params.workspaceSlug);
if (workspace == null) notFound();

const environment = await api.environment.byId(params.environmentId);
if (environment == null) notFound();

return (
<div className="container m-8 mx-auto">
<EditFilterForm environment={environment} workspaceId={workspace.id} />
</div>
);
}
Loading
Loading