Unverified Commit 0a074bda authored by Aurora Scharff's avatar Aurora Scharff Committed by GitHub

fix(dev-overlay): Tidy up issues/insight menu and tab overlay (#94549)

### What?

Tidies up how the dev overlay surfaces Issues vs Insights:

- Tab bar: when there are no insights, the Insights tab is hidden. When
there are no issues but there are insights, the Issues tab stays in
place but reads `No issues` (disabled, no hover).
- Menu row: shows one row labeled `Issues`, `Insights`, or `Issues ·
Insights` with a red badge for issues and an amber badge for insights,
matching the trigger pill colors.

### Verification

Test-app scenarios on the [error-messages-overhaul
demo](https://error-messages-overhaul-ibsl.labs.vercel.dev/):
[41-subnav-cookies](https://error-messages-overhaul-ibsl.labs.vercel.dev/scenario/41-subnav-cookies),
[42-subnav-fetch](https://error-messages-overhaul-ibsl.labs.vercel.dev/scenario/42-subnav-fetch).

### Why?

Reported by icyJoseph in Slack. The red `Issues 1` chip on an
insights-only state looked like a real error; the `0/0` placeholder was
inconsistent.

<!-- NEXT_JS_LLM_PR -->
parent c082ffe4
...@@ -79,6 +79,12 @@ ...@@ -79,6 +79,12 @@
margin-left: auto; margin-left: auto;
} }
.dev-tools-indicator-issue-counts {
display: inline-flex;
align-items: center;
gap: 6px;
}
.dev-tools-indicator-issue-count { .dev-tools-indicator-issue-count {
--color-primary: var(--color-gray-800); --color-primary: var(--color-gray-800);
--color-secondary: var(--color-gray-100); --color-secondary: var(--color-gray-100);
...@@ -105,6 +111,11 @@ ...@@ -105,6 +111,11 @@
--color-secondary: var(--color-red-100); --color-secondary: var(--color-red-100);
} }
&[data-has-issues='true'][data-variant='insight'] {
--color-primary: var(--color-amber-800);
--color-secondary: var(--color-amber-100);
}
.dev-tools-indicator-issue-count-indicator { .dev-tools-indicator-issue-count-indicator {
width: var(--size-8); width: var(--size-8);
height: var(--size-8); height: var(--size-8);
......
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ import {
ACTION_ERROR_OVERLAY_OPEN, ACTION_ERROR_OVERLAY_OPEN,
} from '../../shared' } from '../../shared'
import { usePanelRouterContext } from '../../menu/context' import { usePanelRouterContext } from '../../menu/context'
import { getIssueBucketState } from '../../menu/issue-bucket-state'
import { BASE_LOGO_SIZE } from '../../utils/indicator-metrics' import { BASE_LOGO_SIZE } from '../../utils/indicator-metrics'
import { StatusIndicator, Status, getCurrentStatus } from './status-indicator' import { StatusIndicator, Status, getCurrentStatus } from './status-indicator'
...@@ -84,9 +85,10 @@ export function NextLogo({ ...@@ -84,9 +85,10 @@ export function NextLogo({
const isMenuOpen = panel === 'panel-selector' const isMenuOpen = panel === 'panel-selector'
const hasError = totalErrorCount > 0 const hasError = totalErrorCount > 0
// Only insights remain: use amber styling instead of red. const { insightsOnly } = getIssueBucketState(
const insightsOnly = normalErrorCount,
hasError && normalErrorCount === 0 && instantErrorCount > 0 instantErrorCount
)
const [isErrorExpanded, setIsErrorExpanded] = useState(hasError) const [isErrorExpanded, setIsErrorExpanded] = useState(hasError)
const [previousHasError, setPreviousHasError] = useState(hasError) const [previousHasError, setPreviousHasError] = useState(hasError)
if (previousHasError !== hasError) { if (previousHasError !== hasError) {
......
...@@ -509,31 +509,43 @@ export function ErrorTabBar({ ...@@ -509,31 +509,43 @@ export function ErrorTabBar({
className="error-overlay-tab" className="error-overlay-tab"
data-active={activeTab === 'errors'} data-active={activeTab === 'errors'}
disabled={errorCount === 0} disabled={errorCount === 0}
aria-disabled={errorCount === 0}
onClick={() => onTabChange('errors')} onClick={() => onTabChange('errors')}
> >
Issues {errorCount === 0 ? (
<span 'No issues'
className="error-overlay-tab-count" ) : (
data-active={activeTab === 'errors'} <>
> Issues
{createCount(errorActiveIdx, errorCount, activeTab === 'errors')} <span
</span> className="error-overlay-tab-count"
data-active={activeTab === 'errors'}
>
{createCount(errorActiveIdx, errorCount, activeTab === 'errors')}
</span>
</>
)}
</button> </button>
<button {instantCount > 0 && (
type="button" <button
className="error-overlay-tab" type="button"
data-active={activeTab === 'instant'} className="error-overlay-tab"
disabled={instantCount === 0}
onClick={() => onTabChange('instant')}
>
Insights
<span
className="error-overlay-tab-count"
data-active={activeTab === 'instant'} data-active={activeTab === 'instant'}
onClick={() => onTabChange('instant')}
> >
{createCount(instantActiveIdx, instantCount, activeTab === 'instant')} Insights
</span> <span
</button> className="error-overlay-tab-count"
data-active={activeTab === 'instant'}
>
{createCount(
instantActiveIdx,
instantCount,
activeTab === 'instant'
)}
</span>
</button>
)}
{nextButton} {nextButton}
</div> </div>
) )
...@@ -711,8 +723,10 @@ Next.js version: ${props.versionInfo.installed} (${process.env.__NEXT_BUNDLER})\ ...@@ -711,8 +723,10 @@ Next.js version: ${props.versionInfo.installed} (${process.env.__NEXT_BUNDLER})\
getErrorSource(error) || '' getErrorSource(error) || ''
) )
// Show the tab bar whenever there are instant errors so the user // Show the tab bar only when at least one Insight is present. When the only
// knows they're looking at an insight, even if the other tab is empty. // bucket with content is Issues, the red pill already conveys the count and a
// single-tab bar would be redundant. When Insights exist (alone or alongside
// Issues), the bar is shown so the user can switch between buckets.
const showTabBar = instantErrors.length > 0 const showTabBar = instantErrors.length > 0
const renderTabBar = showTabBar const renderTabBar = showTabBar
? ({ ? ({
...@@ -1297,7 +1311,7 @@ export const styles = ` ...@@ -1297,7 +1311,7 @@ export const styles = `
transition: color 0.15s ease; transition: color 0.15s ease;
border-radius: var(--rounded-md); border-radius: var(--rounded-md);
&:hover { &:hover:not(:disabled) {
color: var(--color-gray-1000); color: var(--color-gray-1000);
} }
......
...@@ -315,11 +315,18 @@ function getClickableItemsCount( ...@@ -315,11 +315,18 @@ function getClickableItemsCount(
return items.filter((item) => item.onClick).length return items.filter((item) => item.onClick).length
} }
export function IssueCount({ children }: { children: number }) { export function IssueCount({
children,
variant = 'issue',
}: {
children: number
variant?: 'issue' | 'insight'
}) {
return ( return (
<span <span
className="dev-tools-indicator-issue-count" className="dev-tools-indicator-issue-count"
data-has-issues={children > 0} data-has-issues={children > 0}
data-variant={variant}
> >
<span className="dev-tools-indicator-issue-count-indicator" /> <span className="dev-tools-indicator-issue-count-indicator" />
{children} {children}
......
export type IssueBucketState = {
hasNormal: boolean
hasInstant: boolean
hasAny: boolean
insightsOnly: boolean
variant: 'issue' | 'insight'
}
export function getIssueBucketState(
normalErrorCount: number,
instantErrorCount: number
): IssueBucketState {
const hasNormal = normalErrorCount > 0
const hasInstant = instantErrorCount > 0
const insightsOnly = !hasNormal && hasInstant
return {
hasNormal,
hasInstant,
hasAny: hasNormal || hasInstant,
insightsOnly,
variant: insightsOnly ? 'insight' : 'issue',
}
}
import { usePanelRouterContext, type PanelStateKind } from './context' import { usePanelRouterContext, type PanelStateKind } from './context'
import { ChevronRight, DevtoolMenu, IssueCount } from './dev-overlay-menu' import { ChevronRight, DevtoolMenu, IssueCount } from './dev-overlay-menu'
import { getIssueBucketState } from './issue-bucket-state'
import { DynamicPanel } from '../panel/dynamic-panel' import { DynamicPanel } from '../panel/dynamic-panel'
import { import {
learnMoreLink, learnMoreLink,
...@@ -35,31 +36,57 @@ import { CacheDisabledBody } from '../components/errors/dev-tools-indicator/dev- ...@@ -35,31 +36,57 @@ import { CacheDisabledBody } from '../components/errors/dev-tools-indicator/dev-
const MenuPanel = () => { const MenuPanel = () => {
const { setPanel, setSelectedIndex } = usePanelRouterContext() const { setPanel, setSelectedIndex } = usePanelRouterContext()
const { state, dispatch } = useDevOverlayContext() const { state, dispatch } = useDevOverlayContext()
const { totalErrorCount } = useRenderErrorContext() const { normalErrorCount, instantErrorCount } = useRenderErrorContext()
const isAppRouter = state.routerType === 'app' const isAppRouter = state.routerType === 'app'
const { hasNormal, hasInstant, hasAny } = getIssueBucketState(
normalErrorCount,
instantErrorCount
)
const titleParts: string[] = []
if (hasNormal) {
titleParts.push(
`${normalErrorCount} ${normalErrorCount === 1 ? 'issue' : 'issues'}`
)
}
if (hasInstant) {
titleParts.push(
`${instantErrorCount} ${instantErrorCount === 1 ? 'insight' : 'insights'}`
)
}
const label =
hasNormal && hasInstant
? 'Issues · Insights'
: hasInstant
? 'Insights'
: 'Issues'
return ( return (
<DevtoolMenu <DevtoolMenu
items={[ items={[
totalErrorCount > 0 && { hasAny && {
title: `${totalErrorCount} ${totalErrorCount === 1 ? 'issue' : 'issues'} found. Click to view details in the dev overlay.`, title: `${titleParts.join(' · ')} found. Click to view details in the dev overlay.`,
label: 'Issues', label,
value: <IssueCount>{totalErrorCount}</IssueCount>, value: (
<span className="dev-tools-indicator-issue-counts">
{hasNormal && (
<IssueCount variant="issue">{normalErrorCount}</IssueCount>
)}
{hasInstant && (
<IssueCount variant="insight">{instantErrorCount}</IssueCount>
)}
</span>
),
onClick: () => { onClick: () => {
if (state.isErrorOverlayOpen) { if (state.isErrorOverlayOpen) {
dispatch({ dispatch({ type: ACTION_ERROR_OVERLAY_CLOSE })
type: ACTION_ERROR_OVERLAY_CLOSE,
})
setPanel(null) setPanel(null)
return return
} }
setPanel(null) setPanel(null)
setSelectedIndex(-1) setSelectedIndex(-1)
if (totalErrorCount > 0) { dispatch({ type: ACTION_ERROR_OVERLAY_OPEN })
dispatch({
type: ACTION_ERROR_OVERLAY_OPEN,
})
}
}, },
}, },
state.staticIndicator === 'disabled' state.staticIndicator === 'disabled'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment