Skip to content
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
46 changes: 9 additions & 37 deletions frontend/src/scenes/project-homepage/today/Today.scss
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,6 @@ html[data-today-transition]::view-transition-new(root) {
color: var(--today-faint);
}

.TodayHome__headingLink {
display: inline-flex;
gap: 5px;
align-items: center;
font-size: 13px;
color: var(--today-muted);

&:hover {
color: var(--today-ink);
text-decoration: underline;
}
}

.TodayHome__headingChevron {
transition: transform 200ms var(--today-ease);

Expand Down Expand Up @@ -207,22 +194,6 @@ html[data-today-transition]::view-transition-new(root) {
}
}

.TodayPulse__edit {
opacity: 0;
transition: opacity 150ms var(--today-ease);

&.TodayPulse__edit--shown,
.TodayHome:has(.TodayHome__intro:hover, .TodayPulse:hover) &,
&:focus-visible,
&[data-popup-open] {
opacity: 1;
}

@media (hover: none) {
opacity: 1;
}
}

.TodayPulse__metric {
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -252,6 +223,15 @@ html[data-today-transition]::view-transition-new(root) {
}
}

.TodayPulse__suggested {
display: inline-block;
width: 12px;
height: 12px;
margin-inline-end: 4px;
color: var(--today-faint);
vertical-align: -1px;
}

