Fixed playground name and collection card

This commit is contained in:
Lucas Oliveira 2024-04-30 15:05:03 +02:00
commit 6b72b41b86
3 changed files with 200 additions and 224 deletions

View file

@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
import { getComponent, postLikeComponent } from "../../controllers/API"; import { getComponent, postLikeComponent } from "../../controllers/API";
import DeleteConfirmationModal from "../../modals/DeleteConfirmationModal"; import DeleteConfirmationModal from "../../modals/DeleteConfirmationModal";
import IOModal from "../../modals/IOModal"; import IOModal from "../../modals/IOModal";
import IOModal from "../../modals/IOModal";
import useAlertStore from "../../stores/alertStore"; import useAlertStore from "../../stores/alertStore";
import useFlowStore from "../../stores/flowStore"; import useFlowStore from "../../stores/flowStore";
import useFlowsManagerStore from "../../stores/flowsManagerStore"; import useFlowsManagerStore from "../../stores/flowsManagerStore";
@ -27,12 +28,15 @@ export default function CollectionCardComponent({
authorized = true, authorized = true,
disabled = false, disabled = false,
button, button,
onClick,
onDelete, onDelete,
playground, playground,
playground,
}: { }: {
data: storeComponent; data: storeComponent;
authorized?: boolean; authorized?: boolean;
disabled?: boolean; disabled?: boolean;
onClick?: () => void;
button?: JSX.Element; button?: JSX.Element;
playground?: boolean; playground?: boolean;
onDelete?: () => void; onDelete?: () => void;
@ -165,72 +169,67 @@ export default function CollectionCardComponent({
} }
return ( return (
<> <Card
<Card className={cn(
className={cn( "group relative flex min-h-[11rem] flex-col justify-between overflow-hidden transition-all hover:shadow-md",
"group relative flex min-h-[11rem] flex-col justify-between overflow-hidden transition-all hover:shadow-md", disabled ? "pointer-events-none opacity-50" : "",
disabled ? "pointer-events-none opacity-50" : "" onClick ? "cursor-pointer" : ""
)} )}
> onClick={onClick}
<div> >
<CardHeader> <div>
<div> <CardHeader>
<CardTitle className="flex w-full items-center justify-between gap-3 text-xl"> <div>
<IconComponent <CardTitle className="flex w-full items-center justify-between gap-3 text-xl">
className={cn( <IconComponent
"flex-shrink-0", className={cn(
data.is_component "flex-shrink-0",
? "mx-0.5 h-6 w-6 text-component-icon" data.is_component
: "h-7 w-7 flex-shrink-0 text-flow-icon" ? "mx-0.5 h-6 w-6 text-component-icon"
)} : "h-7 w-7 flex-shrink-0 text-flow-icon"
name={data.is_component ? "ToyBrick" : "Group"}
/>
<ShadTooltip content={data.name}>
<div className="w-full truncate">{data.name}</div>
</ShadTooltip>
{data?.metadata !== undefined && (
<div className="flex gap-3">
{data.private && (
<ShadTooltip content="Private">
<span className="flex items-center gap-1.5 text-xs text-muted-foreground">
<IconComponent name="Lock" className="h-4 w-4" />
</span>
</ShadTooltip>
)}
{!data.is_component && (
<ShadTooltip content="Components">
<span className="flex items-center gap-1.5 text-xs text-muted-foreground">
<IconComponent name="ToyBrick" className="h-4 w-4" />
<span data-testid={`total-${data.name}`}>
{data?.metadata?.total ?? 0}
</span>
</span>
</ShadTooltip>
)}
<ShadTooltip content="Likes">
<span className="flex items-center gap-1.5 text-xs text-muted-foreground">
<IconComponent
name="Heart"
className={cn("h-4 w-4 ")}
/>
<span data-testid={`likes-${data.name}`}>
{likes_count ?? 0}
</span>
</span>
</ShadTooltip>
<ShadTooltip content="Downloads">
<span className="flex items-center gap-1.5 text-xs text-muted-foreground">
<IconComponent
name="DownloadCloud"
className="h-4 w-4"
/>
<span data-testid={`downloads-${data.name}`}>
{downloads_count ?? 0}
</span>
</span>
</ShadTooltip>
</div>
)} )}
name={data.is_component ? "ToyBrick" : "Group"}
/>
<ShadTooltip content={data.name}>
<div className="w-full truncate">{data.name}</div>
</ShadTooltip>
{data?.metadata !== undefined && (
<div className="flex gap-3">
{data.private && (
<ShadTooltip content="Private">
<span className="flex items-center gap-1.5 text-xs text-muted-foreground">
<IconComponent name="Lock" className="h-4 w-4" />
</span>
</ShadTooltip>
)}
{!data.is_component && (
<ShadTooltip content="Components">
<span className="flex items-center gap-1.5 text-xs text-muted-foreground">
<IconComponent name="ToyBrick" className="h-4 w-4" />
<span data-testid={`total-${data.name}`}>
{data?.metadata?.total ?? 0}
</span>
</span>
</ShadTooltip>
)}
<ShadTooltip content="Likes">
<span className="flex items-center gap-1.5 text-xs text-muted-foreground">
<IconComponent name="Heart" className={cn("h-4 w-4 ")} />
<span data-testid={`likes-${data.name}`}>
{likes_count ?? 0}
</span>
</span>
</ShadTooltip>
<ShadTooltip content="Downloads">
<span className="flex items-center gap-1.5 text-xs text-muted-foreground">
<IconComponent name="DownloadCloud" className="h-4 w-4" />
<span data-testid={`downloads-${data.name}`}>
{downloads_count ?? 0}
</span>
</span>
</ShadTooltip>
</div>
)}
{onDelete && data?.metadata === undefined && ( {onDelete && data?.metadata === undefined && (
<DeleteConfirmationModal <DeleteConfirmationModal
@ -268,180 +267,176 @@ export default function CollectionCardComponent({
</CardHeader> </CardHeader>
</div> </div>
<CardFooter> <CardFooter>
<div className="flex w-full items-center justify-between gap-2"> <div className="flex w-full items-center justify-between gap-2">
<div className="flex w-full flex-wrap items-end justify-between gap-2"> <div className="flex w-full flex-wrap items-end justify-between gap-2">
<div className="flex w-full flex-1 flex-wrap gap-2"> <div className="flex w-full flex-1 flex-wrap gap-2">
{data.tags && {data.tags &&
data.tags.length > 0 && data.tags.length > 0 &&
data.tags.map((tag, index) => ( data.tags.map((tag, index) => (
<Badge <Badge
key={index} key={index}
variant="outline" variant="outline"
size="xq" size="xq"
className="text-muted-foreground" className="text-muted-foreground"
> >
{tag.name} {tag.name}
</Badge> </Badge>
))} ))}
</div> </div>
{data.liked_by_count != undefined && ( {data.liked_by_count != undefined && (
<div className="flex gap-0.5"> <div className="flex gap-0.5">
{onDelete && data?.metadata !== undefined ? ( {onDelete && data?.metadata !== undefined ? (
<ShadTooltip <ShadTooltip
content={ content={
authorized ? "Delete" : "Please review your API key." authorized ? "Delete" : "Please review your API key."
} }
> >
<DeleteConfirmationModal <DeleteConfirmationModal
onConfirm={() => { onConfirm={() => {
onDelete(); onDelete();
}} }}
>
<Button
variant="ghost"
size="icon"
className={
"whitespace-nowrap" +
(!authorized ? " cursor-not-allowed" : "")
}
>
<IconComponent
name="Trash2"
className={cn(
"h-5 w-5",
!authorized ? " text-ring" : ""
)}
/>
</Button>
</DeleteConfirmationModal>
</ShadTooltip>
) : (
<ShadTooltip
content={
authorized ? "Like" : "Please review your API key."
}
> >
<Button <Button
disabled={loadingLike}
variant="ghost" variant="ghost"
size="icon" size="icon"
className={ className={
"whitespace-nowrap" + "whitespace-nowrap" +
(!authorized ? " cursor-not-allowed" : "") (!authorized ? " cursor-not-allowed" : "")
} }
onClick={() => {
if (!authorized) {
return;
}
handleLike();
}}
data-testid={`like-${data.name}`}
> >
<IconComponent <IconComponent
name="Heart" name="Trash2"
className={cn( className={cn(
"h-5 w-5", "h-5 w-5",
liked_by_user
? "fill-destructive stroke-destructive"
: "",
!authorized ? " text-ring" : "" !authorized ? " text-ring" : ""
)} )}
/> />
</Button> </Button>
</ShadTooltip> </DeleteConfirmationModal>
)} </ShadTooltip>
) : (
<ShadTooltip <ShadTooltip
content={ content={
authorized authorized ? "Like" : "Please review your API key."
? isStore
? "Download"
: "Install Locally"
: "Please review your API key."
} }
> >
<Button <Button
disabled={loading} disabled={loadingLike}
variant="ghost" variant="ghost"
size="icon" size="icon"
className={ className={
"whitespace-nowrap" + "whitespace-nowrap" +
(!authorized ? " cursor-not-allowed" : "") + (!authorized ? " cursor-not-allowed" : "")
(!loading ? " p-0.5" : "")
} }
onClick={() => { onClick={() => {
if (loading || !authorized) { if (!authorized) {
return; return;
} }
handleInstall(); handleLike();
}} }}
data-testid={`install-${data.name}`} data-testid={`like-${data.name}`}
> >
<IconComponent <IconComponent
name={ name="Heart"
loading ? "Loader2" : isStore ? "Download" : "Plus"
}
className={cn( className={cn(
loading ? "h-5 w-5 animate-spin" : "h-5 w-5", "h-5 w-5",
liked_by_user
? "fill-destructive stroke-destructive"
: "",
!authorized ? " text-ring" : "" !authorized ? " text-ring" : ""
)} )}
/> />
</Button> </Button>
</ShadTooltip> </ShadTooltip>
</div> )}
)} <ShadTooltip
{button && button} content={
{playground && ( authorized
<Button ? isStore
disabled={loadingPlayground} ? "Download"
key={data.id} : "Install Locally"
tabIndex={-1} : "Please review your API key."
variant="outline" }
size="sm" >
className="whitespace-nowrap " <Button
data-testid={"playground-flow-button-" + data.id} disabled={loading}
onClick={() => { variant="ghost"
setLoadingPlayground(true); size="icon"
if (getFlowById(data.id)) { className={
setCurrentFlowId(data.id); "whitespace-nowrap" +
(!authorized ? " cursor-not-allowed" : "") +
(!loading ? " p-0.5" : "")
}
onClick={() => {
if (loading || !authorized) {
return;
}
handleInstall();
}}
data-testid={`install-${data.name}`}
>
<IconComponent
name={loading ? "Loader2" : isStore ? "Download" : "Plus"}
className={cn(
loading ? "h-5 w-5 animate-spin" : "h-5 w-5",
!authorized ? " text-ring" : ""
)}
/>
</Button>
</ShadTooltip>
</div>
)}
{button && button}
{playground && (
<Button
disabled={loadingPlayground}
key={data.id}
tabIndex={-1}
variant="outline"
size="sm"
className="whitespace-nowrap gap-2"
data-testid={"playground-flow-button-" + data.id}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
setLoadingPlayground(true);
if (getFlowById(data.id)) {
setCurrentFlowId(data.id);
setOpenPlayground(true);
setLoadingPlayground(false);
} else {
getFlowData().then((res) => {
setCurrentFlow(res);
setOpenPlayground(true); setOpenPlayground(true);
setLoadingPlayground(false); setLoadingPlayground(false);
} else { });
getFlowData().then((res) => { }
setCurrentFlow(res); }}
setOpenPlayground(true); >
setLoadingPlayground(false); {!loadingPlayground ? (
}); <IconComponent
} name="Zap"
}} className="h-4 w-4 select-none fill-current text-medium-indigo"
> />
{!loadingPlayground ? ( ) : (
<> <Loading className="h-4 w-4 text-medium-indigo" />
<IconComponent )}
name="ExternalLink" Playground
className="main-page-nav-button select-none" </Button>
/> )}
Playground {openPlayground && (
</> <IOModal
) : ( cleanOnClose={true}
<Loading /> open={openPlayground}
)} setOpen={setOpenPlayground}
</Button> >
)} <></>
</div> </IOModal>
)}
</div> </div>
</CardFooter> </div>
</Card> </CardFooter>
</Card>
{openPlayground && (
<IOModal
cleanOnClose={true}
open={openPlayground}
setOpen={setOpenPlayground}
>
<></>
</IOModal>
)}
</>
); );
} }

View file

@ -126,9 +126,9 @@ export default function IOModal({
{/* TODO ADAPT TO ALL TYPES OF INPUTS AND OUTPUTS */} {/* TODO ADAPT TO ALL TYPES OF INPUTS AND OUTPUTS */}
<BaseModal.Header description={CHAT_FORM_DIALOG_SUBTITLE}> <BaseModal.Header description={CHAT_FORM_DIALOG_SUBTITLE}>
<div className="flex items-center"> <div className="flex items-center">
<span className="pr-2">Interaction Panel</span> <span className="pr-2">Playground</span>
<IconComponent <IconComponent
name="prompts" name="Zap"
className="h-6 w-6 pl-1 text-foreground" className="h-6 w-6 pl-1 text-foreground"
aria-hidden="true" aria-hidden="true"
/> />

View file

@ -146,30 +146,11 @@ export default function ComponentsComponent({
}} }}
key={idx} key={idx}
data={item} data={item}
disabled={isLoading} data-testid={
button={ "edit-flow-button-" + item.id + "-" + idx
!is_component ? (
<Link to={"/flow/" + item.id}>
<Button
tabIndex={-1}
variant="outline"
size="sm"
className="whitespace-nowrap "
data-testid={
"edit-flow-button-" + item.id + "-" + idx
}
>
<IconComponent
name="ExternalLink"
className="main-page-nav-button select-none"
/>
Edit Flow
</Button>
</Link>
) : (
<></>
)
} }
onClick={!is_component ? () => {navigate("/flow/" + item.id);} : undefined}
disabled={isLoading}
playground={!is_component} playground={!is_component}
/> />
)) ))