Unverified Commit c2621a14 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

[devtool] style the segment explorer as nested view (#80212)

parent ecf970a7
......@@ -76,13 +76,33 @@ function PageSegmentTreeLayerPresentation({
node: TrieNode<SegmentNode>
level: number
}) {
const segments = node.value?.pagePath?.split('/') || []
const fileName = segments[segments.length - 1] || ''
const pagePath = node.value?.pagePath || ''
const nodeName = node.value?.type
const pagePathPrefix = segments.slice(0, -1).join('/')
const segments = pagePath.split('/') || []
const fileName = segments.pop() || ''
const segmentPath = segments.join('/')
let pagePathPrefix = segmentPath
const childrenKeys = Object.keys(node.children).sort((a, b) => {
// Prioritize if it's a file convention like layout or page,
// then the rest parallel routes.
const aHasExt = a.includes('.')
const bHasExt = b.includes('.')
if (aHasExt && !bHasExt) return -1
if (!aHasExt && bHasExt) return 1
// Otherwise sort alphabetically
return a.localeCompare(b)
})
return (
<div className="segment-explorer-item">
<div
className={cx(
'segment-explorer-item',
level > 1 && 'segment-explorer-item--nested'
)}
>
{!fileName || level === 0 ? null : (
<div className="segment-explorer-item-row">
<div className="segment-explorer-line">
......@@ -103,17 +123,19 @@ function PageSegmentTreeLayerPresentation({
)}
<div className="tree-node-expanded-rendered-children">
{Object.entries(node.children).map(
([key, child]) =>
{childrenKeys.map((segment) => {
const child = node.children[segment]
return (
child && (
<PageSegmentTreeLayerPresentation
key={key}
key={segment}
tree={tree}
node={child}
level={level + 1}
/>
)
)}
)
})}
</div>
</div>
)
......@@ -141,6 +163,10 @@ export const DEV_TOOLS_INFO_RENDER_FILES_STYLES = css`
font-size: var(--size-14);
}
.segment-explorer-item--nested {
padding-left: 20px;
}
.segment-explorer-item-row {
display: flex;
align-items: center;
......@@ -168,12 +194,9 @@ export const DEV_TOOLS_INFO_RENDER_FILES_STYLES = css`
.segment-explorer-line-icon-page {
color: inherit;
}
.segment-explorer-line-icon-layout {
color: var(--color-gray-1-00);
}
.segment-explorer-line-text-page {
color: var(--color-blue-900);
color: var(--color-gray-1000);
font-weight: 500;
}
`
......@@ -22,13 +22,13 @@ describe('segment-explorer', () => {
'[data-nextjs-devtool-segment-explorer]'
)
expect(await content.text()).toMatchInlineSnapshot(`
"app/parallel-routes/page.tsx
app/parallel-routes/@foo/page.tsx
app/parallel-routes/@foo/layout.tsx
app/parallel-routes/@bar/page.tsx
app/parallel-routes/@bar/layout.tsx
"app/layout.tsx
app/parallel-routes/layout.tsx
app/layout.tsx"
app/parallel-routes/page.tsx
app/parallel-routes/@bar/layout.tsx
app/parallel-routes/@bar/page.tsx
app/parallel-routes/@foo/layout.tsx
app/parallel-routes/@foo/page.tsx"
`)
})
})
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