Skip to content

Commit eca9a8d

Browse files
authored
Merge pull request #32 from diggerhq/feat/project-drift-tab
Add drift tab for project
2 parents a084243 + 9db0271 commit eca9a8d

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { getProjectById, getSlimProjectBySlug } from '@/data/user/projects';
2+
import { projectSlugParamSchema } from '@/utils/zod-schemas/params';
3+
4+
5+
6+
export default async function ProjectSettingsPage({ params }: { params: unknown }) {
7+
const { projectSlug } = projectSlugParamSchema.parse(params);
8+
const projectId = (await getSlimProjectBySlug(projectSlug)).id;
9+
const project = await getProjectById(projectId);
10+
11+
return (
12+
<div className="flex flex-col space-y-4 max-w-5xl mt-2">
13+
<pre className="bg-muted p-4 rounded-md overflow-auto flex-1 max-h-[600px] text-sm whitespace-pre-wrap">
14+
{project.latest_drift_output || "No drift detected as of last run"}
15+
</pre>
16+
</div>
17+
);
18+
}

src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/(specific-project-pages)/layout.tsx

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { PageHeading } from "@/components/PageHeading";
22
import { TabsNavigationV2 } from "@/components/TabsNavigation/TabsNavigation";
33
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
4-
import { getProjectTitleById, getSlimProjectBySlug } from "@/data/user/projects";
5-
import { isLocalEnvironment } from "@/lib/utils";
4+
import { getProjectById, getProjectTitleById, getSlimProjectBySlug } from "@/data/user/projects";
65
import { projectSlugParamSchema } from "@/utils/zod-schemas/params";
7-
import { AlertCircleIcon, GitBranch } from "lucide-react";
6+
import { AlertCircleIcon, ExternalLink, GitBranch } from "lucide-react";
7+
import Link from "next/link";
88
import { Suspense } from "react";
99

1010

@@ -20,11 +20,13 @@ async function ProjectPageHeading({ projectId, branch }: { projectId: string, br
2020

2121
export default async function ProjectPagesLayout({ params, children }: { params: unknown, children: React.ReactNode }) {
2222
const { projectSlug } = projectSlugParamSchema.parse(params);
23-
const project = await getSlimProjectBySlug(projectSlug);
23+
24+
//TODO figure out a better way to access drift, without fetching twice
25+
const projectId = (await getSlimProjectBySlug(projectSlug)).id;
26+
const project = await getProjectById(projectId);
2427

2528

2629

27-
// fetch the drift alerts
2830
const tabs = [
2931
{
3032
label: 'Runs',
@@ -38,17 +40,21 @@ export default async function ProjectPagesLayout({ params, children }: { params:
3840
label: 'Settings',
3941
href: `/project/${projectSlug}/settings`,
4042
},
43+
{
44+
label: 'Drift',
45+
href: `/project/${projectSlug}/drift`,
46+
},
4147
];
4248
return <>
4349
<div className="flex flex-col">
44-
{isLocalEnvironment && (
50+
{project.latest_drift_output && (
4551
<Alert variant="default" className="mb-6 max-w-5xl border-orange-500/50 text-orange-700 dark:border-orange-300/50 dark:text-orange-300 [&>svg]:text-orange-600 dark:[&>svg]:text-orange-400 bg-orange-50 dark:bg-orange-900/10">
4652
<AlertCircleIcon className="h-4 w-4" />
4753
<AlertTitle>
4854
Drift Detected
4955
</AlertTitle>
5056
<AlertDescription>
51-
Changes have been detected in your infrastructure that differ from your Terraform configuration. Please review and reconcile these differences.
57+
Changes have been detected in your infrastructure that differ from your Terraform configuration. <Link href={`/project/${projectSlug}/drift`} className="inline-flex items-center underline underline-offset-2">Review the differences<ExternalLink size={14} className="ml-1 inline-block align-text-bottom" /></Link>
5258
</AlertDescription>
5359
</Alert>
5460
)}

src/lib/database.types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ export type Database = {
277277
digger_job_id: string
278278
digger_job_summary_id: string | null
279279
id: string
280+
is_drift_job: boolean | null
280281
job_spec: string | null
281282
plan_footprint: string | null
282283
pr_comment_url: string | null
@@ -295,6 +296,7 @@ export type Database = {
295296
digger_job_id: string
296297
digger_job_summary_id?: string | null
297298
id?: string
299+
is_drift_job?: boolean | null
298300
job_spec?: string | null
299301
plan_footprint?: string | null
300302
pr_comment_url?: string | null
@@ -313,6 +315,7 @@ export type Database = {
313315
digger_job_id?: string
314316
digger_job_summary_id?: string | null
315317
id?: string
318+
is_drift_job?: boolean | null
316319
job_spec?: string | null
317320
plan_footprint?: string | null
318321
pr_comment_url?: string | null
@@ -1310,6 +1313,7 @@ export type Database = {
13101313
is_managing_state: boolean | null
13111314
labels: string[] | null
13121315
latest_action_on: string | null
1316+
latest_drift_output: string | null
13131317
name: string
13141318
organization_id: string
13151319
project_status: Database["public"]["Enums"]["project_status"]
@@ -1333,6 +1337,7 @@ export type Database = {
13331337
is_managing_state?: boolean | null
13341338
labels?: string[] | null
13351339
latest_action_on?: string | null
1340+
latest_drift_output?: string | null
13361341
name: string
13371342
organization_id: string
13381343
project_status?: Database["public"]["Enums"]["project_status"]
@@ -1356,6 +1361,7 @@ export type Database = {
13561361
is_managing_state?: boolean | null
13571362
labels?: string[] | null
13581363
latest_action_on?: string | null
1364+
latest_drift_output?: string | null
13591365
name?: string
13601366
organization_id?: string
13611367
project_status?: Database["public"]["Enums"]["project_status"]

0 commit comments

Comments
 (0)