-
Notifications
You must be signed in to change notification settings - Fork 522
feat(Segment membership inspection PoC): Surface identity counts in segments UI #7467
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4a4cffd
feat(segment_membership): Surface identity counts in segments UI
khvn26 f87b4eb
refactor(Segment membership): Move identity noun and last-sync into a…
khvn26 8e80b52
refactor(Segment membership): Require environment on env badge
khvn26 edfb511
refactor(CreateSegmentUsersTabContent): Type renderEnvOption with sha…
khvn26 52bf43f
fix(e2e): Match /environments route with or without query string
khvn26 3b6c7d5
fix(e2e): Use the actual /environments URL pattern in route mock
khvn26 2dfbb7b
fix(e2e): Handle /environments returning a raw array, not paged results
khvn26 a4f7dff
test(Segment membership): Drop the synthetic-data Playwright spec
khvn26 a9f61b5
refactor(Tooltip): Make delayShow overridable, drop chip hover to 100ms
khvn26 9abd456
refactor(CreateSegmentUsersTabContent): Resolve envs via RTK Query
khvn26 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
84 changes: 84 additions & 0 deletions
84
frontend/web/components/segments/SegmentMembershipBadge.tsx
This file contains hidden or 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,84 @@ | ||
| import React, { FC } from 'react' | ||
|
|
||
| import { Environment, SegmentMembership } from 'common/types/responses' | ||
| import Tooltip from 'components/Tooltip' | ||
| import UsersIcon from 'components/icons/UsersIcon' | ||
|
|
||
| const shortAgo = (iso: string): string => { | ||
| const diffSec = Math.max(0, Math.round((Date.now() - new Date(iso).getTime()) / 1000)) | ||
| if (diffSec < 60) return `${diffSec}s ago` | ||
| const diffMin = Math.round(diffSec / 60) | ||
| if (diffMin < 60) return `${diffMin}m ago` | ||
| const diffHr = Math.round(diffMin / 60) | ||
| if (diffHr < 24) return `${diffHr}h ago` | ||
| return `${Math.round(diffHr / 24)}d ago` | ||
| } | ||
|
|
||
| const formatTooltip = (count: number, lastSyncedAt: string | undefined): string => { | ||
| const noun = count === 1 ? 'identity' : 'identities' | ||
| const base = `${count} ${noun}` | ||
| return lastSyncedAt ? `${base} — last synced ~${shortAgo(lastSyncedAt)}` : base | ||
| } | ||
|
|
||
| type ChipProps = { | ||
| count: number | ||
| dataTest?: string | ||
| tooltip: string | ||
| } | ||
|
|
||
| const Chip: FC<ChipProps> = ({ count, dataTest, tooltip }) => ( | ||
| <Tooltip | ||
| plainText | ||
| delayShow={100} | ||
|
talissoncosta marked this conversation as resolved.
|
||
| title={ | ||
| <span | ||
| className='chip chip--xs bg-primary text-white ms-3' | ||
| style={{ border: 'none', alignSelf: 'center', verticalAlign: 'middle' }} | ||
| data-test={dataTest} | ||
| > | ||
| <UsersIcon className='chip-svg-icon' /> | ||
| <span>{count}</span> | ||
| </span> | ||
| } | ||
| > | ||
| {tooltip} | ||
| </Tooltip> | ||
| ) | ||
|
|
||
| type TotalProps = { | ||
| memberships: SegmentMembership[] | undefined | ||
| } | ||
|
|
||
| export const SegmentMembershipTotalBadge: FC<TotalProps> = ({ memberships }) => { | ||
| if (!memberships?.length) { | ||
| return null | ||
| } | ||
| const total = memberships.reduce((sum, m) => sum + m.count, 0) | ||
| const latest = memberships.reduce( | ||
| (acc, m) => (!acc || m.last_synced_at > acc ? m.last_synced_at : acc), | ||
| '', | ||
| ) | ||
| return ( | ||
| <Chip | ||
| count={total} | ||
| tooltip={formatTooltip(total, latest || undefined)} | ||
| dataTest='segment-membership-total' | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| type EnvProps = { | ||
| membership: SegmentMembership | ||
| environment: Environment | ||
| } | ||
|
|
||
| export const SegmentMembershipEnvBadge: FC<EnvProps> = ({ | ||
| environment, | ||
| membership, | ||
| }) => ( | ||
| <Chip | ||
| count={membership.count} | ||
| tooltip={formatTooltip(membership.count, membership.last_synced_at)} | ||
| dataTest={`segment-membership-${environment.api_key}`} | ||
| /> | ||
| ) | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.