Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(prompts): update prompt version tags on set #5946

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/src/pages/prompt/NewPromptVersionTagDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ export function NewPromptVersionDialog({
const [commitCreate, isCommitting] = useMutation(graphql`
mutation NewPromptVersionTagDialogMutation(
$input: SetPromptVersionTagInput!
$promptVersionId: GlobalID!
) {
setPromptVersionTag(input: $input) {
promptVersionTag {
id
query {
node(id: $promptVersionId) {
...PromptVersionTagsList_data
}
}
}
}
Expand All @@ -69,6 +72,7 @@ export function NewPromptVersionDialog({
description: newTag.description,
promptVersionId: promptVersionId,
},
promptVersionId,
},
onCompleted: () => {
onNewTagCreated(newTag);
Expand Down
12 changes: 2 additions & 10 deletions app/src/pages/prompt/PromptVersionDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import {
CopyToClipboardButton,
Flex,
Heading,
Tag,
TagGroup,
TagList,
View,
} from "@phoenix/components";
import { PromptModelConfigurationCard } from "@phoenix/pages/prompt/PromptModelConfigurationCard";

import { promptVersionLoaderQuery$data } from "./__generated__/promptVersionLoaderQuery.graphql";
import { PromptChatMessagesCard } from "./PromptChatMessagesCard";
import { PromptCodeExportCard } from "./PromptCodeExportCard";
import { PromptVersionTagsList } from "./PromptVersionTagsList";
import { TagPromptVersionButton } from "./TagPromptVersionButton";

export function PromptVersionDetailsPage() {
Expand All @@ -27,8 +25,6 @@ function PromptVersionDetailsPageContent({
}: {
promptVersion: promptVersionLoaderQuery$data["promptVersion"];
}) {
const tags =
promptVersion?.tags?.map((tag) => ({ id: tag.name, ...tag })) || [];
return (
<View width="100%" overflow="auto" elementType="section">
<View
Expand All @@ -40,11 +36,7 @@ function PromptVersionDetailsPageContent({
<Flex direction="row" justifyContent="space-between">
<Flex direction="row" gap="size-100">
<Heading level={2}>{`Version: ${promptVersion.id}`}</Heading>
<TagGroup aria-label="Prompt Version Tags">
<TagList items={tags}>
{(tag) => <Tag key={tag.name}>{tag.name}</Tag>}
</TagList>
</TagGroup>
<PromptVersionTagsList promptVersion={promptVersion} />
</Flex>
<Flex direction="row" gap="size-100">
<CopyToClipboardButton text={promptVersion.id}>
Expand Down
34 changes: 34 additions & 0 deletions app/src/pages/prompt/PromptVersionTagsList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from "react";
import { graphql, useFragment } from "react-relay";

import { Tag, TagGroup, TagList } from "@phoenix/components";

import { PromptVersionTagsList_data$key } from "./__generated__/PromptVersionTagsList_data.graphql";

export function PromptVersionTagsList({
promptVersion,
}: {
promptVersion: PromptVersionTagsList_data$key;
}) {
const data = useFragment<PromptVersionTagsList_data$key>(
graphql`
fragment PromptVersionTagsList_data on PromptVersion {
tags {
id
name
}
}
`,
promptVersion
);

const tags = data.tags.map((tag) => ({
id: tag.id,
name: tag.name,
}));
return (
<TagGroup aria-label="Prompt Version Tags">
<TagList items={tags}>{(tag) => <Tag>{tag.name}</Tag>}</TagList>
</TagGroup>
Comment on lines +25 to +32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This map seems extraneous

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it seems that way but in reality the aria-components builds a collection under the hood. Without this it's not wrapped in a collection and it doesn't let you map over tags inside the list. It's weird but how it works.

);
}
15 changes: 4 additions & 11 deletions app/src/pages/prompt/PromptVersionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { Link } from "react-router-dom";
import { formatRelative } from "date-fns";
import { css } from "@emotion/react";

import { Flex, Tag, TagGroup, TagList, Text, View } from "@phoenix/components";
import { Flex, Text, View } from "@phoenix/components";
import { Truncate } from "@phoenix/components/utility/Truncate";

import {
PromptVersionsList__main$data,
PromptVersionsList__main$key,
} from "./__generated__/PromptVersionsList__main.graphql";
import { PromptVersionTagsList } from "./PromptVersionTagsList";

export type PromptVersionItemProps = {
version: PromptVersionsList__main$data["promptVersions"]["edges"][number]["version"];
Expand Down Expand Up @@ -44,10 +45,6 @@ export const PromptVersionItem = ({
version,
active,
}: PromptVersionItemProps) => {
const tags = version.tags.map((tag) => ({
id: tag.name,
name: tag.name,
}));
return (
<div css={promptVersionItemCSS} data-active={active}>
<Link to={`${version.id}`}>
Expand All @@ -68,9 +65,7 @@ export const PromptVersionItem = ({
<Truncate maxWidth={"100%"}>
<Text color="text-700">{version.description}</Text>
</Truncate>
<TagGroup aria-label="Prompt Version Tags">
<TagList items={tags}>{(tag) => <Tag>{tag.name}</Tag>}</TagList>
</TagGroup>
<PromptVersionTagsList promptVersion={version} />
</Flex>
</View>
</Link>
Expand Down Expand Up @@ -103,9 +98,7 @@ export const PromptVersionsList = ({
id
description
createdAt
tags {
name
}
...PromptVersionTagsList_data
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions app/src/pages/prompt/TagPromptVersionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,13 @@ function TagList({
const [commitSetTag, isCommitting] = useMutation(graphql`
mutation TagPromptVersionButtonSetTagMutation(
$input: SetPromptVersionTagInput!
$promptVersionId: GlobalID!
) {
setPromptVersionTag(input: $input) {
promptVersionTag {
id
query {
node(id: $promptVersionId) {
...PromptVersionTagsList_data
}
}
}
}
Expand Down Expand Up @@ -169,6 +172,7 @@ function TagList({
name: tagName,
promptVersionId: versionId,
},
promptVersionId: versionId,
},
onCompleted: () => {
onTagSet(tagName);
Expand Down
Loading
Loading