diff --git a/ui/src/components/EntryDetailed/EntrySections.module.sass b/ui/src/components/EntryDetailed/EntrySections.module.sass index a7ec762ca..46a00318c 100644 --- a/ui/src/components/EntryDetailed/EntrySections.module.sass +++ b/ui/src/components/EntryDetailed/EntrySections.module.sass @@ -31,11 +31,8 @@ .dataKey color: $blue-gray - margin: 0 0.5rem 0 0 text-align: right - overflow: hidden text-overflow: ellipsis - width: 1% max-width: 15rem .rulesTitleSuccess diff --git a/ui/src/components/EntryDetailed/EntrySections.tsx b/ui/src/components/EntryDetailed/EntrySections.tsx index 88db7b310..86a7dee65 100644 --- a/ui/src/components/EntryDetailed/EntrySections.tsx +++ b/ui/src/components/EntryDetailed/EntrySections.tsx @@ -3,6 +3,7 @@ import React, {useState} from "react"; import {SyntaxHighlighter} from "../UI/SyntaxHighlighter/index"; import CollapsibleContainer from "../UI/CollapsibleContainer"; import FancyTextDisplay from "../UI/FancyTextDisplay"; +import Queryable from "../UI/Queryable"; import Checkbox from "../UI/Checkbox"; import ProtobufDecoder from "protobuf-decoder"; @@ -15,22 +16,27 @@ interface EntryViewLineProps { } const EntryViewLine: React.FC = ({label, value, updateQuery, selector, overrideQueryValue}) => { - return (label && - { - if (!selector) { - return - } else if (overrideQueryValue) { - updateQuery(`${selector} == ${overrideQueryValue}`) - } else if (typeof(value) === "string") { - updateQuery(`${selector} == "${JSON.stringify(value).slice(1, -1)}"`) - } else { - updateQuery(`${selector} == ${value}`) - } - }} - > - {label} + var query = ""; + if (!selector) { + query = ""; + } else if (overrideQueryValue) { + query = `${selector} == ${overrideQueryValue}`; + } else if (typeof(value) == "string") { + query = `${selector} == "${JSON.stringify(value).slice(1, -1)}"`; + } else { + query = `${selector} == ${value}`; + } + return (label && value && + + >; +} + +const Queryable: React.FC = ({text, query, updateQuery, style, className, isPossibleToCopy = true, applyTextEllipsis = true, useTooltip= false, displayIconOnMouseOver = false}) => { + const [showCopiedNotification, setCopied] = useState(false); + const [showTooltip, setShowTooltip] = useState(false); + text = String(text); + + console.log(style); + + const onCopy = () => { + setCopied(true) + }; + + useEffect(() => { + let timer; + if (showCopiedNotification) { + updateQuery(query); + timer = setTimeout(() => { + setCopied(false); + }, 1000); + } + return () => clearTimeout(timer); + // eslint-disable-next-line + }, [showCopiedNotification]); + + const textElement = {text}; + + const copyButton = text ? + + + {showCopiedNotification && Added} + + : null; + + return
setShowTooltip(true)} + onMouseLeave={ e => setShowTooltip(false)} + > + {textElement} + {copyButton} + {useTooltip && showTooltip && {text}} +
; +}; + +export default Queryable; diff --git a/ui/src/components/UI/style/Queryable.sass b/ui/src/components/UI/style/Queryable.sass new file mode 100644 index 000000000..ef10eb787 --- /dev/null +++ b/ui/src/components/UI/style/Queryable.sass @@ -0,0 +1,45 @@ +.Queryable-Container + display: flex + align-items: center + + &.displayIconOnMouseOver + .Queryable-Icon + opacity: 0 + width: 0px + pointer-events: none + &:hover + .Queryable-Icon + opacity: 1 + pointer-events: all + + + .Queryable-Icon + height: 22px + width: 22px + cursor: pointer + margin-right: 3px + color: #27AE60 + + &:hover + background-color: rgba(255, 255, 255, 0.06) + border-radius: 4px + color: #1E884B + + &.Queryable-ContainerEllipsis + .Queryable-Text + text-align: left + text-overflow: ellipsis + overflow: hidden + white-space: nowrap + width: calc(100% - 30px) + + .Queryable-CopyNotifier + background-color: #1E884B + font-weight: normal + padding: 2px 5px + border-radius: 4px + position: absolute + transform: translate(0, -80%) + color: white + z-index: 1000 +