From 03b1313a9f029e570d2e36446d5951cc157ef556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Mert=20Y=C4=B1ld=C4=B1ran?= Date: Thu, 23 Dec 2021 17:45:51 +0300 Subject: [PATCH] Don't use `Queryable` for the `Mime type` and `Encoding` fields but use it directly in `CollapsibleTitle` suffixed components and only enable it for `EntryBodySection` (#550) Co-authored-by: gadotroee <55343099+gadotroee@users.noreply.github.com> --- .../EntryDetailed/EntrySections.tsx | 77 +++++++++++++------ ui/src/components/UI/CollapsibleContainer.tsx | 25 ++---- 2 files changed, 60 insertions(+), 42 deletions(-) diff --git a/ui/src/components/EntryDetailed/EntrySections.tsx b/ui/src/components/EntryDetailed/EntrySections.tsx index 7201b5206..17bc33357 100644 --- a/ui/src/components/EntryDetailed/EntrySections.tsx +++ b/ui/src/components/EntryDetailed/EntrySections.tsx @@ -10,12 +10,14 @@ import ProtobufDecoder from "protobuf-decoder"; interface EntryViewLineProps { label: string; value: number | string; - updateQuery: any; - selector: string; + updateQuery?: any; + selector?: string; overrideQueryValue?: string; + displayIconOnMouseOver?: boolean; + useTooltip?: boolean; } -const EntryViewLine: React.FC = ({label, value, updateQuery, selector, overrideQueryValue}) => { +const EntryViewLine: React.FC = ({label, value, updateQuery = null, selector = "", overrideQueryValue = "", displayIconOnMouseOver = true, useTooltip = true}) => { let query: string; if (!selector) { query = ""; @@ -34,7 +36,8 @@ const EntryViewLine: React.FC = ({label, value, updateQuery, style={{float: "right", height: "18px"}} iconStyle={{marginRight: "20px"}} flipped={true} - displayIconOnMouseOver={true} + useTooltip={useTooltip} + displayIconOnMouseOver={displayIconOnMouseOver} > {label} @@ -55,30 +58,47 @@ const EntryViewLine: React.FC = ({label, value, updateQuery, interface EntrySectionCollapsibleTitleProps { title: string, color: string, - isExpanded: boolean, + expanded: boolean, + setExpanded: any, + query?: string, + updateQuery?: any, } -const EntrySectionCollapsibleTitle: React.FC = ({title, color, isExpanded}) => { +const EntrySectionCollapsibleTitle: React.FC = ({title, color, expanded, setExpanded, query = "", updateQuery = null}) => { return
-
- {isExpanded ? '-' : '+'} +
{ + setExpanded(!expanded) + }} + > + {expanded ? '-' : '+'}
- {title} + + {title} +
} interface EntrySectionContainerProps { title: string, color: string, + query?: string, + updateQuery?: any, } -export const EntrySectionContainer: React.FC = ({title, color, children}) => { +export const EntrySectionContainer: React.FC = ({title, color, children, query = "", updateQuery = null}) => { const [expanded, setExpanded] = useState(true); return setExpanded(!expanded)} - title={} + expanded={expanded} + title={} > {children} @@ -133,11 +153,16 @@ export const EntryBodySection: React.FC = ({ } return - {content && content?.length > 0 && + {content && content?.length > 0 && - - {encoding && } + + {encoding && }
@@ -195,13 +220,20 @@ interface EntryPolicySectionProps { interface EntryPolicySectionCollapsibleTitleProps { label: string; matched: string; - isExpanded: boolean; + expanded: boolean; + setExpanded: any; } -const EntryPolicySectionCollapsibleTitle: React.FC = ({label, matched, isExpanded}) => { +const EntryPolicySectionCollapsibleTitle: React.FC = ({label, matched, expanded, setExpanded}) => { return
- - {isExpanded ? '-' : '+'} + { + setExpanded(!expanded) + }} + > + {expanded ? '-' : '+'} @@ -222,9 +254,8 @@ export const EntryPolicySectionContainer: React.FC setExpanded(!expanded)} - title={} + expanded={expanded} + title={} > {children} diff --git a/ui/src/components/UI/CollapsibleContainer.tsx b/ui/src/components/UI/CollapsibleContainer.tsx index 4c0452623..c59fcb6be 100644 --- a/ui/src/components/UI/CollapsibleContainer.tsx +++ b/ui/src/components/UI/CollapsibleContainer.tsx @@ -1,38 +1,25 @@ -import React, {useState} from "react"; +import React from "react"; import collapsedImg from "../assets/collapsed.svg"; import expandedImg from "../assets/expanded.svg"; import "./style/CollapsibleContainer.sass"; interface Props { title: string | React.ReactNode, - onClick?: (e: React.SyntheticEvent) => void, - isExpanded?: boolean, + expanded: boolean, titleClassName?: string, - stickyHeader?: boolean, className?: string, - initialExpanded?: boolean; - passiveOnClick?: boolean; //whether specifying onClick overrides internal _isExpanded state handling + stickyHeader?: boolean, } -const CollapsibleContainer: React.FC = ({title, children, isExpanded, onClick, titleClassName, stickyHeader = false, className, initialExpanded = true, passiveOnClick}) => { - const [_isExpanded, _setExpanded] = useState(initialExpanded); - let expanded = isExpanded !== undefined ? isExpanded : _isExpanded; +const CollapsibleContainer: React.FC = ({title, children, expanded, titleClassName, className, stickyHeader = false}) => { const classNames = `CollapsibleContainer ${expanded ? "CollapsibleContainer-Expanded" : "CollapsibleContainer-Collapsed"} ${className ? className : ''}`; - // This is needed to achieve the sticky header feature. + // This is needed to achieve the sticky header feature. // It is needed an un-contained component for the css to work properly. const content =
{ - if (onClick) { - onClick(e) - if (passiveOnClick !== true) - return; - } - _setExpanded(!_isExpanded) - }} > { React.isValidElement(title)?