Skip to content

Commit 0360113

Browse files
eneufeldedgarmueller
authored andcommitted
[mui-tree] Fix imports and context usage (#1402)
1 parent bb82ac2 commit 0360113

File tree

3 files changed

+226
-154
lines changed

3 files changed

+226
-154
lines changed

packages/material-tree-renderer/example/App.tsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
getUiSchema,
3434
JsonFormsStore
3535
} from '@jsonforms/core';
36+
import { JsonFormsReduxContext } from '@jsonforms/react';
3637

3738
interface AppParameter {
3839
store: JsonFormsStore;
@@ -41,21 +42,28 @@ interface AppParameter {
4142
imageProvider: any;
4243
}
4344

44-
const App = ({ store, filterPredicate, labelProviders, imageProvider }: AppParameter) => (
45+
const App = ({
46+
store,
47+
filterPredicate,
48+
labelProviders,
49+
imageProvider
50+
}: AppParameter) => (
4551
<Provider store={store}>
46-
<React.Fragment>
47-
<EditorBar
48-
schema={getSchema(store.getState())}
49-
rootData={getData(store.getState())}
50-
/>
51-
<ThemedTreeWithDetail
52-
filterPredicate={filterPredicate}
53-
labelProviders={labelProviders}
54-
imageProvider={imageProvider}
55-
schema={getSchema(store.getState())}
56-
uischema={getUiSchema(store.getState())as ControlElement}
57-
/>
58-
</React.Fragment>
52+
<JsonFormsReduxContext>
53+
<React.Fragment>
54+
<EditorBar
55+
schema={getSchema(store.getState())}
56+
rootData={getData(store.getState())}
57+
/>
58+
<ThemedTreeWithDetail
59+
filterPredicate={filterPredicate}
60+
labelProviders={labelProviders}
61+
imageProvider={imageProvider}
62+
schema={getSchema(store.getState())}
63+
uischema={getUiSchema(store.getState()) as ControlElement}
64+
/>
65+
</React.Fragment>
66+
</JsonFormsReduxContext>
5967
</Provider>
6068
);
6169

packages/material-tree-renderer/example/app-bar/EditorBar.tsx

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ import isEmpty from 'lodash/isEmpty';
2626
import React from 'react';
2727
import { connect } from 'react-redux';
2828
import { compose } from 'recompose';
29-
import { StyleRulesCallback, withStyles, WithStyles } from '@material-ui/core/styles';
29+
import {
30+
StyleRulesCallback,
31+
withStyles,
32+
WithStyles
33+
} from '@material-ui/core/styles';
3034
import AppBar from '@material-ui/core/AppBar';
3135
import Toolbar from '@material-ui/core/Toolbar';
3236
import Typography from '@material-ui/core/Typography';
@@ -40,18 +44,20 @@ import { createAjv } from '@jsonforms/core/lib/util/validator';
4044

4145
const ajv = createAjv();
4246

43-
const styles: StyleRulesCallback<'root' | 'flex' | 'rightIcon' | 'button'> = theme => ({
47+
const styles: StyleRulesCallback<
48+
'root' | 'flex' | 'rightIcon' | 'button'
49+
> = theme => ({
4450
root: {
45-
flexGrow: 1,
51+
flexGrow: 1
4652
},
4753
flex: {
48-
flex: 1,
54+
flex: 1
4955
},
5056
rightIcon: {
51-
marginLeft: theme.spacing.unit,
57+
marginLeft: Number(theme.spacing)
5258
},
5359
button: {
54-
margin: theme.spacing.unit,
60+
margin: Number(theme.spacing)
5561
}
5662
});
5763

@@ -63,14 +69,17 @@ interface EditorBarProps {
6369

6470
interface EditorBarState {
6571
exportDialog: {
66-
open: boolean
72+
open: boolean;
6773
};
6874
}
6975

70-
class EditorBar extends
71-
React.Component<EditorBarProps & WithStyles<'root' | 'flex' | 'rightIcon' | 'button'>,
72-
EditorBarState> {
73-
constructor(props: EditorBarProps & WithStyles<'root' | 'flex' | 'rightIcon' | 'button'>) {
76+
class EditorBar extends React.Component<
77+
EditorBarProps & WithStyles<'root' | 'flex' | 'rightIcon' | 'button'>,
78+
EditorBarState
79+
> {
80+
constructor(
81+
props: EditorBarProps & WithStyles<'root' | 'flex' | 'rightIcon' | 'button'>
82+
) {
7483
super(props);
7584
this.state = {
7685
exportDialog: {
@@ -97,8 +106,9 @@ class EditorBar extends
97106

98107
handleDownload = () => {
99108
const a = document.createElement('a');
100-
const file = new Blob([JSON.stringify(this.props.rootData, null, 2)],
101-
{type: 'application/json'});
109+
const file = new Blob([JSON.stringify(this.props.rootData, null, 2)], {
110+
type: 'application/json'
111+
});
102112
a.href = URL.createObjectURL(file);
103113
a.download = 'download.json';
104114
a.click();
@@ -132,7 +142,9 @@ class EditorBar extends
132142
return;
133143
}
134144
} else {
135-
console.error('Something went wrong! The file is an ArrayBuffer instead of a string.');
145+
console.error(
146+
'Something went wrong! The file is an ArrayBuffer instead of a string.'
147+
);
136148
}
137149
if (!isEmpty(readData)) {
138150
const valid = ajv.validate(schema, readData);
@@ -159,7 +171,11 @@ class EditorBar extends
159171
<Typography variant='h6' color='inherit' className={classes.flex}>
160172
User and Task Editor
161173
</Typography>
162-
<Button component='label' className={classes.button} color='inherit'>
174+
<Button
175+
component='label'
176+
className={classes.button}
177+
color='inherit'
178+
>
163179
Open Data File
164180
<FolderOpen className={classes.rightIcon} />
165181
<input
@@ -180,11 +196,14 @@ class EditorBar extends
180196
open={this.state.exportDialog.open}
181197
onClose={this.handleExportDialogClose}
182198
/>
183-
<Button className={classes.button} color='inherit' onClick={this.handleDownload}>
199+
<Button
200+
className={classes.button}
201+
color='inherit'
202+
onClick={this.handleDownload}
203+
>
184204
Download Model
185205
<FileDownload className={classes.rightIcon} />
186206
</Button>
187-
188207
</Toolbar>
189208
</AppBar>
190209
</div>
@@ -207,5 +226,8 @@ const mapDispatchToProps = (dispatch: any) => ({
207226

208227
export default compose<any, any>(
209228
withStyles(styles, { name: 'EditorBar' }),
210-
connect(mapStateToProps, mapDispatchToProps)
229+
connect(
230+
mapStateToProps,
231+
mapDispatchToProps
232+
)
211233
)(EditorBar);

0 commit comments

Comments
 (0)