From 13d111aecb96c29d10db03289736c2889d5e02c0 Mon Sep 17 00:00:00 2001 From: Jules Belveze <32683010+JulesBelveze@users.noreply.github.com> Date: Fri, 17 Jan 2025 10:42:22 +0100 Subject: [PATCH] [front] - refacto: `NewDialog` final wave (#10049) * [front/components/spaces] - refactor: improve data source deletion confirmation UI - Modify the UI layout to include a list with bullet points showing which data sources are in use - Enhance the confirmation prompt with bold text for emphasis [front/hooks] - feature: update useAwaitableDialog to use new dialog components - Implement updated dialog infrastructure with improved UI and accessibility support - Add customization options for dialog buttons including labels and variants - Ensure proper handling of dismiss dialog actions by treating them as a cancel event * [misc] - refactor: update dialog components with new design system - Replaced custom dialog components with new design system dialogs across various components - Removed old dialog components from the codebase as they are no longer used - Updated dialog components to use new `NewDialog` patterns including headers, footers, and content for improved consistency - Migrated to using updated icons and spinner components from `@dust-tt/sparkle` library to align with the new design system --- .../poke/plugins/RunPluginDialog.tsx | 132 +++++++++--------- front/components/poke/shadcn/ui/command.tsx | 18 +-- front/components/poke/shadcn/ui/dialog.tsx | 120 ---------------- .../subscriptions/EnterpriseUpgradeDialog.tsx | 46 +++--- .../EditSpaceManagedDatasourcesViews.tsx | 38 ++--- front/hooks/useAwaitableDialog.tsx | 92 +++++++++--- front/pages/poke/templates/[tId].tsx | 34 +++-- 7 files changed, 211 insertions(+), 269 deletions(-) delete mode 100644 front/components/poke/shadcn/ui/dialog.tsx diff --git a/front/components/poke/plugins/RunPluginDialog.tsx b/front/components/poke/plugins/RunPluginDialog.tsx index c308bc09d8ee..6896e5d8f91a 100644 --- a/front/components/poke/plugins/RunPluginDialog.tsx +++ b/front/components/poke/plugins/RunPluginDialog.tsx @@ -1,4 +1,12 @@ -import { Spinner } from "@dust-tt/sparkle"; +import { + NewDialog, + NewDialogContainer, + NewDialogContent, + NewDialogDescription, + NewDialogHeader, + NewDialogTitle, + Spinner, +} from "@dust-tt/sparkle"; import type { PluginWorkspaceResource } from "@dust-tt/types"; import { AlertCircle } from "lucide-react"; import { useCallback, useState } from "react"; @@ -9,10 +17,6 @@ import { PokeAlertDescription, PokeAlertTitle, } from "@app/components/poke/shadcn/ui/alert"; -import { - PokeDialog, - PokeDialogContent, -} from "@app/components/poke/shadcn/ui/dialog"; import type { PluginListItem, PluginResponse } from "@app/lib/api/poke/types"; import { usePokePluginManifest, useRunPokePlugin } from "@app/poke/swr/plugins"; @@ -63,64 +67,66 @@ export function RunPluginDialog({ ); return ( - - -
-

Run {plugin.name} plugin

-

- {plugin.description} -

-
- {isLoading ? ( - - ) : !manifest ? ( - - - Error - - Plugin could not be loaded. - - - ) : ( - <> - {error && ( - - Error - {error} - - )} - {result && result.display === "text" && ( - - Success - - {result.value} - Make sure to reload. - - - )} - {result && result.display === "json" && ( -
-
Result:
-
-
-                    {JSON.stringify(result.value, null, 2)}
-                  
+ + + + Run {plugin.name} plugin + {plugin.description} + + + {isLoading ? ( + + ) : !manifest ? ( + + + Error + + Plugin could not be loaded. + + + ) : ( + <> + {error && ( + + Error + {error} + + )} + {result && result.display === "text" && ( + + Success + + {result.value} - Make sure to reload. + + + )} + {result && result.display === "json" && ( +
+
Result:
+
+
+                      {JSON.stringify(result.value, null, 2)}
+                    
+
-
- )} - - {manifest.warning && ( - - Warning - {manifest.warning} - - )} - - )} - - + )} + + {manifest.warning && ( + + Warning + + {manifest.warning} + + + )} + + )} + + + ); } diff --git a/front/components/poke/shadcn/ui/command.tsx b/front/components/poke/shadcn/ui/command.tsx index 5f131d058fe4..423d95773334 100644 --- a/front/components/poke/shadcn/ui/command.tsx +++ b/front/components/poke/shadcn/ui/command.tsx @@ -1,16 +1,16 @@ "use client"; -import { MagnifyingGlassIcon } from "@dust-tt/sparkle"; +import { + MagnifyingGlassIcon, + NewDialog, + NewDialogContent, +} from "@dust-tt/sparkle"; import type { DialogProps } from "@radix-ui/react-dialog"; import { Command as CommandPrimitive } from "cmdk"; import Link from "next/link"; import * as React from "react"; import { cn } from "@app/components/poke/shadcn/lib/utils"; -import { - PokeDialog, - PokeDialogContent, -} from "@app/components/poke/shadcn/ui/dialog"; const CommandContext = React.createContext<{ selectedIndex: number; @@ -117,16 +117,16 @@ const CommandDialog = ({ return ( - - + + {children} - - + + ); }; diff --git a/front/components/poke/shadcn/ui/dialog.tsx b/front/components/poke/shadcn/ui/dialog.tsx deleted file mode 100644 index 2bf3974be804..000000000000 --- a/front/components/poke/shadcn/ui/dialog.tsx +++ /dev/null @@ -1,120 +0,0 @@ -import * as DialogPrimitive from "@radix-ui/react-dialog"; -import { XIcon } from "lucide-react"; -import * as React from "react"; - -import { cn } from "@app/components/poke/shadcn/lib/utils"; - -const Dialog = DialogPrimitive.Root; - -const DialogTrigger = DialogPrimitive.Trigger; - -const DialogPortal = DialogPrimitive.Portal; - -const DialogClose = DialogPrimitive.Close; - -const DialogOverlay = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -DialogOverlay.displayName = DialogPrimitive.Overlay.displayName; - -const DialogContent = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, children, ...props }, ref) => ( - - - - {children} - - - Close - - - -)); -DialogContent.displayName = DialogPrimitive.Content.displayName; - -const DialogHeader = ({ - className, - ...props -}: React.HTMLAttributes) => ( -
-); -DialogHeader.displayName = "DialogHeader"; - -const DialogFooter = ({ - className, - ...props -}: React.HTMLAttributes) => ( -
-); -DialogFooter.displayName = "DialogFooter"; - -const DialogTitle = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -DialogTitle.displayName = DialogPrimitive.Title.displayName; - -const DialogDescription = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -DialogDescription.displayName = DialogPrimitive.Description.displayName; - -export { - Dialog as PokeDialog, - DialogClose as PokeDialogClose, - DialogContent as PokeDialogContent, - DialogDescription as PokeDialogDescription, - DialogFooter as PokeDialogFooter, - DialogHeader as PokeDialogHeader, - DialogOverlay as PokeDialogOverlay, - DialogPortal as PokeDialogPortal, - DialogTitle as PokeDialogTitle, - DialogTrigger as PokeDialogTrigger, -}; diff --git a/front/components/poke/subscriptions/EnterpriseUpgradeDialog.tsx b/front/components/poke/subscriptions/EnterpriseUpgradeDialog.tsx index a861171b3ca3..acde59fb5d3a 100644 --- a/front/components/poke/subscriptions/EnterpriseUpgradeDialog.tsx +++ b/front/components/poke/subscriptions/EnterpriseUpgradeDialog.tsx @@ -1,4 +1,13 @@ -import { Spinner } from "@dust-tt/sparkle"; +import { + NewDialog, + NewDialogContent, + NewDialogDescription, + NewDialogFooter, + NewDialogHeader, + NewDialogTitle, + NewDialogTrigger, + Spinner, +} from "@dust-tt/sparkle"; import type { EnterpriseUpgradeFormType, WorkspaceType } from "@dust-tt/types"; import { EnterpriseUpgradeFormSchema, removeNulls } from "@dust-tt/types"; import { ioTsResolver } from "@hookform/resolvers/io-ts"; @@ -7,15 +16,6 @@ import { useState } from "react"; import { useForm } from "react-hook-form"; import { PokeButton } from "@app/components/poke/shadcn/ui/button"; -import { - PokeDialog, - PokeDialogContent, - PokeDialogDescription, - PokeDialogFooter, - PokeDialogHeader, - PokeDialogTitle, - PokeDialogTrigger, -} from "@app/components/poke/shadcn/ui/dialog"; import { PokeForm } from "@app/components/poke/shadcn/ui/form"; import { InputField, @@ -95,18 +95,18 @@ export default function EnterpriseUpgradeDialog({ }; return ( - - + + 🏢 Upgrade to Enterprise - - - - Upgrade {owner.name} to Enterprise. - + + + + Upgrade {owner.name} to Enterprise. + Select the enterprise plan and provide the Stripe subscription id of the customer. - - + + {error &&
{error}
} {isSubmitting && } {!isSubmitting && ( @@ -135,18 +135,18 @@ export default function EnterpriseUpgradeDialog({ />
- + Upgrade - + )} - - + + ); } diff --git a/front/components/spaces/EditSpaceManagedDatasourcesViews.tsx b/front/components/spaces/EditSpaceManagedDatasourcesViews.tsx index 27f86566d660..56ba4ae219a7 100644 --- a/front/components/spaces/EditSpaceManagedDatasourcesViews.tsx +++ b/front/components/spaces/EditSpaceManagedDatasourcesViews.tsx @@ -125,32 +125,34 @@ export function EditSpaceManagedDataSourcesViews({ alertDialog: true, children: (
-

The following data sources are currently in use:

- - {deletedViewsWithUsage.map((view) => ( -

- {getDisplayNameForDataSource(view.dataSource)}{" "} - - (used by {view.usage.count} assistant - {view.usage.count > 1 ? "s" : ""}) - -

- ))} - -

- Deleting these data sources will affect the assistants using - them. These assistants will no longer have access to this data - and may not work as expected. -

+ Deleting these data sources will affect the assistants using them. + These assistants will no longer have access to this data and may + not work as expected.
-

Are you sure you want to remove them?

+
+ The following data sources are currently in use: +
    + {deletedViewsWithUsage.map((view) => ( +
  • + {getDisplayNameForDataSource(view.dataSource)}{" "} + + (used by {view.usage.count} assistant + {view.usage.count > 1 ? "s" : ""}) + +
  • + ))} +
+
+
+ Are you sure you want to remove them? +
), }); diff --git a/front/hooks/useAwaitableDialog.tsx b/front/hooks/useAwaitableDialog.tsx index df3355f6aacb..e927f84897c3 100644 --- a/front/hooks/useAwaitableDialog.tsx +++ b/front/hooks/useAwaitableDialog.tsx @@ -1,11 +1,23 @@ -import { Dialog } from "@dust-tt/sparkle"; -import type { ComponentProps } from "react"; -import { useState } from "react"; - -type ShowDialogProps = Omit< - ComponentProps, - "isOpen" | "onCancel" | "onValidate" ->; +import type { Button } from "@dust-tt/sparkle"; +import { + NewDialog, + NewDialogContainer, + NewDialogContent, + NewDialogFooter, + NewDialogHeader, + NewDialogTitle, +} from "@dust-tt/sparkle"; +import React, { useState } from "react"; + +type ShowDialogProps = { + title: string; + children: React.ReactNode; + alertDialog?: boolean; + validateLabel?: string; + validateVariant?: React.ComponentProps["variant"]; + cancelLabel?: string; +}; + interface DialogState { isOpen: boolean; props: ShowDialogProps | null; @@ -38,18 +50,62 @@ export function useAwaitableDialog() { setDialogState({ isOpen: false, props: null }); }; - const DialogRenderer = () => - dialogState.props ? ( - - ) : null; + const AwaitableDialog = () => { + if (!dialogState.props) { + return null; + } + + const { + title, + children, + alertDialog, + validateLabel, + validateVariant, + cancelLabel, + } = dialogState.props; + + return ( + { + if (!open) { + handleCancel(); + } + }} + > + + + {title} + + {children} + + + + + ); + }; return { - AwaitableDialog: DialogRenderer, + AwaitableDialog, showDialog, }; } diff --git a/front/pages/poke/templates/[tId].tsx b/front/pages/poke/templates/[tId].tsx index eff1f3bec603..5ae583b0eb83 100644 --- a/front/pages/poke/templates/[tId].tsx +++ b/front/pages/poke/templates/[tId].tsx @@ -5,11 +5,16 @@ import { DropdownMenuContent, DropdownMenuTrigger, EmojiPicker, + Input, Markdown, + NewDialog, + NewDialogContent, + NewDialogHeader, + NewDialogTitle, + NewDialogTrigger, TextArea, + useSendNotification, } from "@dust-tt/sparkle"; -import { Input } from "@dust-tt/sparkle"; -import { useSendNotification } from "@dust-tt/sparkle"; import type { CreateTemplateFormType, TemplateTagCodeType, @@ -36,13 +41,6 @@ import { MultiSelect } from "react-multi-select-component"; import { makeUrlForEmojiAndBackgroud } from "@app/components/assistant_builder/avatar_picker/utils"; import PokeNavbar from "@app/components/poke/PokeNavbar"; import { PokeButton } from "@app/components/poke/shadcn/ui/button"; -import { - PokeDialog, - PokeDialogContent, - PokeDialogHeader, - PokeDialogTitle, - PokeDialogTrigger, -} from "@app/components/poke/shadcn/ui/dialog"; import { PokeForm, PokeFormControl, @@ -428,22 +426,22 @@ function PreviewDialog({ form }: { form: any }) { ); return ( - - + + ✨ Preview Template Card - - - - Preview - + + + + Preview + console.log("clicked")} /> - - + + ); }