Skip to content

Refactor Devices to /query endpoint#6398

Merged
apata merged 3 commits into
masterfrom
query/migrate-conversions
May 27, 2026
Merged

Refactor Devices to /query endpoint#6398
apata merged 3 commits into
masterfrom
query/migrate-conversions

Conversation

@apata
Copy link
Copy Markdown
Contributor

@apata apata commented May 25, 2026

Changes

Refactors Devices block and modals to /query endpoint

Tests

  • Automated tests have been added

Changelog

  • This PR does not make a user-facing change

Documentation

  • This change does not need a documentation update

Dark mode

  • The UI has been tested both in dark and light mode

@apata apata added the preview label May 25, 2026
@github-actions
Copy link
Copy Markdown

Preview environment👷🏼‍♀️🏗️
PR-6398

import { IndexBreakdown } from '../reports/index-breakdown'
import { chooseBreakdownMetricsByContext } from '../breakdowns'

type Mode = 'browser' | 'os' | 'size'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps let's use this opportunity to change the stored mode keys to follow a consistent naming pattern (camelCase, plural)? Basically, follow what's done in pages:

type Mode = Extract<BreakdownReportKey, 'pages' | 'entryPages' | 'exitPages'>

const initMode = (storedMode: string): Mode => {
  if (['entry-pages', BreakdownReportKey.entryPages].includes(storedMode)) {
    return BreakdownReportKey.entryPages
  }
  if (['exit-pages', BreakdownReportKey.exitPages].includes(storedMode)) {
    return BreakdownReportKey.exitPages
  }
  return BreakdownReportKey.pages
}

We'll still use the legacy names for getting the stored tab, but we'll start writing new keys into storage. How about these for new names:

  • browsers
  • operatingSystems
  • screenSizes

Comment on lines +99 to +101
{ label: 'Browsers', value: 'browser' },
{ label: 'Operating systems', value: 'os' },
{ label: 'Devices', value: 'size' }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation of my other comment -- switching to enums, we'd update these too (e.g. 'browser' -> BreakdownReportKey.browsers)

]
}

const DEVICES_METRICS_BY_CONTEXT: MetricsByContext = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be the new COMMON_METRICS_BY_CONTEXT. The only exceptions (at this stage) would then be:

  • pages - already overwrites defaultDetailedMetrics
  • entryPages - would be {...COMMON_METRICS_BY_CONTEXT, defaultDetailedMetrics: ...} (adds visits)
  • exitPages - already overwrites defaultDetailedMetrics

All devices reports would use the common metrics. Also, sources will use these common metrics.

Comment thread assets/js/dashboard/stats/devices/details.tsx
Comment thread assets/js/dashboard/stats/devices/index.tsx Outdated
@apata apata force-pushed the query/migrate-conversions branch from d649bb3 to 5903e77 Compare May 26, 2026 08:48
@apata apata changed the title WIP Refactor Devices to /query endpoint May 26, 2026
@apata apata force-pushed the query/migrate-conversions branch from 5903e77 to 6191dd6 Compare May 26, 2026 09:23
@apata apata marked this pull request as ready for review May 26, 2026 10:14
@apata apata requested a review from RobertJoonas May 26, 2026 10:35
import { BrowserIcon, OsIcon, ScreenSizeIcon } from './icons'
import { FilterInfo } from '../../components/drilldown-link'

type SelectedTab =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Let's keep consistent style/naming between all of these index components. E.g.: in pages/index.tsx, there's a Mode type defined as:

type Mode = Extract<BreakdownReportKey, 'pages' | 'entryPages' | 'exitPages'>

With tab keys not always representing BreakdownReportKeys, maybe a nice middle ground would be:

type TabKey =
  | BreakdownReportKey.browsers
  | BreakdownReportKey.operatingSystems
  | BreakdownReportKey.screenSizes

type ReportKey =
  | TabKey
  | BreakdownReportKey.browserVersions
  | BreakdownReportKey.operatingSystemVersions
// in pages.index.ts
// Also works as ReportKey
type TabKey =
  | BreakdownReportKey.pages
  | BreakdownReportKey.entryPages
  | BreakdownReportKey.exitPages

const site = useSiteContext()

const tabKey = `deviceTab__${site.domain}`
const [mode, setMode] = useState<SelectedTab>(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick; non-blocking: mode -> tab too to be consistent? Would have to change in pages/index.tsx too then.

@apata apata force-pushed the query/migrate-conversions branch from 8492ec9 to 5b2b634 Compare May 27, 2026 07:41
@apata apata added this pull request to the merge queue May 27, 2026
Merged via the queue into master with commit ba462d7 May 27, 2026
22 checks passed
@apata apata deleted the query/migrate-conversions branch May 27, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants