diff --git a/frontend/src/lib/components/PersonPropertySelect/PersonPropertySelect.tsx b/frontend/src/lib/components/PersonPropertySelect/PersonPropertySelect.tsx index 0b5fe4cf3d571..d981c95aad5a7 100644 --- a/frontend/src/lib/components/PersonPropertySelect/PersonPropertySelect.tsx +++ b/frontend/src/lib/components/PersonPropertySelect/PersonPropertySelect.tsx @@ -7,10 +7,10 @@ import { LemonSnack } from 'lib/lemon-ui/LemonSnack/LemonSnack' import clsx from 'clsx' import { useState } from 'react' -import { DndContext, closestCenter } from '@dnd-kit/core' +import { DndContext, PointerSensor, closestCenter, useSensor, useSensors } from '@dnd-kit/core' import { useSortable, SortableContext, horizontalListSortingStrategy } from '@dnd-kit/sortable' import { CSS } from '@dnd-kit/utilities' -import { restrictToHorizontalAxis } from '@dnd-kit/modifiers' +import { restrictToHorizontalAxis, restrictToParentElement } from '@dnd-kit/modifiers' export interface PersonPropertySelectProps { addText: string @@ -53,6 +53,7 @@ export const PersonPropertySelect = ({ sortable = false, }: PersonPropertySelectProps): JSX.Element => { const [open, setOpen] = useState(false) + const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 1 } })) const handleChange = (name: string): void => { onChange(Array.from(new Set(selectedProperties.concat([name])))) @@ -71,35 +72,38 @@ export const PersonPropertySelect = ({ return (
- { - if (over && active.id !== over.id) { - handleSort({ - oldIndex: selectedProperties.indexOf(active.id.toString()), - newIndex: selectedProperties.indexOf(over.id.toString()), - }) - } - }} - collisionDetection={closestCenter} - modifiers={[restrictToHorizontalAxis]} - > - 0 && ( + { + if (over && active.id !== over.id) { + handleSort({ + oldIndex: selectedProperties.indexOf(active.id.toString()), + newIndex: selectedProperties.indexOf(over.id.toString()), + }) + } + }} + sensors={sensors} + collisionDetection={closestCenter} + modifiers={[restrictToHorizontalAxis, restrictToParentElement]} > -
- {selectedProperties.map((value) => ( - - ))} -
-
-
+ +
+ {selectedProperties.map((value) => ( + + ))} +
+
+ + )} setValue(currentTeam?.person_display_name_properties || PERSON_DEFAULT_DISPLAY_NAME_PROPERTIES), - [currentTeam] - ) + useEffect(() => { + setValue(currentTeam?.person_display_name_properties || []) + setSuggestions(PERSON_DEFAULT_DISPLAY_NAME_PROPERTIES) + }, [currentTeam]) if (!currentTeam) { return } + const activeSuggestions = suggestions.filter((s) => !value.includes(s)) + return ( <>

@@ -33,6 +36,16 @@ export function PersonDisplayNameProperties(): JSX.Element { addText="Add" sortable /> +

+

Suggestions

+
+ {activeSuggestions.map((suggestion) => ( + setValue([...value, suggestion])}> + {suggestion} + + ))} +
+