1- import React from "react" ;
1+ import React , { useEffect , useState } from "react" ;
22import Age from "../../../ui/Age/Age" ;
33import ViewLayout from "./ViewLayout" ;
44import ViewWithSections from "./ViewWithSections" ;
55import { useViewData } from "../hooks/useViewData" ;
66import { ErrorViewer } from "@flanksource-ui/components/ErrorViewer" ;
7+ import {
8+ Dialog ,
9+ DialogContent ,
10+ DialogDescription ,
11+ DialogHeader ,
12+ DialogTitle
13+ } from "@flanksource-ui/components/ui/dialog" ;
714
815interface SingleViewProps {
916 id : string ;
@@ -19,32 +26,43 @@ const SingleView: React.FC<SingleViewProps> = ({ id }) => {
1926 currentVariables,
2027 handleForceRefresh
2128 } = useViewData ( { viewId : id } ) ;
29+ const [ refreshErrorOpen , setRefreshErrorOpen ] = useState ( false ) ;
2230
23- if ( isLoading && ! viewResult ) {
31+ const refreshError =
32+ viewResult ?. refreshStatus === "error" ? viewResult . refreshError : undefined ;
33+ const isCachedResponse = viewResult ?. responseSource === "cache" ;
34+
35+ useEffect ( ( ) => {
36+ if ( refreshError && isCachedResponse ) {
37+ setRefreshErrorOpen ( true ) ;
38+ }
39+ } , [ refreshError , isCachedResponse , viewResult ?. requestFingerprint ] ) ;
40+
41+ if ( error && ! viewResult ) {
2442 return (
2543 < ViewLayout
26- title = "View"
44+ title = "View Error "
2745 icon = "workflow"
2846 onRefresh = { handleForceRefresh }
2947 centered
3048 >
31- < div className = "text-center" >
32- < div className = "mx-auto mb-4 h-12 w-12 animate-spin rounded-full border-b-2 border-blue-600" > </ div >
33- < p className = "text-gray-600" > Loading view results...</ p >
34- </ div >
49+ < ErrorViewer error = { error } className = "mx-auto max-w-3xl" />
3550 </ ViewLayout >
3651 ) ;
3752 }
3853
39- if ( error ) {
54+ if ( isLoading && ! viewResult ) {
4055 return (
4156 < ViewLayout
42- title = "View Error "
57+ title = "View"
4358 icon = "workflow"
4459 onRefresh = { handleForceRefresh }
4560 centered
4661 >
47- < ErrorViewer error = { error } className = "mx-auto max-w-3xl" />
62+ < div className = "text-center" >
63+ < div className = "mx-auto mb-4 h-12 w-12 animate-spin rounded-full border-b-2 border-blue-600" > </ div >
64+ < p className = "text-gray-600" > Loading view results...</ p >
65+ </ div >
4866 </ ViewLayout >
4967 ) ;
5068 }
@@ -68,27 +86,43 @@ const SingleView: React.FC<SingleViewProps> = ({ id }) => {
6886 const { icon, title, name } = viewResult ;
6987
7088 return (
71- < ViewLayout
72- title = { title || name }
73- icon = { icon || "workflow" }
74- onRefresh = { handleForceRefresh }
75- loading = { isFetching }
76- extra = {
77- viewResult . lastRefreshedAt && (
78- < p className = "text-sm text-gray-500" >
79- Last refreshed:{ " " }
80- < Age from = { viewResult . lastRefreshedAt } format = "full" />
81- </ p >
82- )
83- }
84- >
85- < ViewWithSections
86- className = "flex h-full w-full flex-1 flex-col overflow-y-auto px-6"
87- viewResult = { viewResult }
88- aggregatedVariables = { aggregatedVariables }
89- currentVariables = { currentVariables }
90- />
91- </ ViewLayout >
89+ < >
90+ < Dialog open = { refreshErrorOpen } onOpenChange = { setRefreshErrorOpen } >
91+ < DialogContent className = "max-w-xl" >
92+ < DialogHeader >
93+ < DialogTitle > View refresh failed</ DialogTitle >
94+ < DialogDescription >
95+ The view failed to refresh. You are seeing cached data from the
96+ last successful refresh.
97+ </ DialogDescription >
98+ </ DialogHeader >
99+ { refreshError ? (
100+ < ErrorViewer error = { refreshError } className = "mt-4" />
101+ ) : null }
102+ </ DialogContent >
103+ </ Dialog >
104+ < ViewLayout
105+ title = { title || name }
106+ icon = { icon || "workflow" }
107+ onRefresh = { handleForceRefresh }
108+ loading = { isFetching }
109+ extra = {
110+ viewResult . lastRefreshedAt && (
111+ < p className = "text-sm text-gray-500" >
112+ Last refreshed:{ " " }
113+ < Age from = { viewResult . lastRefreshedAt } format = "full" />
114+ </ p >
115+ )
116+ }
117+ >
118+ < ViewWithSections
119+ className = "flex h-full w-full flex-1 flex-col overflow-y-auto px-6"
120+ viewResult = { viewResult }
121+ aggregatedVariables = { aggregatedVariables }
122+ currentVariables = { currentVariables }
123+ />
124+ </ ViewLayout >
125+ </ >
92126 ) ;
93127} ;
94128
0 commit comments