diff --git a/libs/remix-ui/static-analyser/src/lib/Checkbox/StaticAnalyserCheckedBox.tsx b/libs/remix-ui/static-analyser/src/lib/Checkbox/StaticAnalyserCheckedBox.tsx deleted file mode 100644 index e42caa4851..0000000000 --- a/libs/remix-ui/static-analyser/src/lib/Checkbox/StaticAnalyserCheckedBox.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import React from 'react' //eslint-disable-line - -interface StaticAnalyserCheckBoxProps { - onClick?: (event) => void - onChange?: (event) => void - label?: string - inputType?: string - name?: string - checked?: boolean - id?: string - itemName?: string - categoryId?: string -} - -const StaticAnalyserCheckedBox = ({ - id, - label, - onClick, - inputType, - name, - checked, - onChange, - itemName, - categoryId -}: StaticAnalyserCheckBoxProps) => { - return ( -
- - -
- ) -} - -export default StaticAnalyserCheckedBox 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 1a2d365327..27e7e55f1e 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 @@ -55,47 +55,9 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { return indexOfCategory } const [autoRun, setAutoRun] = useState(true) - - // const initialState = { categoryIndex: [] } - - // const reducer = (state, action) => { - // console.log({ action }) - // switch (action.type) { - // case 'initialize': - // return { categoryIndex: groupedModuleIndex(groupedModules) } - // case 'uncheck': - // return { - // categoryIndex: state.categoryIndex.filter((el) => { - // return !action.payload.includes(el) - // }) - // } - // case 'check': - // return { categoryIndex: _.uniq([...state.categoryIndex, ...action.payload]) } - // case 'uncheckSingle': - // return { categoryIndex: state.categoryIndex.filter(val => val !== action.payload) } - // case 'checkSingle': - // return { categoryIndex: _.uniq([...state.categoryIndex, action.payload]) } - // default: - // return { categoryIndex: groupedModuleIndex(groupedModules) } - // } - // } - - const [state, dispatch] = useReducer(analysisReducer, initialState) + const [categoryIndex, setCategoryIndex] = useState(groupedModuleIndex(groupedModules)) const warningContainer = React.useRef(null) - const [runButtonState, setRunButtonState] = useState(true) - - const [result, setResult] = useState({ - lastCompilationResult: null, - lastCompilationSource: null, - currentFile: 'No file compiled' - }) - const [, setModuleNameResult] = useState(null) - const [, setWarning] = useState({ - options: {}, - hasWarning: false, - warningErrors: [] - }) const [warningState, setWarningState] = useState([]) const [state, dispatch] = useReducer(analysisReducer, initialState) @@ -151,7 +113,10 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { ? (more) : ( ) } - }, [autoRun, state, props.analysisModule, setWarning]) + Pos: ${locationString} + ` + ) + } const run = (lastCompilationResult, lastCompilationSource, currentFile) => { if (autoRun) { @@ -159,7 +124,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { let warningCount = 0 const warningMessage = [] - runner.run(lastCompilationResult, state.categoryIndex, results => { + runner.run(lastCompilationResult, categoryIndex, results => { results.map((result) => { let moduleName Object.keys(groupedModules).map(key => { @@ -195,6 +160,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { fileName = Object.keys(lastCompilationResult.contracts)[file] } warningCount++ + const msg = message(item.name, item.warning, item.more, fileName, locationString) const options = { type: 'warning', useSpan: true, @@ -227,16 +193,11 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { return acc }, {}) } + const groupedCategory = groupBy(resultArray, 'warningModuleName') - console.log({ warningCount }, ' 221') - console.log({ groupedCategory }) setWarningState(groupedCategory) - console.log({ warningState }) - console.log({ warningCount }, ' 223') }) - console.log({ warningCount }, ' CategoryIndex outside function') - if (state.categoryIndex.length > 0) { - console.log(state.categoryIndex, ' CategoryIndex in execute funtions') + if (categoryIndex.length > 0) { props.event.trigger('staticAnaysisWarning', [warningCount]) } } else { @@ -250,19 +211,27 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { const handleCheckAllModules = (groupedModules) => { const index = groupedModuleIndex(groupedModules) - if (index.every(el => state.categoryIndex.includes(el))) { - dispatch({ type: 'uncheck', payload: index }) + if (index.every(el => categoryIndex.includes(el))) { + setCategoryIndex( + categoryIndex.filter((el) => { + return !index.includes(el) + }) + ) } else { - dispatch({ type: 'check', payload: index }) + setCategoryIndex(_.uniq([...categoryIndex, ...index])) } } const handleCheckOrUncheckCategory = (category) => { const index = groupedModuleIndex(category) - if (index.every(el => state.categoryIndex.includes(el))) { - dispatch({ type: 'uncheck', payload: index }) + if (index.every(el => categoryIndex.includes(el))) { + setCategoryIndex( + categoryIndex.filter((el) => { + return !index.includes(el) + }) + ) } else { - dispatch({ type: 'check', payload: index }) + setCategoryIndex(_.uniq([...categoryIndex, ...index])) } } @@ -276,10 +245,10 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { const handleCheckSingle = (event, _index) => { _index = _index.toString() - if (state.categoryIndex.includes(_index)) { - dispatch({ type: 'uncheckSingle', payload: _index }) + if (categoryIndex.includes(_index)) { + setCategoryIndex(categoryIndex.filter(val => val !== _index)) } else { - dispatch({ type: 'checkSingle', payload: _index }) + setCategoryIndex(_.uniq([...categoryIndex, _index])) } } @@ -294,7 +263,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { itemName={item.name} label={item.description} onClick={event => handleCheckSingle(event, item._index)} - checked={state.categoryIndex.includes(item._index.toString())} + checked={categoryIndex.includes(item._index.toString())} onChange={() => {}} /> @@ -323,7 +292,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { expand={false} >
- handleCheckOrUncheckCategory(category)} id={categoryId} inputType="checkbox" label={`Select ${category[0].categoryDisplayName}`} name='checkCategoryEntry' checked={category.map(x => x._index.toString()).every(el => state.categoryIndex.includes(el))} onChange={() => {}}/> + handleCheckOrUncheckCategory(category)} id={categoryId} inputType="checkbox" label={`Select ${category[0].categoryDisplayName}`} name='checkCategoryEntry' checked={category.map(x => x._index.toString()).every(el => categoryIndex.includes(el))} onChange={() => {}}/>
{category.map((item, i) => { @@ -351,7 +320,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { return (value.map(x => { return x._index.toString() })) - }).flat().every(el => state.categoryIndex.includes(el))} + }).flat().every(el => categoryIndex.includes(el))} label="Select all" onClick={() => handleCheckAllModules(groupedModules)} onChange={() => {}} @@ -385,11 +354,10 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { {state.file}
- { console.log({ warningState }) } - { state.categoryIndex.length > 0 && Object.entries(warningState).length > 0 && + { categoryIndex.length > 0 && Object.entries(warningState).length > 0 &&
- {/* { + { (Object.entries(warningState).map((element) => ( <> {element[0]} @@ -403,7 +371,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { ))} ))) - } */} + }
}