|
| 1 | +import { useEffect, useState } from "react"; |
| 2 | + |
| 3 | +import { useValidationIssueNavigation } from "@/components/Editor/hooks/useValidationIssueNavigation"; |
| 4 | +import { ActionBlock } from "@/components/shared/ContextPanel/Blocks/ActionBlock"; |
| 5 | +import { ContentBlock } from "@/components/shared/ContextPanel/Blocks/ContentBlock"; |
| 6 | +import { ListBlock } from "@/components/shared/ContextPanel/Blocks/ListBlock"; |
| 7 | +import { TextBlock } from "@/components/shared/ContextPanel/Blocks/TextBlock"; |
| 8 | +import { CopyText } from "@/components/shared/CopyText/CopyText"; |
| 9 | +import { TaskImplementation } from "@/components/shared/TaskDetails"; |
| 10 | +import { BlockStack } from "@/components/ui/layout"; |
| 11 | +import { useComponentSpec } from "@/providers/ComponentSpecProvider"; |
| 12 | +import { getComponentFileFromList } from "@/utils/componentStore"; |
| 13 | +import { USER_PIPELINES_LIST_NAME } from "@/utils/constants"; |
| 14 | + |
| 15 | +import PipelineIO from "../../shared/ArtifactsList/PipelineIO"; |
| 16 | +import { PipelineValidationList } from "./PipelineValidationList"; |
| 17 | +import RenamePipeline from "./RenamePipeline"; |
| 18 | + |
| 19 | +const PipelineDetails = () => { |
| 20 | + const { |
| 21 | + componentSpec, |
| 22 | + digest, |
| 23 | + isComponentTreeValid, |
| 24 | + globalValidationIssues, |
| 25 | + } = useComponentSpec(); |
| 26 | + |
| 27 | + const { handleIssueClick, groupedIssues } = useValidationIssueNavigation( |
| 28 | + globalValidationIssues, |
| 29 | + ); |
| 30 | + |
| 31 | + // State for file metadata |
| 32 | + const [fileMeta, setFileMeta] = useState<{ |
| 33 | + creationTime?: Date; |
| 34 | + modificationTime?: Date; |
| 35 | + createdBy?: string; |
| 36 | + }>({}); |
| 37 | + |
| 38 | + // Fetch file metadata on mount or when componentSpec.name changes |
| 39 | + useEffect(() => { |
| 40 | + const fetchMeta = async () => { |
| 41 | + if (!componentSpec.name) return; |
| 42 | + const file = await getComponentFileFromList( |
| 43 | + USER_PIPELINES_LIST_NAME, |
| 44 | + componentSpec.name, |
| 45 | + ); |
| 46 | + if (file) { |
| 47 | + setFileMeta({ |
| 48 | + creationTime: file.creationTime, |
| 49 | + modificationTime: file.modificationTime, |
| 50 | + createdBy: file.componentRef.spec.metadata?.annotations?.author, |
| 51 | + }); |
| 52 | + } |
| 53 | + }; |
| 54 | + fetchMeta(); |
| 55 | + }, [componentSpec.name]); |
| 56 | + |
| 57 | + const metadata = [ |
| 58 | + { |
| 59 | + label: "Created by", |
| 60 | + value: fileMeta.createdBy, |
| 61 | + }, |
| 62 | + { |
| 63 | + label: "Created at", |
| 64 | + value: fileMeta.creationTime?.toLocaleString(), |
| 65 | + }, |
| 66 | + { |
| 67 | + label: "Last updated", |
| 68 | + value: fileMeta.modificationTime?.toLocaleString(), |
| 69 | + }, |
| 70 | + ]; |
| 71 | + |
| 72 | + const annotations = Object.entries( |
| 73 | + componentSpec.metadata?.annotations || {}, |
| 74 | + ).map(([key, value]) => ({ label: key, value: String(value) })); |
| 75 | + |
| 76 | + const actions = [ |
| 77 | + <RenamePipeline key="rename-pipeline-action" />, |
| 78 | + <TaskImplementation |
| 79 | + key="pipeline-implementation-action" |
| 80 | + displayName={componentSpec.name ?? "Pipeline"} |
| 81 | + componentSpec={componentSpec} |
| 82 | + showInlineContent={false} |
| 83 | + />, |
| 84 | + ]; |
| 85 | + |
| 86 | + return ( |
| 87 | + <BlockStack |
| 88 | + gap="4" |
| 89 | + className="h-full px-2" |
| 90 | + data-context-panel="pipeline-details" |
| 91 | + > |
| 92 | + <CopyText className="text-lg font-semibold"> |
| 93 | + {componentSpec.name ?? "Unnamed Pipeline"} |
| 94 | + </CopyText> |
| 95 | + |
| 96 | + <ActionBlock actions={actions} /> |
| 97 | + |
| 98 | + <ListBlock items={metadata} marker="none" /> |
| 99 | + |
| 100 | + {componentSpec.description && ( |
| 101 | + <TextBlock title="Description" text={componentSpec.description} /> |
| 102 | + )} |
| 103 | + |
| 104 | + {digest && ( |
| 105 | + <TextBlock |
| 106 | + title="Digest" |
| 107 | + text={digest} |
| 108 | + copyable |
| 109 | + className="bg-secondary p-2 rounded-md border" |
| 110 | + mono |
| 111 | + /> |
| 112 | + )} |
| 113 | + |
| 114 | + {annotations.length > 0 && ( |
| 115 | + <ListBlock title="Annotations" items={annotations} marker="none" /> |
| 116 | + )} |
| 117 | + |
| 118 | + <PipelineIO /> |
| 119 | + |
| 120 | + <ContentBlock title="Validations"> |
| 121 | + <PipelineValidationList |
| 122 | + isComponentTreeValid={isComponentTreeValid} |
| 123 | + groupedIssues={groupedIssues} |
| 124 | + totalIssueCount={globalValidationIssues.length} |
| 125 | + onIssueSelect={handleIssueClick} |
| 126 | + /> |
| 127 | + </ContentBlock> |
| 128 | + </BlockStack> |
| 129 | + ); |
| 130 | +}; |
| 131 | + |
| 132 | +export default PipelineDetails; |
0 commit comments