Skip to content

Commit 4bfc660

Browse files
fix enity tabs order
1 parent 3da06d8 commit 4bfc660

File tree

7 files changed

+31
-5
lines changed

7 files changed

+31
-5
lines changed

packages/app/config.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export interface Config {
7474
path: string;
7575
title: string;
7676
mountPoint: string;
77+
priority?: number;
7778
}[];
7879
mountPoints?: {
7980
mountPoint: string;

packages/app/src/components/DynamicRoot/DynamicRoot.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,14 @@ export const DynamicRoot = ({
336336
}, []);
337337

338338
const entityTabOverrides = entityTabs.reduce<EntityTabOverrides>(
339-
(acc, { path, title, mountPoint, scope }) => {
339+
(acc, { path, title, mountPoint, scope, priority }) => {
340340
if (acc[path]) {
341341
// eslint-disable-next-line no-console
342342
console.warn(
343343
`Plugin ${scope} is not configured properly: a tab has already been configured for "${path}", ignoring entry with title: "${title}" and mountPoint: "${mountPoint}"`,
344344
);
345345
} else {
346-
acc[path] = { title, mountPoint };
346+
acc[path] = { title, mountPoint, priority };
347347
}
348348
return acc;
349349
},

packages/app/src/components/DynamicRoot/DynamicRootContext.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export type RemotePlugins = {
104104

105105
export type EntityTabOverrides = Record<
106106
string,
107-
{ title: string; mountPoint: string }
107+
{ title: string; mountPoint: string; priority?: number }
108108
>;
109109

110110
export type MountPoints = Record<string, ScalprumMountPoint[]>;

packages/app/src/components/catalog/EntityPage/DynamicEntityTab.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type DynamicEntityTabProps = {
1515
mountPoint: string;
1616
if?: (entity: Entity) => boolean;
1717
children?: React.ReactNode;
18+
priority?: number;
1819
};
1920

2021
/**

packages/app/src/components/catalog/EntityPage/EntityPage.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ContextMenuAwareEntityLayout } from './ContextMenuAwareEntityLayout';
2-
import { defaultTabs, tabChildren, tabRules } from './defaultTabs';
2+
import { tabChildren, tabRules } from './defaultTabs';
33
import { dynamicEntityTab, DynamicEntityTabProps } from './DynamicEntityTab';
4+
import {mergeTabs} from '../utils'
45

56
/**
67
* Displays the tabs and content for a catalog entity
@@ -16,7 +17,7 @@ export const entityPage = (
1617
) => {
1718
return (
1819
<ContextMenuAwareEntityLayout>
19-
{Object.entries({ ...defaultTabs, ...entityTabOverrides }).map(
20+
{mergeTabs(entityTabOverrides).map(
2021
([path, config]) => {
2122
return dynamicEntityTab({
2223
...config,

packages/app/src/components/catalog/utils.tsx

+19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { type Entity } from '@backstage/catalog-model';
2+
import { defaultTabs } from './EntityPage/defaultTabs';
3+
import { DynamicEntityTabProps } from './EntityPage/DynamicEntityTab';
24

35
export const isType = (types: string | string[]) => (entity: Entity) => {
46
if (!entity?.spec?.type) {
@@ -13,3 +15,20 @@ export const hasAnnotation = (keys: string) => (entity: Entity) =>
1315

1416
export const hasLinks = (entity: Entity) =>
1517
Boolean(entity.metadata.links?.length);
18+
19+
export const mergeTabs = (
20+
entityTabOverrides: Record<
21+
string,
22+
Omit<DynamicEntityTabProps, 'path' | 'if' | 'children'>
23+
>,
24+
) => {
25+
return (
26+
Object.entries({ ...defaultTabs, ...entityTabOverrides })
27+
.filter(([, tab]) => !(tab.priority && tab.priority < 0))
28+
.sort(([, tabA], [, tabB]) => {
29+
const priorityA = tabA.priority ?? 0;
30+
const priorityB = tabB.priority ?? 0;
31+
return priorityB - priorityA;
32+
}) || []
33+
);
34+
};

packages/app/src/utils/dynamicUI/extractDynamicConfig.ts

+4
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,15 @@ type EntityTab = {
106106
mountPoint: string;
107107
path: string;
108108
title: string;
109+
pariority?: number;
109110
};
110111

111112
type EntityTabEntry = {
112113
scope: string;
113114
mountPoint: string;
114115
path: string;
115116
title: string;
117+
priority?: number;
116118
};
117119

118120
type ThemeEntry = {
@@ -307,12 +309,14 @@ function extractDynamicConfig(
307309
);
308310
config.entityTabs = Object.entries(frontend).reduce<EntityTabEntry[]>(
309311
(accEntityTabs, [scope, { entityTabs }]) => {
312+
// console.log('accEntityTabs',accEntityTabs,scope,entityTabs)
310313
accEntityTabs.push(
311314
...(entityTabs ?? []).map(entityTab => ({
312315
...entityTab,
313316
scope,
314317
})),
315318
);
319+
console.log('accEntityTabs', accEntityTabs);
316320
return accEntityTabs;
317321
},
318322
[],

0 commit comments

Comments
 (0)