@@ -3,9 +3,9 @@ import { openDB } from "idb";
3
3
import { createContext , useContext , useState } from "react" ;
4
4
import { Dic } from "~/Helpers/Entities" ;
5
5
import { Logger } from "~/Helpers/Logger" ;
6
- import { StatusEntity } from "./Status.Entities" ;
6
+ import { IncidentEntityV2 , StatusEntityV2 } from "./Status.Entities" ;
7
7
import { IStatusContext } from "./Status.Models" ;
8
- import { Transformer } from "./Status.Trans" ;
8
+ import { TransformerV2 } from "./Status.Trans.V2 " ;
9
9
10
10
/**
11
11
* @author Aloento
@@ -94,20 +94,35 @@ export function useStatus() {
94
94
*/
95
95
export function StatusContext ( { children } : { children : JSX . Element } ) {
96
96
const [ db , setDB ] = useState ( DB ) ;
97
+
97
98
const url = process . env . SD_BACKEND_URL ;
98
99
const uri = process . env . SD_BACKEND_API ;
100
+ const file = process . env . SD_BACKEND_FILE === "true" ;
99
101
100
102
useRequest (
101
103
async ( ) => {
102
- log . info ( "Loading status data..." ) ;
103
- const response = await fetch ( `${ url } ${ uri } /component_status` ) ;
104
- const data = await response . json ( ) ;
105
- log . debug ( "Status data loaded." , data ) ;
106
- return data as StatusEntity [ ] ;
104
+ log . info ( `Loading status data from v2...` ) ;
105
+
106
+ const compLink = file ? "/mock.json" : `${ url } ${ uri } /components` ;
107
+ const compRes = await fetch ( compLink ) ;
108
+ const compData = await compRes . json ( ) ;
109
+
110
+ log . debug ( "Components Status loaded." , compData ) ;
111
+
112
+ const eventLink = file ? "/event.json" : `${ url } ${ uri } /incidents` ;
113
+ const eventRes = await fetch ( eventLink ) ;
114
+ const eventData = ( await eventRes . json ( ) ) . data ;
115
+
116
+ log . debug ( "Events loaded." , eventData ) ;
117
+
118
+ return {
119
+ Components : compData as StatusEntityV2 [ ] ,
120
+ Events : eventData as IncidentEntityV2 [ ]
121
+ } ;
107
122
} ,
108
123
{
109
124
cacheKey : log . namespace ,
110
- onSuccess : ( list ) => update ( Transformer ( list ) ) ,
125
+ onSuccess : ( res ) => update ( TransformerV2 ( res ) ) ,
111
126
}
112
127
) ;
113
128
0 commit comments