Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
2a5ffe1d
Commit
2a5ffe1d
authored
Apr 27, 2021
by
tizah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created actions and reducer to optimise code
parent
01adc298
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
34 deletions
+51
-34
staticAnalysisReducer.ts
...static-analyser/src/lib/reducers/staticAnalysisReducer.ts
+0
-1
remix-ui-static-analyser.tsx
...x-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx
+51
-33
No files found.
libs/remix-ui/static-analyser/src/lib/reducers/staticAnalysisReducer.ts
View file @
2a5ffe1d
export
const
initialState
=
{
export
const
initialState
=
{
file
:
null
,
file
:
null
,
source
:
null
,
source
:
null
,
...
...
libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx
View file @
2a5ffe1d
...
@@ -55,7 +55,32 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
...
@@ -55,7 +55,32 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
return
indexOfCategory
return
indexOfCategory
}
}
const
[
autoRun
,
setAutoRun
]
=
useState
(
true
)
const
[
autoRun
,
setAutoRun
]
=
useState
(
true
)
const
[
categoryIndex
,
setCategoryIndex
]
=
useState
(
groupedModuleIndex
(
groupedModules
))
// 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
warningContainer
=
React
.
useRef
(
null
)
const
warningContainer
=
React
.
useRef
(
null
)
const
[
runButtonState
,
setRunButtonState
]
=
useState
(
true
)
const
[
runButtonState
,
setRunButtonState
]
=
useState
(
true
)
...
@@ -67,7 +92,6 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
...
@@ -67,7 +92,6 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
})
})
const
[,
setModuleNameResult
]
=
useState
(
null
)
const
[,
setModuleNameResult
]
=
useState
(
null
)
const
[,
setWarning
]
=
useState
({
const
[,
setWarning
]
=
useState
({
msg
:
''
,
options
:
{},
options
:
{},
hasWarning
:
false
,
hasWarning
:
false
,
warningErrors
:
[]
warningErrors
:
[]
...
@@ -127,10 +151,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
...
@@ -127,10 +151,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
?
(<
span
><
a
href=
{
more
}
target=
'_blank'
>
more
</
a
></
span
>)
?
(<
span
><
a
href=
{
more
}
target=
'_blank'
>
more
</
a
></
span
>)
:
(<
span
>
</
span
>)
:
(<
span
>
</
span
>)
}
}
<span className="" title={Position in
${
fileName
}
}>Pos:
${
locationString
}
</span>
}, [autoRun, state, props.analysisModule, setWarning])
</span>`
)
}
const run = (lastCompilationResult, lastCompilationSource, currentFile) => {
const run = (lastCompilationResult, lastCompilationSource, currentFile) => {
if (autoRun) {
if (autoRun) {
...
@@ -138,7 +159,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
...
@@ -138,7 +159,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
let warningCount = 0
let warningCount = 0
const warningMessage = []
const warningMessage = []
runner
.
run
(
lastCompilationResult
,
categoryIndex
,
results
=>
{
runner.run(lastCompilationResult,
state.
categoryIndex, results => {
results.map((result) => {
results.map((result) => {
let moduleName
let moduleName
Object.keys(groupedModules).map(key => {
Object.keys(groupedModules).map(key => {
...
@@ -174,7 +195,6 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
...
@@ -174,7 +195,6 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
fileName = Object.keys(lastCompilationResult.contracts)[file]
fileName = Object.keys(lastCompilationResult.contracts)[file]
}
}
warningCount++
warningCount++
const
msg
=
message
(
item
.
name
,
item
.
warning
,
item
.
more
,
fileName
,
locationString
)
const options = {
const options = {
type: 'warning',
type: 'warning',
useSpan: true,
useSpan: true,
...
@@ -207,11 +227,16 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
...
@@ -207,11 +227,16 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
return acc
return acc
}, {})
}, {})
}
}
const groupedCategory = groupBy(resultArray, 'warningModuleName')
const groupedCategory = groupBy(resultArray, 'warningModuleName')
console.log({ warningCount }, ' 221')
console.log({ groupedCategory })
setWarningState(groupedCategory)
setWarningState(groupedCategory)
console.log({ warningState })
console.log({ warningCount }, ' 223')
})
})
if
(
categoryIndex
.
length
>
0
)
{
console.log({ warningCount }, ' CategoryIndex outside function')
if (state.categoryIndex.length > 0) {
console.log(state.categoryIndex, ' CategoryIndex in execute funtions')
props.event.trigger('staticAnaysisWarning', [warningCount])
props.event.trigger('staticAnaysisWarning', [warningCount])
}
}
} else {
} else {
...
@@ -225,27 +250,19 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
...
@@ -225,27 +250,19 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const handleCheckAllModules = (groupedModules) => {
const handleCheckAllModules = (groupedModules) => {
const index = groupedModuleIndex(groupedModules)
const index = groupedModuleIndex(groupedModules)
if
(
index
.
every
(
el
=>
categoryIndex
.
includes
(
el
)))
{
if (index.every(el => state.categoryIndex.includes(el))) {
setCategoryIndex
(
dispatch({ type: 'uncheck', payload: index })
categoryIndex
.
filter
((
el
)
=>
{
return
!
index
.
includes
(
el
)
})
)
} else {
} else {
setCategoryIndex
(
_
.
uniq
([...
categoryIndex
,
...
index
])
)
dispatch({ type: 'check', payload: index }
)
}
}
}
}
const handleCheckOrUncheckCategory = (category) => {
const handleCheckOrUncheckCategory = (category) => {
const index = groupedModuleIndex(category)
const index = groupedModuleIndex(category)
if
(
index
.
every
(
el
=>
categoryIndex
.
includes
(
el
)))
{
if (index.every(el => state.categoryIndex.includes(el))) {
setCategoryIndex
(
dispatch({ type: 'uncheck', payload: index })
categoryIndex
.
filter
((
el
)
=>
{
return
!
index
.
includes
(
el
)
})
)
} else {
} else {
setCategoryIndex
(
_
.
uniq
([...
categoryIndex
,
...
index
])
)
dispatch({ type: 'check', payload: index }
)
}
}
}
}
...
@@ -259,10 +276,10 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
...
@@ -259,10 +276,10 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const handleCheckSingle = (event, _index) => {
const handleCheckSingle = (event, _index) => {
_index = _index.toString()
_index = _index.toString()
if
(
categoryIndex
.
includes
(
_index
))
{
if (
state.
categoryIndex.includes(_index)) {
setCategoryIndex
(
categoryIndex
.
filter
(
val
=>
val
!==
_index
)
)
dispatch({ type: 'uncheckSingle', payload: _index }
)
} else {
} else {
setCategoryIndex
(
_
.
uniq
([...
categoryIndex
,
_index
])
)
dispatch({ type: 'checkSingle', payload: _index }
)
}
}
}
}
...
@@ -277,7 +294,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
...
@@ -277,7 +294,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
itemName={item.name}
itemName={item.name}
label={item.description}
label={item.description}
onClick={event => handleCheckSingle(event, item._index)}
onClick={event => handleCheckSingle(event, item._index)}
checked=
{
categoryIndex
.
includes
(
item
.
_index
.
toString
())
}
checked={
state.
categoryIndex.includes(item._index.toString())}
onChange={() => {}}
onChange={() => {}}
/>
/>
</div>
</div>
...
@@ -306,7 +323,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
...
@@ -306,7 +323,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
expand={false}
expand={false}
>
>
<div>
<div>
<
RemixUiCheckbox
onClick=
{
()
=>
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=
{
()
=>
{}
}
/>
<RemixUiCheckbox onClick={() => 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={() => {}}/>
</div>
</div>
<div className="w-100 d-block px-2 my-1 entries collapse multi-collapse" id={`
heading$
{
categoryId
}
`}>
<div className="w-100 d-block px-2 my-1 entries collapse multi-collapse" id={`
heading$
{
categoryId
}
`}>
{category.map((item, i) => {
{category.map((item, i) => {
...
@@ -334,7 +351,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
...
@@ -334,7 +351,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
return (value.map(x => {
return (value.map(x => {
return x._index.toString()
return x._index.toString()
}))
}))
}).
flat
().
every
(
el
=>
categoryIndex
.
includes
(
el
))
}
}).flat().every(el =>
state.
categoryIndex.includes(el))}
label="Select all"
label="Select all"
onClick={() => handleCheckAllModules(groupedModules)}
onClick={() => handleCheckAllModules(groupedModules)}
onChange={() => {}}
onChange={() => {}}
...
@@ -368,10 +385,11 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
...
@@ -368,10 +385,11 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
{state.file}
{state.file}
</span>
</span>
</div>
</div>
{
categoryIndex
.
length
>
0
&&
Object
.
entries
(
warningState
).
length
>
0
&&
{ console.log({ warningState }) }
{ state.categoryIndex.length > 0 && Object.entries(warningState).length > 0 &&
<div id='staticanalysisresult' >
<div id='staticanalysisresult' >
<div className="mb-4">
<div className="mb-4">
{
{
/* {
(Object.entries(warningState).map((element) => (
(Object.entries(warningState).map((element) => (
<>
<>
<span className="text-dark h6">{element[0]}</span>
<span className="text-dark h6">{element[0]}</span>
...
@@ -385,7 +403,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
...
@@ -385,7 +403,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
))}
))}
</>
</>
)))
)))
}
}
*/}
</div>
</div>
</div>
</div>
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment