|
1 | 1 | import * as React from "react" |
2 | 2 |
|
3 | | -import { styled } from '@mui/material/styles'; |
4 | 3 | import TextField from "@mui/material/TextField" |
5 | 4 | import { Parameter as ParameterT } from "./types" |
6 | 5 | import { ShowAdvancedCtx } from "." |
7 | | -import { IconButton, Tooltip } from "@mui/material" |
| 6 | +import { IconButton, Tooltip, Grid } from "@mui/material" |
8 | 7 | import { Delete } from "@mui/icons-material" |
9 | 8 |
|
10 | | -const PREFIX = 'Parameter'; |
11 | | - |
12 | | -const classes = { |
13 | | - parameter: `${PREFIX}-parameter` |
14 | | -}; |
15 | | - |
16 | | -const Root = styled('section')(( |
17 | | - { |
18 | | - theme |
19 | | - } |
20 | | -) => ({ |
21 | | - [`&.${classes.parameter}`]: { |
22 | | - display: "flex", |
23 | | - "&> *": { |
24 | | - flexGrow: 1, |
25 | | - }, |
26 | | - "&> :not(:first-child)": { |
27 | | - marginLeft: theme.spacing(1), |
28 | | - }, |
29 | | - } |
30 | | -})); |
31 | | - |
32 | 9 | interface Props { |
33 | 10 | parameter: ParameterT |
34 | 11 | setParamName: (name: string) => void |
35 | 12 | setParamValue: (value: string) => void |
| 13 | + setParamTimestamp: (value: number) => void |
36 | 14 | removeParam: () => void |
| 15 | + isUserProperty: boolean |
37 | 16 | } |
38 | 17 |
|
39 | 18 | const Parameter: React.FC<Props> = ({ |
40 | 19 | parameter, |
41 | 20 | setParamName, |
42 | 21 | setParamValue, |
| 22 | + setParamTimestamp, |
43 | 23 | removeParam, |
| 24 | + isUserProperty, |
44 | 25 | }) => { |
45 | | - |
46 | 26 | const showAdvanced = React.useContext(ShowAdvancedCtx) |
47 | 27 |
|
48 | 28 | const [name, setName] = React.useState(parameter.name) |
49 | 29 | const [value, setValue] = React.useState(parameter.value || "") |
| 30 | + const [timestamp, setTimestamp] = React.useState( |
| 31 | + parameter.timestamp_micros?.toString() || "" |
| 32 | + ) |
50 | 33 |
|
51 | 34 | const inputs = ( |
52 | | - <Root className={classes.parameter}> |
53 | | - <TextField |
54 | | - id={`#/events/0/params/${name}`} |
55 | | - variant="outlined" |
56 | | - size="small" |
57 | | - value={name} |
58 | | - onChange={e => setName(e.target.value)} |
59 | | - onBlur={() => setParamName(name)} |
60 | | - label="name" |
61 | | - /> |
62 | | - <TextField |
63 | | - variant="outlined" |
64 | | - size="small" |
65 | | - value={value || ""} |
66 | | - InputLabelProps={{ |
67 | | - ...(parameter.exampleValue === undefined ? {} : { shrink: true }), |
68 | | - }} |
69 | | - onChange={e => setValue(e.target.value)} |
70 | | - onBlur={() => setParamValue(value)} |
71 | | - label={`${parameter.type} value`} |
72 | | - placeholder={parameter.exampleValue?.toString()} |
73 | | - /> |
74 | | - </Root> |
| 35 | + <Grid container spacing={1}> |
| 36 | + <Grid item xs> |
| 37 | + <TextField |
| 38 | + id={`#/events/0/params/${name}`} |
| 39 | + variant="outlined" |
| 40 | + size="small" |
| 41 | + value={name} |
| 42 | + onChange={e => setName(e.target.value)} |
| 43 | + onBlur={() => setParamName(name)} |
| 44 | + label="name" |
| 45 | + fullWidth |
| 46 | + /> |
| 47 | + </Grid> |
| 48 | + <Grid item xs> |
| 49 | + <TextField |
| 50 | + variant="outlined" |
| 51 | + size="small" |
| 52 | + value={value || ""} |
| 53 | + InputLabelProps={{ |
| 54 | + ...(parameter.exampleValue === undefined ? {} : { shrink: true }), |
| 55 | + }} |
| 56 | + onChange={e => setValue(e.target.value)} |
| 57 | + onBlur={() => setParamValue(value)} |
| 58 | + label={`${parameter.type} value`} |
| 59 | + placeholder={parameter.exampleValue?.toString()} |
| 60 | + fullWidth |
| 61 | + /> |
| 62 | + </Grid> |
| 63 | + {isUserProperty && ( |
| 64 | + <Grid item xs> |
| 65 | + <TextField |
| 66 | + variant="outlined" |
| 67 | + size="small" |
| 68 | + value={timestamp} |
| 69 | + onChange={e => setTimestamp(e.target.value)} |
| 70 | + onBlur={() => setParamTimestamp(parseInt(timestamp, 10))} |
| 71 | + label="timestamp micros" |
| 72 | + helperText="The timestamp to be applied to the user property. Optional." |
| 73 | + fullWidth |
| 74 | + /> |
| 75 | + </Grid> |
| 76 | + )} |
| 77 | + </Grid> |
75 | 78 | ) |
76 | 79 | if (showAdvanced) { |
77 | 80 | return ( |
78 | | - <section /* className={formClasses.trashRow} */> |
79 | | - <Tooltip title="remove parameter"> |
80 | | - <IconButton onClick={removeParam}> |
81 | | - <Delete /> |
82 | | - </IconButton> |
83 | | - </Tooltip> |
84 | | - {inputs} |
85 | | - </section> |
| 81 | + <Grid container spacing={1} alignItems="flex-start"> |
| 82 | + <Grid item> |
| 83 | + <Tooltip title="remove parameter"> |
| 84 | + <IconButton onClick={removeParam}> |
| 85 | + <Delete /> |
| 86 | + </IconButton> |
| 87 | + </Tooltip> |
| 88 | + </Grid> |
| 89 | + <Grid item xs> |
| 90 | + {inputs} |
| 91 | + </Grid> |
| 92 | + </Grid> |
86 | 93 | ) |
87 | 94 | } |
88 | 95 | return inputs |
|
0 commit comments