import React, { FC, useContext, useMemo, ComponentProps, useState, useCallback, useRef, } from "react"; import styled from "styled-components"; import { rem } from "polished"; import { ParsedFieldNode } from "../../../context/Explorer/ast"; import { Pane, CodeHighlight } from "../../../components"; import { ExplorerContext } from "../../../context"; import { CacheOutcomeIcon } from "./Icons"; export const NodeInfoPane: FC> = (props) => { const { focusedNode } = useContext(ExplorerContext); const content = useMemo(() => { if (!focusedNode) { return ( Select a node to see more information... ); } return ; }, [focusedNode]); return ( {content} ); }; const NodeInfoContent: FC<{ node: ParsedFieldNode }> = ({ node }) => { const previousNode = useRef(node); const [expanded, setExpanded] = useState(false); const value = useMemo( () => node.value || node.children ? JSON.stringify(node.value || node.children, null, 2) : false, [node.value, node.children] ); const isExpanded = useMemo( () => (value && value.length < 10000) || (expanded && previousNode.current._id == node._id), [node._id, expanded, value] ); const handleReveal = useCallback(() => setExpanded(true), []); previousNode.current = node; return ( <> Name {node.name} {node.cacheOutcome ? ( Cache Outcome {node.cacheOutcome} {getDescription(node.cacheOutcome)} ) : null} {node.args ? ( Arguments ) : null} {value ? ( Value {isExpanded ? ( ) : ( Click to expand )} ) : null} ); }; const getDescription = (status: ParsedFieldNode["cacheOutcome"]) => { switch (status) { case "hit": { return {"This result was served from cache."}; } case "partial": { return ( {"Some values for this result were served from cache."} ); } case "miss": { return ( {"This result wasn't served from cache"} ); } default: { return null; } } }; const ExpandPrompt = styled.div` text-align: center; padding: ${(p) => p.theme.space[5]}; background: ${(p) => p.theme.colors.canvas.elevated05}; color: ${(p) => p.theme.colors.textDimmed.base}; cursor: pointer; `; const Name = styled.code` color: ${(p) => p.theme.colors.textDimmed.base}; `; const Description = styled.p` color: ${(p) => p.theme.colors.textDimmed.base}; margin-bottom: 0; margin-top: ${(p) => p.theme.space[2]}; `; const TextContainer = styled.div` padding: ${(p) => p.theme.space[6]}; `; const Text = styled.p` margin: 0; text-align: center; color: ${(p) => p.theme.colors.textDimmed.base}; `; const CacheIcon = styled(CacheOutcomeIcon)` position: relative; top: ${rem(1)}; margin-right: ${(p) => p.theme.space[3]}; `;