diff --git a/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx b/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx index 8270e8e0e0..6ff31797fb 100644 --- a/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx +++ b/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState, useReducer } from 'react' // eslint-disable-line +import React, { useEffect, useState, useReducer, useRef } from 'react' // eslint-disable-line import Button from './Button/StaticAnalyserButton' // eslint-disable-line import { util } from '@remix-project/remix-lib' import _ from 'lodash' @@ -64,10 +64,12 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { const [autoRun, setAutoRun] = useState(true) const [slitherEnabled, setSlitherEnabled] = useState(false) const [showSlither, setShowSlither] = useState(false) + const [showLibsWarning, setShowLibsWarning] = useState(false) const [categoryIndex, setCategoryIndex] = useState(groupedModuleIndex(groupedModules)) - - const warningContainer = React.useRef(null) const [warningState, setWarningState] = useState({}) + + const warningContainer = useRef(null) + const allWarnings = useRef({}) const [state, dispatch] = useReducer(analysisReducer, initialState) useEffect(() => { @@ -152,6 +154,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { } const groupedCategory = groupBy(resultArray, groupByKey) + allWarnings.current = groupedCategory setWarningState(groupedCategory) } @@ -355,6 +358,21 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { } } + const handleShowLibsWarning = () => { + if (showLibsWarning) setShowLibsWarning(false) + else setShowLibsWarning(true) + let newWarningState = {} + for (const category in allWarnings.current) { + const warnings = allWarnings.current[category] + newWarningState[category] = [] + for (const warning of warnings) { + if (showLibsWarning && warning.options.isLibrary) newWarningState[category].push(warning) + else if (!showLibsWarning && !warning.options.isLibrary) newWarningState[category].push(warning) + } + } + setWarningState(newWarningState) + } + const categoryItem = (categoryId, item, i) => { return (