From 46b029cb0e7483ba93f377ce87b78ce786c3cc1a Mon Sep 17 00:00:00 2001 From: sdairs Date: Sun, 5 Jan 2025 20:59:04 +0000 Subject: [PATCH 1/5] sidebar notoken & perm state, add DS read to read token --- apps/web/src/components/sidebar.tsx | 40 ++++++++++++--------- tinybird/datasources/auth0.datasource | 1 + tinybird/datasources/clerk.datasource | 1 + tinybird/datasources/github.datasource | 1 + tinybird/datasources/gitlab.datasource | 1 + tinybird/datasources/knock.datasource | 1 + tinybird/datasources/mailgun.datasource | 1 + tinybird/datasources/orb.datasource | 1 + tinybird/datasources/pagerduty.datasource | 1 + tinybird/datasources/resend.datasource | 1 + tinybird/datasources/sentry.datasource | 1 + tinybird/datasources/stripe.datasource | 1 + tinybird/datasources/vercel.datasource | 1 + tinybird/datasources/vercel_logs.datasource | 1 + 14 files changed, 36 insertions(+), 17 deletions(-) diff --git a/apps/web/src/components/sidebar.tsx b/apps/web/src/components/sidebar.tsx index 988b3a2..cfa5bc6 100644 --- a/apps/web/src/components/sidebar.tsx +++ b/apps/web/src/components/sidebar.tsx @@ -39,7 +39,7 @@ function AppCard({

{app.name}

- ({state}) + {/* ({state}) */}
@@ -75,28 +75,34 @@ function SidebarContent({ activeAppId }: { activeAppId?: string }) { useEffect(() => { async function fetchToolStates() { - if (!token) return; - setIsLoading(true); - // setError(undefined); - try { - const allStates = await checkToolState(token); + if (!token) { const states = Object.values(TOOLS).map((app) => { - return [app.id, allStates[app.ds]] as const; + return [app.id, 'available'] as const; }); setToolStates(Object.fromEntries(states)); - } catch (error) { - if (error instanceof InvalidTokenError) { - // setError('Invalid token'); - setToken(null); - } else { - console.error('Failed to fetch tool states:', error); - // setError('Failed to fetch tool states'); + } else { + setIsLoading(true); + // setError(undefined); + try { + const allStates = await checkToolState(token); + const states = Object.values(TOOLS).map((app) => { + return [app.id, allStates[app.ds] ?? 'available'] as const; + }); + setToolStates(Object.fromEntries(states)); + } catch (error) { + if (error instanceof InvalidTokenError) { + // setError('Invalid token'); + setToken(null); + } else { + console.error('Failed to fetch tool states:', error); + // setError('Failed to fetch tool states'); + } + } finally { + setIsLoading(false); } - } finally { - setIsLoading(false); } } - if (token) fetchToolStates(); + fetchToolStates(); }, [token, setToken]); return ( diff --git a/tinybird/datasources/auth0.datasource b/tinybird/datasources/auth0.datasource index 8cfad4e..0943c9d 100644 --- a/tinybird/datasources/auth0.datasource +++ b/tinybird/datasources/auth0.datasource @@ -1,4 +1,5 @@ TOKEN "append" APPEND +TOKEN "read" READ # Refer to https://github.com/auth0/auth0-log-schemas and https://auth0.com/docs/deploy-monitor/logs/log-event-type-codes for the type codes diff --git a/tinybird/datasources/clerk.datasource b/tinybird/datasources/clerk.datasource index 0fe5ea7..54d3dc9 100644 --- a/tinybird/datasources/clerk.datasource +++ b/tinybird/datasources/clerk.datasource @@ -1,4 +1,5 @@ TOKEN "append" APPEND +TOKEN "read" READ # Refer to https://clerk.com/docs/webhooks/overview#payload-structure diff --git a/tinybird/datasources/github.datasource b/tinybird/datasources/github.datasource index 5613c80..6a2a78d 100644 --- a/tinybird/datasources/github.datasource +++ b/tinybird/datasources/github.datasource @@ -1,4 +1,5 @@ TOKEN "append" APPEND +TOKEN "read" READ # Refer to https://docs.github.com/en/webhooks/webhook-events-and-payloads diff --git a/tinybird/datasources/gitlab.datasource b/tinybird/datasources/gitlab.datasource index a5da26f..edcc383 100644 --- a/tinybird/datasources/gitlab.datasource +++ b/tinybird/datasources/gitlab.datasource @@ -1,4 +1,5 @@ TOKEN "append" APPEND +TOKEN "read" READ # Refer to https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html diff --git a/tinybird/datasources/knock.datasource b/tinybird/datasources/knock.datasource index 971ac67..77fe3ed 100644 --- a/tinybird/datasources/knock.datasource +++ b/tinybird/datasources/knock.datasource @@ -1,4 +1,5 @@ TOKEN "append" APPEND +TOKEN "read" READ # Refer to https://docs.knock.app/developer-tools/outbound-webhooks/event-types diff --git a/tinybird/datasources/mailgun.datasource b/tinybird/datasources/mailgun.datasource index 7bcd658..0459c57 100644 --- a/tinybird/datasources/mailgun.datasource +++ b/tinybird/datasources/mailgun.datasource @@ -1,4 +1,5 @@ TOKEN "append" APPEND +TOKEN "read" READ # Refer to https://mailgun-docs.redoc.ly/docs/mailgun/user-manual/events/#event-structure diff --git a/tinybird/datasources/orb.datasource b/tinybird/datasources/orb.datasource index 1c4e53a..ff44a38 100644 --- a/tinybird/datasources/orb.datasource +++ b/tinybird/datasources/orb.datasource @@ -1,4 +1,5 @@ TOKEN "append" APPEND +TOKEN "read" READ # Refer to https://docs.withorb.com/guides/integrations-and-exports/webhooks for the `details` schema definition for each resource type diff --git a/tinybird/datasources/pagerduty.datasource b/tinybird/datasources/pagerduty.datasource index 880243b..cbaca23 100644 --- a/tinybird/datasources/pagerduty.datasource +++ b/tinybird/datasources/pagerduty.datasource @@ -1,4 +1,5 @@ TOKEN "append" APPEND +TOKEN "read" READ # Refer to https://developer.pagerduty.com/docs/webhooks-overview#webhook-payload diff --git a/tinybird/datasources/resend.datasource b/tinybird/datasources/resend.datasource index 827a094..2e6cc10 100644 --- a/tinybird/datasources/resend.datasource +++ b/tinybird/datasources/resend.datasource @@ -1,4 +1,5 @@ TOKEN "append" APPEND +TOKEN "read" READ # Refer to https://resend.com/docs/dashboard/webhooks/event-types diff --git a/tinybird/datasources/sentry.datasource b/tinybird/datasources/sentry.datasource index 9942b5f..fa438e0 100644 --- a/tinybird/datasources/sentry.datasource +++ b/tinybird/datasources/sentry.datasource @@ -1,4 +1,5 @@ TOKEN "append" APPEND +TOKEN "read" READ # Refer to https://docs.sentry.io/organization/integrations/integration-platform/webhooks/ for the json schemas diff --git a/tinybird/datasources/stripe.datasource b/tinybird/datasources/stripe.datasource index 143e128..1428dba 100644 --- a/tinybird/datasources/stripe.datasource +++ b/tinybird/datasources/stripe.datasource @@ -1,4 +1,5 @@ TOKEN "append" APPEND +TOKEN "read" READ # Refer to https://docs.stripe.com/api/events/object for the event schemas diff --git a/tinybird/datasources/vercel.datasource b/tinybird/datasources/vercel.datasource index 8a04bb1..d94742c 100644 --- a/tinybird/datasources/vercel.datasource +++ b/tinybird/datasources/vercel.datasource @@ -1,4 +1,5 @@ TOKEN "append" APPEND +TOKEN "read" READ # Refer to https://vercel.com/docs/observability/webhooks-overview#events for the event types and payload schema diff --git a/tinybird/datasources/vercel_logs.datasource b/tinybird/datasources/vercel_logs.datasource index 2c666f2..bfcf6d5 100644 --- a/tinybird/datasources/vercel_logs.datasource +++ b/tinybird/datasources/vercel_logs.datasource @@ -1,4 +1,5 @@ TOKEN "append" APPEND +TOKEN "read" READ # Refer to https://vercel.com/docs/observability/log-drains/log-drains-reference for the logs schema From 1ad33da3c46c9fe1a5729a27e220521ffe0abbbf Mon Sep 17 00:00:00 2001 From: sdairs Date: Sun, 5 Jan 2025 21:08:15 +0000 Subject: [PATCH 2/5] remove color, use icons, change headers --- apps/web/src/components/sidebar.tsx | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/apps/web/src/components/sidebar.tsx b/apps/web/src/components/sidebar.tsx index cfa5bc6..77c067d 100644 --- a/apps/web/src/components/sidebar.tsx +++ b/apps/web/src/components/sidebar.tsx @@ -8,7 +8,7 @@ import { checkToolState, InvalidTokenError } from '@/lib/tinybird'; import { TOOLS, type AppGridItem, type ToolState } from '@/lib/constants'; import { SectionHeader } from '@/components/section-header'; import { ScrollArea } from '@/components/ui/scroll-area'; -import { MessageSquare } from 'lucide-react'; +import { MessageSquare, HardDriveDownload, Settings } from 'lucide-react'; import Image from 'next/image'; function AppCard({ @@ -23,8 +23,8 @@ function AppCard({ isActive: boolean; }) { const stateColors = { - configured: 'border-green-500', - installed: 'border-blue-500', + configured: '', + installed: '', available: '' }; @@ -34,13 +34,14 @@ function AppCard({ href={`/${app.id}${token ? `?token=${token}` : ''}`} > -
- {app.icon_url && {app.name}} +
+
+ {app.icon_url && {app.name}} + {app.name} +
-
-

{app.name}

- {/* ({state}) */} -
+ {state === 'available' && } + {state === 'installed' && }
@@ -141,7 +142,7 @@ function SidebarContent({ activeAppId }: { activeAppId?: string }) { {Object.values(TOOLS).some(app => toolStates[app.id] === 'configured') && (
@@ -164,7 +165,7 @@ function SidebarContent({ activeAppId }: { activeAppId?: string }) { {Object.values(TOOLS).some(app => toolStates[app.id] === 'installed') && (
@@ -187,7 +188,7 @@ function SidebarContent({ activeAppId }: { activeAppId?: string }) { {Object.values(TOOLS).some(app => toolStates[app.id] === 'available') && (
From 0566f2eeddb43d2868be07a0de585aaca77bb8a2 Mon Sep 17 00:00:00 2001 From: sdairs Date: Sun, 5 Jan 2025 21:39:46 +0000 Subject: [PATCH 3/5] collapsible, mobile --- apps/web/src/components/sidebar.tsx | 165 ++++++++++++++++++++------- apps/web/src/components/ui/sheet.tsx | 140 +++++++++++++++++++++++ 2 files changed, 266 insertions(+), 39 deletions(-) create mode 100644 apps/web/src/components/ui/sheet.tsx diff --git a/apps/web/src/components/sidebar.tsx b/apps/web/src/components/sidebar.tsx index 77c067d..01f7d51 100644 --- a/apps/web/src/components/sidebar.tsx +++ b/apps/web/src/components/sidebar.tsx @@ -8,7 +8,9 @@ import { checkToolState, InvalidTokenError } from '@/lib/tinybird'; import { TOOLS, type AppGridItem, type ToolState } from '@/lib/constants'; import { SectionHeader } from '@/components/section-header'; import { ScrollArea } from '@/components/ui/scroll-area'; -import { MessageSquare, HardDriveDownload, Settings } from 'lucide-react'; +import { MessageSquare, HardDriveDownload, Settings, ChevronRight, ChevronLeft, Menu, LayoutDashboard, Download, Plus } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { Sheet, SheetContent, SheetTrigger } from '@/components/ui/sheet'; import Image from 'next/image'; function AppCard({ @@ -16,11 +18,13 @@ function AppCard({ state, token, isActive, + isCollapsed }: { app: AppGridItem; state: ToolState; token?: string | null; isActive: boolean; + isCollapsed?: boolean; }) { const stateColors = { configured: '', @@ -30,19 +34,21 @@ function AppCard({ return ( - -
-
- {app.icon_url && {app.name}} - {app.name} -
-
- {state === 'available' && } - {state === 'installed' && } + +
+
+ {app.icon_url && {app.name}} + {!isCollapsed && {app.name}}
+ {!isCollapsed && ( +
+ {state === 'available' && } + {state === 'installed' && } +
+ )}
@@ -72,7 +78,7 @@ function SidebarContent({ activeAppId }: { activeAppId?: string }) { const [token, setToken] = useQueryState('token'); const [toolStates, setToolStates] = useState>({}); const [isLoading, setIsLoading] = useState(false); - // const [error,setError] = useState(); + const [isCollapsed, setIsCollapsed] = useState(false); useEffect(() => { async function fetchToolStates() { @@ -83,7 +89,6 @@ function SidebarContent({ activeAppId }: { activeAppId?: string }) { setToolStates(Object.fromEntries(states)); } else { setIsLoading(true); - // setError(undefined); try { const allStates = await checkToolState(token); const states = Object.values(TOOLS).map((app) => { @@ -92,11 +97,9 @@ function SidebarContent({ activeAppId }: { activeAppId?: string }) { setToolStates(Object.fromEntries(states)); } catch (error) { if (error instanceof InvalidTokenError) { - // setError('Invalid token'); setToken(null); } else { console.error('Failed to fetch tool states:', error); - // setError('Failed to fetch tool states'); } } finally { setIsLoading(false); @@ -107,17 +110,78 @@ function SidebarContent({ activeAppId }: { activeAppId?: string }) { }, [token, setToken]); return ( -
+ <> + {/* Mobile Menu Button */} + + + + + + + + + + {/* Desktop Sidebar */} + + + ); +} + +// New component for the inner content of the sidebar +function SidebarInner({ + token, + activeAppId, + toolStates, + isLoading, + isCollapsed +}: { + token: string | null | undefined; + activeAppId?: string; + toolStates: Record; + isLoading: boolean; + isCollapsed?: boolean; +}) { + return ( + <>
- tinynest + {isCollapsed ? 'tn' : 'tinynest'}
- + {isLoading ? (

Loading...

@@ -128,11 +192,15 @@ function SidebarContent({ activeAppId }: { activeAppId?: string }) { href={token ? `/chat?token=${token}` : '/chat'} className="block" > - -
- -
-

Chat

+ +
+
+ + {!isCollapsed && ( +
+

Chat

+
+ )}
@@ -141,10 +209,16 @@ function SidebarContent({ activeAppId }: { activeAppId?: string }) { {/* Configured Apps */} {Object.values(TOOLS).some(app => toolStates[app.id] === 'configured') && (
- + {isCollapsed ? ( +
+ +
+ ) : ( + + )}
{Object.values(TOOLS) .filter(app => toolStates[app.id] === 'configured') @@ -155,6 +229,7 @@ function SidebarContent({ activeAppId }: { activeAppId?: string }) { state={toolStates[app.id]} token={token} isActive={app.id === activeAppId} + isCollapsed={isCollapsed} /> ))}
@@ -164,10 +239,16 @@ function SidebarContent({ activeAppId }: { activeAppId?: string }) { {/* Installed Apps */} {Object.values(TOOLS).some(app => toolStates[app.id] === 'installed') && (
- + {isCollapsed ? ( +
+ +
+ ) : ( + + )}
{Object.values(TOOLS) .filter(app => toolStates[app.id] === 'installed') @@ -178,6 +259,7 @@ function SidebarContent({ activeAppId }: { activeAppId?: string }) { state={toolStates[app.id]} token={token} isActive={app.id === activeAppId} + isCollapsed={isCollapsed} /> ))}
@@ -187,10 +269,16 @@ function SidebarContent({ activeAppId }: { activeAppId?: string }) { {/* Available Apps */} {Object.values(TOOLS).some(app => toolStates[app.id] === 'available') && (
- + {isCollapsed ? ( +
+ +
+ ) : ( + + )}
{Object.values(TOOLS) .filter(app => !toolStates[app.id] || toolStates[app.id] === 'available') @@ -201,16 +289,15 @@ function SidebarContent({ activeAppId }: { activeAppId?: string }) { state={toolStates[app.id] || 'available'} token={token} isActive={app.id === activeAppId} + isCollapsed={isCollapsed} /> ))}
)} -
- )} -
+ ); } diff --git a/apps/web/src/components/ui/sheet.tsx b/apps/web/src/components/ui/sheet.tsx new file mode 100644 index 0000000..272cb72 --- /dev/null +++ b/apps/web/src/components/ui/sheet.tsx @@ -0,0 +1,140 @@ +"use client" + +import * as React from "react" +import * as SheetPrimitive from "@radix-ui/react-dialog" +import { cva, type VariantProps } from "class-variance-authority" +import { X } from "lucide-react" + +import { cn } from "@/lib/utils" + +const Sheet = SheetPrimitive.Root + +const SheetTrigger = SheetPrimitive.Trigger + +const SheetClose = SheetPrimitive.Close + +const SheetPortal = SheetPrimitive.Portal + +const SheetOverlay = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +SheetOverlay.displayName = SheetPrimitive.Overlay.displayName + +const sheetVariants = cva( + "fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=open]:animate-in data-[state=closed]:animate-out", + { + variants: { + side: { + top: "inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top", + bottom: + "inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom", + left: "inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm", + right: + "inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm", + }, + }, + defaultVariants: { + side: "right", + }, + } +) + +interface SheetContentProps + extends React.ComponentPropsWithoutRef, + VariantProps {} + +const SheetContent = React.forwardRef< + React.ElementRef, + SheetContentProps +>(({ side = "right", className, children, ...props }, ref) => ( + + + + + + Close + + {children} + + +)) +SheetContent.displayName = SheetPrimitive.Content.displayName + +const SheetHeader = ({ + className, + ...props +}: React.HTMLAttributes) => ( +
+) +SheetHeader.displayName = "SheetHeader" + +const SheetFooter = ({ + className, + ...props +}: React.HTMLAttributes) => ( +
+) +SheetFooter.displayName = "SheetFooter" + +const SheetTitle = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +SheetTitle.displayName = SheetPrimitive.Title.displayName + +const SheetDescription = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +SheetDescription.displayName = SheetPrimitive.Description.displayName + +export { + Sheet, + SheetPortal, + SheetOverlay, + SheetTrigger, + SheetClose, + SheetContent, + SheetHeader, + SheetFooter, + SheetTitle, + SheetDescription, +} From e7850b30fc91f8f19732b6408673f3bfa6e26aae Mon Sep 17 00:00:00 2001 From: sdairs Date: Sun, 5 Jan 2025 21:41:42 +0000 Subject: [PATCH 4/5] err on mobile --- apps/web/src/components/sidebar.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/sidebar.tsx b/apps/web/src/components/sidebar.tsx index 01f7d51..bb47f6a 100644 --- a/apps/web/src/components/sidebar.tsx +++ b/apps/web/src/components/sidebar.tsx @@ -10,7 +10,7 @@ import { SectionHeader } from '@/components/section-header'; import { ScrollArea } from '@/components/ui/scroll-area'; import { MessageSquare, HardDriveDownload, Settings, ChevronRight, ChevronLeft, Menu, LayoutDashboard, Download, Plus } from 'lucide-react'; import { Button } from '@/components/ui/button'; -import { Sheet, SheetContent, SheetTrigger } from '@/components/ui/sheet'; +import { Sheet, SheetContent, SheetTrigger, SheetTitle } from '@/components/ui/sheet'; import Image from 'next/image'; function AppCard({ @@ -119,6 +119,7 @@ function SidebarContent({ activeAppId }: { activeAppId?: string }) { + Navigation Menu Date: Mon, 6 Jan 2025 11:12:35 +0000 Subject: [PATCH 5/5] fix build err --- apps/web/src/components/sidebar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/src/components/sidebar.tsx b/apps/web/src/components/sidebar.tsx index bb47f6a..345c283 100644 --- a/apps/web/src/components/sidebar.tsx +++ b/apps/web/src/components/sidebar.tsx @@ -8,7 +8,7 @@ import { checkToolState, InvalidTokenError } from '@/lib/tinybird'; import { TOOLS, type AppGridItem, type ToolState } from '@/lib/constants'; import { SectionHeader } from '@/components/section-header'; import { ScrollArea } from '@/components/ui/scroll-area'; -import { MessageSquare, HardDriveDownload, Settings, ChevronRight, ChevronLeft, Menu, LayoutDashboard, Download, Plus } from 'lucide-react'; +import { MessageSquare, HardDriveDownload, Settings, ChevronRight, ChevronLeft, Menu, LayoutDashboard, Plus } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Sheet, SheetContent, SheetTrigger, SheetTitle } from '@/components/ui/sheet'; import Image from 'next/image';