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 @@
margin-left: auto;
}
.dev-tools-indicator-issue-counts {
display: inline-flex;
align-items: center;
gap: 6px;
}
.dev-tools-indicator-issue-count {
--color-primary: var(--color-gray-800);
--color-secondary: var(--color-gray-100);
......@@ -105,6 +111,11 @@
--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 {
width: var(--size-8);
height: var(--size-8);
......
......@@ -13,6 +13,7 @@ import {
ACTION_ERROR_OVERLAY_OPEN,
} from '../../shared'
import { usePanelRouterContext } from '../../menu/context'
import { getIssueBucketState } from '../../menu/issue-bucket-state'
import { BASE_LOGO_SIZE } from '../../utils/indicator-metrics'
import { StatusIndicator, Status, getCurrentStatus } from './status-indicator'
......@@ -84,9 +85,10 @@ export function NextLogo({
const isMenuOpen = panel === 'panel-selector'
const hasError = totalErrorCount > 0
// Only insights remain: use amber styling instead of red.
const insightsOnly =
hasError && normalErrorCount === 0 && instantErrorCount > 0
const { insightsOnly } = getIssueBucketState(
normalErrorCount,
instantErrorCount
)
const [isErrorExpanded, setIsErrorExpanded] = useState(hasError)
const [previousHasError, setPreviousHasError] = useState(hasError)
if (previousHasError !== hasError) {
......
......@@ -509,31 +509,43 @@ export function ErrorTabBar({
className="error-overlay-tab"
data-active={activeTab === 'errors'}
disabled={errorCount === 0}
aria-disabled={errorCount === 0}
onClick={() => onTabChange('errors')}
>
Issues
<span
className="error-overlay-tab-count"
data-active={activeTab === 'errors'}
>
{createCount(errorActiveIdx, errorCount, activeTab === 'errors')}
</span>
{errorCount === 0 ? (
'No issues'
) : (
<>
Issues
<span
className="error-overlay-tab-count"
data-active={activeTab === 'errors'}
>
{createCount(errorActiveIdx, errorCount, activeTab === 'errors')}
</span>
</>
)}
</button>
<button
type="button"
className="error-overlay-tab"
data-active={activeTab === 'instant'}
disabled={instantCount === 0}
onClick={() => onTabChange('instant')}
>
Insights
<span
className="error-overlay-tab-count"
{instantCount > 0 && (
<button
type="button"
className="error-overlay-tab"
data-active={activeTab === 'instant'}
onClick={() => onTabChange('instant')}
>
{createCount(instantActiveIdx, instantCount, activeTab === 'instant')}
</span>
</button>
Insights
<span
className="error-overlay-tab-count"
data-active={activeTab === 'instant'}
>
{createCount(
instantActiveIdx,
instantCount,
activeTab === 'instant'
)}
</span>
</button>
)}
{nextButton}
</div>
)
......@@ -711,8 +723,10 @@ Next.js version: ${props.versionInfo.installed} (${process.env.__NEXT_BUNDLER})\
getErrorSource(error) || ''
)
// Show the tab bar whenever there are instant errors so the user
// knows they're looking at an insight, even if the other tab is empty.
// Show the tab bar only when at least one Insight is present. When the only
// 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 renderTabBar = showTabBar
? ({
......@@ -1297,7 +1311,7 @@ export const styles = `
transition: color 0.15s ease;
border-radius: var(--rounded-md);
&:hover {
&:hover:not(:disabled) {
color: var(--color-gray-1000);
}
......
......@@ -315,11 +315,18 @@ function getClickableItemsCount(
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 (
<span
className="dev-tools-indicator-issue-count"
data-has-issues={children > 0}
data-variant={variant}
>
<span className="dev-tools-indicator-issue-count-indicator" />
{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 { ChevronRight, DevtoolMenu, IssueCount } from './dev-overlay-menu'
import { getIssueBucketState } from './issue-bucket-state'
import { DynamicPanel } from '../panel/dynamic-panel'
import {
learnMoreLink,
......@@ -35,31 +36,57 @@ import { CacheDisabledBody } from '../components/errors/dev-tools-indicator/dev-
const MenuPanel = () => {
const { setPanel, setSelectedIndex } = usePanelRouterContext()
const { state, dispatch } = useDevOverlayContext()
const { totalErrorCount } = useRenderErrorContext()
const { normalErrorCount, instantErrorCount } = useRenderErrorContext()
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 (
<DevtoolMenu
items={[
totalErrorCount > 0 && {
title: `${totalErrorCount} ${totalErrorCount === 1 ? 'issue' : 'issues'} found. Click to view details in the dev overlay.`,
label: 'Issues',
value: <IssueCount>{totalErrorCount}</IssueCount>,
hasAny && {
title: `${titleParts.join(' · ')} found. Click to view details in the dev overlay.`,
label,
value: (
<span className="dev-tools-indicator-issue-counts">
{hasNormal && (
<IssueCount variant="issue">{normalErrorCount}</IssueCount>
)}
{hasInstant && (
<IssueCount variant="insight">{instantErrorCount}</IssueCount>
)}
</span>
),
onClick: () => {
if (state.isErrorOverlayOpen) {
dispatch({
type: ACTION_ERROR_OVERLAY_CLOSE,
})
dispatch({ type: ACTION_ERROR_OVERLAY_CLOSE })
setPanel(null)
return
}
setPanel(null)
setSelectedIndex(-1)
if (totalErrorCount > 0) {
dispatch({
type: ACTION_ERROR_OVERLAY_OPEN,
})
}
dispatch({ type: ACTION_ERROR_OVERLAY_OPEN })
},
},
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