Skip to content

Commit 24f55c9

Browse files
authored
fix: custom tabs not working in globals (#7148)
1 parent 940d0ad commit 24f55c9

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

packages/next/src/views/Document/getViewsFromConfig.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ export const getViewsFromConfig = ({
185185
}
186186

187187
if (!EditOverride) {
188-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
189188
const [globalEntity, globalSlug, segment3, ...remainingSegments] = routeSegments
190189

191190
if (!docPermissions?.read?.permission) {
@@ -228,7 +227,19 @@ export const getViewsFromConfig = ({
228227

229228
default: {
230229
if (docPermissions?.read?.permission) {
231-
CustomView = getCustomViewByKey(views, 'Default')
230+
const baseRoute = [adminRoute, globalEntity, globalSlug, segment3]
231+
.filter(Boolean)
232+
.join('/')
233+
234+
const currentRoute = [baseRoute, segment3, ...remainingSegments]
235+
.filter(Boolean)
236+
.join('/')
237+
238+
CustomView = getCustomViewByRoute({
239+
baseRoute,
240+
currentRoute,
241+
views,
242+
})
232243
DefaultView = DefaultEditView
233244
} else {
234245
ErrorView = UnauthorizedView

test/admin/components/CustomTabComponent/client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const CustomTabComponentClient: React.FC<{
1515
} = useConfig()
1616
const params = useParams()
1717

18-
const baseRoute = (params.segments.slice(0, 3) as string[]).join('/')
18+
const baseRoute = (params.segments.slice(0, 2) as string[]).join('/')
1919

2020
return <Link href={`${adminRoute}/${baseRoute}${path}`}>Custom Tab Component</Link>
2121
}

test/admin/e2e/1/e2e.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
} from '../../shared.js'
3636
import {
3737
customFieldsSlug,
38+
customGlobalViews2GlobalSlug,
3839
customIdCollectionId,
3940
customViews2CollectionSlug,
4041
disableDuplicateSlug,
@@ -482,6 +483,28 @@ describe('admin1', () => {
482483

483484
await expect(customTab).toBeVisible()
484485
})
486+
487+
test('global — should render custom tab label', async () => {
488+
await page.goto(globalURL.global(customGlobalViews2GlobalSlug) + '/custom-tab-view')
489+
490+
const title = page.locator('#custom-view-title')
491+
492+
const docTab = page.locator('.doc-tab__link:has-text("Custom")')
493+
494+
await expect(docTab).toBeVisible()
495+
await expect(title).toContainText('Custom Tab Label View')
496+
})
497+
498+
test('global — should render custom tab component', async () => {
499+
await page.goto(globalURL.global(customGlobalViews2GlobalSlug) + '/custom-tab-component')
500+
const title = page.locator('#custom-view-title')
501+
502+
const docTab = page.locator('.custom-doc-tab').first()
503+
504+
await expect(docTab).toBeVisible()
505+
await expect(docTab).toContainText('Custom Tab Component')
506+
await expect(title).toContainText('Custom View With Tab Component')
507+
})
485508
})
486509

487510
describe('custom fields', () => {

0 commit comments

Comments
 (0)