Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(web): Stabilize table overlay state (#17584)

Ben Bachem37f0a73d2989
diff --git a/web/src/components/table/use-cases/score-configs.tsx b/web/src/components/table/use-cases/score-configs.tsx
index 290ab948d2..edb34ad655 100644
--- a/web/src/components/table/use-cases/score-configs.tsx
+++ b/web/src/components/table/use-cases/score-configs.tsx
@@ -31,8 +31,15 @@ import {
DropdownMenuContent,
DropdownMenuItem,
} from "@/src/components/ui/dropdown-menu";
-import { ArchiveScoreConfigDialogController } from "@/src/features/score-configs/components/ArchiveScoreConfigDialogController";
-import { UpsertScoreConfigDialogController } from "@/src/features/score-configs/components/UpsertScoreConfigDialogController";
+import {
+ ArchiveScoreConfigDialogController,
+ type ArchiveScoreConfigState,
+} from "@/src/features/score-configs/components/ArchiveScoreConfigDialogController";
+import {
+ CreateScoreConfigDialogController,
+ EditScoreConfigDialogController,
+} from "@/src/features/score-configs/components/UpsertScoreConfigDialogController";
+import { type UpdateConfig } from "@/src/features/score-configs/lib/upsertFormTypes";
type ScoreConfigTableRow = {
id: string;
@@ -75,6 +82,38 @@ function getConfigRange(
}
export function ScoreConfigsTable({ projectId }: { projectId: string }) {
+ return (
+ <EditScoreConfigDialogController projectId={projectId}>
+ {(editControl) => (
+ <ArchiveScoreConfigDialogController projectId={projectId}>
+ {(archiveControl) => (
+ <ScoreConfigsTableContent
+ projectId={projectId}
+ editControl={editControl}
+ archiveControl={archiveControl}
+ />
+ )}
+ </ArchiveScoreConfigDialogController>
+ )}
+ </EditScoreConfigDialogController>
+ );
+}
+
+function ScoreConfigsTableContent({
+ projectId,
+ editControl,
+ archiveControl,
+}: {
+ projectId: string;
+ editControl: {
+ disabled: { reason: string } | undefined;
+ openDialog: (config: UpdateConfig) => void;
+ };
+ archiveControl: {
+ disabled: { reason: string } | undefined;
+ openDialog: (config: ArchiveScoreConfigState) => void;
+ };
+}) {
const [paginationState, setPaginationState] = usePaginationState(0, 50, {
page: "pageIndex",
limit: "pageSize",
@@ -158,62 +197,50 @@ export function ScoreConfigsTable({ projectId }: { projectId: string }) {
const { id: configId, isArchived, name } = row.original;
return (
- <UpsertScoreConfigDialogController
- mode="edit"
- projectId={projectId}
- defaultValues={{
- id: configId,
- name,
- dataType: row.original.dataType,
- minValue: row.original.range.minValue ?? undefined,
- maxValue: row.original.range.maxValue ?? undefined,
- description: row.original.description ?? undefined,
- categories: row.original.range.categories?.length
- ? row.original.range.categories
- : undefined,
- }}
- >
- {({ disabled: editDisabled, Trigger }) => (
- <ArchiveScoreConfigDialogController
- configId={configId}
- projectId={projectId}
- isArchived={isArchived}
- name={name}
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button variant="ghost">
+ <MoreVertical className="h-4 w-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent>
+ <DropdownMenuItem
+ aria-label="edit"
+ disabled={editControl.disabled !== undefined}
+ title={editControl.disabled?.reason}
+ onSelect={() =>
+ editControl.openDialog({
+ id: configId,
+ name,
+ dataType: row.original.dataType,
+ minValue: row.original.range.minValue ?? undefined,
+ maxValue: row.original.range.maxValue ?? undefined,
+ description: row.original.description ?? undefined,
+ categories: row.original.range.categories?.length
+ ? row.original.range.categories
+ : undefined,
+ })
+ }
>
- {({ disabled, openDialog }) => (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="ghost">
- <MoreVertical className="h-4 w-4" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent>
- <Trigger asChild>
- <DropdownMenuItem
- aria-label="edit"
- disabled={editDisabled !== undefined}
- title={editDisabled?.reason}
- >
- <Edit className="mr-2 h-4 w-4" />
- Edit
- </DropdownMenuItem>
- </Trigger>
- <DropdownMenuItem
- key="archive"
- disabled={disabled !== undefined}
- title={disabled?.reason}
- onClick={(event) => event.stopPropagation()}
- onSelect={openDialog}
- >
- <Archive className="mr-2 h-4 w-4" />
- Archive
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- )}
- </ArchiveScoreConfigDialogController>
- )}
- </UpsertScoreConfigDialogController>
+ <Edit className="mr-2 h-4 w-4" />
+ Edit
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ disabled={archiveControl.disabled !== undefined}
+ title={archiveControl.disabled?.reason}
+ onSelect={() =>
+ archiveControl.openDialog({
+ id: configId,
+ isArchived,
+ name,
+ })
+ }
+ >
+ <Archive className="mr-2 h-4 w-4" />
+ {isArchived ? "Restore" : "Archive"}
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
);
},
},
@@ -242,28 +269,23 @@ export function ScoreConfigsTable({ projectId }: { projectId: string }) {
rowHeight={rowHeight}
setRowHeight={setRowHeight}
actionButtons={
- <UpsertScoreConfigDialogController
- key="new-config-dialog"
- mode="create"
- projectId={projectId}
- >
- {({ disabled, isSubmitting, Trigger }) => (
- <Trigger asChild>
- <Button
- variant="secondary"
- disabled={disabled !== undefined}
- loading={isSubmitting}
- title={disabled?.reason}
- >
- <PlusIcon
- className="mr-1.5 -ml-0.5 h-4 w-4"
- aria-hidden="true"
- />
- Add new score config
- </Button>
- </Trigger>
+ <CreateScoreConfigDialogController projectId={projectId}>
+ {({ disabled, isSubmitting, openDialog }) => (
+ <Button
+ variant="secondary"
+ disabled={disabled !== undefined}
+ loading={isSubmitting}
+ title={disabled?.reason}
+ onClick={openDialog}
+ >
+ <PlusIcon
+ className="mr-1.5 -ml-0.5 h-4 w-4"
+ aria-hidden="true"
+ />
+ Add new score config
+ </Button>
)}
- </UpsertScoreConfigDialogController>
+ </CreateScoreConfigDialogController>
}
className="px-0"
/>
diff --git a/web/src/ee/features/sso-settings/components/SSOSettings.tsx b/web/src/ee/features/sso-settings/components/SSOSettings.tsx
index 65f9e73e3d..d10334d9f5 100644
--- a/web/src/ee/features/sso-settings/components/SSOSettings.tsx
+++ b/web/src/ee/features/sso-settings/components/SSOSettings.tsx
@@ -2,6 +2,7 @@
import { showErrorToast, showSuccessToast } from "@/src/features/notifications";
import { Alert } from "@/src/components/design-system/Alert/Alert";
import { ConfirmationDialogController } from "@/src/components/design-system/ConfirmationDialogController/ConfirmationDialogController";
+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
import { Badge } from "@/src/components/ui/badge";
import { Button } from "@/src/components/ui/button";
import { Card } from "@/src/components/ui/card";
@@ -11,13 +12,11 @@ import { SimpleDataTable } from "@/src/components/table/simple-data-table";
import { type LangfuseColumnDef } from "@/src/components/table/types";
import { SelectInput } from "@/src/components/design-system/SelectInput/SelectInput";
import {
- Dialog,
DialogBody,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
- DialogTrigger,
} from "@/src/components/ui/dialog";
import {
Form,
@@ -37,7 +36,7 @@ import { SsoProviderSchema } from "@/src/ee/features/multi-tenant-sso/types";
import { api } from "@/src/utils/api";
import { zodResolver } from "@hookform/resolvers/zod";
import { AlertCircle, Check, Copy, TrashIcon } from "lucide-react";
-import { useEffect, useMemo, useState } from "react";
+import { useMemo, useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { useCopyToClipboard } from "@/src/hooks/useCopyToClipboard";
@@ -191,6 +190,13 @@ function SsoConfigsTable({ orgId }: { orgId: string }) {
return map;
}, [ssoConfigsQuery.data]);
+ const data: SsoConfigTableRow[] = verifiedDomains.map(
+ (domain: { domain: string }) => ({
+ domain: domain.domain,
+ config: configByDomain.get(domain.domain) ?? null,
+ }),
+ );
+
if (verifiedDomains.length === 0) {
return (
<Card className="overflow-hidden">
@@ -201,83 +207,124 @@ function SsoConfigsTable({ orgId }: { orgId: string }) {
);
}
- const data: SsoConfigTableRow[] = verifiedDomains.map(
- (domain: { domain: string }) => ({
- domain: domain.domain,
- config: configByDomain.get(domain.domain) ?? null,
- }),
+ return (
+ <SsoConfigDialogController orgId={orgId}>
+ {({ openDialog: openConfigDialog }) => (
+ <DeleteSsoConfigDialogController orgId={orgId}>
+ {({ openDialog: openDeleteDialog }) => {
+ const columns: LangfuseColumnDef<SsoConfigTableRow>[] = [
+ createTextTableColumn<SsoConfigTableRow>({
+ accessorKey: "domain",
+ header: "Domain",
+ }),
+ {
+ accessorKey: "config",
+ header: "Provider",
+ cell: ({ row }) =>
+ row.original.config ? (
+ <Badge variant="default">
+ {providerLabel(row.original.config.authProvider)}
+ </Badge>
+ ) : (
+ <Badge variant="secondary">Not configured</Badge>
+ ),
+ },
+ {
+ accessorKey: "config",
+ id: "updatedAt",
+ header: "Updated",
+ hideBelowMd: true,
+ cell: ({ row }) =>
+ row.original.config
+ ? row.original.config.updatedAt.toLocaleDateString()
+ : "—",
+ },
+ {
+ accessorKey: "domain",
+ id: "actions",
+ header: "",
+ cell: ({ row }) => (
+ <div className="flex items-center justify-end gap-2">
+ <Button
+ size="sm"
+ variant={row.original.config ? "outline" : "default"}
+ onClick={() => openConfigDialog(row.original)}
+ >
+ {row.original.config ? "Update" : "Configure SSO"}
+ </Button>
+ {row.original.config ? (
+ <Button
+ variant="ghost"
+ size="icon-xs"
+ aria-label={`Delete SSO for ${row.original.domain}`}
+ onClick={() => openDeleteDialog(row.original.domain)}
+ >
+ <TrashIcon className="h-4 w-4" />
+ </Button>
+ ) : null}
+ </div>
+ ),
+ },
+ ];
+
+ return (
+ <Card className="mb-4 overflow-hidden">
+ <SimpleDataTable
+ columns={columns}
+ data={data}
+ isLoading={false}
+ noResults={null}
+ bodyTone="muted"
+ rowVariant="primary-hover"
+ />
+ </Card>
+ );
+ }}
+ </DeleteSsoConfigDialogController>
+ )}
+ </SsoConfigDialogController>
);
+}
- const columns: LangfuseColumnDef<SsoConfigTableRow>[] = [
- createTextTableColumn<SsoConfigTableRow>({
- accessorKey: "domain",
- header: "Domain",
- }),
- {
- accessorKey: "config",
- header: "Provider",
- cell: ({ row }) =>
- row.original.config ? (
- <Badge variant="default">
- {providerLabel(row.original.config.authProvider)}
- </Badge>
- ) : (
- <Badge variant="secondary">Not configured</Badge>
- ),
- },
- {
- accessorKey: "config",
- id: "updatedAt",
- header: "Updated",
- hideBelowMd: true,
- cell: ({ row }) =>
- row.original.config
- ? row.original.config.updatedAt.toLocaleDateString()
- : "—",
- },
- {
- accessorKey: "domain",
- id: "actions",
- header: "",
- cell: ({ row }) => (
- <div className="flex items-center justify-end gap-2">
- <SsoConfigDialog
+function SsoConfigDialogController({
+ orgId,
+ children,
+}: {
+ orgId: string;
+ children: (control: {
+ openDialog: (config: SsoConfigTableRow) => void;
+ }) => React.ReactNode;
+}) {
+ return (
+ <DialogController<SsoConfigTableRow>
+ renderDialog={({ state, closeDialog }) => (
+ <DialogContent className="sm:max-w-xl">
+ <SsoConfigDialogContent
+ key={state.domain}
orgId={orgId}
- domain={row.original.domain}
- existing={row.original.config}
+ domain={state.domain}
+ existing={state.config}
+ closeDialog={closeDialog}
/>
- {row.original.config ? (
- <DeleteSsoConfigButton orgId={orgId} domain={row.original.domain} />
- ) : null}
- </div>
- ),
- },
- ];
-
- return (
- <Card className="mb-4 overflow-hidden">
- <SimpleDataTable
- columns={columns}
- data={data}
- isLoading={false}
- noResults={null}
- bodyTone="muted"
- rowVariant="primary-hover"
- />
- </Card>
+ </DialogContent>
+ )}
+ >
+ {({ openDialog }) => children({ openDialog })}
+ </DialogController>
);
}
-function SsoConfigDialog({
+function SsoConfigDialogContent({
orgId,
domain,
existing,
+ closeDialog,
}: {
orgId: string;
domain: string;
existing: SsoConfigRow | null;
+ closeDialog: () => void;
}) {
- const [dialogOpen, setDialogOpen] = useState(false);
const [pendingValues, setPendingValues] = useState<FormValues | null>(null);
const utils = api.useUtils();
@@ -303,12 +350,6 @@ function SsoConfigDialog({
resolver: zodResolver(formSchema),
defaultValues,
});
- // Reset the form when the dialog reopens against new defaults (e.g. user
- // toggled between Configure and Update without remounting the component).
- useEffect(() => {
- if (dialogOpen) form.reset(defaultValues);
- }, [dialogOpen, defaultValues, form]);
-
const selectedProvider = form.watch("authProvider");
const providerSpec = useMemo(
() =>
@@ -328,7 +369,7 @@ function SsoConfigDialog({
title: existing ? "SSO updated" : "SSO configured",
description: `Active for @${domain} within 1 hour.`,
});
- setDialogOpen(false);
+ closeDialog();
setPendingValues(null);
form.reset();
},
@@ -397,74 +438,123 @@ function SsoConfigDialog({
onConfirm={handleConfirm}
>
{({ openDialog }) => (
- <Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
- <DialogTrigger asChild>
- <Button size="sm" variant={existing ? "outline" : "default"}>
- {existing ? "Update" : "Configure SSO"}
- </Button>
- </DialogTrigger>
- <DialogContent className="sm:max-w-xl">
- <DialogHeader>
- <DialogTitle>
- {existing
- ? `Update SSO for ${domain}`
- : `Configure SSO for ${domain}`}
- </DialogTitle>
- </DialogHeader>
- <Form {...form}>
- <form
- onSubmit={form.handleSubmit((values) => {
- setPendingValues(values);
- openDialog();
- })}
- >
- <DialogBody className="space-y-4">
+ <>
+ <DialogHeader>
+ <DialogTitle>
+ {existing
+ ? `Update SSO for ${domain}`
+ : `Configure SSO for ${domain}`}
+ </DialogTitle>
+ </DialogHeader>
+ <Form {...form}>
+ <form
+ onSubmit={form.handleSubmit((values) => {
+ setPendingValues(values);
+ openDialog();
+ })}
+ >
+ <DialogBody className="space-y-4">
+ <FormField
+ control={form.control}
+ name="authProvider"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Provider</FormLabel>
+ <FormControl>
+ <SelectInput
+ value={field.value}
+ onValueChange={field.onChange}
+ placeholder="Select an SSO provider"
+ options={SSO_PROVIDERS.map((provider) => ({
+ value: provider.id,
+ label: provider.label,
+ }))}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ <CallbackUrlPanel callbackUrl={callbackUrl} />
+
+ {providerSpec.fields.includes("name") ? (
+ <FormField
+ control={form.control}
+ name="authConfig.name"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Display Name</FormLabel>
+ <FormControl>
+ <Input placeholder="Acme SSO" {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ ) : null}
+
+ <FormField
+ control={form.control}
+ name="authConfig.clientId"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Client ID</FormLabel>
+ <FormControl>
+ <Input {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ <FormField
+ control={form.control}
+ name="authConfig.clientSecret"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Client Secret</FormLabel>
+ <FormControl>
+ <Input
+ type="password"
+ autoComplete="off"
+ placeholder={
+ existing ? "Re-enter to update" : undefined
+ }
+ {...field}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {providerSpec.fields.includes("issuer") ? (
<FormField
control={form.control}
- name="authProvider"
+ name="authConfig.issuer"
render={({ field }) => (
<FormItem>
- <FormLabel>Provider</FormLabel>
+ <FormLabel>Issuer URL</FormLabel>
<FormControl>
- <SelectInput
- value={field.value}
- onValueChange={field.onChange}
- placeholder="Select an SSO provider"
- options={SSO_PROVIDERS.map((provider) => ({
- value: provider.id,
- label: provider.label,
- }))}
+ <Input
+ placeholder="https://example.okta.com"
+ {...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
+ ) : null}
- <CallbackUrlPanel callbackUrl={callbackUrl} />
-
- {providerSpec.fields.includes("name") ? (
- <FormField
- control={form.control}
- name="authConfig.name"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Display Name</FormLabel>
- <FormControl>
- <Input placeholder="Acme SSO" {...field} />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- ) : null}
-
+ {providerSpec.fields.includes("tenantId") ? (
<FormField
control={form.control}
- name="authConfig.clientId"
+ name="authConfig.tenantId"
render={({ field }) => (
<FormItem>
- <FormLabel>Client ID</FormLabel>
+ <FormLabel>Tenant ID</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
@@ -472,20 +562,18 @@ function SsoConfigDialog({
</FormItem>
)}
/>
+ ) : null}
+ {providerSpec.fields.includes("baseUrl") ? (
<FormField
control={form.control}
- name="authConfig.clientSecret"
+ name="authConfig.baseUrl"
render={({ field }) => (
<FormItem>
- <FormLabel>Client Secret</FormLabel>
+ <FormLabel>Base URL</FormLabel>
<FormControl>
<Input
- type="password"
- autoComplete="off"
- placeholder={
- existing ? "Re-enter to update" : undefined
- }
+ placeholder="https://github.acme.com"
{...field}
/>
</FormControl>
@@ -493,107 +581,49 @@ function SsoConfigDialog({
</FormItem>
)}
/>
+ ) : null}
- {providerSpec.fields.includes("issuer") ? (
+ {selectedProvider === "custom" ? (
+ <>
<FormField
control={form.control}
- name="authConfig.issuer"
+ name="authConfig.idToken"
render={({ field }) => (
- <FormItem>
- <FormLabel>Issuer URL</FormLabel>
+ <FormItem className="flex flex-row items-start space-y-0 space-x-3 rounded-md border p-4">
<FormControl>
- <Input
- placeholder="https://example.okta.com"
- {...field}
+ <Checkbox
+ checked={field.value ?? false}
+ onCheckedChange={(checked) =>
+ field.onChange(checked === true)
+ }
/>
</FormControl>
- <FormMessage />
+ <div className="space-y-1 leading-none">
+ <FormLabel>
+ Use id_token claims only (skip userinfo)
+ </FormLabel>
+ <FormDescription>
+ Leave off for IdPs that release email only via the
+ userinfo endpoint.
+ </FormDescription>
+ </div>
</FormItem>
)}
/>
- ) : null}
-
- {providerSpec.fields.includes("tenantId") ? (
- <FormField
- control={form.control}
- name="authConfig.tenantId"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Tenant ID</FormLabel>
- <FormControl>
- <Input {...field} />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- ) : null}
-
- {providerSpec.fields.includes("baseUrl") ? (
- <FormField
- control={form.control}
- name="authConfig.baseUrl"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Base URL</FormLabel>
- <FormControl>
- <Input
- placeholder="https://github.acme.com"
- {...field}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- ) : null}
-
- {selectedProvider === "custom" ? (
- <>
- <FormField
- control={form.control}
- name="authConfig.idToken"
- render={({ field }) => (
- <FormItem className="flex flex-row items-start space-y-0 space-x-3 rounded-md border p-4">
- <FormControl>
- <Checkbox
- checked={field.value ?? false}
- onCheckedChange={(checked) =>
- field.onChange(checked === true)
- }
- />
- </FormControl>
- <div className="space-y-1 leading-none">
- <FormLabel>
- Use id_token claims only (skip userinfo)
- </FormLabel>
- <FormDescription>
- Leave off for IdPs that release email only via
- the userinfo endpoint.
- </FormDescription>
- </div>
- </FormItem>
- )}
- />
- </>
- ) : null}
- </DialogBody>
- <DialogFooter>
- <Button
- type="button"
- variant="ghost"
- onClick={() => setDialogOpen(false)}
- >
- Cancel
- </Button>
- <Button type="submit" loading={saveMutation.isPending}>
- Save
- </Button>
- </DialogFooter>
- </form>
- </Form>
- </DialogContent>
- </Dialog>
+ </>
+ ) : null}
+ </DialogBody>
+ <DialogFooter>
+ <Button type="button" variant="ghost" onClick={closeDialog}>
+ Cancel
+ </Button>
+ <Button type="submit" loading={saveMutation.isPending}>
+ Save
+ </Button>
+ </DialogFooter>
+ </form>
+ </Form>
+ </>
)}
</ConfirmationDialogController>
);
@@ -657,13 +687,16 @@ function CopyableCallbackUrl({ value }: { value: string }) {
);
}
-function DeleteSsoConfigButton({
+function DeleteSsoConfigDialogController({
orgId,
- domain,
+ children,
}: {
orgId: string;
- domain: string;
+ children: (control: {
+ openDialog: (domain: string) => void;
+ }) => React.ReactNode;
}) {
+ const [selectedDomain, setSelectedDomain] = useState<string | null>(null);
const utils = api.useUtils();
const deleteMutation = api.ssoConfig.delete.useMutation({
@@ -671,7 +704,7 @@ function DeleteSsoConfigButton({
utils.ssoConfig.get.invalidate({ orgId });
showSuccessToast({
title: "SSO disabled",
- description: `SSO for @${domain} has been removed.`,
+ description: `SSO for @${selectedDomain} has been removed.`,
});
},
onError: (err) => {
@@ -681,25 +714,24 @@ function DeleteSsoConfigButton({
return (
<ConfirmationDialogController
- title={`Remove SSO for @${domain}?`}
+ title={`Remove SSO for @${selectedDomain ?? "this domain"}?`}
text="Users at this domain will be able to sign in with any enabled method again. Active sessions are not invalidated."
confirmLabel="Remove"
variant="destructive"
loading={deleteMutation.isPending}
onConfirm={async () => {
- await deleteMutation.mutateAsync({ orgId, domain });
+ if (!selectedDomain) return;
+ await deleteMutation.mutateAsync({ orgId, domain: selectedDomain });
}}
>
- {({ openDialog }) => (
- <Button
- variant="ghost"
- size="icon-xs"
- aria-label={`Delete SSO for ${domain}`}
- onClick={openDialog}
- >
- <TrashIcon className="h-4 w-4" />
- </Button>
- )}
+ {({ openDialog }) =>
+ children({
+ openDialog: (domain) => {
+ setSelectedDomain(domain);
+ openDialog();
+ },
+ })
+ }
</ConfirmationDialogController>
);
}
diff --git a/web/src/ee/features/verified-domains/components/VerifiedDomainsSettings.tsx b/web/src/ee/features/verified-domains/components/VerifiedDomainsSettings.tsx
index d5c218b69a..959bf38d95 100644
--- a/web/src/ee/features/verified-domains/components/VerifiedDomainsSettings.tsx
+++ b/web/src/ee/features/verified-domains/components/VerifiedDomainsSettings.tsx
@@ -39,7 +39,7 @@ import {
Copy,
TrashIcon,
} from "lucide-react";
-import { useState } from "react";
+import { useMemo, useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { useCopyToClipboard } from "@/src/hooks/useCopyToClipboard";
@@ -128,62 +128,65 @@ function DomainsTable({ orgId }: { orgId: string }) {
const query = api.verifiedDomain.list.useQuery({ orgId });
const [collapsedRows, setCollapsedRows] = useState<Set<string>>(new Set());
- const columns: LangfuseColumnDef<DomainRowData>[] = [
- {
- accessorKey: "domain",
- header: "Domain",
- cell: ({ row }) =>
- !row.original.verifiedAt ? (
- <button
- type="button"
- onClick={() =>
- setCollapsedRows((current) => {
- const next = new Set(current);
- if (next.has(row.original.id)) next.delete(row.original.id);
- else next.add(row.original.id);
- return next;
- })
- }
- className="flex items-center gap-1"
- >
- <ChevronRight
- className={`h-3 w-3 transition-transform ${
- collapsedRows.has(row.original.id) ? "" : "rotate-90"
- }`}
- />
- {row.original.domain}
- </button>
- ) : (
- row.original.domain
- ),
- },
- {
- accessorKey: "verifiedAt",
- header: "Status",
- cell: ({ row }) =>
- row.original.verifiedAt ? (
- <Badge variant="default">Verified</Badge>
- ) : (
- <Badge variant="secondary">Pending verification</Badge>
+ const columns = useMemo<LangfuseColumnDef<DomainRowData>[]>(
+ () => [
+ {
+ accessorKey: "domain",
+ header: "Domain",
+ cell: ({ row }) =>
+ !row.original.verifiedAt ? (
+ <button
+ type="button"
+ onClick={() =>
+ setCollapsedRows((current) => {
+ const next = new Set(current);
+ if (next.has(row.original.id)) next.delete(row.original.id);
+ else next.add(row.original.id);
+ return next;
+ })
+ }
+ className="flex items-center gap-1"
+ >
+ <ChevronRight
+ className={`h-3 w-3 transition-transform ${
+ collapsedRows.has(row.original.id) ? "" : "rotate-90"
+ }`}
+ />
+ {row.original.domain}
+ </button>
+ ) : (
+ row.original.domain
+ ),
+ },
+ {
+ accessorKey: "verifiedAt",
+ header: "Status",
+ cell: ({ row }) =>
+ row.original.verifiedAt ? (
+ <Badge variant="default">Verified</Badge>
+ ) : (
+ <Badge variant="secondary">Pending verification</Badge>
+ ),
+ },
+ {
+ accessorKey: "createdAt",
+ header: "Added",
+ hideBelowMd: true,
+ cell: ({ row }) => row.original.createdAt.toLocaleDateString(),
+ },
+ {
+ accessorKey: "id",
+ id: "actions",
+ header: "",
+ cell: ({ row }) => (
+ <div className="flex items-center justify-end gap-2">
+ <DomainActions orgId={orgId} row={row.original} />
+ </div>
),
- },
- {
- accessorKey: "createdAt",
- header: "Added",
- hideBelowMd: true,
- cell: ({ row }) => row.original.createdAt.toLocaleDateString(),
- },
- {
- accessorKey: "id",
- id: "actions",
- header: "",
- cell: ({ row }) => (
- <div className="flex items-center justify-end gap-2">
- <DomainActions orgId={orgId} row={row.original} />
- </div>
- ),
- },
- ];
+ },
+ ],
+ [collapsedRows, orgId],
+ );
const renderDetailRow = (row: Row<DomainRowData>) =>
!row.original.verifiedAt && !collapsedRows.has(row.original.id) ? (
diff --git a/web/src/features/public-api/components/ApiKeyList.tsx b/web/src/features/public-api/components/ApiKeyList.tsx
index 4184492cc4..6ca92cc5bd 100644
--- a/web/src/features/public-api/components/ApiKeyList.tsx
+++ b/web/src/features/public-api/components/ApiKeyList.tsx
@@ -16,7 +16,7 @@ import {
} from "@/src/features/rbac";
import { api, reportNonTrpcError } from "@/src/utils/api";
import { Check, Copy, TrashIcon } from "lucide-react";
-import { useState } from "react";
+import { useMemo, useState } from "react";
import { Alert } from "@/src/components/design-system/Alert/Alert";
import startCase from "lodash/startCase";
import { useLangfuseEnvCode } from "@/src/features/public-api/hooks/useLangfuseEnvCode";
@@ -79,50 +79,53 @@ export function ApiKeyList(props: { entityId: string; scope: ApiKeyScope }) {
const apiKeysQuery =
props.scope === "project" ? projectApiKeysQuery : organizationApiKeysQuery;
- const columns: LangfuseColumnDef<ApiKeyRow>[] = [
- createTextTableColumn<ApiKeyRow, Date>({
- accessorKey: "createdAt",
- header: "Created",
- mapValue: (value) => value?.toLocaleDateString(),
- hideBelowMd: true,
- }),
- {
- accessorKey: "createdByUser",
- header: "Created By",
- hideBelowMd: true,
- cell: ({ row }) => <ApiKeyCreatedBy apiKey={row.original} />,
- },
- {
- accessorKey: "note",
- header: "Note",
- cell: ({ row }) => (
- <ApiKeyNote apiKey={row.original} entityId={entityId} scope={scope} />
- ),
- },
- {
- accessorKey: "publicKey",
- header: "Public Key",
- cell: ({ row }) => <PublicKeyCell publicKey={row.original.publicKey} />,
- },
- {
- accessorKey: "displaySecretKey",
- header: "Secret Key",
- cell: ({ getValue }) => (
- <span className="font-mono">{getValue<string>()}</span>
- ),
- },
- {
- accessorKey: "id",
- header: "",
- cell: ({ row }) => (
- <DeleteApiKeyButton
- entityId={entityId}
- apiKeyId={row.original.id}
- scope={scope}
- />
- ),
- },
- ];
+ const columns = useMemo<LangfuseColumnDef<ApiKeyRow>[]>(
+ () => [
+ createTextTableColumn<ApiKeyRow, Date>({
+ accessorKey: "createdAt",
+ header: "Created",
+ mapValue: (value) => value?.toLocaleDateString(),
+ hideBelowMd: true,
+ }),
+ {
+ accessorKey: "createdByUser",
+ header: "Created By",
+ hideBelowMd: true,
+ cell: ({ row }) => <ApiKeyCreatedBy apiKey={row.original} />,
+ },
+ {
+ accessorKey: "note",
+ header: "Note",
+ cell: ({ row }) => (
+ <ApiKeyNote apiKey={row.original} entityId={entityId} scope={scope} />
+ ),
+ },
+ {
+ accessorKey: "publicKey",
+ header: "Public Key",
+ cell: ({ row }) => <PublicKeyCell publicKey={row.original.publicKey} />,
+ },
+ {
+ accessorKey: "displaySecretKey",
+ header: "Secret Key",
+ cell: ({ getValue }) => (
+ <span className="font-mono">{getValue<string>()}</span>
+ ),
+ },
+ {
+ accessorKey: "id",
+ header: "",
+ cell: ({ row }) => (
+ <DeleteApiKeyButton
+ entityId={entityId}
+ apiKeyId={row.original.id}
+ scope={scope}
+ />
+ ),
+ },
+ ],
+ [entityId, scope],
+ );
if (!hasAccess) {
return (
diff --git a/web/src/features/score-configs/components/ArchiveScoreConfigDialogController.tsx b/web/src/features/score-configs/components/ArchiveScoreConfigDialogController.tsx
index be526710ee..c1b7a3650e 100644
--- a/web/src/features/score-configs/components/ArchiveScoreConfigDialogController.tsx
+++ b/web/src/features/score-configs/components/ArchiveScoreConfigDialogController.tsx
@@ -1,30 +1,30 @@
import type * as React from "react";
+import { useState } from "react";
import { ConfirmationDialogController } from "@/src/components/design-system/ConfirmationDialogController/ConfirmationDialogController";
-import { useHasProjectAccess } from "@/src/features/rbac";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
+import { useHasProjectAccess } from "@/src/features/rbac";
import { useEmptyScoreConfigs } from "@/src/features/scores";
import { api } from "@/src/utils/api";
-type ArchiveScoreConfigDialogControllerProps = {
- children: (control: {
- disabled: { reason: string } | undefined;
- isOpen: boolean;
- openDialog: () => void;
- }) => React.ReactNode;
- configId: string;
- projectId: string;
+export type ArchiveScoreConfigState = {
+ id: string;
isArchived: boolean;
name: string;
};
export const ArchiveScoreConfigDialogController = ({
children,
- configId,
projectId,
- isArchived,
- name,
-}: ArchiveScoreConfigDialogControllerProps) => {
+}: {
+ children: (control: {
+ disabled: { reason: string } | undefined;
+ openDialog: (config: ArchiveScoreConfigState) => void;
+ }) => React.ReactNode;
+ projectId: string;
+}) => {
+ const [selectedConfig, setSelectedConfig] =
+ useState<ArchiveScoreConfigState | null>(null);
const capture = usePostHogClientCapture();
const { emptySelectedConfigIds, setEmptySelectedConfigIds } =
useEmptyScoreConfigs();
@@ -33,7 +33,7 @@ export const ArchiveScoreConfigDialogController = ({
scope: "scoreConfigs:CUD",
});
const utils = api.useUtils();
- const configMutation = api.scoreConfigs.update.useMutation({
+ const mutation = api.scoreConfigs.update.useMutation({
onSuccess: () => utils.scoreConfigs.invalidate(),
});
const disabled = hasAccess
@@ -42,32 +42,34 @@ export const ArchiveScoreConfigDialogController = ({
return (
<ConfirmationDialogController
- title={isArchived ? "Restore config" : "Archive config"}
+ title={selectedConfig?.isArchived ? "Restore config" : "Archive config"}
text={
- isArchived
- ? `Your config is currently archived. Restore if you want to use "${name}" in annotation again.`
- : `Your config is currently active. Archive if you no longer want to use "${name}" in annotation. Historic "${name}" scores will still be shown and can be deleted. You can restore your config at any point.`
+ selectedConfig?.isArchived
+ ? `Your config is currently archived. Restore if you want to use "${selectedConfig.name}" in annotation again.`
+ : `Your config is currently active. Archive if you no longer want to use "${selectedConfig?.name ?? "this config"}" in annotation. Historic scores will still be shown and can be deleted. You can restore your config at any point.`
}
confirmLabel="Confirm"
- variant={isArchived ? "default" : "destructive"}
- loading={configMutation.isPending}
+ variant={selectedConfig?.isArchived ? "default" : "destructive"}
+ loading={mutation.isPending}
onConfirm={async () => {
- await configMutation.mutateAsync({
+ if (!selectedConfig) return;
+
+ await mutation.mutateAsync({
projectId,
- id: configId,
- isArchived: !isArchived,
+ id: selectedConfig.id,
+ isArchived: !selectedConfig.isArchived,
});
setEmptySelectedConfigIds(
- emptySelectedConfigIds.filter((id) => id !== configId),
+ emptySelectedConfigIds.filter((id) => id !== selectedConfig.id),
);
capture("score_configs:archive_form_submit");
}}
>
- {({ isOpen, openDialog }) =>
+ {({ openDialog }) =>
children({
disabled,
- isOpen,
- openDialog: () => {
+ openDialog: (config) => {
+ setSelectedConfig(config);
capture("score_configs:archive_form_open");
openDialog();
},
diff --git a/web/src/features/score-configs/components/UpsertScoreConfigDialogController.tsx b/web/src/features/score-configs/components/UpsertScoreConfigDialogController.tsx
index d4c55c2d50..cb411e2dcd 100644
--- a/web/src/features/score-configs/components/UpsertScoreConfigDialogController.tsx
+++ b/web/src/features/score-configs/components/UpsertScoreConfigDialogController.tsx
@@ -1,13 +1,10 @@
-import { useHasProjectAccess } from "@/src/features/rbac";
import { ScoreDataTypeEnum } from "@langfuse/shared";
-import { type ReactNode, useState } from "react";
+import { type ReactNode } from "react";
-import {
- Dialog,
- DialogContent,
- DialogTrigger,
-} from "@/src/components/ui/dialog";
+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
+import { DialogContent } from "@/src/components/ui/dialog";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
+import { useHasProjectAccess } from "@/src/features/rbac";
import { UpsertScoreConfigDialogContent } from "@/src/features/score-configs/components/UpsertScoreConfigDialogContent";
import {
type CreateConfig,
@@ -15,15 +12,6 @@ import {
} from "@/src/features/score-configs/lib/upsertFormTypes";
import { api } from "@/src/utils/api";
-type UpsertScoreConfigDialogControllerProps = {
- projectId: string;
- children: (control: {
- disabled: { reason: string } | undefined;
- isSubmitting: boolean;
- Trigger: typeof DialogTrigger;
- }) => ReactNode;
-} & ({ mode: "create" } | { mode: "edit"; defaultValues: UpdateConfig });
-
const createDefaultValues: CreateConfig = {
dataType: ScoreDataTypeEnum.NUMERIC,
minValue: undefined,
@@ -31,81 +19,115 @@ const createDefaultValues: CreateConfig = {
name: "",
};
-export function UpsertScoreConfigDialogController(
- props: UpsertScoreConfigDialogControllerProps,
-) {
- const { children, projectId, mode } = props;
- const [open, setOpen] = useState(false);
+export function CreateScoreConfigDialogController({
+ projectId,
+ children,
+}: {
+ projectId: string;
+ children: (control: {
+ disabled: { reason: string } | undefined;
+ isSubmitting: boolean;
+ openDialog: () => void;
+ }) => ReactNode;
+}) {
const capture = usePostHogClientCapture();
const hasAccess = useHasProjectAccess({
projectId,
scope: "scoreConfigs:CUD",
});
const utils = api.useUtils();
- const createScoreConfig = api.scoreConfigs.create.useMutation({
+ const mutation = api.scoreConfigs.create.useMutation({
onSuccess: () => utils.scoreConfigs.invalidate(),
});
- const updateScoreConfig = api.scoreConfigs.update.useMutation({
- onSuccess: () => utils.scoreConfigs.invalidate(),
- });
-
- const isSubmitting =
- createScoreConfig.isPending || updateScoreConfig.isPending;
const disabled = hasAccess
? undefined
- : { reason: `You don't have permission to ${mode} score configs.` };
-
- async function handleSubmit(values: CreateConfig | UpdateConfig) {
- if (mode === "edit") {
- await updateScoreConfig.mutateAsync({
- ...values,
- projectId,
- id: props.defaultValues.id,
- description: values.description ?? null,
- categories: values.categories?.length ? values.categories : undefined,
- });
- capture("score_configs:update_form_submit", {
- dataType: values.dataType,
- });
- return;
- }
+ : { reason: "You don't have permission to create score configs." };
- await createScoreConfig.mutateAsync({
- projectId,
- ...values,
- description: values.description ?? null,
- categories: values.categories?.length ? values.categories : undefined,
- });
- capture("score_configs:create_form_submit", {
- dataType: values.dataType,
- });
- }
+ return (
+ <DialogController
+ renderDialog={({ closeDialog }) => (
+ <DialogContent className="max-h-[90vh] overflow-y-auto">
+ <UpsertScoreConfigDialogContent
+ mode="create"
+ defaultValues={createDefaultValues}
+ onSubmit={async (values) => {
+ await mutation.mutateAsync({
+ projectId,
+ ...values,
+ description: values.description ?? null,
+ categories: values.categories?.length
+ ? values.categories
+ : undefined,
+ });
+ capture("score_configs:create_form_submit", {
+ dataType: values.dataType,
+ });
+ }}
+ onFormSuccess={closeDialog}
+ isSubmitting={mutation.isPending}
+ />
+ </DialogContent>
+ )}
+ >
+ {({ openDialog }) =>
+ children({ disabled, isSubmitting: mutation.isPending, openDialog })
+ }
+ </DialogController>
+ );
+}
- const content =
- mode === "edit" ? (
- <UpsertScoreConfigDialogContent
- mode="edit"
- defaultValues={props.defaultValues}
- onSubmit={handleSubmit}
- onFormSuccess={() => setOpen(false)}
- isSubmitting={isSubmitting}
- />
- ) : (
- <UpsertScoreConfigDialogContent
- mode="create"
- defaultValues={createDefaultValues}
- onSubmit={handleSubmit}
- onFormSuccess={() => setOpen(false)}
- isSubmitting={isSubmitting}
- />
- );
+export function EditScoreConfigDialogController({
+ projectId,
+ children,
+}: {
+ projectId: string;
+ children: (control: {
+ disabled: { reason: string } | undefined;
+ openDialog: (defaultValues: UpdateConfig) => void;
+ }) => ReactNode;
+}) {
+ const capture = usePostHogClientCapture();
+ const hasAccess = useHasProjectAccess({
+ projectId,
+ scope: "scoreConfigs:CUD",
+ });
+ const utils = api.useUtils();
+ const mutation = api.scoreConfigs.update.useMutation({
+ onSuccess: () => utils.scoreConfigs.invalidate(),
+ });
+ const disabled = hasAccess
+ ? undefined
+ : { reason: "You don't have permission to edit score configs." };
return (
- <Dialog open={hasAccess && open} onOpenChange={setOpen}>
- {children({ disabled, isSubmitting, Trigger: DialogTrigger })}
- <DialogContent className="max-h-[90vh] overflow-y-auto">
- {hasAccess && open ? content : null}
- </DialogContent>
- </Dialog>
+ <DialogController<UpdateConfig>
+ renderDialog={({ state: defaultValues, closeDialog }) => (
+ <DialogContent className="max-h-[90vh] overflow-y-auto">
+ <UpsertScoreConfigDialogContent
+ key={defaultValues.id}
+ mode="edit"
+ defaultValues={defaultValues}
+ onSubmit={async (values) => {
+ await mutation.mutateAsync({
+ ...values,
+ projectId,
+ id: defaultValues.id,
+ description: values.description ?? null,
+ categories: values.categories?.length
+ ? values.categories
+ : undefined,
+ });
+ capture("score_configs:update_form_submit", {
+ dataType: values.dataType,
+ });
+ }}
+ onFormSuccess={closeDialog}
+ isSubmitting={mutation.isPending}
+ />
+ </DialogContent>
+ )}
+ >
+ {({ openDialog }) => children({ disabled, openDialog })}
+ </DialogController>
);
}
diff --git a/web/src/features/web-callouts/components/WebCalloutSettingsPage.tsx b/web/src/features/web-callouts/components/WebCalloutSettingsPage.tsx
index cf9cae7ff3..57530f3007 100644
--- a/web/src/features/web-callouts/components/WebCalloutSettingsPage.tsx
+++ b/web/src/features/web-callouts/components/WebCalloutSettingsPage.tsx
@@ -1,12 +1,18 @@
-/* eslint-disable @repo/no-abstracted-overlay-trigger */
import { showErrorToast, showSuccessToast } from "@/src/features/notifications";
import { zodResolver } from "@hookform/resolvers/zod";
import { Pencil, Plus, Trash2, Webhook, X } from "lucide-react";
-import { type ReactNode, useEffect, useState } from "react";
+import {
+ type ReactNode,
+ useCallback,
+ useEffect,
+ useMemo,
+ useState,
+} from "react";
import { useFieldArray, useForm } from "react-hook-form";
import { z } from "zod";
import { ActionButton } from "@/src/components/ActionButton";
+import { ConfirmationDialogController } from "@/src/components/design-system/ConfirmationDialogController/ConfirmationDialogController";
import { createStatusTableColumn } from "@/src/components/design-system/table/columns/createStatusTableColumn";
import { createTextTableColumn } from "@/src/components/design-system/table/columns/createTextTableColumn";
import { SimpleDataTable } from "@/src/components/table/simple-data-table";
@@ -119,33 +125,6 @@ export function WebCalloutSettingsPage(props: { projectId: string }) {
{ projectId: props.projectId },
{ enabled: hasAccess },
);
- const utils = api.useUtils();
-
- const deleteMutation = api.webCallouts.delete.useMutation({
- onSuccess: async () => {
- await utils.webCallouts.invalidate();
- showSuccessToast({
- title: "Callout endpoint deleted",
- description: "The endpoint was removed from this project.",
- });
- },
- onError: (error) => {
- showErrorToast("Failed to delete callout endpoint", error.message);
- },
- });
-
- if (!hasAccess) {
- return (
- <div>
- <Alert>
- <Alert.Title>Access Denied</Alert.Title>
- <Alert.Description>
- You do not have permission to manage integrations for this project.
- </Alert.Description>
- </Alert>
- </div>
- );
- }
const configuredEndpoint = endpoints.data?.[0];
const canCreateEndpoint = !configuredEndpoint;
@@ -162,75 +141,96 @@ export function WebCalloutSettingsPage(props: { projectId: string }) {
setDialogOpen(true);
};
- const openEditDialog = (endpoint: WebCalloutEndpoint) => {
+ const openEditDialog = useCallback((endpoint: WebCalloutEndpoint) => {
setEditingEndpoint(endpoint);
setDialogOpen(true);
- };
+ }, []);
- const columns: LangfuseColumnDef<WebCalloutEndpoint>[] = [
- createTextTableColumn<WebCalloutEndpoint>({
- accessorKey: "name",
- header: "Name",
- }),
- {
- accessorKey: "url",
- header: "Endpoint",
- size: 576,
- cell: ({ getValue }) => {
- const url = getValue<string>();
- return (
- <span className="font-mono break-all" title={url}>
- {url}
- </span>
- );
+ const columns = useMemo<LangfuseColumnDef<WebCalloutEndpoint>[]>(
+ () => [
+ createTextTableColumn<WebCalloutEndpoint>({
+ accessorKey: "name",
+ header: "Name",
+ }),
+ {
+ accessorKey: "url",
+ header: "Endpoint",
+ size: 576,
+ cell: ({ getValue }) => {
+ const url = getValue<string>();
+ return (
+ <span className="font-mono break-all" title={url}>
+ {url}
+ </span>
+ );
+ },
},
- },
- {
- accessorKey: "toastMessage",
- header: "Toast Message",
- cell: ({ row }) => <ToastMessageCell endpoint={row.original} />,
- },
- {
- accessorKey: "requestHeaderKeys",
- header: "Headers",
- cell: ({ row }) => <HeaderList endpoint={row.original} />,
- },
- createStatusTableColumn<WebCalloutEndpoint, boolean>({
- accessorKey: "enabled",
- header: "Status",
- getStatus: (enabled) => (enabled ? "active" : "disabled"),
- }),
- {
- accessorKey: "id",
- header: "",
- cell: ({ row }) => (
- <div className="flex justify-end gap-1">
- <Tooltip>
- <TooltipTrigger asChild>
- <Button
- variant="ghost"
- size="icon"
- onClick={() => openEditDialog(row.original)}
- >
- <Pencil className="h-4 w-4" />
- </Button>
- </TooltipTrigger>
- <TooltipContent>Edit endpoint</TooltipContent>
- </Tooltip>
- <DeleteEndpointButton
- endpoint={row.original}
- onDelete={(id) => {
- deleteMutation.mutate({
- projectId: props.projectId,
- id,
- });
- }}
- loading={deleteMutation.isPending}
- />
- </div>
- ),
- },
- ];
+ {
+ accessorKey: "toastMessage",
+ header: "Toast Message",
+ cell: ({ row }) => <ToastMessageCell endpoint={row.original} />,
+ },
+ {
+ accessorKey: "requestHeaderKeys",
+ header: "Headers",
+ cell: ({ row }) => <HeaderList endpoint={row.original} />,
+ },
+ createStatusTableColumn<WebCalloutEndpoint, boolean>({
+ accessorKey: "enabled",
+ header: "Status",
+ getStatus: (enabled) => (enabled ? "active" : "disabled"),
+ }),
+ {
+ accessorKey: "id",
+ header: "",
+ cell: ({ row }) => (
+ <div className="flex justify-end gap-1">
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button
+ variant="ghost"
+ size="icon"
+ onClick={() => openEditDialog(row.original)}
+ >
+ <Pencil className="h-4 w-4" />
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>Edit endpoint</TooltipContent>
+ </Tooltip>
+ <DeleteEndpointDialogController
+ projectId={props.projectId}
+ endpoint={row.original}
+ >
+ {({ openDialog }) => (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button variant="ghost" size="icon" onClick={openDialog}>
+ <Trash2 className="h-4 w-4" />
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>Delete endpoint</TooltipContent>
+ </Tooltip>
+ )}
+ </DeleteEndpointDialogController>
+ </div>
+ ),
+ },
+ ],
+ [openEditDialog, props.projectId],
+ );
+
+ if (!hasAccess) {
+ return (
+ <div>
+ <Alert>
+ <Alert.Title>Access Denied</Alert.Title>
+ <Alert.Description>
+ You do not have permission to manage integrations for this project.
+ </Alert.Description>
+ </Alert>
+ </div>
+ );
+ }
return (
<div>
@@ -605,50 +605,41 @@ function WebCalloutEndpointDialog(props: {
);
}
-function DeleteEndpointButton(props: {
+function DeleteEndpointDialogController(props: {
+ projectId: string;
endpoint: WebCalloutEndpoint;
- onDelete: (id: string) => void;
- loading: boolean;
+ children: (control: { openDialog: () => void }) => ReactNode;
}) {
- const [open, setOpen] = useState(false);
+ const utils = api.useUtils();
+ const deleteMutation = api.webCallouts.delete.useMutation({
+ onSuccess: async () => {
+ await utils.webCallouts.invalidate();
+ showSuccessToast({
+ title: "Callout endpoint deleted",
+ description: "The endpoint was removed from this project.",
+ });
+ },
+ onError: (error) => {
+ showErrorToast("Failed to delete callout endpoint", error.message);
+ },
+ });
return (
- <Dialog open={open} onOpenChange={setOpen}>
- <Tooltip>
- <TooltipTrigger asChild>
- <DialogTrigger asChild>
- <Button variant="ghost" size="icon">
- <Trash2 className="h-4 w-4" />
- </Button>
- </DialogTrigger>
- </TooltipTrigger>
- <TooltipContent>Delete endpoint</TooltipContent>
- </Tooltip>
- <DialogContent>
- <DialogHeader>
- <DialogTitle>Delete Callout Endpoint</DialogTitle>
- <DialogDescription>
- This removes the configured endpoint and hides the web callout
- action.
- </DialogDescription>
- </DialogHeader>
- <DialogFooter>
- <Button variant="ghost" onClick={() => setOpen(false)}>
- Cancel
- </Button>
- <Button
- variant="destructive"
- loading={props.loading}
- onClick={() => {
- props.onDelete(props.endpoint.id);
- setOpen(false);
- }}
- >
- Delete endpoint
- </Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
+ <ConfirmationDialogController
+ title="Delete Callout Endpoint"
+ text="This removes the configured endpoint and hides the web callout action."
+ confirmLabel="Delete endpoint"
+ variant="destructive"
+ loading={deleteMutation.isPending}
+ onConfirm={() =>
+ deleteMutation.mutateAsync({
+ projectId: props.projectId,
+ id: props.endpoint.id,
+ })
+ }
+ >
+ {props.children}
+ </ConfirmationDialogController>
);
}