Skip to content

Commit

Permalink
feature/run details
Browse files Browse the repository at this point in the history
  • Loading branch information
psiddharthdesign committed Jul 26, 2024
1 parent f41a40c commit 005e0c4
Show file tree
Hide file tree
Showing 13 changed files with 522 additions and 97 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@
"dev:debug": "NODE_OPTIONS='--inspect' next dev",
"email:dev": "email dev",
"start": "next start",
"generate:types": "supabase gen types typescript --linked --schema public > src/lib/database.types.ts",
"generate:types:local": "supabase gen types typescript --local > src/lib/database.types.ts",
"generate:types": "supabase gen types --lang=typescript --linked --schema public > src/lib/database.types.ts",
"generate:types:local": "supabase gen types --lang=typescript --local > src/lib/database.types.ts",
"build": "next build",
"test:e2e": "cross-env NODE_ENV=test playwright test",
"test:e2e:ui": "cross-env NODE_ENV=test playwright test --ui",
Expand Down

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@

import { PageHeading } from "@/components/PageHeading";
import { T } from "@/components/ui/Typography";
import { getLoggedInUserOrganizationRole } from "@/data/user/organizations";
import { getSlimProjectById } from "@/data/user/projects";
import { getRunById } from "@/data/user/runs";
import { getUserProfile } from "@/data/user/user";
import { Table } from "@/types";
import { serverGetLoggedInUser } from "@/utils/server/serverGetLoggedInUser";
import {
runIdParamSchema
} from "@/utils/zod-schemas/params";
import type { Metadata } from "next";
import { Suspense } from "react";
import { RunDetails } from "./RunDetails";
import dynamic from 'next/dynamic';
import { ComponentType, Suspense } from "react";

export const metadata: Metadata = {
title: "Projects",
Expand All @@ -20,22 +25,43 @@ type RunDetailPageProps = {
};
};

type ProjectRunDetailsProps = {
run: Table<'digger_runs'>,
loggedInUser: Table<'user_profiles'>,
isUserOrgAdmin: boolean
}



const DynamicProjectRunDetails = dynamic<ProjectRunDetailsProps>(() =>
import('./ProjectRunDetails').then((mod) => mod.ProjectRunDetails as ComponentType<ProjectRunDetailsProps>),
{ ssr: false }
)


export default async function RunDetailPage({
params,

}: RunDetailPageProps) {
const { runId } = runIdParamSchema.parse(params);
const run = await getRunById(runId);
const project_id = run.project_id;
const [project, user] = await Promise.all([
getSlimProjectById(project_id),
serverGetLoggedInUser()
]);
const userProfile = await getUserProfile(user.id);
const organizationRole = await getLoggedInUserOrganizationRole(project.organization_id);

const isOrganizationAdmin =
organizationRole === "admin" || organizationRole === "owner";
return (
<div className="flex flex-col space-y-4 max-w-5xl mt-8">
<div className="flex flex-col space-y-4 w-full mt-8">
<PageHeading
title="Run Details"
subTitle="Details about the specific project run will be displayed here."
/>
<div className="flex justify-between gap-2">

</div>
{
<Suspense
Expand All @@ -45,7 +71,7 @@ export default async function RunDetailPage({
</T.P>
}
>
<RunDetails run={run} />
<DynamicProjectRunDetails run={run} loggedInUser={userProfile} isUserOrgAdmin={isOrganizationAdmin} />
</Suspense>
}
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import '@/styles/globals.css';
import '@/styles/prosemirror.css';
import { GeistMono } from 'geist/font/mono';
import { GeistSans } from 'geist/font/sans';
import { Metadata } from 'next';
import 'server-only';
Expand All @@ -22,7 +23,7 @@ export default async function RootLayout({
children: React.ReactNode;
}) {
return (
<html lang="en" className={GeistSans.className} suppressHydrationWarning>
<html lang="en" className={`${GeistSans.className} ${GeistMono.variable}`} suppressHydrationWarning>
<head></head>
<body className="">
<AppProviders>{children}</AppProviders>
Expand Down
17 changes: 17 additions & 0 deletions src/data/user/projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,21 @@ export async function updateProjectSettingsAction({
console.error("Error updating project settings:", error);
return { status: 'error', message: 'Failed to update project settings' };
}
}

export async function deleteProject(projectId: string): Promise<SAPayload<unknown>> {
const supabase = createSupabaseUserServerComponentClient();
const { data, error } = await supabase
.from('projects')
.update({
deleted_at: new Date().toISOString(),
})
.eq('id', projectId)
.single();

if (error) {
return { status: 'error', message: error.message };
}

return { status: 'success', data };
}
74 changes: 74 additions & 0 deletions src/data/user/runs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use server';

import { createSupabaseUserServerComponentClient } from '@/supabase-clients/user/createSupabaseUserServerComponentClient';
import { SAPayload } from '@/types';

export async function getTFVarsByProjectId(projectId: string) {
const supabaseClient = createSupabaseUserServerComponentClient();
Expand Down Expand Up @@ -122,3 +123,76 @@ export async function getRunsByProjectId(projectId: string) {
if (error) throw error;
return data;
}

export async function requestRunApproval(
runId: string,
): Promise<SAPayload<string>> {
const supabase = createSupabaseUserServerComponentClient();
const { data, error } = await supabase
.from('digger_runs')
.update({ status: 'pending_approval' })
.eq('id', runId)
.select('id')
.single();

if (error) {
return { status: 'error', message: error.message };
}
return { status: 'success', data: data.id };
}

export async function approveRun(
runId: string,
userId: string,
): Promise<SAPayload<string>> {
const supabase = createSupabaseUserServerComponentClient();
const { data, error } = await supabase
.from('digger_runs')
.update({
status: 'pending_apply',
approver_user_id: userId,
is_approved: true,
})
.eq('id', runId)
.select('id')
.single();

if (error) {
return { status: 'error', message: error.message };
}
return { status: 'success', data: data.id };
}

export async function rejectRun(
runId: string,
userId: string,
): Promise<SAPayload<string>> {
const supabase = createSupabaseUserServerComponentClient();
const { data, error } = await supabase
.from('digger_runs')
.update({
status: 'rejected',
approver_user_id: userId,
is_approved: false,
})
.eq('id', runId)
.select('id')
.single();

if (error) {
return { status: 'error', message: error.message };
}
return { status: 'success', data: data.id };
}

export async function changeRunStatus(runId: string, status: string) {
const supabase = createSupabaseUserServerComponentClient();
const { error } = await supabase
.from('digger_runs')
.update({ status: status })
.eq('id', runId)
.select('id')
.single();

if (error) throw error;
}
Loading

0 comments on commit 005e0c4

Please sign in to comment.