From ee69f8a0e90d34fe20b2c25566287294764a4257 Mon Sep 17 00:00:00 2001 From: cccs-rs <62077998+cccs-rs@users.noreply.github.com> Date: Mon, 23 Dec 2024 17:09:51 +0000 Subject: [PATCH] Set the drawers based on the type of hash in navigation --- src/components/visual/FileDetail.tsx | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/components/visual/FileDetail.tsx b/src/components/visual/FileDetail.tsx index a0039f3a8..7eea898f1 100644 --- a/src/components/visual/FileDetail.tsx +++ b/src/components/visual/FileDetail.tsx @@ -34,6 +34,7 @@ import type { CustomUser } from 'components/models/ui/user'; import ForbiddenPage from 'components/routes/403'; import { DEFAULT_TAB, TAB_OPTIONS } from 'components/routes/file/viewer'; import HeuristicDetail from 'components/routes/manage/heuristic_detail'; +import SignatureDetail from 'components/routes/manage/signature_detail'; import AISummarySection from 'components/routes/submission/detail/ai_summary'; import Classification from 'components/visual/Classification'; import { emptyResult } from 'components/visual/ResultCard'; @@ -92,6 +93,7 @@ const WrappedFileDetail: React.FC = ({ const [promotedSections, setPromotedSections] = useState([]); const [insideDrawer, setInsideDrawer] = useState(null); const [loaded, setLoaded] = useState(false); + const [heuristics, setHeuristics] = useState([]); const ref = useRef(); @@ -139,6 +141,15 @@ const WrappedFileDetail: React.FC = ({ newData.emptys = data.results.filter(result => emptyResult(result)); newData.results = data.results.filter(result => !emptyResult(result)); newData.errors = liveErrors ? [...data.errors, ...liveErrors] : data.errors; + + // Compile a simplified list of heuristics for later reference + const heurs = []; + Object.values(newData?.heuristics || {}).map(hs => { + hs.map(h => { + heurs.push(h[0]); + }); + }); + setHeuristics(heurs); return newData; }; @@ -325,10 +336,19 @@ const WrappedFileDetail: React.FC = ({ useEffect(() => { if (insideDrawer === false) { setLoaded(true); - if (location.hash) setGlobalDrawer(); - else if (!location.hash) setGlobalDrawer(null); + if (!location.hash) { + setGlobalDrawer(null); + } else if (file) { + // Set the drawer content based on the hash + var id = location.hash.slice(1); + if (heuristics.includes(id)) { + setGlobalDrawer(); + } else { + setGlobalDrawer(); + } + } } - }, [insideDrawer, location.hash, setGlobalDrawer]); + }, [insideDrawer, location.hash, setGlobalDrawer, file]); useEffect(() => { if (loaded && insideDrawer === false && !globalDrawerOpened && location.hash) {