From dc46f664e9065a7d66a696e9c793a8bd586d2594 Mon Sep 17 00:00:00 2001 From: Raditya Harya Date: Fri, 3 May 2024 21:37:39 +0000 Subject: [PATCH] fix: lastrun order & lint --- src/app/api/user/[uid]/workflows/route.ts | 3 +- src/app/layout.tsx | 3 +- src/app/utils/reactFlowToWorkflow.ts | 1 - src/app/workflows/RunsGrid.tsx | 46 +++++---------------- src/app/workflows/WorkflowGrid.tsx | 35 +++++++--------- src/components/main-nav.tsx | 5 +-- src/components/nodes/Filter/RemoveMatch.tsx | 1 - src/hooks/useBasicNodeState.ts | 5 +-- src/middlewares/handlers/userApi.ts | 4 +- src/providers/SWRCacheProvider.tsx | 2 - 10 files changed, 36 insertions(+), 69 deletions(-) diff --git a/src/app/api/user/[uid]/workflows/route.ts b/src/app/api/user/[uid]/workflows/route.ts index 95a84d7..f5af8e4 100644 --- a/src/app/api/user/[uid]/workflows/route.ts +++ b/src/app/api/user/[uid]/workflows/route.ts @@ -53,6 +53,7 @@ export async function GET( completedAt: true, error: true, }, + orderBy: (workflowRuns, { desc }) => [desc(workflowRuns.startedAt)], }, }, }); @@ -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, })), ); diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 4f8b1e0..623b305 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -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"], @@ -24,7 +24,6 @@ export default async function RootLayout({ }: { children: React.ReactNode; }) { - const session = await getServerSession(); return ( diff --git a/src/app/utils/reactFlowToWorkflow.ts b/src/app/utils/reactFlowToWorkflow.ts index d6c6382..08cc4d4 100644 --- a/src/app/utils/reactFlowToWorkflow.ts +++ b/src/app/utils/reactFlowToWorkflow.ts @@ -10,7 +10,6 @@ type ReactFlowToWorkflowInput = { }; function addNodesToWorkflow(nodes, workflow) { - nodes.forEach((node) => { const typeWithoutPostfix = node.type!.split("-")[0]; workflow.operations.push({ diff --git a/src/app/workflows/RunsGrid.tsx b/src/app/workflows/RunsGrid.tsx index 78295ee..3a16ae4 100644 --- a/src/app/workflows/RunsGrid.tsx +++ b/src/app/workflows/RunsGrid.tsx @@ -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, @@ -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); @@ -68,22 +51,15 @@ interface PlaylistCardProps { }; } - const RunCard = ({ d }) => { return ( - - {d.workflow.name} - - - - - - - - - - + + {d.workflow.name} + + + + ); }; @@ -110,7 +86,7 @@ const CardSkeleton = () => { ); -} +}; export const fetcher = async (url: string) => { const res = await fetch(url); @@ -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, diff --git a/src/app/workflows/WorkflowGrid.tsx b/src/app/workflows/WorkflowGrid.tsx index 42decb5..559a2ba 100644 --- a/src/app/workflows/WorkflowGrid.tsx +++ b/src/app/workflows/WorkflowGrid.tsx @@ -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, @@ -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( @@ -512,7 +505,9 @@ export function WorkflowsGrid({ workflows }: WorkflowTableProps) { ) : data && data.length > 0 ? ( data.map((d) => ) ) : ( -

You have no workflows! Make a new one by clicking the button

+

+ You have no workflows! Make a new one by clicking the button +

)} diff --git a/src/components/main-nav.tsx b/src/components/main-nav.tsx index eb3ea96..0cf14c3 100644 --- a/src/components/main-nav.tsx +++ b/src/components/main-nav.tsx @@ -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; @@ -126,7 +125,7 @@ export function SiteNav({ className, session }: SiteNavProps) {
- +
{session ? (
diff --git a/src/components/nodes/Filter/RemoveMatch.tsx b/src/components/nodes/Filter/RemoveMatch.tsx index 659dc81..f19148b 100644 --- a/src/components/nodes/Filter/RemoveMatch.tsx +++ b/src/components/nodes/Filter/RemoveMatch.tsx @@ -25,7 +25,6 @@ type PlaylistProps = { data: any; }; - const formSchema = z.object({ filterKey: z.string().min(1, { message: "Playlist is required.", diff --git a/src/hooks/useBasicNodeState.ts b/src/hooks/useBasicNodeState.ts index ab9daa9..30bc591 100644 --- a/src/hooks/useBasicNodeState.ts +++ b/src/hooks/useBasicNodeState.ts @@ -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"; @@ -69,14 +69,13 @@ const usePlaylistLogic = (id: string, formSchema?: ZodObject) => { 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}`; diff --git a/src/middlewares/handlers/userApi.ts b/src/middlewares/handlers/userApi.ts index 70e19a9..e757e79 100644 --- a/src/middlewares/handlers/userApi.ts +++ b/src/middlewares/handlers/userApi.ts @@ -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) { diff --git a/src/providers/SWRCacheProvider.tsx b/src/providers/SWRCacheProvider.tsx index b6d2bf2..5d58e5d 100644 --- a/src/providers/SWRCacheProvider.tsx +++ b/src/providers/SWRCacheProvider.tsx @@ -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({