From 8ca1ba26670c8745a641839dd717171ceea32f48 Mon Sep 17 00:00:00 2001 From: Determinant Date: Tue, 29 Jan 2019 13:31:29 -0500 Subject: support dropdown selection --- src/App.js | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 97 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/App.js b/src/App.js index a8acbc8..4cd1610 100755 --- a/src/App.js +++ b/src/App.js @@ -30,6 +30,8 @@ import Grid from '@material-ui/core/Grid'; import DeleteOutlinedIcon from '@material-ui/icons/DeleteOutlined'; import AddCircleIcon from '@material-ui/icons/AddCircle'; import IconButton from '@material-ui/core/IconButton'; +import MenuItem from '@material-ui/core/MenuItem'; +import Select from '@material-ui/core/Select'; import { PieChart, Pie, Cell, Tooltip } from 'recharts'; import Logo from './Logo'; @@ -85,7 +87,7 @@ function getColors(token) { function filterPatterns(patterns, calName) { return patterns.filter(p => { - let re = new RegExp(p.cal); + let re = new RegExp(p.cal.regex && p.cal.value || `^${p.cal.value}$`); return re.test(calName); }); } @@ -129,6 +131,12 @@ const styles = theme => ({ }, fab: { margin: theme.spacing.unit, + }, + fieldNoRegex: { + width: 200 + }, + fieldRegex: { + marginRight: '0.5em' } }); @@ -195,6 +203,77 @@ ChromiclePieChart.propTypes = { patterncalendarData: PropTypes.object.isRequired, }; +class RegexField extends React.Component { + render() { + var pitems = this.props.items; + let items = []; + pitems['0'] = {regex: true, label: null, id: '0'}; + for (let id in pitems) + { + items.push( + + {pitems[id].label != null && pitems[id].label || 'Regex'} + ); + } + return ( + + + {this.props.value.label == null && ( + + this.props.onChange({target: { value: {regex: true, value: event.target.value, label: null, id: '0'}}})} /> + )} + + ); + } +} + +function CalendarField(props) { + let items = {}; + for (let id in props.cached.calendars) { + items[id] = { + regex: false, + value: props.cached.calendars[id].name, + label: props.cached.calendars[id].name, id} + } + return ( + ); +} + +function EventField(props) { + let items = {'any': { + regex: true, + value: '.*', + label: 'Any', id: 'any'}}; + return ( + ); +} + class Dashboard extends React.Component { state = { open: true, @@ -213,9 +292,9 @@ class Dashboard extends React.Component { }; static patternHead = [ - {label: "Name", field: "name"}, - {label: "Calendar", field: "cal"}, - {label: "Event", field: 'event'}]; + {label: "Name", field: "name", elem: TextField}, + {label: "Calendar", field: "cal", elem: CalendarField}, + {label: "Event", field: 'event', elem: EventField}]; handleChangePage = (event, page) => { this.setState({ page }); @@ -240,8 +319,10 @@ class Dashboard extends React.Component { }; newPattern = () => { - let patterns = [{name: '', cal: '', event: '', idx: 0 }, - ...this.state.patterns]; + let patterns = [{name: '', + cal: { regex: true, label: null, id: '0' }, + event: { regex: true, value: '.*', label: 'Any', id: 'any' }, + idx: 0 }, ...this.state.patterns]; for (let i = 1; i < patterns.length; i++) patterns[i].idx = i; this.setState({ patterns }); @@ -269,7 +350,7 @@ class Dashboard extends React.Component { results[i] = 0; for (let id in this.cached.calendars) { let patterns = filterPatterns(this.state.patterns, this.cached.calendars[id].name) - .map(p => { return { regex: new RegExp(p.event), idx: p.idx } }); + .map(p => { return { regex: new RegExp(p.event.value), idx: p.idx } }); if (!this.cached.calendars[id].events) continue; this.cached.calendars[id].events.forEach(event => { if (event.status != "confirmed") return; @@ -315,8 +396,8 @@ class Dashboard extends React.Component { }); this.setState({ patterns: items.map((item, idx) => { return { name: item.summary, - cal: item.summary, - event: '.*', + cal: { regex: false, value: item.summary, label: item.summary, id: item.id }, + event: { regex: true, value: '.*', label: 'Any', id: 'any' }, idx } })}); }); @@ -362,12 +443,16 @@ class Dashboard extends React.Component { this.setState({ activePattern: p.idx })} onMouseOut={() => this.setState({ activePattern: null })}> - {Dashboard.patternHead.map(s => ( + {Dashboard.patternHead.map(s => { + const CustomText = s.elem; + return ( - this.updatePattern(s.field, p.idx, event.target.value)}/> - ))} + )})} -- cgit v1.2.3-70-g09d2