Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ All notable changes to this project will be documented in this file.

### Fixed

- Top pages, Entry pages and Exit pages details broken down by URL now keep separate sort orders
- "Previous period" comparison with "Match day of week" now shifts to the nearest matching weekday instead of always the next one, which could overlap the selected range
- Cache warmer retries a failed warm-up of critical caches
- Stats API `/api/v1/stats/breakdown` now returns a `400` error for an invalid `page` parameter instead of crashing with a `500`
Expand Down
39 changes: 36 additions & 3 deletions assets/js/dashboard/stats/modals/details-breakdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ function buildResponse(
}
}

function buildFullPage(offset: number) {
function buildFullPage(offset: number, dimensionCount = 1) {
return Array.from({ length: PAGINATION_LIMIT }, (_, i) => {
return {
dimensions: [`/page-${offset + i}`],
dimensions: [
...Array(dimensionCount - 1).fill(domain),
`/page-${offset + i}`
],
metrics: PAGES_DETAILED_METRICS.map((_metric) => 1)
}
})
Expand All @@ -63,7 +66,10 @@ function setupQueryHandler({ delay = false } = {}) {
)
}

const results = buildFullPage(body.pagination?.offset || 0)
const results = buildFullPage(
body.pagination?.offset || 0,
body.dimensions.length
)
return {
status: 200,
ok: true,
Expand Down Expand Up @@ -244,6 +250,33 @@ test('clicking a column header cycles sort direction', async () => {
})
})

test('sorting Top pages by URL does not change the Entry pages by URL sort', async () => {
localStorage.clear()
const { requestBodies } = setupQueryHandler({ delay: true })

const renderDetails = (breakdownReportKey: BreakdownReportKey) =>
render(
<TestContextProviders siteOptions={{ domain }}>
<PagesDetails breakdownReportKey={breakdownReportKey} />
</TestContextProviders>
)

const topPages = renderDetails(BreakdownReportKey.pagesWithHostname)
await settle()
act(() => fireEvent.click(screen.getByRole('button', { name: /visitors/i })))
await expectAndAwaitLoading()
expect(requestBodies.at(-1)!.order_by![0]).toEqual(['visitors', 'asc'])
topPages.unmount()

renderDetails(BreakdownReportKey.entryPagesWithHostname)
await settle()
expect(requestBodies.at(-1)!.dimensions).toEqual([
'visit:entry_page_hostname',
'visit:entry_page'
])
expect(requestBodies.at(-1)!.order_by![0]).toEqual(['visitors', 'desc'])
})

test('toggling sort back to the original direction gets results from cache', async () => {
const { requestBodies } = setupQueryHandler({ delay: true })
const { open } = renderModal()
Expand Down
6 changes: 4 additions & 2 deletions assets/js/dashboard/stats/modals/details-breakdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type PaginatedData = { pages: QueryApiResponse[] }

type DetailsBreakdownProps = SharedBreakdownReportProps & {
title: ReactNode
orderByStorageId?: string
defaultOrderBy?: MetricOrderBy
searchEnabled?: boolean
searchDimension?: NonTimeDimension
Expand Down Expand Up @@ -87,6 +88,7 @@ const getMetricCellWidthClass = (
export function DetailsBreakdown({
title,
dimensionLabel,
orderByStorageId = dimensionLabel,
dimensions,
metrics,
alwaysOnFilters,
Expand All @@ -105,7 +107,7 @@ export function DetailsBreakdown({

const storedOrderBy = getStoredOrderBy({
domain: site.domain,
dimensionLabel,
dimensionLabel: orderByStorageId,
metrics,
fallbackValue: defaultOrderBy
})
Expand All @@ -118,7 +120,7 @@ export function DetailsBreakdown({
useRememberOrderBy({
effectiveOrderBy: orderBy,
metrics,
dimensionLabel
dimensionLabel: orderByStorageId
})

const statsReportQueryKey: StatsReportQueryKey = [
Expand Down
1 change: 1 addition & 0 deletions assets/js/dashboard/stats/pages/details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export function PagesDetails({
<DetailsBreakdown
title={pagesDetailsTitle(breakdownReportKey, dashboardState)}
dimensionLabel={reportConfig.dimensionLabel}
orderByStorageId={reportConfig.orderByStorageId}
dimensions={reportConfig.dimensions}
metrics={metrics}
alwaysOnFilters={reportConfig.alwaysOnFilters}
Expand Down
4 changes: 4 additions & 0 deletions assets/js/dashboard/stats/reports/reports-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type BreakdownReportConfig = {
detailsTitle: string
detailsPath: string
dimensionLabel: string
orderByStorageId?: string
alwaysOnFilters?: ApiFilter[]
searchDimension?: NonTimeDimension
}
Expand Down Expand Up @@ -168,6 +169,7 @@ export const BREAKDOWN_REPORTS: Record<
detailsTitle: 'Top pages',
detailsPath: 'pages-with-hostname',
dimensionLabel: 'URL',
orderByStorageId: 'pages-with-hostname',
searchDimension: 'event:page'
},
[BreakdownReportKey.entryPages]: {
Expand Down Expand Up @@ -204,6 +206,7 @@ export const BREAKDOWN_REPORTS: Record<
detailsTitle: 'Entry pages',
detailsPath: 'entry-pages-with-hostname',
dimensionLabel: 'URL',
orderByStorageId: 'entry-pages-with-hostname',
alwaysOnFilters: [['is_not', 'visit:entry_page', ['']]],
searchDimension: 'visit:entry_page'
},
Expand Down Expand Up @@ -253,6 +256,7 @@ export const BREAKDOWN_REPORTS: Record<
detailsTitle: 'Exit pages',
detailsPath: 'exit-pages-with-hostname',
dimensionLabel: 'URL',
orderByStorageId: 'exit-pages-with-hostname',
alwaysOnFilters: [['is_not', 'visit:exit_page', ['']]],
searchDimension: 'visit:exit_page'
},
Expand Down