Unverified Commit 212d0e7e authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

[devtools] segment explorer tab (#80805)

parent ba70eda3
......@@ -107,6 +107,10 @@ export function getDefineEnv({
const isDynamicIOEnabled = !!config.experimental.dynamicIO
const isUseCacheEnabled = !!config.experimental.useCache
const isDevToolPanelUIEnabled =
!!process.env.__NEXT_DEVTOOL_NEW_PANEL_UI ||
!!config.experimental.devtoolNewPanelUI
const defineEnv: DefineEnv = {
// internal field to identify the plugin config
__NEXT_DEFINE_ENV: true,
......@@ -297,9 +301,9 @@ export function getDefineEnv({
}
: {}),
'process.env.__NEXT_DEVTOOL_SEGMENT_EXPLORER':
config.experimental.devtoolSegmentExplorer ?? false,
'process.env.__NEXT_DEVTOOL_NEW_PANEL_UI':
config.experimental.devtoolNewPanelUI ?? false,
// Enable segment explorer in devtools
isDevToolPanelUIEnabled || !!config.experimental.devtoolSegmentExplorer,
'process.env.__NEXT_DEVTOOL_NEW_PANEL_UI': isDevToolPanelUIEnabled,
// The devtools need to know whether or not to show an option to clear the
// bundler cache. This option may be removed later once Turbopack's
......
......@@ -6,11 +6,13 @@ import type { HydrationErrorState } from '../../../../shared/hydration-error'
import { SettingsTab } from './settings-tab'
import { IssuesTab } from './issues-tab/issues-tab'
import { SegmentsExplorerTab } from './segments-explorer-tab'
export function DevToolsPanelTab({
activeTab,
devToolsPosition,
scale,
routerType,
handlePositionChange,
handleScaleChange,
debugInfo,
......@@ -20,6 +22,7 @@ export function DevToolsPanelTab({
}: {
activeTab: DevToolsPanelTabType
devToolsPosition: Corners
routerType: 'app' | 'pages'
scale: number
handlePositionChange: (e: React.ChangeEvent<HTMLSelectElement>) => void
handleScaleChange: (e: React.ChangeEvent<HTMLSelectElement>) => void
......@@ -39,7 +42,7 @@ export function DevToolsPanelTab({
/>
)
case 'route':
return <div>Route</div>
return <SegmentsExplorerTab routerType={routerType} />
case 'issues':
return (
<IssuesTab
......
import { useSegmentTree } from '../../../segment-explorer'
import { PageSegmentTree } from '../../overview/segment-explorer'
function SegmentsExplorer({
routerType,
}: React.HTMLProps<HTMLDivElement> & {
routerType: 'app' | 'pages'
}) {
const tree = useSegmentTree()
const isAppRouter = routerType === 'app'
return <PageSegmentTree tree={tree} isAppRouter={isAppRouter} />
}
export function SegmentsExplorerTab({
routerType,
}: {
routerType: 'app' | 'pages'
}) {
return (
<div data-nextjs-devtools-panel-segments-explorer>
<SegmentsExplorer routerType={routerType} />
</div>
)
}
export const SEGMENTS_EXPLORER_TAB_STYLES = `
[data-nextjs-devtools-panel-segments-explorer] {
padding: 0 8px;
}
`
......@@ -163,6 +163,7 @@ export function DevToolsPanel({
activeTab={activeTab}
devToolsPosition={state.devToolsPosition}
scale={state.scale}
routerType={state.routerType}
handlePositionChange={handlePositionChange}
handleScaleChange={handleScaleChange}
debugInfo={state.debugInfo}
......
......@@ -9,7 +9,7 @@ const isFileNode = (node: SegmentTrieNode) => {
return !!node.value?.type && !!node.value?.pagePath
}
function PageSegmentTree({
export function PageSegmentTree({
tree,
isAppRouter,
}: {
......
......@@ -35,6 +35,7 @@ import { DEVTOOLS_PANEL_TAB_ISSUES_SIDEBAR_FRAME_SKELETON_STYLES } from '../comp
import { DEVTOOLS_PANEL_TAB_ISSUES_CONTENT_STYLES } from '../components/devtools-panel/devtools-panel-tab/issues-tab/issues-tab-content'
import { ISSUE_FEEDBACK_BUTTON_STYLES } from '../components/errors/error-overlay-toolbar/issue-feedback-button'
import { ERROR_CONTENT_SKELETON_STYLES } from '../container/runtime-error/error-content-skeleton'
import { SEGMENTS_EXPLORER_TAB_STYLES } from '../components/devtools-panel/devtools-panel-tab/segments-explorer-tab'
export function ComponentStyles() {
return (
......@@ -76,6 +77,7 @@ export function ComponentStyles() {
${DEVTOOLS_PANEL_TAB_ISSUES_CONTENT_STYLES}
${ISSUE_FEEDBACK_BUTTON_STYLES}
${ERROR_CONTENT_SKELETON_STYLES}
${SEGMENTS_EXPLORER_TAB_STYLES}
`}
</style>
)
......
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