Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"@mui/material": "^5.13.0",
"@mui/styles": "^5.14.15",
"@mui/x-data-grid": "^6.4.0",
"@mui/x-date-pickers": "^8.11.2",
"@typescript-eslint/eslint-plugin": "^4.0.0",
"@typescript-eslint/parser": "^4.0.0",
"babel-eslint": "^10.0.0",
"classnames": "^2.3.2",
"copy-to-clipboard": "^3.3.3",
"dayjs": "^1.11.18",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please double check if it really necessary to introduce another 3rd party library just for the purpose of date manipulation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it seems to be the recommended approach for handling timezones when working with the Material UI date time picker based on the documentation:

"eslint": "^7.0.0",
"gatsby": "^5.9.1",
"gatsby-plugin-emotion": "^8.9.0",
Expand All @@ -44,8 +46,8 @@
"react-helmet": "^6.1.0",
"react-icons": "^4.8.0",
"react-json-view": "^1.21.3",
"react-markdown": "^9.0.1",
"react-loader-spinner": "^6.1.6",
"react-markdown": "^9.0.1",
"react-redux": "^8.0.5",
"react-syntax-highlighter": "^15.5.0",
"redux": "^4.2.1",
Expand Down Expand Up @@ -104,7 +106,7 @@
"react": "^18.2.0"
}
},
"resolutions": {
"resolutions": {
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0"
},
Expand Down
46 changes: 20 additions & 26 deletions src/components/ExternalLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,25 @@ import { PropsWithChildren } from "react"
const PREFIX = "ExternalLink"

const classes = {
link: `${PREFIX}-link`,
icon: `${PREFIX}-icon`,
hover: `${PREFIX}-hover`,
}

const Root = styled("span")(() => ({
[`& .${classes.link}`]: {
display: "inline-flex",
alignItems: "center",
},

const StyledLink = styled("a")({
display: "inline-flex",
alignItems: "center",
[`& .${classes.icon}`]: {
marginLeft: "0.5ch",
color: "inherit",
},

[`& .${classes.hover}`]: {
[`&.${classes.hover}`]: {
"&:hover": {
opacity: 1.0,
},
opacity: 0.3,
},
}))
})

type Props = {
href: string
Expand All @@ -48,23 +44,21 @@ const ExternalLink: React.FC<PropsWithChildren<Props>> = ({
hover,
}) => {
return (
<Root>
<Tooltip title={title || ""}>
<a
className={clsx({ [classes.hover]: hover }, classes.link)}
href={href}
target="_blank"
rel="noreferrer"
>
{children}
<Launch
className={clsx({ [classes.icon]: children !== undefined })}
color="action"
fontSize={children === undefined ? undefined : "inherit"}
/>
</a>
</Tooltip>
</Root>
<Tooltip title={title || ""}>
<StyledLink
className={clsx({ [classes.hover]: hover })}
href={href}
target="_blank"
rel="noreferrer"
>
{children}
<Launch
className={clsx({ [classes.icon]: children !== undefined })}
color="action"
fontSize={children === undefined ? undefined : "inherit"}
/>
</StyledLink>
</Tooltip>
)
}

Expand Down
10 changes: 9 additions & 1 deletion src/components/LinkedTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ export interface LinkedTextFieldProps {
value: string | undefined
label: string
onChange: (e: string) => void
onBlur?: () => void
helperText: string | JSX.Element
extraAction?: JSX.Element
required?: true
disabled?: boolean
id?: string
error?: boolean
size?: "small" | "medium"
}

const LinkedTextField: React.FC<LinkedTextFieldProps> = ({
Expand All @@ -21,11 +24,14 @@ const LinkedTextField: React.FC<LinkedTextFieldProps> = ({
label,
value,
onChange,
onBlur,
required,
helperText,
disabled,
extraAction,
id,
error,
size = "small",
}) => {
return (
<TextField
Expand All @@ -42,15 +48,17 @@ const LinkedTextField: React.FC<LinkedTextFieldProps> = ({
),
}}
id={id}
size="small"
size={size}
variant="outlined"
fullWidth
label={label}
value={value === undefined ? "" : value}
onChange={e => onChange(e.target.value)}
onBlur={onBlur}
required={required}
helperText={helperText}
disabled={disabled}
error={error}
/>
)
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/ga4/EventBuilder/Items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ const Items: React.FC<Props> = ({
addNumberParam={() => addItemNumberParam(idx)}
removeParam={(itemIdx: number) => removeItemParam(idx, itemIdx)}
removeItem={() => removeItem(idx)}
setParamTimestamp={() => {}}
allowTimestampOverride={false}
/>
</WithHelpText>
))}
Expand Down
129 changes: 72 additions & 57 deletions src/components/ga4/EventBuilder/Parameter.tsx
Original file line number Diff line number Diff line change
@@ -1,91 +1,106 @@
import * as React from "react"

import { styled } from '@mui/material/styles';
import TextField from "@mui/material/TextField"
import { Parameter as ParameterT } from "./types"
import { ShowAdvancedCtx } from "."
import { IconButton, Tooltip } from "@mui/material"
import {
IconButton,
Tooltip,
Grid
} from "@mui/material"
import { Delete } from "@mui/icons-material"

const PREFIX = 'Parameter';

const classes = {
parameter: `${PREFIX}-parameter`
};

const Root = styled('section')((
{
theme
}
) => ({
[`&.${classes.parameter}`]: {
display: "flex",
"&> *": {
flexGrow: 1,
},
"&> :not(:first-child)": {
marginLeft: theme.spacing(1),
},
}
}));
import TimestampPicker from "./TimestampPicker"
import { TimestampScope } from "@/constants"

interface Props {
parameter: ParameterT
idx: number
setParamName: (name: string) => void
setParamValue: (value: string) => void
setParamTimestamp: (idx: number, value: number | undefined) => void
removeParam: () => void
allowTimestampOverride: boolean
}

const Parameter: React.FC<Props> = ({
parameter,
idx,
setParamName,
setParamValue,
setParamTimestamp,
removeParam,
allowTimestampOverride,
}) => {

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() || ""
)

React.useEffect(() => {
const num = parseInt(timestamp, 10)
setParamTimestamp(idx, isNaN(num) ? undefined : num)
}, [timestamp, setParamTimestamp, idx])

const inputs = (
<Root className={classes.parameter}>
<TextField
id={`#/events/0/params/${name}`}
variant="outlined"
size="small"
value={name}
onChange={e => setName(e.target.value)}
onBlur={() => setParamName(name)}
label="name"
/>
<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()}
/>
</Root>
<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>
{allowTimestampOverride && (
<Grid item xs={12}>
<TimestampPicker
timestamp={timestamp}
scope={TimestampScope.USER_PROPERTY}
setTimestamp={setTimestamp}
/>
</Grid>
)}
</Grid>
)
if (showAdvanced) {
return (
<section /* className={formClasses.trashRow} */>
<Tooltip title="remove parameter">
<IconButton onClick={removeParam}>
<Delete />
</IconButton>
</Tooltip>
{inputs}
</section>
<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
export default Parameter
7 changes: 7 additions & 0 deletions src/components/ga4/EventBuilder/Parameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,26 @@
parameters: ParameterT[]
setParamName: (idx: number, name: string) => void
setParamValue: (idx: number, value: string) => void
setParamTimestamp: (idx: number, value: number | undefined) => void
addStringParam: () => void
addNumberParam: () => void
removeParam: (idx: number) => void
removeItem?: () => void
addItemsParam?: () => void
allowTimestampOverride: boolean
}

const Parameters: React.FC<Props> = ({
parameters,
setParamName,
setParamValue,
setParamTimestamp,
addStringParam,
addNumberParam,
removeParam,
addItemsParam,
removeItem,
allowTimestampOverride: allowTimestampOverride,

Check warning on line 57 in src/components/ga4/EventBuilder/Parameters.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Destructuring assignment allowTimestampOverride unnecessarily renamed
}) => {
const showAdvanced = React.useContext(ShowAdvancedCtx)

Expand All @@ -62,7 +66,10 @@
parameter={parameter}
setParamName={name => setParamName(idx, name)}
setParamValue={value => setParamValue(idx, value)}
setParamTimestamp={setParamTimestamp}
idx={idx}
removeParam={() => removeParam(idx)}
allowTimestampOverride={allowTimestampOverride}
/>
))}
<section className={classes.buttonRow} >
Expand Down
Loading
Loading