File size: 2,492 Bytes
ae01f49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2024, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////

import gettext from 'sources/gettext';
import _ from 'lodash';
import { FormGroup, Grid, Typography } from '@mui/material';
import { makeStyles } from '@mui/styles';
import React from 'react';
import { InputText } from './FormComponents';
import PropTypes from 'prop-types';

const useStyles = makeStyles(() => ({
  formControlLabel: {
    padding: '3px',
  },
  formInput: {
    marginLeft: '5px'
  },
  formCheckboxControl: {
    padding: '3px',
    border: '1px solid',
    borderRadius: '0.25rem',
  },
  formGroup: {
    padding: '5px'
  },
  contentTextAlign: {
    textAlign: 'center'
  },
  contentStyle: {
    paddingLeft: 10,
  }
}));

export default function QueryThresholds({ value, onChange }) {
  const classes = useStyles();
  const warningCid = _.uniqueId('c');
  const warninghelpid = `h${warningCid}`;
  const alertCid = _.uniqueId('c');
  const alerthelpid = `h${alertCid}`;

  const onWarningChange = (val) => {
    let new_val = { ...value };
    new_val['warning'] = val;
    onChange(new_val);
  };

  const onAlertChange = (val) => {
    let new_val = { ...value };
    new_val['alert'] = val;
    onChange(new_val);
  };

  return (
    <FormGroup>
      <Grid
        container
        direction="row"
        alignItems="center"
      >
        <Grid item lg={2} md={2} sm={2} xs={12}>
          <Typography>{gettext('Warning')}</Typography>
        </Grid>
        <Grid item lg={2} md={2} sm={2} xs={12}>
          <InputText cid={warningCid} helpid={warninghelpid} type='numeric' value={value?.warning} onChange={onWarningChange} />
        </Grid>
        <Grid item lg={2} md={2} sm={2} xs={12} className={classes.contentTextAlign}>
          <Typography>{gettext('Alert')}</Typography>
        </Grid>
        <Grid item lg={2} md={2} sm={2} xs={12}>
          <InputText cid={alertCid} helpid={alerthelpid} type='numeric' value={value?.alert} onChange={onAlertChange} />
        </Grid>
        <Grid item lg={4} md={4} sm={4} xs={12} className={classes.contentStyle}>
          <Typography>{gettext('(in minutes)')}</Typography>
        </Grid>
      </Grid>
    </FormGroup >
  );
}

QueryThresholds.propTypes = {
  value: PropTypes.object,
  onChange: PropTypes.func,
};