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: logs on component output #2740

Merged
merged 15 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LogsLogType, OutputLogType } from "@/types/api";
import DataOutputComponent from "../../../../../../components/dataOutputComponent";
import ForwardedIconComponent from "../../../../../../components/genericIconComponent";
import {
Expand All @@ -13,26 +14,28 @@ import ErrorOutput from "./components";
interface SwitchOutputViewProps {
nodeId: string;
outputName: string;
type: "Outputs" | "Logs";
}
const SwitchOutputView: React.FC<SwitchOutputViewProps> = ({
nodeId,
outputName,
type,
}) => {
const flowPool = useFlowStore((state) => state.flowPool);
const flowPoolNode = (flowPool[nodeId] ?? [])[
(flowPool[nodeId]?.length ?? 1) - 1
];
let results = flowPoolNode?.data?.outputs[outputName] ?? "";
if (Array.isArray(results)) {
return;
}
let results: OutputLogType | LogsLogType =
(type === "Outputs"
? flowPoolNode?.data?.outputs[outputName]
: flowPoolNode?.data?.logs[outputName]) ?? {};
const resultType = results?.type;
let resultMessage = results?.message;
let resultMessage = results?.message ?? {};
const RECORD_TYPES = ["data", "object", "array", "message"];
if (resultMessage?.raw) {
resultMessage = resultMessage.raw;
}
return (
return type === "Outputs" ? (
<>
<Case condition={!resultType || resultType === "unknown"}>
<div>NO OUTPUT</div>
Expand All @@ -54,7 +57,9 @@ const SwitchOutputView: React.FC<SwitchOutputViewProps> = ({
? (resultMessage as Array<any>).every((item) => item.data)
? (resultMessage as Array<any>).map((item) => item.data)
: resultMessage
: [resultMessage]
: Object.keys(resultMessage).length > 0
? [resultMessage]
: []
}
pagination={true}
columnMode="union"
Expand All @@ -78,6 +83,20 @@ const SwitchOutputView: React.FC<SwitchOutputViewProps> = ({
</div>
</Case>
</>
) : (
<DataOutputComponent
rows={
Array.isArray(results)
? (results as Array<any>).every((item) => item.data)
? (results as Array<any>).map((item) => item.data)
: results
: Object.keys(results).length > 0
? [results]
: []
}
pagination={true}
columnMode="union"
/>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { useState } from "react";
import { Button } from "../../../../components/ui/button";
import BaseModal from "../../../../modals/baseModal";
import SwitchOutputView from "./components/switchOutputView";
Expand All @@ -8,15 +10,32 @@ export default function OutputModal({
nodeId,
outputName,
}): JSX.Element {
const [activeTab, setActiveTab] = useState<"Outputs" | "Logs">("Outputs");
return (
<BaseModal open={open} setOpen={setOpen} size="medium-tall">
<BaseModal open={open} setOpen={setOpen} size="large">
<BaseModal.Header description="Inspect the output of the component below.">
<div className="flex items-center">
<span className="pr-2">Component Output</span>
</div>
</BaseModal.Header>
<BaseModal.Content>
<SwitchOutputView nodeId={nodeId} outputName={outputName} />
<Tabs
value={activeTab}
onValueChange={(value) => setActiveTab(value as "Outputs" | "Logs")}
className={
"absolute top-6 flex flex-col self-center overflow-hidden rounded-md border bg-muted text-center"
}
>
<TabsList>
<TabsTrigger value="Outputs">Outputs</TabsTrigger>
<TabsTrigger value="Logs">Logs</TabsTrigger>
</TabsList>
</Tabs>
<SwitchOutputView
nodeId={nodeId}
outputName={outputName}
type={activeTab}
/>
</BaseModal.Content>
<BaseModal.Footer>
<div className="flex w-full justify-end pt-2">
Expand Down
6 changes: 6 additions & 0 deletions src/frontend/src/types/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,18 @@ export type OutputLogType = {
message: any | ErrorLogType;
type: string;
};
export type LogsLogType = {
name: string;
message: any | ErrorLogType;
type: string;
};

// data is the object received by the API
// it has results, artifacts, timedelta, duration
export type VertexDataTypeAPI = {
results: { [key: string]: string };
outputs: { [key: string]: OutputLogType };
logs: { [key: string]: LogsLogType };
messages: ChatOutputType[] | ChatInputType[];
inactive?: boolean;
timedelta?: number;
Expand Down
Loading