Skip to content

Commit

Permalink
Merge branch 'main' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
daryllimyt committed Dec 24, 2024
2 parents 4c9b130 + b4e6787 commit eca20d6
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 86 deletions.
175 changes: 98 additions & 77 deletions frontend/src/components/dashboard/dashboard-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import React, { useState } from "react"
import { useRouter, useSearchParams } from "next/navigation"
import { WorkflowMetadataResponse } from "@/client"
import { TagRead, WorkflowMetadataResponse } from "@/client"
import { useWorkspace } from "@/providers/workspace"
import { DotsHorizontalIcon } from "@radix-ui/react-icons"
import { Row } from "@tanstack/react-table"
Expand Down Expand Up @@ -155,19 +155,7 @@ export function WorkflowsDashboardTable() {
?.length ? (
row
.getValue<WorkflowMetadataResponse["tags"]>("tags")
?.map((tag) => (
<Badge
key={tag.id}
variant="secondary"
className="text-xs"
style={{
backgroundColor: tag.color || undefined,
color: tag.color ? "white" : undefined,
}}
>
{tag.name}
</Badge>
))
?.map((tag) => <TagBadge key={tag.id} tag={tag} />)
) : (
<span className="text-xs text-muted-foreground">-</span>
)}
Expand Down Expand Up @@ -222,72 +210,89 @@ export function WorkflowsDashboardTable() {
>
Copy Workflow ID
</DropdownMenuItem>
<DropdownMenuSub>
<DropdownMenuSubTrigger
className="text-xs"
onClick={(e) => e.stopPropagation()}
>
Tags
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent>
{tags?.map((tag) => {
const hasTag = row.original.tags?.some(
(t) => t.id === tag.id
)
return (
<DropdownMenuCheckboxItem
key={tag.id}
className="text-xs"
checked={hasTag}
onClick={async (e) => {
e.stopPropagation()
try {
if (hasTag) {
// Delete tag if already exists
await removeWorkflowTag({
workflowId: row.original.id,
workspaceId,
tagId: tag.id,
})
toast({
title: "Tag removed",
description: `Successfully removed tag "${tag.name}" from workflow`,
})
} else {
// Add tag if doesn't exist
await addWorkflowTag({
workflowId: row.original.id,
workspaceId,
requestBody: {
tag_id: tag.id,
},
})
{tags && tags.length > 0 ? (
<DropdownMenuSub>
<DropdownMenuSubTrigger
className="text-xs"
onClick={(e) => e.stopPropagation()}
>
Tags
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent>
{/* No tags */}

{tags.map((tag) => {
const hasTag = row.original.tags?.some(
(t) => t.id === tag.id
)
return (
<DropdownMenuCheckboxItem
key={tag.id}
className="text-xs"
checked={hasTag}
onClick={async (e) => {
e.stopPropagation()
try {
if (hasTag) {
// Delete tag if already exists
await removeWorkflowTag({
workflowId: row.original.id,
workspaceId,
tagId: tag.id,
})
toast({
title: "Tag removed",
description: `Successfully removed tag "${tag.name}" from workflow`,
})
} else {
// Add tag if doesn't exist
await addWorkflowTag({
workflowId: row.original.id,
workspaceId,
requestBody: {
tag_id: tag.id,
},
})
toast({
title: "Tag added",
description: `Successfully added tag "${tag.name}" to workflow`,
})
}
} catch (error) {
console.error(
"Failed to modify tag:",
error
)
toast({
title: "Tag added",
description: `Successfully added tag "${tag.name}" to workflow`,
title: "Error",
description: `Failed to ${hasTag ? "remove" : "add"} tag ${hasTag ? "from" : "to"} workflow`,
variant: "destructive",
})
}
} catch (error) {
console.error(
"Failed to modify tag:",
error
)
toast({
title: "Error",
description: `Failed to ${hasTag ? "remove" : "add"} tag ${hasTag ? "from" : "to"} workflow`,
variant: "destructive",
})
}
}}
>
{tag.name}
</DropdownMenuCheckboxItem>
)
})}
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
}}
>
<div
className="mr-2 flex size-2 rounded-full"
style={{
backgroundColor: tag.color || undefined,
}}
/>
<span>{tag.name}</span>
</DropdownMenuCheckboxItem>
)
})}
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
) : (
<DropdownMenuItem
className="!bg-transparent text-xs !text-muted-foreground hover:cursor-not-allowed"
onClick={(e) => e.stopPropagation()}
>
<span>No tags available</span>
</DropdownMenuItem>
)}
<DropdownMenuItem
className="text-xs"
onClick={async (e) => {
Expand Down Expand Up @@ -367,3 +372,19 @@ const defaultToolbarProps: DataTableToolbarProps = {
column: "title",
},
}

export function TagBadge({ tag }: { tag: TagRead }) {
return (
<Badge
key={tag.id}
variant="secondary"
className="text-xs"
style={{
backgroundColor: tag.color || undefined,
color: tag.color ? "white" : undefined,
}}
>
{tag.name}
</Badge>
)
}
14 changes: 6 additions & 8 deletions frontend/src/components/dashboard/workflow-tags-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ import { useRouter } from "next/navigation"
import { TagCreate, TagRead, TagUpdate } from "@/client"
import { useWorkspace } from "@/providers/workspace"
import { zodResolver } from "@hookform/resolvers/zod"
import {
EllipsisIcon,
PencilIcon,
Plus,
Tag,
Trash2Icon,
} from "lucide-react"
import { EllipsisIcon, PencilIcon, Plus, Tag, Trash2Icon } from "lucide-react"
import { useForm } from "react-hook-form"
import z from "zod"

Expand Down Expand Up @@ -73,11 +67,15 @@ const createTagSchema = z.object({

export function WorkflowTagsSidebar({ workspaceId }: { workspaceId: string }) {
const router = useRouter()
const { tags, createTag, tagsIsLoading, deleteTag } = useTags(workspaceId)
const { tags, createTag, tagsIsLoading } = useTags(workspaceId)
const [showTagDialog, setShowTagDialog] = useState(false)

const methods = useForm<TagCreate>({
resolver: zodResolver(createTagSchema),
defaultValues: {
name: "",
color: "#aabbcc",
},
})

const handleCreateTag = async (params: TagCreate) => {
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ build:
docker compose build --no-cache

lint-ui:
cd frontend && pnpm lint:fix && cd ..
cd frontend && pnpm lint:fix && pnpm typecheck && cd ..
lint-app:
ruff check .

Expand Down

0 comments on commit eca20d6

Please sign in to comment.