Skip to content

Commit 7575f95

Browse files
committed
Implement feedback
- Refactor site switcher to use a static component when not logged in - Add test for static site switcher - Fix padding on period picker when arrows are hidden - Fix focus-visible ring on period picker - Update typography for site switcher and current visitors
1 parent e773d64 commit 7575f95

File tree

5 files changed

+61
-12
lines changed

5 files changed

+61
-12
lines changed

assets/js/dashboard/nav-menu/query-periods/dashboard-period-menu.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
import { DateRangeCalendar } from './date-range-calendar'
3737
import { formatISO, nowForSite } from '../../util/date'
3838
import { MenuSeparator } from '../nav-menu-components'
39-
import { MovePeriodArrows } from './move-period-arrows'
39+
import { MovePeriodArrows, periodsWithArrows } from './move-period-arrows'
4040

4141
function DashboardPeriodMenuKeybinds({
4242
closeDropdown,
@@ -102,12 +102,18 @@ export const DashboardPeriodMenu = ({
102102
'flex rounded-md h-8 transition-all duration-150',
103103
'hover:bg-gray-150/80 dark:hover:bg-gray-800',
104104
'has-[[aria-expanded=true]]:bg-gray-150/80 dark:has-[[aria-expanded=true]]:bg-gray-800',
105+
'has-[button:focus-visible]:ring-2 has-[button:focus-visible]:ring-indigo-500 has-[button:focus-visible]:ring-offset-2 dark:has-[button:focus-visible]:ring-offset-gray-900',
105106
isComparing && 'bg-gray-150/80 dark:bg-gray-800'
106107
)}
107108
>
108109
<Popover.Button
109110
ref={buttonRef}
110-
className="flex items-center gap-x-1.5 pl-2.5 pr-1.5 text-sm font-medium text-gray-700 dark:text-gray-100 leading-tight h-full rounded-md"
111+
className={classNames(
112+
'flex items-center gap-x-1.5 pl-2.5 text-sm font-medium text-gray-700 dark:text-gray-100 leading-tight h-full rounded-md focus-visible:ring-0 focus-visible:ring-offset-0',
113+
periodsWithArrows.includes(dashboardState.period)
114+
? 'pr-1.5'
115+
: 'pr-2.5'
116+
)}
111117
>
112118
<DateMenuCalendarIcon />
113119
<span

assets/js/dashboard/nav-menu/query-periods/move-period-arrows.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function ArrowIcon({
7272
)
7373
}
7474

75-
const periodsWithArrows = [
75+
export const periodsWithArrows = [
7676
DashboardPeriod.year,
7777
DashboardPeriod.month,
7878
DashboardPeriod.day

assets/js/dashboard/site-switcher.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,27 @@ const getSwitchToSiteURL = (
6767
return `/${encodeURIComponent(site.domain)}`
6868
}
6969

70+
const SiteSwitcherStatic = () => {
71+
const currentSite = useSiteContext()
72+
73+
return (
74+
<div
75+
data-testid="site-switcher-static"
76+
className={classNames(
77+
popover.toggleButton.classNames.rounded,
78+
'gap-x-1.5 px-2.5 font-medium text-gray-700 dark:text-gray-100',
79+
'!pl-0'
80+
)}
81+
title={currentSite.domain}
82+
>
83+
<Favicon domain={currentSite.domain} className="block size-4" />
84+
<span className="truncate hidden sm:block sm:mr-1 lg:mr-0 font-semibold">
85+
{currentSite.domain}
86+
</span>
87+
</div>
88+
)
89+
}
90+
7091
export const SiteSwitcher = () => {
7192
const dashboardRouteMatch = useMatch(rootRoute.path)
7293
const { modal } = useRoutelessModalsContext()
@@ -83,10 +104,11 @@ export const SiteSwitcher = () => {
83104
placeholderData: (previousData) => previousData
84105
})
85106

86-
const sitesInDropdown = user.loggedIn
87-
? sitesQuery.data?.data
88-
: // show only current site in dropdown when viewing public / embedded dashboard
89-
[{ domain: currentSite.domain }]
107+
if (!user.loggedIn) {
108+
return <SiteSwitcherStatic />
109+
}
110+
111+
const sitesInDropdown = sitesQuery.data?.data
90112

91113
const canSeeSiteSettings: boolean =
92114
user.loggedIn &&
@@ -160,7 +182,9 @@ export const SiteSwitcher = () => {
160182
)}
161183
<span
162184
data-testid="site-switcher-current-site"
163-
className={'truncate hidden sm:block sm:mr-1 lg:mr-0'}
185+
className={
186+
'truncate hidden sm:block sm:mr-1 lg:mr-0 font-semibold'
187+
}
164188
>
165189
{currentSite.isConsolidatedView
166190
? 'All sites'

assets/js/dashboard/stats/current-visitors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default function CurrentVisitors({ className = '' }) {
6565
>
6666
<circle cx="8" cy="8" r="8" />
6767
</svg>
68-
<div className="inline-block">
68+
<div className="inline-block text-gray-500 dark:text-gray-400">
6969
{currentVisitors}
7070
<span className="hidden lg:inline">
7171
{' '}

e2e/tests/dashboard/general.spec.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test('dashboard renders for anonymous viewer', async ({ page, request }) => {
2828

2929
await expect(page).toHaveTitle(/Plausible/)
3030

31-
await expect(page.getByRole('button', { name: domain })).toBeVisible()
31+
await expect(page.getByTestId('site-switcher-static')).toContainText(domain)
3232
})
3333

3434
test('dashboard renders via shared link', async ({ page, request }) => {
@@ -46,7 +46,7 @@ test('dashboard renders via shared link', async ({ page, request }) => {
4646
await test.step('public link', async () => {
4747
await page.goto(link, { waitUntil: 'commit' })
4848

49-
await expect(page.getByRole('button', { name: domain })).toBeVisible()
49+
await expect(page.getByTestId('site-switcher-static')).toContainText(domain)
5050

5151
await expect(page.locator('#visitors')).toHaveText('1')
5252
})
@@ -58,12 +58,31 @@ test('dashboard renders via shared link', async ({ page, request }) => {
5858

5959
await page.getByRole('button', { name: 'Continue' }).click()
6060

61-
await expect(page.getByRole('button', { name: domain })).toBeVisible()
61+
await expect(page.getByTestId('site-switcher-static')).toContainText(domain)
6262

6363
await expect(page.locator('#visitors')).toHaveText('1')
6464
})
6565
})
6666

67+
test('site switcher is not shown when viewing without being logged in', async ({
68+
page,
69+
request
70+
}) => {
71+
const { domain } = await setupSite({ page, request })
72+
await makeSitePublic({ page, domain })
73+
await populateStats({ request, domain, events: [{ name: 'pageview' }] })
74+
await logout(page)
75+
76+
await page.goto('/' + domain, { waitUntil: 'commit' })
77+
78+
const siteSwitcherStatic = page.getByTestId('site-switcher-static')
79+
await expect(siteSwitcherStatic).toContainText(domain)
80+
await expect(siteSwitcherStatic).not.toHaveRole('button')
81+
82+
await siteSwitcherStatic.click()
83+
await expect(page.getByTestId('sitemenu')).not.toBeVisible()
84+
})
85+
6786
test('dashboard renders with imported data', async ({ page, request }) => {
6887
const { domain } = await setupSite({ page, request })
6988
await populateStats({

0 commit comments

Comments
 (0)