.TodayPulse__trigger {
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -705,14 +685,6 @@ html[data-today-transition]::view-transition-new(root) {
color: var(--today-muted);
}

.TodayHome__metaRow {
display: flex;
gap: 8px;
align-items: center;
justify-content: space-between;
min-width: 0;
}

.TodayHome__intro {
margin-top: 8px;
color: var(--today-faint);
Expand Down
35 changes: 35 additions & 0 deletions frontend/src/scenes/project-homepage/today/TodayHomePage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jest.mock('./TodayPulseHoverCard', () => ({
TodayPulseHoverCard: ({ children }: { children: ReactNode }) => <>{children}</>,
}))
jest.mock('./TodaySparkline', () => ({ TodaySparkline: () => null }))
jest.mock('./TodayPulseEditor', () => ({ TodayPulseEditor: () => <button type="button">Edit</button> }))

describe('TodayHomePage loading', () => {
afterEach(cleanup)
Expand Down Expand Up @@ -59,6 +60,40 @@ describe('TodayHomePage loading', () => {
expect(actions.pulseViewMounted).toHaveBeenLastCalledWith(false)
expect(actions.pulseViewUpdated).toHaveBeenCalledTimes(1)
})
it('keeps Edit available when the numbers fail to load', () => {
const home = {
greeting: 'Hello',
now: Date.now(),
isNewProject: false,
recentObjects: [],
returnFocusReportId: null,
useSampleData: false,
}
const numbers = {
currentProjectId: 1,
highlights: makeHighlights({ status: 'failed' }),
highlightsLoading: false,
highlightsFailed: false,
highlightsPending: false,
pulsePending: false,
pulseTiles: [],
pulseSlots: [],
pulsePinsLoaded: true,
}
jest.mocked(useValues).mockImplementation((logic) => (logic === todayLogic ? home : numbers))
jest.mocked(useActions).mockImplementation(() => ({
setReturnFocusReportId: jest.fn(),
pulseViewMounted: jest.fn(),
pulseViewUpdated: jest.fn(),
pulseViewUnmounted: jest.fn(),
}))

render(<TodayHomePage />)

expect(screen.getByText('At a glance')).toBeVisible()
expect(screen.getByText('Edit')).toBeVisible()
})

it('replaces only a completed number and keeps the other named loaders in place', () => {
const metrics = ['Sign-ups', 'Payments', 'Active users', 'Uploads'].map((name, i) =>
makePulseMetric({ key: `number:${i}`, name, value: i === 1 ? 0 : 120 })
Expand Down
43 changes: 4 additions & 39 deletions frontend/src/scenes/project-homepage/today/TodayHomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,18 @@ import { useActions, useValues } from 'kea'
import { router } from 'kea-router'
import { useLayoutEffect, useRef } from 'react'

import { Skeleton, Text } from '@posthog/quill'
import { Text } from '@posthog/quill'

import { TodayExplore } from './TodayExplore'
import { TodayForYou } from './TodayForYou'
import { todayHighlightsLogic } from './todayHighlightsLogic'
import { reportIdFromPath, todayLogic } from './todayLogic'
import { TodayPulse } from './TodayPulse'
import { TodayPulseEditor } from './TodayPulseEditor'
import { TodayPulseSection } from './TodayPulseSection'
import { TodayRecents } from './TodayRecents'
import { TodaySampleBanner } from './TodaySampleBanner'

const DATE_FORMAT = new Intl.DateTimeFormat(undefined, { weekday: 'long', day: 'numeric', month: 'long' })

function TodayPulseSkeleton(): JSX.Element {
return (
<ul className="TodayPulse" aria-busy aria-label="Loading key numbers">
{['w-14', 'w-20', 'w-16', 'w-24'].map((width) => (
<li key={width} className="TodayPulse__metric">
<span className="TodayPulse__name">
<Skeleton className={`inline-block h-3 align-middle ${width}`} />
</span>
<span className="TodayPulse__row">
<span className="TodayPulse__value">
<Skeleton className="inline-block h-4 w-28 align-middle" />
</span>
</span>
<span className="TodayPulse__spark">
<Skeleton className="h-3 w-full" />
</span>
</li>
))}
</ul>
)
}

function TodayMetaLine(): JSX.Element {
const { now } = useValues(todayLogic)
const date = new Date(now)
Expand All @@ -61,7 +38,6 @@ export function TodayHomePage(): JSX.Element {
pulsePending,
pulseTiles,
pulseSlots,
pulsePinsLoaded,
} = useValues(todayHighlightsLogic)
const { pulseViewMounted, pulseViewUpdated, pulseViewUnmounted } = useActions(todayHighlightsLogic)
const rootRef = useRef<HTMLDivElement>(null)
Expand Down Expand Up @@ -119,21 +95,10 @@ export function TodayHomePage(): JSX.Element {
{greeting}
</Text>
</div>
<div className="TodayHome__metaRow">
<TodayMetaLine />
{!pulsePending && highlights && pulsePinsLoaded ? <TodayPulseEditor /> : null}
</div>
<TodayMetaLine />
</section>
<div className="TodayHome__body">
{pulsePending ? (
<TodayPulseSkeleton />
) : highlights && pulseSlots?.length > 0 ? (
<TodayPulse metrics={pulseTiles} slots={pulseSlots} />
) : highlights?.status === 'ready' ? (
<Text size="sm" variant="muted" render={<p />} className="m-0">
Key numbers show here when you or your team open a few trend insights.
</Text>
) : null}
<TodayPulseSection />
{isNewProject && recentObjects.length === 0 ? <TodayExplore /> : <TodayRecents />}
<TodayForYou />
</div>
Expand Down
53 changes: 11 additions & 42 deletions frontend/src/scenes/project-homepage/today/TodayPulse.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useActions, useValues } from 'kea'
import { type RefObject, Suspense, lazy, useLayoutEffect, useRef } from 'react'

import { Button, Skeleton, Text } from '@posthog/quill'
import { IconSparkles } from '@posthog/icons'

import { dayjs } from 'lib/dayjs'
import { formatAggregationAxisValue } from 'lib/insights/aggregationAxisFormat'
Expand All @@ -21,6 +21,7 @@ import { TodayPulseCard } from './TodayPulseCard'
import { pulseChange } from './todayPulseFacts'
import { TodayPulseHoverCard } from './TodayPulseHoverCard'
import { pulseOpenHandlers } from './todayPulseOpenHandlers'
import { pulsePlaceholderLabel, TodayPulsePlaceholder } from './TodayPulsePlaceholder'
import type { TodayTone } from './todayTone'

// The charts are most of the code the home page adds, so the numbers render first and the sparklines follow.
Expand Down Expand Up @@ -110,61 +111,26 @@ export function TodayPulse({ metrics, slots }: { metrics: HighlightMetricApi[];
interval: metric.interval,
})
)
const { highlightsLoading, highlights, highlightsFailed, pulsePins, pulsePinsUnavailableReason } =
useValues(todayHighlightsLogic)
const { pulsePins, pulsePinsUnavailableReason } = useValues(todayHighlightsLogic)
const listRef = useRef<HTMLUListElement>(null)
useSettleOnReorder(listRef, cards.map((tile) => tile.key).join('|'))
const { baseCurrency } = useValues(teamLogic)
const { pulseMetricOpened, pulseMetricPreviewed, hidePulseMetric, togglePulsePin, retryPulse } =
const { pulseMetricOpened, pulseMetricPreviewed, hidePulseMetric, togglePulsePin } =
useActions(todayHighlightsLogic)
return (
<ul ref={listRef} className="TodayPulse" aria-label="Key numbers, against the period before">
{cards.map((slot, position) => {
const metric = metrics.find((metric) => metric.key === slot.key)
if (!metric) {
const loading = slot.status === 'pending'
return (
<li
key={slot.key}
data-pulse-key={slot.key}
className="TodayPulse__metric"
aria-busy={loading}
aria-label={`${slot.name}: ${loading ? 'Loading' : slot.status === 'error' ? 'Could not load' : 'No data'}`}
aria-busy={slot.status === 'pending'}
aria-label={pulsePlaceholderLabel(slot)}
>
{slot.url ? (
<LinkPrimitive to={slot.url} className="TodayPulse__name">
{slot.name}
</LinkPrimitive>
) : (
<span className="TodayPulse__name">{slot.name}</span>
)}
<span className="TodayPulse__row">
{loading ? (
<Skeleton className="inline-block h-5 w-24" />
) : (
<Text size="sm" variant="muted">
{slot.status === 'error' ? 'Could not load' : 'No data'}
</Text>
)}
</span>
<span className="TodayPulse__spark">
{loading ? (
<Skeleton className="h-3 w-full" />
) : slot.status === 'error' ? (
<Button
size="xs"
variant="link-muted"
className="-ms-2"
disabled={
highlightsLoading ||
(!highlightsFailed && highlights?.status === 'computing')
}
onClick={retryPulse}
>
Retry
</Button>
) : null}
</span>
<TodayPulsePlaceholder slot={slot} />
</li>
)
}
Expand All @@ -176,7 +142,10 @@ export function TodayPulse({ metrics, slots }: { metrics: HighlightMetricApi[];
const change = pulseChange(metric)
const content = (
<>
<span className="TodayPulse__name">{metric.name}</span>
<span className="TodayPulse__name">
{!pinned && <IconSparkles className="TodayPulse__suggested" aria-label="Suggested" />}
<span>{metric.name}</span>
</span>
<span className="TodayPulse__row">
<span className="TodayPulse__value" translate="no">
{formatValue(metric.value)}
Expand Down
Loading
Loading