|
16 | 16 | * specific language governing permissions and limitations |
17 | 17 | * under the License. |
18 | 18 | */ |
19 | | -import { Flex, Heading, HStack } from "@chakra-ui/react"; |
| 19 | +import { Flex, Heading, HStack, Text } from "@chakra-ui/react"; |
20 | 20 | import type { NodeProps, Node as NodeType } from "@xyflow/react"; |
21 | 21 | import { FiDatabase } from "react-icons/fi"; |
| 22 | +import { useParams } from "react-router-dom"; |
22 | 23 |
|
| 24 | +import { useAssetServiceGetAssetEvents, useDagRunServiceGetUpstreamAssetEvents } from "openapi/queries"; |
| 25 | +import { pluralize } from "src/utils"; |
| 26 | + |
| 27 | +import Time from "../Time"; |
23 | 28 | import { NodeWrapper } from "./NodeWrapper"; |
24 | 29 | import type { CustomNodeProps } from "./reactflowUtils"; |
25 | 30 |
|
26 | 31 | export const AssetNode = ({ |
27 | 32 | data: { height, isSelected, label, width }, |
28 | | -}: NodeProps<NodeType<CustomNodeProps, "asset">>) => ( |
29 | | - <NodeWrapper> |
30 | | - <Flex |
31 | | - bg="bg" |
32 | | - borderColor={isSelected ? "border.inverted" : "border"} |
33 | | - borderRadius={5} |
34 | | - borderWidth={isSelected ? 6 : 2} |
35 | | - cursor="default" |
36 | | - flexDirection="column" |
37 | | - height={`${height}px`} |
38 | | - px={3} |
39 | | - py={isSelected ? 0 : 1} |
40 | | - width={`${width}px`} |
41 | | - > |
42 | | - <HStack> |
43 | | - <Heading ml={-2} size="sm"> |
44 | | - <FiDatabase /> |
45 | | - </Heading> |
46 | | - {label} |
47 | | - </HStack> |
48 | | - </Flex> |
49 | | - </NodeWrapper> |
50 | | -); |
| 33 | +}: NodeProps<NodeType<CustomNodeProps, "asset">>) => { |
| 34 | + const { dagId = "", runId = "" } = useParams(); |
| 35 | + const { data: upstreamEventsData } = useDagRunServiceGetUpstreamAssetEvents( |
| 36 | + { dagId, dagRunId: runId }, |
| 37 | + undefined, |
| 38 | + { enabled: Boolean(dagId) && Boolean(runId) }, |
| 39 | + ); |
| 40 | + |
| 41 | + const { data: downstreamEventsData } = useAssetServiceGetAssetEvents( |
| 42 | + { sourceDagId: dagId, sourceRunId: runId }, |
| 43 | + undefined, |
| 44 | + { enabled: Boolean(dagId) && Boolean(runId) }, |
| 45 | + ); |
| 46 | + |
| 47 | + const datasetEvent = [ |
| 48 | + ...(upstreamEventsData?.asset_events ?? []), |
| 49 | + ...(downstreamEventsData?.asset_events ?? []), |
| 50 | + ].find((event) => event.name === label); |
| 51 | + |
| 52 | + return ( |
| 53 | + <NodeWrapper> |
| 54 | + <Flex |
| 55 | + bg="bg" |
| 56 | + borderColor={isSelected ? "border.inverted" : "border"} |
| 57 | + borderRadius={5} |
| 58 | + borderWidth={isSelected ? 6 : 2} |
| 59 | + cursor="default" |
| 60 | + flexDirection="column" |
| 61 | + height={`${height}px`} |
| 62 | + px={3} |
| 63 | + py={isSelected ? 0 : 1} |
| 64 | + width={`${width}px`} |
| 65 | + > |
| 66 | + <HStack> |
| 67 | + <Heading ml={-2} size="sm"> |
| 68 | + <FiDatabase /> |
| 69 | + </Heading> |
| 70 | + {label} |
| 71 | + </HStack> |
| 72 | + {datasetEvent === undefined ? undefined : ( |
| 73 | + <> |
| 74 | + <Text color="fg.muted"> |
| 75 | + <Time datetime={datasetEvent.timestamp} /> |
| 76 | + </Text> |
| 77 | + {datasetEvent.created_dagruns.length && datasetEvent.created_dagruns.length > 1 ? ( |
| 78 | + <Text color="fg.muted" fontSize="sm"> |
| 79 | + +{pluralize("other Dag Run", datasetEvent.created_dagruns.length)} |
| 80 | + </Text> |
| 81 | + ) : undefined} |
| 82 | + </> |
| 83 | + )} |
| 84 | + </Flex> |
| 85 | + </NodeWrapper> |
| 86 | + ); |
| 87 | +}; |
0 commit comments