Skip to content

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

style(score-configs): add confirm modal upon score config creation; add score data type icons on annotation drawer (#2910)

marliessophiec42ff44f8f3d
diff --git a/web/src/components/grouped-score-badge.tsx b/web/src/components/grouped-score-badge.tsx
index 5e9192f68a..0108fad22a 100644
--- a/web/src/components/grouped-score-badge.tsx
+++ b/web/src/components/grouped-score-badge.tsx
@@ -36,7 +36,7 @@ export const GroupedScoreBadges = <T extends APIScore | LastUserScore>({
<p className="truncate" title={name}>
{name}:
</p>
- <div className="flex items-center gap-3 text-nowrap">
+ <div className="flex items-center gap-1 text-nowrap">
{scores.map((s, i) => (
<span
key={i}
diff --git a/web/src/features/scores/components/AnnotateDrawer.tsx b/web/src/features/scores/components/AnnotateDrawer.tsx
index e8c8cb0433..d12a634f91 100644
--- a/web/src/features/scores/components/AnnotateDrawer.tsx
+++ b/web/src/features/scores/components/AnnotateDrawer.tsx
@@ -73,6 +73,7 @@ import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePos
import { cn } from "@/src/utils/tailwind";
import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
import { isPresent } from "@/src/utils/typeChecks";
+import { getScoreDataTypeIcon } from "@/src/features/scores/components/ScoreDetailColumnHelpers";
const AnnotationScoreDataSchema = z.object({
name: z.string(),
@@ -608,7 +609,7 @@ function AnnotateDrawerInner({
)
.map((config) => ({
key: config.id,
- value: config.name,
+ value: `${getScoreDataTypeIcon(config.dataType)} ${config.name}`,
disabled: fields.some(
(field) =>
!!field.scoreId && field.configId === config.id,
@@ -618,7 +619,7 @@ function AnnotateDrawerInner({
values={fields
.filter((field) => !!field.configId)
.map((field) => ({
- value: field.name,
+ value: `${getScoreDataTypeIcon(field.dataType)} ${field.name}`,
key: field.configId as string,
}))}
controlButtons={
@@ -628,9 +629,7 @@ function AnnotateDrawerInner({
type: type,
source: source,
});
- router.push(
- `/project/${projectId}/settings#score-configs`,
- );
+ router.push(`/project/${projectId}/settings/scores`);
}}
>
Manage score configs
diff --git a/web/src/features/scores/components/CreateScoreConfigButton.tsx b/web/src/features/scores/components/CreateScoreConfigButton.tsx
index da652a4819..a0c838540e 100644
--- a/web/src/features/scores/components/CreateScoreConfigButton.tsx
+++ b/web/src/features/scores/components/CreateScoreConfigButton.tsx
@@ -60,7 +60,11 @@ const validateScoreConfig = (values: CreateConfig): string | null => {
const { dataType, maxValue, minValue, categories } = values;
if (isNumericDataType(dataType)) {
- if (isPresent(maxValue) && isPresent(minValue) && maxValue <= minValue) {
+ if (
+ isPresent(maxValue) &&
+ isPresent(minValue) &&
+ Number(maxValue) <= Number(minValue)
+ ) {
return "Maximum value must be greater than Minimum value.";
}
} else if (isCategoricalDataType(dataType)) {
@@ -98,6 +102,7 @@ const validateScoreConfig = (values: CreateConfig): string | null => {
export function CreateScoreConfigButton({ projectId }: { projectId: string }) {
const [open, setOpen] = useState(false);
const [formError, setFormError] = useState<string | null>(null);
+ const [confirmOpen, setConfirmOpen] = useState(false);
const capture = usePostHogClientCapture();
const hasAccess = useHasProjectAccess({
@@ -129,15 +134,17 @@ export function CreateScoreConfigButton({ projectId }: { projectId: string }) {
if (!hasAccess) return null;
- function onSubmit(values: CreateConfig) {
+ async function onSubmit(values: CreateConfig) {
const error = validateScoreConfig(values);
setFormError(error);
- if (error) return;
+ const isValid = await form.trigger();
+ if (!isValid || error) return;
return createScoreConfig
.mutateAsync({
projectId,
...values,
+ categories: values.categories?.length ? values.categories : undefined,
})
.then(() => {
capture("score_configs:create_form_submit", {
@@ -145,12 +152,22 @@ export function CreateScoreConfigButton({ projectId }: { projectId: string }) {
});
form.reset();
setOpen(false);
+ setConfirmOpen(false);
})
.catch((error) => {
console.error(error);
});
}
+ const handleSubmitConfirm = async () => {
+ const error = validateScoreConfig(form.getValues());
+ setFormError(error);
+ const isValid = await form.trigger();
+ if (isValid && !error) {
+ setConfirmOpen(true);
+ }
+ };
+
return (
<>
<Dialog
@@ -158,6 +175,7 @@ export function CreateScoreConfigButton({ projectId }: { projectId: string }) {
onOpenChange={(v) => {
setOpen(v);
form.reset();
+ setFormError(null);
}}
>
<DialogTrigger asChild>
@@ -396,14 +414,50 @@ export function CreateScoreConfigButton({ projectId }: { projectId: string }) {
</>
)}
/>
- <Button
- type="submit"
- className="w-full"
- loading={form.formState.isSubmitting}
- >
- Submit
- </Button>
</form>
+ <Dialog
+ open={confirmOpen}
+ onOpenChange={(isOpenAction) => {
+ if (!isOpenAction && !form.formState.isSubmitting)
+ setConfirmOpen(false);
+ }}
+ >
+ <DialogTrigger asChild>
+ <Button
+ type="button"
+ className="w-full"
+ onClick={handleSubmitConfirm}
+ >
+ Submit
+ </Button>
+ </DialogTrigger>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Confirm Submission</DialogTitle>
+ </DialogHeader>
+ <p className="text-sm">
+ Score configs cannot be edited or deleted after they have been
+ created. Are you sure you want to proceed?
+ </p>
+ <div className="flex justify-end space-x-2">
+ <Button
+ type="button"
+ variant="outline"
+ disabled={form.formState.isSubmitting}
+ onClick={() => setConfirmOpen(false)}
+ >
+ Continue Editing
+ </Button>
+ <Button
+ type="submit"
+ loading={form.formState.isSubmitting}
+ onClick={form.handleSubmit(onSubmit)}
+ >
+ Confirm
+ </Button>
+ </div>
+ </DialogContent>
+ </Dialog>
{formError ? (
<p className="text-red text-center">
<span className="font-bold">Error:</span> {formError}
diff --git a/web/src/features/scores/components/ScoreDetailColumnHelpers.tsx b/web/src/features/scores/components/ScoreDetailColumnHelpers.tsx
index b197ad16f7..2ab8e58f6b 100644
--- a/web/src/features/scores/components/ScoreDetailColumnHelpers.tsx
+++ b/web/src/features/scores/components/ScoreDetailColumnHelpers.tsx
@@ -28,7 +28,7 @@ const prefixScoreColKey = (
prefix: "Trace" | "Generation",
): string => `${prefix}-${key}`;
-const getScoreDataTypeIcon = (dataType: ScoreDataType): string => {
+export const getScoreDataTypeIcon = (dataType: ScoreDataType): string => {
switch (dataType) {
case "NUMERIC":
default: