Repository navigation
feat(app): make content font size configurable #3166
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
Changes from all commits
149591c
a96146b
2d7e1bc
38e9883
e78ca84
5a6ee92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| '@hyperdx/app': minor | ||
| --- | ||
|
|
||
| feat: add a content font size preference | ||
|
|
||
| Small text in the log/trace table was not adjustable without browser zoom, which | ||
| also shrinks the surrounding chrome. User preferences now carry a **Content font | ||
| size** setting (small / medium / large) that scales the search results table, | ||
| data tables, expanded row JSON, and chart axes, legends, and tooltips. Small is | ||
| the default and matches the previous sizes, so nothing changes until you opt in. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import { Provider } from 'jotai'; | ||
| import { act, renderHook } from '@testing-library/react'; | ||
|
|
||
| import { CONTENT_FONT_SIZES } from '@/config/fonts'; | ||
| import { useContentFontSize, useUserPreferences } from '@/useUserPreferences'; | ||
|
|
||
| const STORAGE_KEY = 'hdx-user-preferences'; | ||
|
|
||
| const renderContentFontSize = () => | ||
| renderHook( | ||
| () => ({ | ||
| resolved: useContentFontSize(), | ||
| preferences: useUserPreferences(), | ||
| }), | ||
| { wrapper: Provider }, | ||
| ); | ||
|
|
||
| describe('useContentFontSize', () => { | ||
| beforeEach(() => { | ||
| window.localStorage.clear(); | ||
| }); | ||
|
|
||
| // The `sm` scale is what every content surface had hardcoded before the | ||
| // preference existed, so it has to stay the default. | ||
| it('defaults to the small scale', () => { | ||
| const { result } = renderContentFontSize(); | ||
|
|
||
| expect(CONTENT_FONT_SIZES.sm).toEqual({ base: 12, compact: 11 }); | ||
| expect(result.current.resolved).toEqual({ | ||
| contentFontSize: 'sm', | ||
| ...CONTENT_FONT_SIZES.sm, | ||
| scale: 1, | ||
| }); | ||
| }); | ||
|
|
||
| it('falls back to the default for preferences stored before the setting existed', () => { | ||
| window.localStorage.setItem( | ||
| STORAGE_KEY, | ||
| JSON.stringify({ | ||
| isUTC: true, | ||
| timeFormat: '24h', | ||
| colorMode: 'dark', | ||
| font: 'Inter', | ||
| }), | ||
| ); | ||
|
|
||
| const { result } = renderContentFontSize(); | ||
|
|
||
| expect(result.current.resolved.contentFontSize).toBe('sm'); | ||
| }); | ||
|
|
||
| it('loads a non-default preference saved in a previous session', () => { | ||
| window.localStorage.setItem( | ||
| STORAGE_KEY, | ||
| JSON.stringify({ | ||
| isUTC: false, | ||
| timeFormat: '12h', | ||
| colorMode: 'dark', | ||
| font: 'IBM Plex Mono', | ||
| contentFontSize: 'md', | ||
| }), | ||
| ); | ||
|
|
||
| const { result } = renderContentFontSize(); | ||
|
|
||
| expect(result.current.resolved).toEqual({ | ||
| contentFontSize: 'md', | ||
| ...CONTENT_FONT_SIZES.md, | ||
| scale: CONTENT_FONT_SIZES.md.base / CONTENT_FONT_SIZES.sm.base, | ||
| }); | ||
| }); | ||
|
|
||
| it('falls back to the default when the stored size is not one we ship', () => { | ||
| window.localStorage.setItem( | ||
| STORAGE_KEY, | ||
| JSON.stringify({ | ||
| isUTC: false, | ||
| timeFormat: '12h', | ||
| colorMode: 'dark', | ||
| font: 'IBM Plex Mono', | ||
| contentFontSize: 'xl', | ||
| }), | ||
| ); | ||
|
|
||
| const { result } = renderContentFontSize(); | ||
|
|
||
| expect(result.current.resolved).toEqual({ | ||
| contentFontSize: 'sm', | ||
| ...CONTENT_FONT_SIZES.sm, | ||
| scale: 1, | ||
| }); | ||
| }); | ||
|
|
||
| it('resolves the stored preference', () => { | ||
| const { result } = renderContentFontSize(); | ||
|
|
||
| act(() => | ||
| result.current.preferences.setUserPreference({ contentFontSize: 'lg' }), | ||
| ); | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| expect(result.current.resolved).toEqual({ | ||
| contentFontSize: 'lg', | ||
| ...CONTENT_FONT_SIZES.lg, | ||
| scale: CONTENT_FONT_SIZES.lg.base / CONTENT_FONT_SIZES.sm.base, | ||
| }); | ||
| expect( | ||
| JSON.parse(window.localStorage.getItem(STORAGE_KEY) ?? '{}'), | ||
| ).toEqual(expect.objectContaining({ contentFontSize: 'lg' })); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 minor — The px-budget scaling — the part most likely to regress — has no test The only new test covers the hook's resolved numbers; nothing exercises 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.
🔵 minor — Users with a non-default size see a flash of small text and a column reflow on every load
userPreferencesAtomis anatomWithStoragewith nogetOnInit, and the vars are only written in a post-mountuseEffect. So the first paint always uses 12px andscale: 1, then the text and the default column widths jump.SystemColorSchemeScriptinuseUserPreferences.tsxalready solves this for color mode by readinghdx-user-preferencesin an inline script before React runs. Have it set--hdx-content-font-sizeand--hdx-content-font-size-compactfromcontentFontSizetoo.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