Skip to content

Commit

Permalink
feat(flags): Autoselect identified distinct ID in Person flags tab wh…
Browse files Browse the repository at this point in the history
…en possible (#26857)
  • Loading branch information
havenbarnes authored Dec 12, 2024
1 parent 95713b3 commit dfa9fa8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion frontend/src/scenes/persons/PersonScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export function PersonScene(): JSX.Element | null {
splitMergeModalShown,
urlId,
distinctId,
primaryDistinctId,
} = useValues(personsLogic)
const { loadPersons, editProperty, deleteProperty, navigateToTab, setSplitMergeModalShown, setDistinctId } =
useActions(personsLogic)
Expand Down Expand Up @@ -297,7 +298,7 @@ export function PersonScene(): JSX.Element | null {
</Tooltip>
</div>
<LemonSelect
value={distinctId || person.distinct_ids[0]}
value={distinctId || primaryDistinctId}
onChange={(value) => value && setDistinctId(value)}
options={person.distinct_ids.map((distinct_id) => ({
label: distinct_id,
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/scenes/persons/personsLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,24 @@ export const personsLogic = kea<personsLogicType>([
(featureFlags) => featureFlags[FEATURE_FLAGS.CS_DASHBOARDS],
],
feedEnabled: [(s) => [s.featureFlags], (featureFlags) => !!featureFlags[FEATURE_FLAGS.PERSON_FEED_CANVAS]],
primaryDistinctId: [
(s) => [s.person],
(person): string | null => {
// We do not track which distinct ID was created through identify, but we can try to guess
const nonUuidDistinctIds = person?.distinct_ids.filter((id) => id?.split('-').length !== 5)

if (nonUuidDistinctIds && nonUuidDistinctIds?.length >= 1) {
/**
* If there are one or more distinct IDs that are not a UUID, one of them is most likely
* the identified ID. In most cases, there would be only one non-UUID distinct ID.
*/
return nonUuidDistinctIds[0]
}

// Otherwise, just fall back to the default first distinct ID
return person?.distinct_ids[0] || null
},
],
})),
listeners(({ actions, values }) => ({
editProperty: async ({ key, newValue }) => {
Expand Down

0 comments on commit dfa9fa8

Please sign in to comment.