-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement and show upptime status in footer
Fetching data from the readme of the repo hehe - couldn't find a better api
- Loading branch information
1 parent
300d8a7
commit 2659bc4
Showing
6 changed files
with
180 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
|
||
export type SystemStatus = { | ||
status: 'operational' | 'degraded' | 'major'; | ||
message: string; | ||
}; | ||
|
||
type UptimeService = { | ||
name: string; | ||
status: 'up' | 'down' | 'degraded'; | ||
uptime: string; | ||
}; | ||
|
||
export const fetchSystemStatus = createAsyncThunk( | ||
'status/fetch', | ||
async (): Promise<SystemStatus> => { | ||
const response = await fetch( | ||
'https://raw.githubusercontent.com/webkom/uptime/master/history/summary.json', | ||
); | ||
|
||
if (!response.ok) { | ||
throw new Error('Failed to fetch system status'); | ||
} | ||
|
||
const data = (await response.json()) as UptimeService[]; | ||
|
||
const servicesDown = data.filter( | ||
(service) => service.status === 'down', | ||
).length; | ||
const servicesDegraded = data.filter( | ||
(service) => service.status === 'degraded', | ||
).length; | ||
|
||
let status: SystemStatus['status']; | ||
let message: string; | ||
|
||
if (servicesDown > 0) { | ||
status = 'major'; | ||
message = `${servicesDown} ${servicesDown === 1 ? 'tjeneste er' : 'tjenester er'} nede`; | ||
} else if (servicesDegraded > 0) { | ||
status = 'degraded'; | ||
message = `${servicesDegraded} ${servicesDegraded === 1 ? 'tjeneste har' : 'tjenester har'} redusert ytelse`; | ||
} else { | ||
status = 'operational'; | ||
message = `Alle tjenester opererer normalt`; | ||
} | ||
|
||
return { status, message }; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
import { fetchSystemStatus } from 'app/actions/StatusActions'; | ||
import { EntityType } from 'app/store/models/entities'; | ||
import createLegoAdapter from 'app/utils/legoAdapter/createLegoAdapter'; | ||
import type { SystemStatus } from 'app/actions/StatusActions'; | ||
import type { RootState } from 'app/store/createRootReducer'; | ||
|
||
type ExtraStatusState = { | ||
systemStatus: SystemStatus | null; | ||
}; | ||
|
||
const legoAdapter = createLegoAdapter(EntityType.SystemStatus); | ||
|
||
const statusSlice = createSlice({ | ||
name: EntityType.SystemStatus, | ||
initialState: legoAdapter.getInitialState({ | ||
systemStatus: null, | ||
} as ExtraStatusState), | ||
reducers: {}, | ||
extraReducers: legoAdapter.buildReducers({ | ||
extraCases: (addCase) => { | ||
addCase(fetchSystemStatus.fulfilled, (state, action) => { | ||
state.systemStatus = action.payload; | ||
}); | ||
}, | ||
}), | ||
}); | ||
|
||
export default statusSlice.reducer; | ||
|
||
export const selectSystemStatus = (state: RootState) => | ||
state.status.systemStatus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters