Skip to content

Commit

Permalink
fix: lastrun order & lint
Browse files Browse the repository at this point in the history
  • Loading branch information
radityaharya committed May 3, 2024
1 parent a2727e4 commit dc46f66
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 69 deletions.
3 changes: 2 additions & 1 deletion src/app/api/user/[uid]/workflows/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export async function GET(
completedAt: true,
error: true,
},
orderBy: (workflowRuns, { desc }) => [desc(workflowRuns.startedAt)],
},
},
});
Expand All @@ -68,7 +69,7 @@ export async function GET(
workflow: workflow && JSON.parse(workflow),
createdAt: createdAt?.getTime(),
lastRunAt: workflowRuns[0]?.startedAt?.getTime(),
runs: workflowRuns
runs: workflowRuns,
})),
);

Expand Down
3 changes: 1 addition & 2 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import "~/styles/globals.css";

import { Toaster } from "@/components/ui/sonner";
import { getServerSession } from "next-auth";
import { Inter } from "next/font/google";
import { SiteNav } from "~/components/main-nav";
import NextAuthProvider from "~/providers/NextAuthProvider";
import SWRCacheProvider from "~/providers/SWRCacheProvider";
import { getServerSession } from 'next-auth';

const inter = Inter({
subsets: ["latin"],
Expand All @@ -24,7 +24,6 @@ export default async function RootLayout({
}: {
children: React.ReactNode;
}) {

const session = await getServerSession();

return (
Expand Down
1 change: 0 additions & 1 deletion src/app/utils/reactFlowToWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ type ReactFlowToWorkflowInput = {
};

function addNodesToWorkflow(nodes, workflow) {

nodes.forEach((node) => {
const typeWithoutPostfix = node.type!.split("-")[0];
workflow.operations.push({
Expand Down
46 changes: 11 additions & 35 deletions src/app/workflows/RunsGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
"use client";

import { formatDistanceToNow } from "date-fns";
import {
ArrowUpDown,
Calendar,
ChevronsUpDown,
RefreshCcw,
} from "lucide-react";
import Image from "next/image";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useState } from "react";
import useSWR from "swr";
import { Button, buttonVariants } from "~/components/ui/button";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import { formatDistanceToNow } from "date-fns";
import { useState } from "react";
import useSWR from "swr";
import {
Card,
CardContent,
Expand All @@ -33,8 +18,6 @@ import {
CardTitle,
} from "~/components/ui/card";
import { Skeleton } from "~/components/ui/skeleton";
import { like } from "drizzle-orm";


function relativeDate(date: number) {
const dateObj = new Date(date);
Expand Down Expand Up @@ -68,22 +51,15 @@ interface PlaylistCardProps {
};
}


const RunCard = ({ d }) => {
return (
<Card>
<CardHeader>
<CardTitle className="text-base">{d.workflow.name}</CardTitle>
<CardDescription className="text-balance">

</CardDescription>
</CardHeader>
<CardContent>

</CardContent>
<CardFooter className="text-muted-foreground text-sm flex flex-col gap-2 items-start">

</CardFooter>
<CardHeader>
<CardTitle className="text-base">{d.workflow.name}</CardTitle>
<CardDescription className="text-balance"></CardDescription>
</CardHeader>
<CardContent></CardContent>
<CardFooter className="text-muted-foreground text-sm flex flex-col gap-2 items-start"></CardFooter>
</Card>
);
};
Expand All @@ -110,7 +86,7 @@ const CardSkeleton = () => {
</CardFooter>
</Card>
);
}
};

export const fetcher = async (url: string) => {
const res = await fetch(url);
Expand All @@ -125,7 +101,7 @@ export const fetcher = async (url: string) => {
throw error;
}

const data = await res.json() as Workflow.WorkflowResponse[];
const data = (await res.json()) as Workflow.WorkflowResponse[];
// return data.map((workflow) => {
// return {
// id: workflow.id,
Expand Down
35 changes: 15 additions & 20 deletions src/app/workflows/WorkflowGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
"use client";

import { formatDistanceToNow } from "date-fns";
import {
ArrowUpDown,
Calendar,
ChevronsUpDown,
Clock,
RefreshCcw,
} from "lucide-react";
import Image from "next/image";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useState } from "react";
import useSWR, { mutate } from "swr";
import { Button, buttonVariants } from "~/components/ui/button";
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import { formatDistanceToNow } from "date-fns";
import { ArrowUpDown, Calendar, ChevronsUpDown, Clock } from "lucide-react";
import Image from "next/image";
import Link from "next/link";
import { useState } from "react";
import useSWR from "swr";
import { Badge } from "~/components/ui/badge";
import { Button, buttonVariants } from "~/components/ui/button";
import {
Card,
CardContent,
Expand All @@ -34,7 +28,6 @@ import {
CardTitle,
} from "~/components/ui/card";
import { Skeleton } from "~/components/ui/skeleton";
import { Badge } from "~/components/ui/badge";
import { runWorkflow } from "../utils/runWorkflow";

function getTargets(
Expand Down Expand Up @@ -512,7 +505,9 @@ export function WorkflowsGrid({ workflows }: WorkflowTableProps) {
) : data && data.length > 0 ? (
data.map((d) => <WorkflowCard key={d.id} d={d} />)
) : (
<p className="text-muted-foreground">You have no workflows! Make a new one by clicking the button</p>
<p className="text-muted-foreground">
You have no workflows! Make a new one by clicking the button
</p>
)}
</div>
</div>
Expand Down
5 changes: 2 additions & 3 deletions src/components/main-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import { usePathname } from "next/navigation";
import { buttonVariants } from "~/components/ui/button";

import { cn } from "@/lib/utils";
import { useSession } from "next-auth/react";
import { Avatar, AvatarFallback, AvatarImage } from "./ui/avatar";

import useStore from "@/app/states/store";
import { useMemo } from "react";
import { Session } from "next-auth";
import { useMemo } from "react";

interface NavLinkProps extends LinkProps {
href: string;
Expand Down Expand Up @@ -126,7 +125,7 @@ export function SiteNav({ className, session }: SiteNavProps) {
<MainNav />
<div className="flex flex-row gap-6 items-center">
<div className="hidden sm:block">
<SystemInfo />
<SystemInfo />
</div>
{session ? (
<div className="flex flex-row items-center gap-4">
Expand Down
1 change: 0 additions & 1 deletion src/components/nodes/Filter/RemoveMatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type PlaylistProps = {
data: any;
};


const formSchema = z.object({
filterKey: z.string().min(1, {
message: "Playlist is required.",
Expand Down
5 changes: 2 additions & 3 deletions src/hooks/useBasicNodeState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { useHandleConnections, getIncomers, getOutgoers } from "@xyflow/react";
import { useHandleConnections } from "@xyflow/react";
import { useEffect, useMemo } from "react";
import { useForm } from "react-hook-form";
import { type ZodObject } from "zod";
Expand Down Expand Up @@ -69,14 +69,13 @@ const usePlaylistLogic = (id: string, formSchema?: ZodObject<any>) => {
playlists = [],
} = target as any;


const hasPlaylistId = Boolean(playlistId);
const hasPlaylistIds = Boolean(playlistIds && playlistIds.length > 0);

if (!(hasPlaylistId || hasPlaylistIds)) {
invalidNodesCount++;
}

if (currentNode?.type === "Selector.recommend") {
playlistId = `recommend-${playlistId}`;
name = `[Recommended] ${name}`;
Expand Down
4 changes: 3 additions & 1 deletion src/middlewares/handlers/userApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ export const withUserApi = (
const user = await getUser(request);

if (!user && pathname.startsWith("/workflow")) {
return NextResponse.redirect(new URL("/auth/login", process.env.NEXTAUTH_URL));
return NextResponse.redirect(
new URL("/auth/login", process.env.NEXTAUTH_URL),
);
}

if (!user) {
Expand Down
2 changes: 0 additions & 2 deletions src/providers/SWRCacheProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"use client";

import { SessionProvider } from "next-auth/react";
import { type ReactNode } from "react";
import { SWRConfig } from "swr";
export default function SWRCacheProvider({
Expand Down

0 comments on commit dc46f66

Please sign in to comment.