Skip to content

Commit 6628283

Browse files
committed
Finished files
1 parent 653149a commit 6628283

File tree

2 files changed

+48
-58
lines changed

2 files changed

+48
-58
lines changed

src/components/Props.tsx

Lines changed: 47 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component, Fragment } from 'react';
22
import { connect } from 'react-redux';
3-
import { withStyles } from '@material-ui/core/styles';
3+
import { withStyles, Theme } from '@material-ui/core/styles';
44
import FormControl from '@material-ui/core/FormControl';
55
import Grid from '@material-ui/core/Grid';
66
import TextField from '@material-ui/core/TextField';
@@ -10,9 +10,15 @@ import Switch from '@material-ui/core/Switch';
1010
import InputLabel from '@material-ui/core/InputLabel';
1111
import { addProp, deleteProp } from '../actions/components';
1212
import DataTable from './DataTable';
13-
import { ComponentInt } from '../utils/Interfaces';
13+
import { ComponentInt, PropInt, PropsInt } from '../utils/Interfaces';
1414

15-
const styles = theme => ({
15+
interface PropsPropsInt extends PropsInt {
16+
classes: any;
17+
addProp(arg: PropInt): void;
18+
deleteProp(propId: number): void;
19+
}
20+
21+
const styles = (theme: Theme) => ({
1622
root: {
1723
display: 'flex',
1824
justifyContent: 'center',
@@ -59,25 +65,7 @@ const styles = theme => ({
5965
});
6066

6167
const mapDispatchToProps = (dispatch: any) => ({
62-
addProp: ({
63-
key,
64-
value,
65-
required,
66-
type
67-
}: {
68-
key: string;
69-
value: string;
70-
required: boolean;
71-
type: string;
72-
}) =>
73-
dispatch(
74-
addProp({
75-
key,
76-
value,
77-
required,
78-
type
79-
})
80-
),
68+
addProp: (prop: PropInt) => dispatch(addProp(prop)),
8169
deleteProp: (propId: number) => dispatch(deleteProp(propId))
8270
});
8371

@@ -103,21 +91,29 @@ const availablePropTypes = {
10391

10492
// generates the various options for the prop type selection
10593
const typeOptions = [
106-
<option value='' key='' />,
94+
<option value="" key="" />,
10795
...Object.keys(availablePropTypes).map(type => (
10896
<option value={type} key={type} style={{ color: '#000' }}>
10997
{type}
11098
</option>
11199
))
112100
];
113-
114-
class Props extends Component {
115-
state = {
116-
propKey: '',
117-
propValue: '',
118-
propRequired: true,
119-
propType: ''
120-
};
101+
interface StateInt {
102+
propKey: string;
103+
propValue: string;
104+
propRequired: boolean;
105+
propType: string;
106+
}
107+
class Props extends Component<PropsPropsInt, StateInt> {
108+
constructor(props: PropsPropsInt) {
109+
super(props);
110+
this.state = {
111+
propKey: '',
112+
propValue: '',
113+
propRequired: true,
114+
propType: ''
115+
};
116+
}
121117

122118
handleChange = (event: MouseEvent) => {
123119
if (event.target.id === 'propKey') {
@@ -198,18 +194,18 @@ class Props extends Component {
198194
) : (
199195
<Fragment>
200196
<div
201-
className='props-container'
197+
className="props-container"
202198
style={{ marginTop: '20px', width: '90%', height: '80%' }}
203199
>
204200
<Grid container spacing={8}>
205201
<Grid item xs={3}>
206-
<form className='props-input' onSubmit={this.handleAddProp}>
202+
<form className="props-input" onSubmit={this.handleAddProp}>
207203
<Grid container spacing={8}>
208204
<Grid item xs={6}>
209205
<TextField
210-
id='propKey'
211-
label='Key'
212-
margin='normal'
206+
id="propKey"
207+
label="Key"
208+
margin="normal"
213209
autoFocus
214210
onChange={this.handleChange}
215211
value={this.state.propKey}
@@ -224,9 +220,9 @@ class Props extends Component {
224220
</Grid>
225221
<Grid item xs={6}>
226222
<TextField
227-
id='propValue'
228-
label='Value'
229-
margin='normal'
223+
id="propValue"
224+
label="Value"
225+
margin="normal"
230226
onChange={this.handleChange}
231227
InputProps={{
232228
className: classes.input
@@ -239,17 +235,14 @@ class Props extends Component {
239235
</Grid>
240236
<Grid item xs={6}>
241237
<FormControl required>
242-
<InputLabel
243-
className={classes.light}
244-
htmlFor='propType'
245-
>
238+
<InputLabel className={classes.light} htmlFor="propType">
246239
Type
247240
</InputLabel>
248241
<Select
249242
native
250243
className={classes.light}
251-
id='propType'
252-
placeholder='title'
244+
id="propType"
245+
placeholder="title"
253246
onChange={this.handleChange}
254247
value={this.state.propType}
255248
required
@@ -260,29 +253,26 @@ class Props extends Component {
260253
</Grid>
261254
<Grid item xs={6}>
262255
<div className={classes.column}>
263-
<InputLabel
264-
className={classes.light}
265-
htmlFor='propRequired'
266-
>
256+
<InputLabel className={classes.light} htmlFor="propRequired">
267257
Required?
268258
</InputLabel>
269259
<Switch
270260
checked={this.state.propRequired}
271261
onChange={this.togglePropRequired}
272-
value='propRequired'
273-
color='primary'
274-
id='propRequired'
262+
value="propRequired"
263+
color="primary"
264+
id="propRequired"
275265
/>
276266
</div>
277267
</Grid>
278268
<Grid item>
279269
<Button
280-
color='primary'
281-
aria-label='Add'
282-
type='submit'
270+
color="primary"
271+
aria-label="Add"
272+
type="submit"
283273
// disabled={!this.state.propKey || !this.state.propType}
284-
variant='contained'
285-
size='large'
274+
variant="contained"
275+
size="large"
286276
>
287277
ADD PROP
288278
</Button>

src/utils/Interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//This itnerface seems to be very specific to the prop argument passed into the reducer function 'addProp'.
22
//It actually might not make too muich sense being in this file.
33
export interface PropInt {
4-
id: number;
4+
id?: number;
55
key: string;
66
value: string;
77
required: boolean;

0 commit comments

Comments
 (0)