Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.editor
Commits
99987dfd
Commit
99987dfd
authored
Mar 09, 2018
by
Jaden DIEFENBAUGH
Browse files
cleaned up rmd typedefs & now using reselect to sanitize malformed objs, closes
#63
parent
fd402257
Changes
15
Hide whitespace changes
Inline
Side-by-side
package.json
View file @
99987dfd
...
...
@@ -11,7 +11,7 @@
"test"
:
"cross-env BABEL_ENV=test NODE_ENV=test karma start"
,
"lint"
:
"eslint --ext .js,.jsx src && eslint test && stylelint 'src/**/*.jsx, src/**/*.css, src/**/*.html' && npm run flow"
,
"lint:fix"
:
"eslint --ext .js,.jsx src --fix && eslint test --fix"
,
"flow"
:
"flow
--show-all-errors
"
,
"flow"
:
"flow"
,
"prepush"
:
"npm test"
},
"browserslist"
:
[
...
...
src/components/EntityDetail.jsx
View file @
99987dfd
...
...
@@ -12,7 +12,6 @@ import {
}
from
'
reactstrap
'
;
import
{
connect
}
from
'
react-redux
'
;
import
type
{
MapStateToProps
,
MapDispatchToProps
}
from
'
react-redux
'
;
import
cn
from
'
classnames
'
;
...
...
@@ -25,6 +24,7 @@ import {
}
from
'
react-router-dom
'
;
import
type
{
BeatObject
}
from
'
@helpers/beat
'
;
import
{
getDefaultEntityObject
}
from
'
@helpers/beat
'
;
import
ValidSchemaBadge
from
'
./ValidSchemaBadge.jsx
'
;
import
DataformatEditorContainer
from
'
./dataformat
'
;
...
...
@@ -174,9 +174,7 @@ export class EntityDetail extends React.Component<Props, State> {
}
}
export
const
getDefaultEntityObject
=
()
=>
({
name
:
''
,
contents
:
{}});
const
mapStateToProps
:
MapStateToProps
<*
,
*
,
*>
=
(
state
,
ownProps
)
=>
{
const
mapStateToProps
=
(
state
,
ownProps
)
=>
{
const
entity
=
ownProps
.
match
.
params
.
entity
;
const
name
=
ownProps
.
match
.
params
.
name
;
const
obj
=
{
...
...
@@ -186,7 +184,7 @@ const mapStateToProps: MapStateToProps<*,*,*> = (state, ownProps) => {
return
obj
;
};
const
mapDispatchToProps
:
MapDispatchToProps
<*
,
*
,
*>
=
(
dispatch
,
ownProps
)
=>
({
const
mapDispatchToProps
=
(
dispatch
,
ownProps
)
=>
({
updateFunc
:
(
obj
)
=>
{
dispatch
(
Actions
[
`
${
ownProps
.
match
.
params
.
entity
}
Update`
](
ownProps
.
match
.
params
.
name
,
obj
));
ownProps
.
history
.
push
(
`/
${
ownProps
.
match
.
params
.
entity
}
/
${
obj
.
name
}
`
);
...
...
src/components/EntityList.jsx
View file @
99987dfd
...
...
@@ -21,7 +21,6 @@ import {
}
from
'
react-router-dom
'
;
import
{
connect
}
from
'
react-redux
'
;
import
type
{
MapStateToProps
,
MapDispatchToProps
}
from
'
react-redux
'
;
import
*
as
Selectors
from
'
@store/selectors.js
'
;
import
*
as
Actions
from
'
@store/actions.js
'
;
...
...
@@ -130,11 +129,11 @@ export class EntityList extends React.Component<Props, State> {
}
}
const
mapStateToProps
:
MapStateToProps
<*
,
*
,
*>
=
(
state
,
ownProps
)
=>
({
const
mapStateToProps
=
(
state
,
ownProps
)
=>
({
data
:
Selectors
[
`
${
ownProps
.
entity
}
Get`
](
state
),
});
const
mapDispatchToProps
:
MapDispatchToProps
<*
,
*
,
*>
=
(
dispatch
,
ownProps
)
=>
({
const
mapDispatchToProps
=
(
dispatch
,
ownProps
)
=>
({
deleteFunc
:
(
obj
)
=>
dispatch
(
Actions
.
deleteObject
(
ownProps
.
entity
,
obj
)()),
});
...
...
src/components/MainNav.jsx
View file @
99987dfd
...
...
@@ -16,7 +16,6 @@ import {
}
from
'
react-router-dom
'
;
import
{
connect
}
from
'
react-redux
'
;
import
type
{
MapStateToProps
}
from
'
react-redux
'
;
import
*
as
Selectors
from
'
@store/selectors
'
;
...
...
@@ -120,7 +119,7 @@ export class MainNav extends React.Component<Props, State> {
}
}
const
mapStateToProps
:
MapStateToProps
<*
,
*
,
*>
=
state
=>
({
const
mapStateToProps
=
state
=>
({
database
:
Selectors
.
databaseGet
(
state
),
library
:
Selectors
.
libraryGet
(
state
),
dataformat
:
Selectors
.
dataformatGet
(
state
),
...
...
src/components/NewEntityModal.jsx
View file @
99987dfd
...
...
@@ -12,23 +12,38 @@ import {
import
{
connect
}
from
'
react-redux
'
;
import
{
generateNewKey
}
from
'
@helpers
'
;
import
{
BEAT_ENTITIES
,
nameValidator
,
nameSegmentsForEntity
}
from
'
@helpers/beat
'
;
import
{
BEAT_ENTITIES
,
nameValidator
,
nameSegmentsForEntity
,
getTcFromExpName
}
from
'
@helpers/beat
'
;
import
type
{
BeatEntity
,
BeatObject
}
from
'
@helpers/beat
'
;
import
CacheInput
from
'
./CacheInput.jsx
'
;
import
type
{
MapStateToProps
,
MapDispatchToProps
}
from
'
react-redux
'
;
import
*
as
Selectors
from
'
@store/selectors.js
'
;
import
*
as
Actions
from
'
@store/actions
'
;
import
{
getValidObj
as
getDatabaseObj
}
from
'
./database/DatabaseEditor.jsx
'
;
import
{
getValidObj
as
getDataformatObj
}
from
'
./dataformat/DataformatEditor.jsx
'
;
import
{
getValidObj
as
getLibraryObj
}
from
'
./library/LibraryEditor.jsx
'
;
import
{
getValidObj
as
getAlgorithmObj
}
from
'
./algorithm/AlgorithmEditor.jsx
'
;
import
{
getValidObj
as
getToolchainObj
}
from
'
./toolchain/ToolchainEditor.jsx
'
;
import
{
getValidObj
as
getExperimentObj
}
from
'
./experiment/ExperimentEditor.jsx
'
;
const
getObjs
=
{
database
:
getDatabaseObj
,
dataformat
:
getDataformatObj
,
library
:
getLibraryObj
,
algorithm
:
getAlgorithmObj
,
toolchain
:
getToolchainObj
,
experiment
:
getExperimentObj
,
};
type
Props
=
{
isOpen
:
boolean
,
toggle
:
()
=>
mixed
,
entity
:
BeatEntity
,
copyObj
?:
BeatObject
,
create
:
(
string
,
?{}
)
=>
mixed
,
create
:
(
string
,
BeatObject
[],
BeatObject
[],
?
BeatObject
)
=>
mixed
,
data
:
BeatObject
[],
toolchains
:
BeatObject
[],
algorithms
:
BeatObject
[],
};
type
State
=
{
...
...
@@ -68,7 +83,7 @@ export class NewEntityModal extends React.Component<Props, State> {
if
(
!
this
.
nameIsValid
())
return
;
this
.
props
.
create
(
name
,
this
.
props
.
copyObj
);
this
.
props
.
create
(
name
,
this
.
props
.
algorithms
,
this
.
props
.
toolchains
,
this
.
props
.
copyObj
);
this
.
props
.
toggle
();
}
...
...
@@ -359,24 +374,22 @@ export class NewEntityModal extends React.Component<Props, State> {
}
}
const
mapStateToProps
:
MapStateToProps
<*
,
*
,
*>
=
(
state
,
ownProps
)
=>
({
const
mapStateToProps
=
(
state
,
ownProps
)
=>
({
data
:
Selectors
[
`
${
ownProps
.
entity
}
Get`
](
state
),
toolchains
:
Selectors
.
toolchainGet
(
state
),
algorithms
:
Selectors
.
algorithmGet
(
state
),
});
const
mapDispatchToProps
=
(
dispatch
,
ownProps
)
=>
({
create
:
(
name
:
string
,
copyObj
?:
{}
=
{})
=>
{
const
newContents
=
ownProps
.
entity
===
'
toolchain
'
?
{
datasets
:
[],
blocks
:
[],
analyzers
:
[],
}
:
{};
const
newObj
=
{
contents
:
newContents
,
...
copyObj
,
name
,
};
create
:
(
name
:
string
,
algorithms
:
BeatObject
[],
toolchains
:
BeatObject
[],
copyObj
?:
{}
=
{})
=>
{
let
newObj
;
if
(
ownProps
.
entity
===
'
experiment
'
){
const
tcName
=
getTcFromExpName
(
name
);
const
tc
=
toolchains
.
find
(
o
=>
o
.
name
===
tcName
);
newObj
=
getObjs
[
ownProps
.
entity
]({
...
copyObj
,
name
},
tc
,
algorithms
);
}
else
{
newObj
=
getObjs
[
ownProps
.
entity
]({
...
copyObj
,
name
});
}
return
dispatch
(
Actions
.
createObject
(
ownProps
.
entity
,
newObj
)());
}
...
...
src/components/Settings.jsx
View file @
99987dfd
...
...
@@ -7,7 +7,6 @@ import {
}
from
'
reactstrap
'
;
import
{
connect
}
from
'
react-redux
'
;
import
type
{
MapStateToProps
,
MapDispatchToProps
}
from
'
react-redux
'
;
import
*
as
Actions
from
'
@store/actions.js
'
;
import
*
as
Selectors
from
'
@store/selectors
'
;
...
...
@@ -69,11 +68,11 @@ export class Settings extends React.PureComponent<Props> {
}
}
const
mapStateToProps
:
MapStateToProps
<*
,
*
,
*>
=
state
=>
({
const
mapStateToProps
=
state
=>
({
settings
:
Selectors
.
settingsGet
(
state
),
});
const
mapDispatchToProps
:
MapDispatchToProps
<*
,
*
,
*>
=
(
dispatch
,
ownProps
)
=>
({
const
mapDispatchToProps
=
(
dispatch
,
ownProps
)
=>
({
updateSettings
:
(
obj
)
=>
{
dispatch
(
Actions
.
settingsUpdate
(
obj
));
},
...
...
src/components/algorithm/AlgorithmEditor.jsx
View file @
99987dfd
...
...
@@ -14,7 +14,6 @@ import {
}
from
'
reactstrap
'
;
import
{
connect
}
from
'
react-redux
'
;
import
type
{
MapStateToProps
,
MapDispatchToProps
}
from
'
react-redux
'
;
import
cn
from
'
classnames
'
;
...
...
@@ -28,7 +27,6 @@ import CacheInput from '../CacheInput.jsx';
import
ValidSchemaBadge
from
'
../ValidSchemaBadge.jsx
'
;
import
DeleteInputBtn
from
'
../DeleteInputBtn.jsx
'
;
import
TypedField
from
'
../TypedField.jsx
'
;
import
{
getDefaultEntityObject
}
from
'
../EntityDetail.jsx
'
;
type
Props
=
{
data
:
BeatObject
,
...
...
@@ -59,7 +57,7 @@ type Group = {
outputs
?:
IOObject
,
};
const
getValidObj
=
(
data
=
{
})
=>
{
export
const
getValidObj
=
(
data
:
BeatObject
=
{
name
:
''
,
contents
:
{}
})
=>
{
const
getObj
=
{
name
:
''
,
contents
:
{},
...
...
@@ -79,7 +77,7 @@ const getValidObj = (data = {}) => {
},
};
if
(
JSON
.
stringify
(
data
.
contents
)
===
JSON
.
stringify
(
getDefaultEntityObject
().
contents
)
)
if
(
JSON
.
stringify
(
data
.
contents
)
===
'
{}
'
)
obj
.
contents
.
splittable
=
false
;
return
obj
;
...
...
@@ -946,7 +944,7 @@ export class AlgorithmEditor extends React.Component<Props, State> {
);
}
const
mapStateToProps
:
MapStateToProps
<*
,
*
,
*>
=
(
state
,
ownProps
)
=>
{
const
mapStateToProps
=
(
state
,
ownProps
)
=>
{
const
obj
=
{
algorithms
:
Selectors
.
algorithmGet
(
state
),
libraries
:
Selectors
.
libraryGet
(
state
),
...
...
src/components/database/DatabaseEditor.jsx
View file @
99987dfd
...
...
@@ -25,7 +25,6 @@ import {
}
from
'
reactstrap
'
;
import
{
connect
}
from
'
react-redux
'
;
import
type
{
MapStateToProps
,
MapDispatchToProps
}
from
'
react-redux
'
;
import
'
./DatabaseEditor.css
'
;
...
...
@@ -70,7 +69,7 @@ export type Protocol = {
sets
:
Set
[],
};
const
getValidObj
=
(
data
=
{
})
=>
{
export
const
getValidObj
=
(
data
:
BeatObject
=
{
name
:
''
,
contents
:
{}
})
=>
{
const
getObj
=
{
name
:
''
,
contents
:
{},
...
...
@@ -793,7 +792,7 @@ export class DatabaseEditor extends React.Component<Props, State> {
}
}
const
mapStateToProps
:
MapStateToProps
<*
,
*
,
*>
=
(
state
,
ownProps
)
=>
{
const
mapStateToProps
=
(
state
,
ownProps
)
=>
{
const
obj
=
{
databases
:
Selectors
.
databaseGet
(
state
),
dataformats
:
Selectors
.
dataformatGet
(
state
),
...
...
src/components/dataformat/DataformatEditor.jsx
View file @
99987dfd
...
...
@@ -23,7 +23,6 @@ import {
}
from
'
reactstrap
'
;
import
{
connect
}
from
'
react-redux
'
;
import
type
{
MapStateToProps
,
MapDispatchToProps
}
from
'
react-redux
'
;
import
*
as
Selectors
from
'
@store/selectors.js
'
;
...
...
@@ -49,7 +48,7 @@ type State = {
cache
:
any
,
};
const
getValidObj
=
(
data
=
{
})
=>
{
export
const
getValidObj
=
(
data
:
BeatObject
=
{
name
:
''
,
contents
:
{}
})
=>
{
const
getObj
=
{
name
:
''
,
contents
:
{},
...
...
@@ -305,7 +304,7 @@ export class DataformatEditor extends React.Component<Props, State> {
);
}
const
mapStateToProps
:
MapStateToProps
<*
,
*
,
*>
=
(
state
,
ownProps
)
=>
{
const
mapStateToProps
=
(
state
,
ownProps
)
=>
{
const
obj
=
{
dataformats
:
Selectors
.
dataformatGet
(
state
),
};
...
...
src/components/experiment/ExperimentEditor.jsx
View file @
99987dfd
...
...
@@ -23,7 +23,6 @@ import {
}
from
'
reactstrap
'
;
import
{
connect
}
from
'
react-redux
'
;
import
type
{
MapStateToProps
,
MapDispatchToProps
}
from
'
react-redux
'
;
import
cn
from
'
classnames
'
;
...
...
@@ -101,7 +100,7 @@ const getDefaultParameterValue = (parameter: any): ParameterValue => {
}
};
const
getValidObj
=
(
data
=
{
},
tc
:
BeatObject
,
algs
:
BeatObject
[])
=>
{
export
const
getValidObj
=
(
data
:
BeatObject
=
{
name
:
''
,
contents
:
{}
},
tc
:
BeatObject
,
algs
:
BeatObject
[])
=>
{
const
getObj
=
{
name
:
''
,
contents
:
{},
...
...
@@ -1301,7 +1300,7 @@ export class ExperimentEditor extends React.Component<Props, State> {
);
}
const
mapStateToProps
:
MapStateToProps
<*
,
*
,
*>
=
(
state
,
ownProps
)
=>
{
const
mapStateToProps
=
(
state
,
ownProps
)
=>
{
const
tcName
=
ownProps
.
data
.
name
.
split
(
'
/
'
).
slice
(
1
,
4
).
join
(
'
/
'
);
const
tc
=
Selectors
.
toolchainGet
(
state
).
find
(
t
=>
t
.
name
===
tcName
)
||
{
name
:
''
,
...
...
src/components/library/LibraryEditor.jsx
View file @
99987dfd
...
...
@@ -22,7 +22,6 @@ import {
}
from
'
reactstrap
'
;
import
{
connect
}
from
'
react-redux
'
;
import
type
{
MapStateToProps
,
MapDispatchToProps
}
from
'
react-redux
'
;
import
type
{
BeatObject
}
from
'
@helpers/beat
'
;
import
{
changeObjFieldName
,
jsonClone
}
from
'
@helpers
'
;
...
...
@@ -44,7 +43,7 @@ type State = {
cache
:
any
,
};
const
getValidObj
=
(
data
=
{
})
=>
{
export
const
getValidObj
=
(
data
:
BeatObject
=
{
name
:
''
,
contents
:
{}
})
=>
{
const
getObj
=
{
name
:
''
,
contents
:
{},
...
...
@@ -196,7 +195,7 @@ export class LibraryEditor extends React.Component<Props, State> {
);
}
const
mapStateToProps
:
MapStateToProps
<*
,
*
,
*>
=
(
state
,
ownProps
)
=>
{
const
mapStateToProps
=
(
state
,
ownProps
)
=>
{
const
obj
=
{
libraries
:
Selectors
.
libraryGet
(
state
),
};
...
...
src/components/toolchain/InsertObjectModal.jsx
View file @
99987dfd
...
...
@@ -18,7 +18,6 @@ import {
}
from
'
reactstrap
'
;
import
{
connect
}
from
'
react-redux
'
;
import
type
{
MapStateToProps
,
MapDispatchToProps
}
from
'
react-redux
'
;
import
*
as
Selectors
from
'
@store/selectors.js
'
;
import
type
{
FlattenedDatabaseEntry
}
from
'
@store/selectors
'
;
...
...
@@ -391,7 +390,7 @@ class InsertObjectModal extends React.PureComponent<Props, State> {
}
}
const
mapStateToProps
:
MapStateToProps
<*
,
*
,
*>
=
(
state
,
ownProps
)
=>
{
const
mapStateToProps
=
(
state
,
ownProps
)
=>
{
const
obj
=
{
toolchains
:
Selectors
.
toolchainGet
(
state
),
protocols
:
Selectors
.
databaseProtocols
(
state
),
...
...
src/components/toolchain/ToolchainEditor.jsx
View file @
99987dfd
...
...
@@ -27,7 +27,6 @@ import {
}
from
'
reactstrap
'
;
import
{
connect
}
from
'
react-redux
'
;
import
type
{
MapStateToProps
,
MapDispatchToProps
}
from
'
react-redux
'
;
import
{
ContextMenu
,
MenuItem
,
ContextMenuTrigger
,
SubMenu
}
from
'
react-contextmenu
'
;
import
{
getRandomBrightColor
,
generateNewKey
,
jsonClone
}
from
'
@helpers
'
;
...
...
@@ -90,7 +89,7 @@ type State = {
};
// makes sure the toolchain object is valid before passing it to the ToolchainEditor
const
getValidObj
=
(
data
=
{
})
=>
{
export
const
getValidObj
=
(
data
:
BeatObject
=
{
name
:
''
,
contents
:
{}
})
=>
{
const
getObj
=
{
name
:
''
,
contents
:
{},
...
...
@@ -1210,7 +1209,7 @@ export class ToolchainEditor extends React.PureComponent<Props, State> {
);
}
const
mapStateToProps
:
MapStateToProps
<*
,
*
,
*>
=
(
state
,
ownProps
)
=>
{
const
mapStateToProps
=
(
state
,
ownProps
)
=>
{
const
obj
=
{
toolchains
:
Selectors
.
toolchainGet
(
state
),
databases
:
Selectors
.
databaseGet
(
state
),
...
...
src/helpers/beat.js
View file @
99987dfd
...
...
@@ -53,6 +53,10 @@ Object.freeze(BEAT_ENTITIES);
Object
.
freeze
(
BUILTIN_TYPES
);
Object
.
freeze
(
ANALYZER_RESULT_TYPES
);
export
const
getTcFromExpName
=
(
expName
:
string
)
=>
expName
.
split
(
'
/
'
).
slice
(
1
,
4
).
join
(
'
/
'
);
export
const
getDefaultEntityObject
=
()
=>
({
name
:
''
,
contents
:
{}});
export
const
rxField
=
/^
[
a-zA-Z_
][
a-zA-Z0-9_-
]
*$/
;
export
const
nameSegmentsForEntity
=
(
entity
:
BeatEntity
)
=>
{
...
...
src/store/selectors.js
View file @
99987dfd
// @flow
import
{
createSelector
}
from
'
reselect
'
;
import
type
{
State
}
from
'
./reducers.js
'
;
import
{
getTcFromExpName
}
from
'
@helpers/beat
'
;
export
const
databaseGet
=
(
state
:
State
)
=>
state
.
database
;
export
const
libraryGet
=
(
state
:
State
)
=>
state
.
library
;
export
const
dataformatGet
=
(
state
:
State
)
=>
state
.
dataformat
;
export
const
algorithmGet
=
(
state
:
State
)
=>
state
.
algorithm
;
export
const
toolchainGet
=
(
state
:
State
)
=>
state
.
toolchain
;
export
const
experimentGet
=
(
state
:
State
)
=>
state
.
experiment
;
import
{
getValidObj
as
getDatabaseObj
}
from
'
../components/database/DatabaseEditor.jsx
'
;
import
{
getValidObj
as
getDataformatObj
}
from
'
../components/dataformat/DataformatEditor.jsx
'
;
import
{
getValidObj
as
getLibraryObj
}
from
'
../components/library/LibraryEditor.jsx
'
;
import
{
getValidObj
as
getAlgorithmObj
}
from
'
../components/algorithm/AlgorithmEditor.jsx
'
;
import
{
getValidObj
as
getToolchainObj
}
from
'
../components/toolchain/ToolchainEditor.jsx
'
;
import
{
getValidObj
as
getExperimentObj
}
from
'
../components/experiment/ExperimentEditor.jsx
'
;
const
getObjs
=
{
database
:
getDatabaseObj
,
dataformat
:
getDataformatObj
,
library
:
getLibraryObj
,
algorithm
:
getAlgorithmObj
,
toolchain
:
getToolchainObj
,
experiment
:
getExperimentObj
,
};
export
const
databaseGet
=
(
state
:
State
)
=>
state
.
database
.
map
(
o
=>
getObjs
[
'
database
'
](
o
));
export
const
dataformatGet
=
(
state
:
State
)
=>
state
.
dataformat
.
map
(
o
=>
getObjs
[
'
dataformat
'
](
o
));
export
const
libraryGet
=
(
state
:
State
)
=>
state
.
library
.
map
(
o
=>
getObjs
[
'
library
'
](
o
));
export
const
algorithmGet
=
(
state
:
State
)
=>
state
.
algorithm
.
map
(
o
=>
getObjs
[
'
algorithm
'
](
o
));
export
const
toolchainGet
=
(
state
:
State
)
=>
state
.
toolchain
.
map
(
o
=>
getObjs
[
'
toolchain
'
](
o
));
export
const
experimentGet
=
(
state
:
State
)
=>
createSelector
(
state
=>
state
.
experiment
,
algorithmGet
,
toolchainGet
,
(
exps
,
algs
,
tcs
)
=>
exps
.
map
(
o
=>
{
const
tcName
=
getTcFromExpName
(
o
.
name
);
const
tc
=
tcs
.
find
(
tc
=>
tc
.
name
===
tcName
);
if
(
!
tc
)
throw
new
Error
(
`Could not find toolchain for experiment "
${
o
.
name
}
`
);
return
getObjs
[
'
experiment
'
](
o
,
tc
,
algs
);
})
)(
state
);
export
const
settingsGet
=
(
state
:
State
)
=>
state
.
settings
;
export
type
FlattenedDatabaseEntry
=
{
|
...
...
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