fix badge logic. make tab switching stateful

pull/3838/head
Joseph Izang 1 year ago
parent 1de29961c4
commit 171617d1e3
  1. 7
      libs/remix-ui/static-analyser/src/lib/components/BasicTitle.tsx
  2. 22
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx

@ -4,6 +4,7 @@ import { ErrorRendererOptions } from '../../staticanalyser'
type BasicTitleProps = { type BasicTitleProps = {
warningStateEntries: any warningStateEntries: any
hideWarnings?: boolean hideWarnings?: boolean
showLibsWarnings?: boolean
} }
type warningResultOption = { type warningResultOption = {
@ -32,13 +33,15 @@ export function calculateWarningStateEntries(entries: [string, any][]) {
export function BasicTitle(props: BasicTitleProps) { export function BasicTitle(props: BasicTitleProps) {
return ( return (
<span>Remix{props.warningStateEntries.length > 0 ? !props.hideWarnings ? <i data-id="StaticAnalysisErrorCount" className={`badge ${calculateWarningStateEntries(props.warningStateEntries).length > 0 ? 'badge-warning' : 'badge-danger'} rounded-circle ml-1 text-center`}>{calculateWarningStateEntries(props.warningStateEntries).length}</i>: ( <span>Remix{props.warningStateEntries.length > 0 ? !props.hideWarnings ? props.showLibsWarnings ? <i data-id="StaticAnalysisErrorCount" className={`badge ${calculateWarningStateEntries(props.warningStateEntries).length > 0 ? 'badge-warning' : 'badge-danger'} rounded-circle ml-1 text-center`}>
{
calculateWarningStateEntries(props.warningStateEntries).length}</i>: (
<i className="badge badge-warning rounded-circle ml-1 text-center"> <i className="badge badge-warning rounded-circle ml-1 text-center">
{ {
calculateWarningStateEntries(props.warningStateEntries).errors.length calculateWarningStateEntries(props.warningStateEntries).errors.length
} }
</i> </i>
) : null} ) : null : null}
</span> </span>
) )
} }

@ -81,6 +81,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const [hints, setHints] = useState<SolHintReport[]>([]) const [hints, setHints] = useState<SolHintReport[]>([])
const [slitherWarnings, setSlitherWarnings] = useState([]) const [slitherWarnings, setSlitherWarnings] = useState([])
const [ssaWarnings, setSsaWarnings] = useState([]) const [ssaWarnings, setSsaWarnings] = useState([])
const [tabKey, setTabKey] = useState('basic')
const warningContainer = useRef(null) const warningContainer = useRef(null)
const allWarnings = useRef({}) const allWarnings = useRef({})
@ -107,6 +108,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
} }
useEffect(() => { useEffect(() => {
setWarningState({})
setHints([]) setHints([])
setSlitherWarnings([]) setSlitherWarnings([])
setSsaWarnings([]) setSsaWarnings([])
@ -143,7 +145,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
useEffect(() => { useEffect(() => {
props.analysisModule.on('filePanel', 'setWorkspace', (currentWorkspace) => { props.analysisModule.on('filePanel', 'setWorkspace', (currentWorkspace) => {
// Reset warning state // Reset warning state
setWarningState([]) setWarningState({})
// Reset badge // Reset badge
props.event.trigger('staticAnaysisWarning', []) props.event.trigger('staticAnaysisWarning', [])
// Reset state // Reset state
@ -165,7 +167,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
// Hide 'Enable Slither Analysis' checkbox // Hide 'Enable Slither Analysis' checkbox
if (plugin.name === 'remixd') { if (plugin.name === 'remixd') {
// Reset warning state // Reset warning state
setWarningState([]) setWarningState({})
setHints([]) setHints([])
setSlitherWarnings([]) setSlitherWarnings([])
setSlitherEnabled(false) setSlitherEnabled(false)
@ -218,9 +220,11 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
} }
} }
} }
if (newWarningCount > 0) {
props.event.trigger('staticAnaysisWarning', [newWarningCount]) props.event.trigger('staticAnaysisWarning', [newWarningCount])
setWarningState(newWarningState) setWarningState(newWarningState)
} }
}
useEffect(() => { useEffect(() => {
if(hints.length > 0) { if(hints.length > 0) {
@ -511,6 +515,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
<BasicTitle <BasicTitle
warningStateEntries={Object.entries(warningState)} warningStateEntries={Object.entries(warningState)}
hideWarnings={hideWarnings} hideWarnings={hideWarnings}
showLibsWarnings={showLibsWarning}
/> />
), ),
child: ( child: (
@ -520,8 +525,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
<div className="mb-4 pt-2"> <div className="mb-4 pt-2">
{Object.entries(warningState).map((element, index) => ( {Object.entries(warningState).map((element, index) => (
<div key={index}> <div key={index}>
{ !hideWarnings && element[1]['length'] > 0 ? <span className="text-dark h6">{element[0]}</span> : null} { hideWarnings === false ? <span className="text-dark h6">{element[0]}</span> : null}
{!hideWarnings ? element[1]["map"]( { hideWarnings === false ? element[1]["map"](
(x,i) => // eslint-disable-line dot-notation (x,i) => // eslint-disable-line dot-notation
x.hasWarning x.hasWarning
? ( // eslint-disable-next-line dot-notation ? ( // eslint-disable-next-line dot-notation
@ -753,8 +758,9 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
/> />
</div> </div>
<Tabs <Tabs
defaultActiveKey={tabKeys[0].tabKey} defaultActiveKey={tabKeys[1].tabKey}
className="px-1" className="px-1"
onSelect={(newKey) => setTabKey(newKey)}
> >
{ {
checkBasicStatus() ? <Tab checkBasicStatus() ? <Tab
@ -766,14 +772,16 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
{tabKeys[1].child} {tabKeys[1].child}
</Tab> : null </Tab> : null
} }
{solhintEnabled ? <Tab {
solhintEnabled ? <Tab
key={tabKeys[0].tabKey} key={tabKeys[0].tabKey}
title={tabKeys[0].title} title={tabKeys[0].title}
eventKey={tabKeys[0].tabKey} eventKey={tabKeys[0].tabKey}
tabClassName="text-decoration-none font-weight-bold px-2" tabClassName="text-decoration-none font-weight-bold px-2"
> >
{tabKeys[0].child} {tabKeys[0].child}
</Tab> : null} </Tab> : null
}
{ showSlither && slitherEnabled ? <Tab { showSlither && slitherEnabled ? <Tab
key={tabKeys[2].tabKey} key={tabKeys[2].tabKey}
title={tabKeys[2].title} title={tabKeys[2].title}

Loading…
Cancel
Save