-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update new property form (#18576)
- Loading branch information
Showing
3 changed files
with
131 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { useState } from 'react' | ||
import { LemonButton } from 'lib/lemon-ui/LemonButton' | ||
import { LemonInput, LemonLabel, LemonModal, LemonSegmentedButton } from '@posthog/lemon-ui' | ||
|
||
interface NewPropertyInterface { | ||
creating: boolean | ||
propertyType: 'string' | 'boolean' | ||
key?: string | null | ||
value?: string | number | ||
} | ||
|
||
export interface NewPropertyProps { | ||
onSave: (key: string, newValue?: string | number) => void | ||
} | ||
|
||
export function NewProperty({ onSave }: NewPropertyProps): JSX.Element { | ||
const initialState = { creating: false, propertyType: 'string', value: '' } as NewPropertyInterface | ||
const [state, setState] = useState(initialState) | ||
|
||
const saveProperty = (): void => { | ||
if (state.key && state.value !== undefined) { | ||
onSave(state.key, state.value) | ||
setState(initialState) | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<LemonButton | ||
data-attr="add-prop-button" | ||
onClick={() => setState({ ...state, creating: true })} | ||
type="primary" | ||
> | ||
New property | ||
</LemonButton> | ||
<LemonModal | ||
isOpen={state.creating} | ||
onClose={() => setState(initialState)} | ||
title="Add new property" | ||
footer={ | ||
<LemonButton | ||
disabledReason={(!state.key || state.value === undefined) && 'Set a key and a value'} | ||
type="secondary" | ||
onClick={saveProperty} | ||
> | ||
Save | ||
</LemonButton> | ||
} | ||
> | ||
<div className="space-y-2"> | ||
<div> | ||
<LemonLabel>Key</LemonLabel> | ||
<LemonInput | ||
id="propertyKey" | ||
autoFocus | ||
placeholder="try email, first_name, is_verified, membership_level, total_revenue" | ||
onChange={(key) => setState({ ...state, key: key })} | ||
autoComplete="off" | ||
autoCapitalize="off" | ||
/> | ||
</div> | ||
<div> | ||
<LemonLabel>Type of Property</LemonLabel> | ||
<LemonSegmentedButton | ||
onChange={(value: 'string' | 'boolean') => | ||
setState({ | ||
...state, | ||
propertyType: value, | ||
value: value === 'string' ? '' : 'true', | ||
}) | ||
} | ||
value={state.propertyType} | ||
options={[ | ||
{ | ||
value: 'string', | ||
label: 'Text or Number', | ||
}, | ||
{ | ||
value: 'boolean', | ||
label: 'Boolean or Null', | ||
}, | ||
]} | ||
fullWidth | ||
/> | ||
</div> | ||
<div> | ||
<LemonLabel>Value</LemonLabel> | ||
{state.propertyType === 'boolean' ? ( | ||
<LemonSegmentedButton | ||
onChange={(value) => | ||
setState({ | ||
...state, | ||
value: value, | ||
}) | ||
} | ||
fullWidth | ||
value={state.value} | ||
options={[ | ||
{ | ||
value: 'true', | ||
label: 'True', | ||
}, | ||
{ | ||
value: 'false', | ||
label: 'False', | ||
}, | ||
{ | ||
value: 'null', | ||
label: 'Null', | ||
}, | ||
]} | ||
size="small" | ||
/> | ||
) : ( | ||
<LemonInput | ||
id="propertyValue" | ||
placeholder="try [email protected], gold, 1" | ||
onChange={(value) => setState({ ...state, value: value })} | ||
onKeyDown={(e) => e.key === 'Enter' && saveProperty()} | ||
autoComplete="off" | ||
autoCapitalize="off" | ||
/> | ||
)} | ||
</div> | ||
</div> | ||
</LemonModal> | ||
</> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.