@@ -4,15 +4,20 @@ import {
4
4
InfoCard as BSInfoCard ,
5
5
CopyTextButton ,
6
6
} from '@backstage/core-components' ;
7
+ import { configApiRef , useApi } from '@backstage/core-plugin-api' ;
7
8
8
9
import UnfoldLessIcon from '@mui/icons-material/UnfoldLess' ;
9
10
import UnfoldMoreIcon from '@mui/icons-material/UnfoldMore' ;
10
11
import IconButton from '@mui/material/IconButton' ;
11
12
import Typography from '@mui/material/Typography' ;
12
13
13
14
import buildMetadata from '../../build-metadata.json' ;
15
+ import { BuildInfo } from '../../types/types' ;
14
16
15
17
export const InfoCard = ( ) => {
18
+ const config = useApi ( configApiRef ) ;
19
+ const buildInfo : BuildInfo | undefined = config . getOptional ( 'buildInfo' ) ;
20
+
16
21
const [ showBuildInformation , setShowBuildInformation ] =
17
22
React . useState < boolean > (
18
23
( ) =>
@@ -32,24 +37,47 @@ export const InfoCard = () => {
32
37
}
33
38
} ;
34
39
35
- let clipboardText = buildMetadata . title ;
36
- if ( buildMetadata . card ?. length ) {
40
+ const buildDetailsTitle = ( ) => {
41
+ if ( buildInfo ?. title && Object . keys ( buildInfo ?. card ?? { } ) . length > 0 ) {
42
+ return buildInfo . title ;
43
+ }
44
+ if ( ! buildInfo ?. title && Object . keys ( buildInfo ?. card ?? { } ) . length > 0 ) {
45
+ // eslint-disable-next-line no-console
46
+ console . warn (
47
+ 'Set a custom title for your build details to display your preferred title.' ,
48
+ ) ;
49
+ return 'Build Metadata' ;
50
+ }
51
+ return buildMetadata . title ;
52
+ } ;
53
+
54
+ let clipboardText = buildDetailsTitle ( ) ;
55
+ const buildDetails = Object . entries (
56
+ buildInfo ?. card && Object . keys ( buildInfo . card ) . length > 0
57
+ ? buildInfo . card
58
+ : buildMetadata ?. card || { } ,
59
+ ) . map ( ( [ key , value ] ) => `${ key } : ${ value } ` ) ;
60
+ if ( buildDetails ?. length ) {
37
61
clipboardText += '\n\n' ;
38
- buildMetadata . card . forEach ( text => {
62
+ buildDetails . forEach ( text => {
39
63
clipboardText += `${ text } \n` ;
40
64
} ) ;
41
65
}
42
66
43
- const filteredCards = showBuildInformation
44
- ? buildMetadata . card
45
- : buildMetadata . card . filter (
46
- text =>
47
- text . startsWith ( 'RHDH Version' ) ||
48
- text . startsWith ( 'Backstage Version' ) ,
49
- ) ;
67
+ const filteredContent = ( ) => {
68
+ if ( Object . keys ( buildInfo ?. card ?? { } ) ?. length > 0 ) {
69
+ return buildDetails . slice ( 0 , 2 ) ;
70
+ }
71
+ return buildDetails . filter (
72
+ text =>
73
+ text . startsWith ( 'RHDH Version' ) || text . startsWith ( 'Backstage Version' ) ,
74
+ ) ;
75
+ } ;
76
+
77
+ const filteredCards = showBuildInformation ? buildDetails : filteredContent ( ) ;
50
78
// Ensure that we show always some information
51
79
const versionInfo =
52
- filteredCards . length > 0 ? filteredCards . join ( '\n' ) : buildMetadata . card [ 0 ] ;
80
+ filteredCards . length > 0 ? filteredCards . join ( '\n' ) : buildDetails [ 0 ] ;
53
81
54
82
/**
55
83
* Show all build information and automatically select them
@@ -80,7 +108,7 @@ export const InfoCard = () => {
80
108
81
109
return (
82
110
< BSInfoCard
83
- title = { buildMetadata . title }
111
+ title = { buildDetailsTitle ( ) }
84
112
action = {
85
113
// This is a workaround to ensure that the buttons doesn't increase the header size.
86
114
< div style = { { position : 'relative' } } >
0 commit comments