import { Component } from 'react'; import { ValidatorForm, SelectValidator } from 'react-material-ui-form-validator'; import { Typography, Grid } from '@material-ui/core'; import MenuItem from '@material-ui/core/MenuItem'; import { redirectingAuthorizedFetch, withAuthenticatedContext, AuthenticatedContextProps } from '../authentication'; import { RestFormProps } from '../components'; import { LogSettings } from './types'; import { ENDPOINT_ROOT } from '../api'; export const LOG_SETTINGS_ENDPOINT = ENDPOINT_ROOT + 'logSettings'; type LogEventFormProps = AuthenticatedContextProps & RestFormProps; class LogEventForm extends Component { changeLevel = (event: React.ChangeEvent) => { const { data, setData } = this.props; setData({ ...data, level: parseInt(event.target.value) }); redirectingAuthorizedFetch(LOG_SETTINGS_ENDPOINT, { method: 'POST', body: JSON.stringify({ level: event.target.value }), headers: { 'Content-Type': 'application/json' } }) .then((response) => { if (response.status === 200) { return response.json(); } throw Error('Unexpected response code: ' + response.status); }) .then((json) => { this.props.enqueueSnackbar('Log settings changed', { variant: 'success' }); setData({ ...data, level: json.level }); }) .catch((error) => { this.props.enqueueSnackbar( error.message || 'Problem changing log settings', { variant: 'warning' } ); }); }; render() { const { data, saveData } = this.props; return ( OFF ERROR WARNING NOTICE INFO DEBUG ALL  (the last {data.max_messages} messages are retained and all new log events are shown in real time below) ); } } export default withAuthenticatedContext(LogEventForm);