-
Notifications
You must be signed in to change notification settings - Fork 617
Expand file tree
/
Copy pathParameter.tsx
More file actions
98 lines (92 loc) · 2.62 KB
/
Parameter.tsx
File metadata and controls
98 lines (92 loc) · 2.62 KB
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
92
93
94
95
96
97
98
import * as React from "react"
import TextField from "@mui/material/TextField"
import { Parameter as ParameterT } from "./types"
import { ShowAdvancedCtx } from "."
import { IconButton, Tooltip, Grid } from "@mui/material"
import { Delete } from "@mui/icons-material"
interface Props {
parameter: ParameterT
setParamName: (name: string) => void
setParamValue: (value: string) => void
setParamTimestamp: (value: number) => void
removeParam: () => void
isUserProperty: boolean
}
const Parameter: React.FC<Props> = ({
parameter,
setParamName,
setParamValue,
setParamTimestamp,
removeParam,
isUserProperty,
}) => {
const showAdvanced = React.useContext(ShowAdvancedCtx)
const [name, setName] = React.useState(parameter.name)
const [value, setValue] = React.useState(parameter.value || "")
const [timestamp, setTimestamp] = React.useState(
parameter.timestamp_micros?.toString() || ""
)
const inputs = (
<Grid container spacing={1}>
<Grid item xs>
<TextField
id={`#/events/0/params/${name}`}
variant="outlined"
size="small"
value={name}
onChange={e => setName(e.target.value)}
onBlur={() => setParamName(name)}
label="name"
fullWidth
/>
</Grid>
<Grid item xs>
<TextField
variant="outlined"
size="small"
value={value || ""}
InputLabelProps={{
...(parameter.exampleValue === undefined ? {} : { shrink: true }),
}}
onChange={e => setValue(e.target.value)}
onBlur={() => setParamValue(value)}
label={`${parameter.type} value`}
placeholder={parameter.exampleValue?.toString()}
fullWidth
/>
</Grid>
{isUserProperty && (
<Grid item xs>
<TextField
variant="outlined"
size="small"
value={timestamp}
onChange={e => setTimestamp(e.target.value)}
onBlur={() => setParamTimestamp(parseInt(timestamp, 10))}
label="timestamp micros"
helperText="The timestamp to be applied to the user property. Optional."
fullWidth
/>
</Grid>
)}
</Grid>
)
if (showAdvanced) {
return (
<Grid container spacing={1} alignItems="flex-start">
<Grid item>
<Tooltip title="remove parameter">
<IconButton onClick={removeParam}>
<Delete />
</IconButton>
</Tooltip>
</Grid>
<Grid item xs>
{inputs}
</Grid>
</Grid>
)
}
return inputs
}
export default Parameter