Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make PropertySelect component generic #19971

Merged
merged 2 commits into from
Jan 26, 2024
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { useState } from 'react'

import { mswDecorator } from '~/mocks/browser'

import { PersonPropertySelect, PersonPropertySelectProps } from './PersonPropertySelect'
import { TaxonomicFilterGroupType } from '../TaxonomicFilter/types'
import { PropertySelect, PropertySelectProps } from './PropertySelect'

type Story = StoryObj<typeof PersonPropertySelect>
const meta: Meta<typeof PersonPropertySelect> = {
title: 'Filters/Person Property Select',
component: PersonPropertySelect,
type Story = StoryObj<typeof PropertySelect>
const meta: Meta<typeof PropertySelect> = {
title: 'Filters/Property Select',
component: PropertySelect,
decorators: [
mswDecorator({
get: {
Expand All @@ -31,7 +32,7 @@ const meta: Meta<typeof PersonPropertySelect> = {
}
export default meta

const Template: StoryFn<typeof PersonPropertySelect> = (props: Partial<PersonPropertySelectProps>) => {
const Template: StoryFn<typeof PropertySelect> = (props: Partial<PropertySelectProps>) => {
const [selectedProperties, setSelectProperties] = useState<string[]>([
'$initial_geoip_postal_code',
'$initial_geoip_latitude',
Expand All @@ -54,9 +55,10 @@ const Template: StoryFn<typeof PersonPropertySelect> = (props: Partial<PersonPro
])

return (
<PersonPropertySelect
<PropertySelect
selectedProperties={selectedProperties}
onChange={setSelectProperties}
taxonomicFilterGroup={TaxonomicFilterGroupType.PersonProperties}
addText="Add"
{...props}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import { LemonSnack } from 'lib/lemon-ui/LemonSnack/LemonSnack'
import { Popover } from 'lib/lemon-ui/Popover/Popover'
import { useState } from 'react'

export interface PersonPropertySelectProps {
export interface PropertySelectProps {
addText: string
onChange: (names: string[]) => void
selectedProperties: string[]
sortable?: boolean
taxonomicFilterGroup: TaxonomicFilterGroupType.PersonProperties | TaxonomicFilterGroupType.EventProperties
}

const SortableProperty = ({
Expand Down Expand Up @@ -46,12 +47,13 @@ const SortableProperty = ({
)
}

export const PersonPropertySelect = ({
export const PropertySelect = ({
onChange,
selectedProperties,
addText,
sortable = false,
}: PersonPropertySelectProps): JSX.Element => {
taxonomicFilterGroup,
}: PropertySelectProps): JSX.Element => {
const [open, setOpen] = useState<boolean>(false)
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 1 } }))

Expand Down Expand Up @@ -114,7 +116,7 @@ export const PersonPropertySelect = ({
handleChange(value as string)
setOpen(false)
}}
taxonomicGroupTypes={[TaxonomicFilterGroupType.PersonProperties]}
taxonomicGroupTypes={[taxonomicFilterGroup]}
/>
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { LemonButton, LemonCheckbox } from '@posthog/lemon-ui'
import { ConfigProvider, Empty, Table } from 'antd'
import Column from 'antd/lib/table/Column'
import { useActions, useValues } from 'kea'
import { PersonPropertySelect } from 'lib/components/PersonPropertySelect/PersonPropertySelect'
import { PropertyKeyInfo } from 'lib/components/PropertyKeyInfo'
import { PropertySelect } from 'lib/components/PropertySelect/PropertySelect'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { VisibilitySensor } from 'lib/components/VisibilitySensor/VisibilitySensor'
import { IconSelectProperties, IconTrendingDown, IconTrendingUp } from 'lib/lemon-ui/icons'
import { Link } from 'lib/lemon-ui/Link'
Expand Down Expand Up @@ -148,7 +149,8 @@ export function FunnelPropertyCorrelationTable(): JSX.Element | null {
onClickOutside={() => setIsPropertiesOpen(false)}
overlay={
<div className="p-4">
<PersonPropertySelect
<PropertySelect
taxonomicFilterGroup={TaxonomicFilterGroupType.PersonProperties}
onChange={setPropertyNames}
selectedProperties={
propertyNames.length === 1 && propertyNames[0] === '$all'
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/scenes/settings/project/CorrelationConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { LemonButton } from '@posthog/lemon-ui'
import { useActions, useValues } from 'kea'
import { EventSelect } from 'lib/components/EventSelect/EventSelect'
import { PersonPropertySelect } from 'lib/components/PersonPropertySelect/PersonPropertySelect'
import { PropertySelect } from 'lib/components/PropertySelect/PropertySelect'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { IconPlus, IconSelectEvents, IconSelectProperties } from 'lib/lemon-ui/icons'
import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
import { LemonSelectMultiple } from 'lib/lemon-ui/LemonSelectMultiple/LemonSelectMultiple'
Expand Down Expand Up @@ -48,7 +49,8 @@ export function CorrelationConfig(): JSX.Element {
<IconSelectProperties className="text-lg" />
Excluded person properties
</h3>
<PersonPropertySelect
<PropertySelect
taxonomicFilterGroup={TaxonomicFilterGroupType.PersonProperties}
onChange={(properties) => handleChange(properties)}
selectedProperties={funnelCorrelationConfig.excluded_person_property_names || []}
addText="Add exclusion"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LemonButton } from '@posthog/lemon-ui'
import { useActions, useValues } from 'kea'
import { PersonPropertySelect } from 'lib/components/PersonPropertySelect/PersonPropertySelect'
import { PropertySelect } from 'lib/components/PropertySelect/PropertySelect'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { PERSON_DEFAULT_DISPLAY_NAME_PROPERTIES } from 'lib/constants'
import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'
import { useEffect, useState } from 'react'
Expand All @@ -27,7 +28,8 @@ export function PersonDisplayNameProperties(): JSX.Element {
property to be found on the Person will be used. Drag the items to re-order the priority.
</p>
<div className="space-y-4">
<PersonPropertySelect
<PropertySelect
taxonomicFilterGroup={TaxonomicFilterGroupType.PersonProperties}
onChange={(properties) => setValue(properties)}
selectedProperties={value || []}
addText="Add"
Expand Down
Loading