Repository navigation
feat(app): pick the dashboard live mode refresh interval #3745
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
Open
MikeShi42
wants to merge
4
commits into
main
Choose a base branch
from
cursor/dashboard-live-refresh-interval-06d1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
040649d
feat(app): let users pick the dashboard live refresh interval
cursoragent 767631d
chore: format changeset
cursoragent 42f492b
feat(app): add an auto refresh interval that follows the date range
cursoragent 726b2e4
fix(app): drop the sub-30s fixed interval and cap the refresh timer d…
cursoragent 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@hyperdx/app': patch | ||
| --- | ||
|
|
||
| feat: Pick the dashboard live mode refresh interval, from 30s up to the time | ||
| range's default |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import { Granularity } from '@hyperdx/common-utils/dist/core/utils'; | ||
| import { mapGranularityToExternalFormat } from '@hyperdx/common-utils/dist/externalSource'; | ||
| import { Box, Button, Menu, Tooltip } from '@mantine/core'; | ||
| import { IconCheck, IconChevronDown } from '@tabler/icons-react'; | ||
|
|
||
| function IntervalItem({ | ||
| label, | ||
| checked, | ||
| onClick, | ||
| }: { | ||
| label: string; | ||
| checked: boolean; | ||
| onClick: () => void; | ||
| }) { | ||
| return ( | ||
| <Menu.Item | ||
| data-checked={checked} | ||
| onClick={onClick} | ||
| leftSection={checked ? <IconCheck size={14} /> : <Box w={14} />} | ||
| > | ||
| {label} | ||
| </Menu.Item> | ||
| ); | ||
| } | ||
|
|
||
| export function DashboardLiveButton({ | ||
| isLive, | ||
| onToggleLive, | ||
| refreshInterval, | ||
| isAutoRefreshInterval, | ||
| defaultRefreshInterval, | ||
| refreshIntervalOptions, | ||
| onRefreshIntervalChange, | ||
| }: { | ||
| isLive: boolean; | ||
| onToggleLive: () => void; | ||
| refreshInterval: Granularity; | ||
| isAutoRefreshInterval: boolean; | ||
| defaultRefreshInterval: Granularity; | ||
| refreshIntervalOptions: Granularity[]; | ||
| /** Undefined selects auto, which follows the date range's default. */ | ||
| onRefreshIntervalChange: (interval: Granularity | undefined) => void; | ||
| }) { | ||
| const variant = isLive ? 'primary' : 'secondary'; | ||
| const intervalLabel = mapGranularityToExternalFormat(refreshInterval); | ||
| const autoLabel = `Auto (${mapGranularityToExternalFormat(defaultRefreshInterval)})`; | ||
| const triggerLabel = isAutoRefreshInterval ? autoLabel : intervalLabel; | ||
|
|
||
| return ( | ||
| <Button.Group> | ||
| <Tooltip | ||
| withArrow | ||
| label={ | ||
| isLive | ||
| ? `Auto-refreshing every ${intervalLabel}` | ||
| : 'Enable auto-refresh' | ||
| } | ||
| fz="xs" | ||
| color="gray" | ||
| > | ||
| <Button | ||
| onClick={onToggleLive} | ||
| size="sm" | ||
| variant={variant} | ||
| title={isLive ? 'Disable auto-refresh' : 'Enable auto-refresh'} | ||
| data-testid="dashboard-live-button" | ||
| > | ||
| Live | ||
| </Button> | ||
| </Tooltip> | ||
| <Menu position="bottom-end" withinPortal> | ||
| <Menu.Target> | ||
| <Button | ||
| size="sm" | ||
| variant={variant} | ||
| px="xs" | ||
| rightSection={<IconChevronDown size={14} />} | ||
| aria-label={`Refresh interval ${triggerLabel}`} | ||
| data-testid="dashboard-refresh-interval-button" | ||
| style={{ | ||
| borderInlineStart: '1px solid var(--color-border)', | ||
| }} | ||
| > | ||
| {triggerLabel} | ||
| </Button> | ||
| </Menu.Target> | ||
| <Menu.Dropdown data-testid="dashboard-refresh-interval-menu"> | ||
| <Menu.Label>Refresh every</Menu.Label> | ||
| <IntervalItem | ||
| label={autoLabel} | ||
| checked={isAutoRefreshInterval} | ||
| onClick={() => onRefreshIntervalChange(undefined)} | ||
| /> | ||
| {refreshIntervalOptions.length > 0 && <Menu.Divider />} | ||
| {refreshIntervalOptions.map(interval => ( | ||
| <IntervalItem | ||
| key={interval} | ||
| label={mapGranularityToExternalFormat(interval)} | ||
| checked={!isAutoRefreshInterval && interval === refreshInterval} | ||
| onClick={() => onRefreshIntervalChange(interval)} | ||
| /> | ||
| ))} | ||
| </Menu.Dropdown> | ||
| </Menu> | ||
| </Button.Group> | ||
| ); | ||
| } | ||
112 changes: 112 additions & 0 deletions
112
packages/app/src/components/__tests__/DashboardLiveButton.test.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,112 @@ | ||
| import React from 'react'; | ||
| import { Granularity } from '@hyperdx/common-utils/dist/core/utils'; | ||
| import { fireEvent, screen } from '@testing-library/react'; | ||
|
|
||
| import { DashboardLiveButton } from '@/components/DashboardLiveButton'; | ||
|
|
||
| const OPTIONS = [ | ||
| Granularity.ThirtySecond, | ||
| Granularity.OneMinute, | ||
| Granularity.FiveMinute, | ||
| ]; | ||
|
|
||
| function renderButton( | ||
| props: Partial<React.ComponentProps<typeof DashboardLiveButton>> = {}, | ||
| ) { | ||
| const onToggleLive = jest.fn(); | ||
| const onRefreshIntervalChange = jest.fn(); | ||
| renderWithMantine( | ||
| <DashboardLiveButton | ||
| isLive={false} | ||
| onToggleLive={onToggleLive} | ||
| refreshInterval={Granularity.FiveMinute} | ||
| isAutoRefreshInterval | ||
| defaultRefreshInterval={Granularity.FiveMinute} | ||
| refreshIntervalOptions={OPTIONS} | ||
| onRefreshIntervalChange={onRefreshIntervalChange} | ||
| {...props} | ||
| />, | ||
| ); | ||
| return { onToggleLive, onRefreshIntervalChange }; | ||
| } | ||
|
|
||
| async function openMenu() { | ||
| fireEvent.click(screen.getByTestId('dashboard-refresh-interval-button')); | ||
| await screen.findByTestId('dashboard-refresh-interval-menu'); | ||
| } | ||
|
|
||
| describe('DashboardLiveButton', () => { | ||
| it('toggles live mode', () => { | ||
| const { onToggleLive } = renderButton(); | ||
|
|
||
| fireEvent.click(screen.getByTestId('dashboard-live-button')); | ||
|
|
||
| expect(onToggleLive).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('shows auto as the first, checked item', async () => { | ||
| renderButton(); | ||
|
|
||
| expect( | ||
| screen.getByTestId('dashboard-refresh-interval-button'), | ||
| ).toHaveTextContent('Auto (5m)'); | ||
|
|
||
| await openMenu(); | ||
| const items = screen.getAllByRole('menuitem', { hidden: true }); | ||
| expect(items.map(item => item.textContent)).toEqual([ | ||
| 'Auto (5m)', | ||
| '30s', | ||
| '1m', | ||
| '5m', | ||
| ]); | ||
| expect(items[0]).toHaveAttribute('data-checked', 'true'); | ||
| expect(items[3]).toHaveAttribute('data-checked', 'false'); | ||
| }); | ||
|
|
||
| it('checks a fixed interval equal to auto without checking auto', async () => { | ||
| renderButton({ isAutoRefreshInterval: false }); | ||
|
|
||
| expect( | ||
| screen.getByTestId('dashboard-refresh-interval-button'), | ||
| ).toHaveTextContent(/^5m$/); | ||
|
|
||
| await openMenu(); | ||
| expect( | ||
| screen.getByRole('menuitem', { name: 'Auto (5m)', hidden: true }), | ||
| ).toHaveAttribute('data-checked', 'false'); | ||
| expect( | ||
| screen.getByRole('menuitem', { name: '5m', hidden: true }), | ||
| ).toHaveAttribute('data-checked', 'true'); | ||
| }); | ||
|
|
||
| it('selects a fixed interval or auto', async () => { | ||
| const { onRefreshIntervalChange } = renderButton(); | ||
|
|
||
| await openMenu(); | ||
| fireEvent.click(screen.getByRole('menuitem', { name: '1m', hidden: true })); | ||
| expect(onRefreshIntervalChange).toHaveBeenLastCalledWith( | ||
| Granularity.OneMinute, | ||
| ); | ||
|
|
||
| await openMenu(); | ||
| fireEvent.click( | ||
| screen.getByRole('menuitem', { name: 'Auto (5m)', hidden: true }), | ||
| ); | ||
| expect(onRefreshIntervalChange).toHaveBeenLastCalledWith(undefined); | ||
| }); | ||
|
|
||
| it('offers only auto when there are no fixed intervals', async () => { | ||
| renderButton({ | ||
| refreshInterval: Granularity.FifteenSecond, | ||
| defaultRefreshInterval: Granularity.FifteenSecond, | ||
| refreshIntervalOptions: [], | ||
| }); | ||
|
|
||
| await openMenu(); | ||
| expect( | ||
| screen | ||
| .getAllByRole('menuitem', { hidden: true }) | ||
| .map(item => item.textContent), | ||
| ).toEqual(['Auto (15s)']); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 P2 — Screen readers can't tell which refresh interval is selected
The selected item is marked only by a visual
IconCheckand adata-checkedattribute, and assistive tech reads neither. Give eachMenu.Itemrole="menuitemradio"andaria-checked={checked}, and have the tests assertaria-checkedinstead ofdata-checked.Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried this: Mantine's
Menu.Itemsetsrole: "menuitem"after spreading props, sorole="menuitemradio"is overridden, andaria-checkedisn't valid on a plainmenuitem. Fixing it means replacingMenu.Itemwith a custom item, which is more than this PR should take on; leaving it for a maintainer to decide.