Skip to content

Commit

Permalink
refactor: Avoid changing LemonInput
Browse files Browse the repository at this point in the history
There's a weird E2E test failing after the `LemonInput` changes, let's revert them to see if this works now
  • Loading branch information
rafaeelaudibert committed Dec 26, 2024
1 parent 50daa4d commit cbb72cf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
6 changes: 1 addition & 5 deletions frontend/src/lib/lemon-ui/LemonInput/LemonInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export interface LemonInputPropsNumber
extends LemonInputPropsBase,
Pick<React.InputHTMLAttributes<HTMLInputElement>, 'step' | 'min' | 'max'> {
type: 'number'
value?: number | null
value?: number
defaultValue?: number
onChange?: (newValue: number | undefined) => void
}
Expand Down Expand Up @@ -154,10 +154,6 @@ export const LemonInput = React.forwardRef<HTMLDivElement, LemonInputProps>(func

const InputComponent = autoWidth ? RawInputAutosize : 'input'

if (value == null) {
value = ''
}

return (
<span
className={clsx(
Expand Down
10 changes: 6 additions & 4 deletions frontend/src/scenes/settings/environment/BounceRateDuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import { teamLogic } from 'scenes/teamLogic'

const MIN_BOUNCE_RATE_DURATION = 1
const MAX_BOUNCE_RATE_DURATION = 120
const DEFAULT_BOUNCE_RATE_DURATION = 10

export function BounceRateDurationSetting(): JSX.Element {
const { updateCurrentTeam } = useActions(teamLogic)
const { currentTeam } = useValues(teamLogic)

const savedDuration =
currentTeam?.modifiers?.bounceRateDurationSeconds ?? currentTeam?.default_modifiers?.bounceRateDurationSeconds
const [bounceRateDuration, setBounceRateDuration] = useState<number | undefined>(savedDuration)
const [bounceRateDuration, setBounceRateDuration] = useState<number>(savedDuration ?? DEFAULT_BOUNCE_RATE_DURATION)

const handleChange = (duration: number | undefined): void => {
if (Number.isNaN(duration)) {
Expand All @@ -31,7 +32,8 @@ export function BounceRateDurationSetting(): JSX.Element {
<>
<p>
Choose how long a user can stay on a page, in seconds, before the session is not a bounce. Leave blank
to use the default of 10 seconds, or set a custom value between 1 second and 120 seconds inclusive.
to use the default of {DEFAULT_BOUNCE_RATE_DURATION} seconds, or set a custom value between{' '}
{MIN_BOUNCE_RATE_DURATION} second and {MAX_BOUNCE_RATE_DURATION} seconds inclusive.
</p>
<LemonInput
type="number"
Expand All @@ -40,7 +42,7 @@ export function BounceRateDurationSetting(): JSX.Element {
value={bounceRateDuration ?? null}
onChange={(x) => {
if (x == null || Number.isNaN(x)) {
setBounceRateDuration(undefined)
setBounceRateDuration(DEFAULT_BOUNCE_RATE_DURATION)
} else {
setBounceRateDuration(x)
}
Expand All @@ -54,7 +56,7 @@ export function BounceRateDurationSetting(): JSX.Element {
tooltip="Clear input"
onClick={(e) => {
e.stopPropagation()
setBounceRateDuration(undefined)
setBounceRateDuration(DEFAULT_BOUNCE_RATE_DURATION)
inputRef.current?.focus()
}}
/>
Expand Down

0 comments on commit cbb72cf

Please sign in to comment.