-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ActionEditor to visualize actions json, update tests
closes #226
- Loading branch information
Showing
7 changed files
with
281 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import React, { Component } from 'react'; | ||
import classNames from 'classnames'; | ||
import { withStyles } from '@material-ui/core'; | ||
import { withTranslation } from 'react-i18next'; | ||
import { withRouter } from 'react-router'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import CssBaseline from '@material-ui/core/CssBaseline'; | ||
import AppBar from '@material-ui/core/AppBar'; | ||
import Toolbar from '@material-ui/core/Toolbar'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import MenuIcon from '@material-ui/icons/Menu'; | ||
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft'; | ||
import ChevronRightIcon from '@material-ui/icons/ChevronRight'; | ||
import Drawer from '@material-ui/core/Drawer'; | ||
import Divider from '@material-ui/core/Divider'; | ||
import PropTypes from 'prop-types'; | ||
import MainMenu from '../common/MainMenu'; | ||
import ActionEditor from './ActionEditor'; | ||
import Styles from '../../Styles'; | ||
import Banner from '../common/Banner'; | ||
|
||
export class ActionDashboard extends Component { | ||
state = { | ||
open: false, | ||
}; | ||
|
||
static propTypes = { | ||
t: PropTypes.func.isRequired, | ||
classes: PropTypes.shape({ | ||
root: PropTypes.string.isRequired, | ||
appBar: PropTypes.string.isRequired, | ||
appBarShift: PropTypes.string.isRequired, | ||
menuButton: PropTypes.string.isRequired, | ||
hide: PropTypes.string.isRequired, | ||
drawer: PropTypes.string.isRequired, | ||
drawerPaper: PropTypes.string.isRequired, | ||
drawerHeader: PropTypes.string.isRequired, | ||
content: PropTypes.string.isRequired, | ||
contentShift: PropTypes.string.isRequired, | ||
developer: PropTypes.string.isRequired, | ||
screenTitle: PropTypes.string.isRequired, | ||
}).isRequired, | ||
theme: PropTypes.shape({ | ||
direction: PropTypes.string.isRequired, | ||
}).isRequired, | ||
history: PropTypes.shape({ | ||
replace: PropTypes.func.isRequired, | ||
}).isRequired, | ||
i18n: PropTypes.shape({ | ||
changeLanguage: PropTypes.func.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
handleDrawerOpen = () => { | ||
this.setState({ open: true }); | ||
}; | ||
|
||
handleDrawerClose = () => { | ||
this.setState({ open: false }); | ||
}; | ||
|
||
render() { | ||
const { classes, theme, t } = this.props; | ||
const { open } = this.state; | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<CssBaseline /> | ||
<AppBar | ||
position="fixed" | ||
className={classNames(classes.appBar, { | ||
[classes.appBarShift]: open, | ||
})} | ||
> | ||
<Toolbar disableGutters={!open}> | ||
<IconButton | ||
color="inherit" | ||
aria-label="Open drawer" | ||
onClick={this.handleDrawerOpen} | ||
className={classNames(classes.menuButton, open && classes.hide)} | ||
> | ||
<MenuIcon /> | ||
</IconButton> | ||
</Toolbar> | ||
</AppBar> | ||
<Drawer | ||
className={classes.drawer} | ||
variant="persistent" | ||
anchor="left" | ||
open={open} | ||
classes={{ | ||
paper: classes.drawerPaper, | ||
}} | ||
> | ||
<div className={classes.drawerHeader}> | ||
<IconButton onClick={this.handleDrawerClose}> | ||
{theme.direction === 'ltr' ? ( | ||
<ChevronLeftIcon /> | ||
) : ( | ||
<ChevronRightIcon /> | ||
)} | ||
</IconButton> | ||
</div> | ||
<Divider /> | ||
<MainMenu /> | ||
</Drawer> | ||
<main | ||
className={classNames(classes.content, { | ||
[classes.contentShift]: open, | ||
})} | ||
> | ||
<div className={classes.drawerHeader} /> | ||
<div className={classes.developer}> | ||
<Typography variant="h4" className={classes.screenTitle}> | ||
{t('Action Dashboard')} | ||
</Typography> | ||
<br /> | ||
<Banner | ||
text={t( | ||
'Danger Zone! Proceed with caution as changes to this section might lead to data loss.' | ||
)} | ||
type="error" | ||
/> | ||
<ActionEditor /> | ||
</div> | ||
</main> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const StyledComponent = withStyles(Styles, { withTheme: true })( | ||
ActionDashboard | ||
); | ||
|
||
const TranslatedComponent = withTranslation()(StyledComponent); | ||
|
||
export default withRouter(TranslatedComponent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React, { Component } from 'react'; | ||
import _ from 'lodash'; | ||
import { connect } from 'react-redux'; | ||
import ReactJson from 'react-json-view'; | ||
import PropTypes from 'prop-types'; | ||
import Button from '@material-ui/core/Button'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import { withTranslation } from 'react-i18next'; | ||
import { withStyles } from '@material-ui/core'; | ||
import { getDatabase, setDatabase } from '../../actions'; | ||
import Loader from '../common/Loader'; | ||
import Styles from '../../Styles'; | ||
import SampleDatabase from '../../data/sample.json'; | ||
|
||
export class ActionEditor extends Component { | ||
static propTypes = { | ||
t: PropTypes.func.isRequired, | ||
classes: PropTypes.shape({ | ||
button: PropTypes.string.isRequired, | ||
}).isRequired, | ||
dispatchGetDatabase: PropTypes.func.isRequired, | ||
dispatchSetDatabase: PropTypes.func.isRequired, | ||
database: PropTypes.shape({ | ||
user: PropTypes.object, | ||
spaces: PropTypes.array, | ||
actions: PropTypes.array, | ||
}), | ||
}; | ||
|
||
static defaultProps = { | ||
database: {}, | ||
}; | ||
|
||
componentDidMount() { | ||
const { dispatchGetDatabase } = this.props; | ||
dispatchGetDatabase(); | ||
} | ||
|
||
handleEdit = ({ updated_src: updatedSrc }) => { | ||
const { dispatchSetDatabase } = this.props; | ||
dispatchSetDatabase(updatedSrc); | ||
}; | ||
|
||
handleUseSampleDatabase = () => { | ||
const { dispatchSetDatabase } = this.props; | ||
dispatchSetDatabase(SampleDatabase); | ||
}; | ||
|
||
render() { | ||
const { database, t, classes } = this.props; | ||
|
||
if (!database || _.isEmpty(database)) { | ||
return <Loader />; | ||
} | ||
|
||
return ( | ||
<div> | ||
<Typography variant="h6">{t('Manually Edit the Database')}</Typography> | ||
<ReactJson | ||
name="actions" | ||
collapsed | ||
src={database.actions} | ||
onEdit={this.handleEdit} | ||
onAdd={this.handleEdit} | ||
onDelete={this.handleEdit} | ||
/> | ||
<br /> | ||
<Button | ||
variant="contained" | ||
className={classes.button} | ||
onClick={this.handleUseSampleDatabase} | ||
color="primary" | ||
> | ||
{t('Use Sample Database')} | ||
</Button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = ({ Developer }) => ({ | ||
database: Developer.get('database'), | ||
}); | ||
|
||
const mapDispatchToProps = { | ||
dispatchGetDatabase: getDatabase, | ||
dispatchSetDatabase: setDatabase, | ||
}; | ||
|
||
const StyledComponent = withStyles(Styles, { withTheme: true })(ActionEditor); | ||
const TranslatedComponent = withTranslation()(StyledComponent); | ||
const ConnectedComponent = connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(TranslatedComponent); | ||
|
||
export default ConnectedComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters