From 6738cb883c37f2e388f1c86c84bd4c34a98699bd Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 14 Feb 2019 18:28:06 -0500 Subject: ... --- src/PatternTable.tsx | 60 +++++++++++++++++++++++++++++++-------------------- src/Settings.tsx | 61 +++++++++++++++++++++++++++++++--------------------- src/duration.ts | 12 +++++------ 3 files changed, 80 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/PatternTable.tsx b/src/PatternTable.tsx index 93be293..60acd3c 100644 --- a/src/PatternTable.tsx +++ b/src/PatternTable.tsx @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { withStyles, withTheme } from '@material-ui/core/styles'; +import { Theme, withStyles, withTheme } from '@material-ui/core/styles'; import TextField from '@material-ui/core/TextField'; import Table from '@material-ui/core/Table'; import TableBody from '@material-ui/core/TableBody'; @@ -13,8 +13,10 @@ import Popover from '@material-ui/core/Popover'; import MaterialColorPicker from 'react-material-color-picker'; import { CalendarField, EventField } from './RegexField'; import { theme, defaultChartColor } from './theme'; +import { PatternEntry, PatternEntryColor } from './pattern'; +import { GCalendarMeta } from './gapi'; -const styles = theme => ({ +const styles = (theme: Theme) => ({ deleteButton: { width: 0, position: 'absolute', @@ -50,7 +52,12 @@ let nameFieldstyles = { } }; -function NameField(props) { +function NameField(props: { + value: PatternEntry, + classes: { colorSample: string }, + colorOnClick: (e: React.MouseEvent) => void, + onChange: (f: string, v: string) => void + }) { let color = props.value.color; return ( @@ -68,23 +75,39 @@ function NameField(props) { const patternHead = [ {label: "Name", elem: withStyles(nameFieldstyles)(NameField)}, {label: "Calendar", elem: withTheme(theme)(CalendarField)}, - {label: "Event", elem: withTheme(theme)(EventField)}]; + {label: "Event", elem: withTheme(theme)(EventField)}] as {label: string, elem: any}[]; -class PatternTable extends React.Component { +class PatternTable extends React.Component<{ + classes: { + deleteButton: string, + deleteButtonHide: string, + deleteButtonShow: string, + deleteIcon: string, + patternTableWrapper: string, + patternTable: string, + }, + calendars: { [id: string]: GCalendarMeta }, + patterns: PatternEntry[], + onRemovePattern: (idx: number) => void, + onUpdatePattern: (field: string, idx: number, value: any) => void + }> { + + activeColorPattern: number; + chosenColor: string; state = { page: 0, rowsPerPage: 5, - activePattern: null, - anchorEl: null, + activePattern: null as number, + anchorEl: null as HTMLElement, colorPickerOpen: false, colorPickerDefault: defaultChartColor }; - handleChangePage = (event, page) => { + handleChangePage = (event: React.MouseEvent, page: number) => { this.setState({ page }); } - handleChangeRowsPerPage = event => { + handleChangeRowsPerPage = (event: any) => { this.setState({ rowsPerPage: event.target.value }); } @@ -93,7 +116,7 @@ class PatternTable extends React.Component { this.activeColorPattern !== null && this.chosenColor && this.props.onUpdatePattern('color', this.activeColorPattern, - {background: this.chosenColor.target.value}) + {background: this.chosenColor}) } render() { @@ -123,8 +146,8 @@ class PatternTable extends React.Component { this.props.onUpdatePattern(field, p.idx, value)} - colorOnClick={event => { + onChange={(field: string, value: any) => this.props.onUpdatePattern(field, p.idx, value)} + colorOnClick={(event: any) => { this.activeColorPattern = p.idx; this.setState({ anchorEl: event.currentTarget, @@ -155,9 +178,9 @@ class PatternTable extends React.Component { }}> { + onSelect={(event: any) => { console.log("select"); - this.chosenColor = color; + this.chosenColor = event.target.value; }} onSubmit={this.handleColorPickerClose} onReset={() => {}} @@ -196,13 +219,4 @@ class PatternTable extends React.Component { } } - -PatternTable.propTypes = { - classes: PropTypes.object.isRequired, - patterns: PropTypes.array.isRequired, - calendars: PropTypes.object.isRequired, - onRemovePattern: PropTypes.func.isRequired, - onUpdatePattern: PropTypes.func.isRequired, -}; - export default withStyles(styles)(PatternTable); diff --git a/src/Settings.tsx b/src/Settings.tsx index 1626a7a..e08a89b 100644 --- a/src/Settings.tsx +++ b/src/Settings.tsx @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { withStyles } from '@material-ui/core/styles'; +import { Theme, withStyles } from '@material-ui/core/styles'; import CssBaseline from '@material-ui/core/CssBaseline'; import Typography from '@material-ui/core/Typography'; import Button from '@material-ui/core/Button'; @@ -30,7 +30,7 @@ import MenuItem from '@material-ui/core/MenuItem'; import Select from '@material-ui/core/Select'; import { Duration } from './duration'; -const styles = theme => ({ +const styles = (theme: Theme) => ({ tableHead: { verticalAlign: 'top', textAlign: 'right', @@ -59,12 +59,19 @@ const CompactListItem = withStyles(theme => ({ }, }))(ListItem); -class TrackedPeriod extends React.Component { - valueOnChange = (old, onChange) => event => { +class TrackedPeriod extends React.Component<{ + name: string + fromDuration: Duration, + toDuration: Duration, + nameOnChange: (name: string) => void, + fromOnChange: (d: Duration) => void, + toOnChange: (d: Duration) => void + }>{ + valueOnChange = (old: Duration, onChange: (d: Duration) => void) => (event: any) => { onChange(new Duration(event.target.value, old.unit)); } - unitOnChange = (old, onChange) => event => { + unitOnChange = (old: Duration, onChange: (d: Duration) => void) => (event: any) => { onChange(new Duration(old.value, event.target.value)); } @@ -78,7 +85,7 @@ class TrackedPeriod extends React.Component { } }; - static toValue(value) { + static toValue(value: any) { if (isNaN(value)) return null; let v = parseInt(value, 10); if (v < 0 || v > 999) return null; @@ -86,7 +93,7 @@ class TrackedPeriod extends React.Component { } render() { - let { classes, fromDuration, toDuration, nameOnChange, fromOnChange, toOnChange, name } = this.props; + let { fromDuration, toDuration, nameOnChange, fromOnChange, toOnChange, name } = this.props; let units = [ Day(s), Week(s), @@ -95,19 +102,19 @@ class TrackedPeriod extends React.Component { return ( nameOnChange(event.target.value)}/>: from ago to