@@ -1943,68 +1943,93 @@ export const ExecutiveReportButton = (props) => {
1943
1943
infographics : true ,
1944
1944
} ) ;
1945
1945
1946
- // Get real secure score data
1947
- const secureScore = useSecureScore ( ) ;
1946
+ // Only fetch additional data when preview dialog is opened
1947
+ const secureScore = useSecureScore ( { waiting : previewOpen } ) ;
1948
1948
1949
- // Get real license data
1949
+ // Get real license data - only when preview is open
1950
1950
const licenseData = ApiGetCall ( {
1951
1951
url : "/api/ListLicenses" ,
1952
1952
data : {
1953
1953
tenantFilter : settings . currentTenant ,
1954
1954
} ,
1955
1955
queryKey : `licenses-report-${ settings . currentTenant } ` ,
1956
+ waiting : previewOpen ,
1956
1957
} ) ;
1957
- // Get real device data
1958
+
1959
+ // Get real device data - only when preview is open
1958
1960
const deviceData = ApiGetCall ( {
1959
1961
url : "/api/ListDevices" ,
1960
1962
data : {
1961
1963
tenantFilter : settings . currentTenant ,
1962
1964
} ,
1963
1965
queryKey : `devices-report-${ settings . currentTenant } ` ,
1966
+ waiting : previewOpen ,
1964
1967
} ) ;
1965
1968
1966
- // Get real conditional access policy data
1969
+ // Get real conditional access policy data - only when preview is open
1967
1970
const conditionalAccessData = ApiGetCall ( {
1968
1971
url : "/api/ListConditionalAccessPolicies" ,
1969
1972
data : {
1970
1973
tenantFilter : settings . currentTenant ,
1971
1974
} ,
1972
1975
queryKey : `ca-policies-report-${ settings . currentTenant } ` ,
1976
+ waiting : previewOpen ,
1973
1977
} ) ;
1974
1978
1975
- // Get real standards data
1979
+ // Get real standards data - only when preview is open
1976
1980
const standardsCompareData = ApiGetCall ( {
1977
1981
url : "/api/ListStandardsCompare" ,
1978
1982
data : {
1979
1983
tenantFilter : settings . currentTenant ,
1980
1984
} ,
1981
1985
queryKey : `standards-compare-report-${ settings . currentTenant } ` ,
1986
+ waiting : previewOpen ,
1982
1987
} ) ;
1983
1988
1984
- // Check if all data is loaded (either successful or failed)
1985
- const isDataLoading =
1989
+ // Check if all data is loaded (either successful or failed) - only relevant when preview is open
1990
+ const isDataLoading = previewOpen && (
1986
1991
secureScore . isFetching ||
1987
1992
licenseData . isFetching ||
1988
1993
deviceData . isFetching ||
1989
1994
conditionalAccessData . isFetching ||
1990
- standardsCompareData . isFetching ;
1995
+ standardsCompareData . isFetching
1996
+ ) ;
1991
1997
1992
- const hasAllDataFinished =
1998
+ const hasAllDataFinished = ! previewOpen || (
1993
1999
( secureScore . isSuccess || secureScore . isError ) &&
1994
2000
( licenseData . isSuccess || licenseData . isError ) &&
1995
2001
( deviceData . isSuccess || deviceData . isError ) &&
1996
2002
( conditionalAccessData . isSuccess || conditionalAccessData . isError ) &&
1997
- ( standardsCompareData . isSuccess || standardsCompareData . isError ) ;
2003
+ ( standardsCompareData . isSuccess || standardsCompareData . isError )
2004
+ ) ;
1998
2005
1999
- // Show button when all data is finished loading (regardless of success/failure)
2000
- const shouldShowButton = hasAllDataFinished && ! isDataLoading ;
2006
+ // Button is always available now since we don't need to wait for data
2007
+ const shouldShowButton = true ;
2001
2008
2002
2009
const fileName = `Executive_Report_${ tenantName ?. replace ( / [ ^ a - z A - Z 0 - 9 ] / g, "_" ) || "Tenant" } _${
2003
2010
new Date ( ) . toISOString ( ) . split ( "T" ) [ 0 ]
2004
2011
} .pdf`;
2005
2012
2006
- // Memoize the document to prevent unnecessary re-renders
2013
+ // Memoize the document to prevent unnecessary re-renders - only when dialog is open
2007
2014
const reportDocument = useMemo ( ( ) => {
2015
+ // Don't create document if dialog is closed
2016
+ if ( ! previewOpen ) {
2017
+ return null ;
2018
+ }
2019
+
2020
+ // Only create document if preview is open and data is ready
2021
+ if ( ! hasAllDataFinished ) {
2022
+ return (
2023
+ < Document >
2024
+ < Page size = "A4" style = { { padding : 40 , fontFamily : "Helvetica" } } >
2025
+ < Text style = { { fontSize : 14 , textAlign : "center" , marginTop : 100 } } >
2026
+ Loading report data...
2027
+ </ Text >
2028
+ </ Page >
2029
+ </ Document >
2030
+ ) ;
2031
+ }
2032
+
2008
2033
console . log ( "Creating report document with:" , {
2009
2034
tenantName,
2010
2035
tenantId,
@@ -2052,18 +2077,20 @@ export const ExecutiveReportButton = (props) => {
2052
2077
) ;
2053
2078
}
2054
2079
} , [
2080
+ previewOpen , // Most important - prevents creation when dialog is closed
2081
+ hasAllDataFinished ,
2055
2082
tenantName ,
2056
2083
tenantId ,
2057
2084
userStats ,
2058
2085
standardsData ,
2059
2086
organizationData ,
2060
2087
brandingSettings ,
2061
- secureScore ,
2062
- licenseData ,
2063
- deviceData ,
2064
- conditionalAccessData ,
2065
- standardsCompareData ,
2066
- sectionConfig ,
2088
+ secureScore ?. isSuccess ,
2089
+ licenseData ?. isSuccess ,
2090
+ deviceData ?. isSuccess ,
2091
+ conditionalAccessData ?. isSuccess ,
2092
+ standardsCompareData ?. isSuccess ,
2093
+ JSON . stringify ( sectionConfig ) , // Stringify to prevent reference issues
2067
2094
] ) ;
2068
2095
2069
2096
// Handle section toggle
@@ -2084,6 +2111,11 @@ export const ExecutiveReportButton = (props) => {
2084
2111
} ) ;
2085
2112
} ;
2086
2113
2114
+ // Close handler with cleanup
2115
+ const handleClose = ( ) => {
2116
+ setPreviewOpen ( false ) ;
2117
+ } ;
2118
+
2087
2119
// Section configuration options
2088
2120
const sectionOptions = [
2089
2121
{
@@ -2123,32 +2155,9 @@ export const ExecutiveReportButton = (props) => {
2123
2155
} ,
2124
2156
] ;
2125
2157
2126
- // Don't render the button if data is not ready
2127
- if ( ! shouldShowButton ) {
2128
- return (
2129
- < Tooltip title = "Loading report data..." >
2130
- < Button
2131
- variant = "contained"
2132
- startIcon = { < PictureAsPdf /> }
2133
- disabled = { true }
2134
- sx = { {
2135
- fontWeight : "bold" ,
2136
- textTransform : "none" ,
2137
- borderRadius : 2 ,
2138
- boxShadow : "0 2px 8px rgba(0,0,0,0.15)" ,
2139
- transition : "all 0.2s ease-in-out" ,
2140
- } }
2141
- { ...other }
2142
- >
2143
- Loading Data...
2144
- </ Button >
2145
- </ Tooltip >
2146
- ) ;
2147
- }
2148
-
2149
2158
return (
2150
2159
< >
2151
- { /* Main Executive Summary Button */ }
2160
+ { /* Main Executive Summary Button - Always available */ }
2152
2161
< Tooltip title = "Generate Executive Report with preview and configuration" >
2153
2162
< Button
2154
2163
variant = "contained"
@@ -2170,7 +2179,7 @@ export const ExecutiveReportButton = (props) => {
2170
2179
{ /* Combined Preview and Configuration Dialog */ }
2171
2180
< Dialog
2172
2181
open = { previewOpen }
2173
- onClose = { ( ) => setPreviewOpen ( false ) }
2182
+ onClose = { handleClose }
2174
2183
maxWidth = "xl"
2175
2184
fullWidth
2176
2185
sx = { {
@@ -2193,7 +2202,7 @@ export const ExecutiveReportButton = (props) => {
2193
2202
< Typography variant = "h6" component = "div" >
2194
2203
Executive Report - { tenantName }
2195
2204
</ Typography >
2196
- < IconButton onClick = { ( ) => setPreviewOpen ( false ) } size = "small" >
2205
+ < IconButton onClick = { handleClose } size = "small" >
2197
2206
< Close />
2198
2207
</ IconButton >
2199
2208
</ DialogTitle >
@@ -2303,17 +2312,47 @@ export const ExecutiveReportButton = (props) => {
2303
2312
2304
2313
{ /* Right Panel - PDF Preview */ }
2305
2314
< Box sx = { { flex : 1 , height : "100%" } } >
2306
- < PDFViewer
2307
- key = { JSON . stringify ( sectionConfig ) } // Force re-render when sections change
2308
- style = { {
2309
- width : "100%" ,
2310
- height : "100%" ,
2311
- border : "none" ,
2312
- } }
2313
- showToolbar = { true }
2314
- >
2315
- { reportDocument }
2316
- </ PDFViewer >
2315
+ { isDataLoading ? (
2316
+ < Box
2317
+ sx = { {
2318
+ display : "flex" ,
2319
+ flexDirection : "column" ,
2320
+ alignItems : "center" ,
2321
+ justifyContent : "center" ,
2322
+ height : "100%" ,
2323
+ gap : 2 ,
2324
+ } }
2325
+ >
2326
+ < Typography variant = "h6" > Loading Report Data...</ Typography >
2327
+ < Typography variant = "body2" color = "text.secondary" >
2328
+ Fetching additional data for comprehensive report generation
2329
+ </ Typography >
2330
+ </ Box >
2331
+ ) : reportDocument ? (
2332
+ < PDFViewer
2333
+ style = { {
2334
+ width : "100%" ,
2335
+ height : "100%" ,
2336
+ border : "none" ,
2337
+ } }
2338
+ showToolbar = { true }
2339
+ >
2340
+ { reportDocument }
2341
+ </ PDFViewer >
2342
+ ) : (
2343
+ < Box
2344
+ sx = { {
2345
+ display : "flex" ,
2346
+ alignItems : "center" ,
2347
+ justifyContent : "center" ,
2348
+ height : "100%" ,
2349
+ } }
2350
+ >
2351
+ < Typography variant = "body1" color = "text.secondary" >
2352
+ Report preview will appear here
2353
+ </ Typography >
2354
+ </ Box >
2355
+ ) }
2317
2356
</ Box >
2318
2357
</ DialogContent >
2319
2358
@@ -2328,7 +2367,7 @@ export const ExecutiveReportButton = (props) => {
2328
2367
< Button
2329
2368
variant = "contained"
2330
2369
startIcon = { < Download /> }
2331
- disabled = { ! shouldShowButton }
2370
+ disabled = { isDataLoading }
2332
2371
sx = { { minWidth : 140 } }
2333
2372
onClick = { ( ) => {
2334
2373
// Create document dynamically when download is clicked
@@ -2373,10 +2412,10 @@ export const ExecutiveReportButton = (props) => {
2373
2412
} ) ;
2374
2413
} }
2375
2414
>
2376
- Download PDF
2415
+ { isDataLoading ? "Loading..." : " Download PDF" }
2377
2416
</ Button >
2378
2417
2379
- < Button onClick = { ( ) => setPreviewOpen ( false ) } variant = "outlined" >
2418
+ < Button onClick = { handleClose } variant = "outlined" >
2380
2419
Close
2381
2420
</ Button >
2382
2421
</ DialogActions >
0 commit comments