@@ -43,6 +43,41 @@ const PageContent: React.FC = () => {
4343 [ baseConfluenceUrl ]
4444 ) ;
4545
46+ const fetchMissingPageTitles = useCallback (
47+ async ( pages : EntityPageI [ ] ) : Promise < EntityPageI [ ] > => {
48+ if ( pages . length === 0 ) return [ ] ;
49+ const updatedPages = await Promise . all (
50+ pages . map ( async ( page ) => {
51+ if ( page . title && page . title . length > 0 ) {
52+ return page ;
53+ }
54+ try {
55+ const contentJSON = await fetchConfluencePageContent (
56+ baseConfluenceUrl ,
57+ page . id
58+ ) ;
59+ return {
60+ ...page ,
61+ title :
62+ page . title && page . title . length > 0
63+ ? page . title
64+ : contentJSON . title ,
65+ } ;
66+ } catch ( error ) {
67+ console . error (
68+ `Error fetching page title for page with ID ${ page . id } : ${
69+ ( error as Error ) . message
70+ } `
71+ ) ;
72+ return page ;
73+ }
74+ } )
75+ ) ;
76+ return updatedPages ;
77+ } ,
78+ [ baseConfluenceUrl ]
79+ ) ;
80+
4681 useEffect ( ( ) => {
4782 if ( ! context ?. apiBaseUrl ) return ;
4883 const getConfig = async ( ) : Promise < void > => {
@@ -85,7 +120,10 @@ const PageContent: React.FC = () => {
85120 setErrorStr ( "No Confluence details exist on this entity." ) ;
86121 return ;
87122 }
88- setEntityPages ( fetchedEntityPages ) ;
123+ const pagesWithTitles = await fetchMissingPageTitles (
124+ fetchedEntityPages
125+ ) ;
126+ setEntityPages ( pagesWithTitles ) ;
89127 } catch ( error ) {
90128 setErrorStr (
91129 `Error retrieving Confluence page: ${ ( error as Error ) . message } `
@@ -95,7 +133,12 @@ const PageContent: React.FC = () => {
95133 }
96134 } ;
97135 void fetchEntityYamlData ( ) ;
98- } , [ context . apiBaseUrl , context . entity ?. tag , baseConfluenceUrl ] ) ;
136+ } , [
137+ context . apiBaseUrl ,
138+ context . entity ?. tag ,
139+ baseConfluenceUrl ,
140+ fetchMissingPageTitles ,
141+ ] ) ;
99142
100143 useEffect ( ( ) => {
101144 const setFirstPageContent = async ( ) : Promise < void > => {
0 commit comments