Skip to content

Commit 93097c3

Browse files
Fix hostgroup, servicegroup, programstatus data after change to axios
1 parent 0edac56 commit 93097c3

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

src/atoms/programAtom.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@ import { atom } from 'jotai';
22

33
export const programStatusIsFetchingAtom = atom(false);
44

5+
interface ProgramStatus {
6+
program_start: number;
7+
version: string;
8+
}
9+
510
export interface ProgramStatusWrap {
611
error: boolean;
712
errorCount: number;
813
errorMessage: string;
914
lastUpdate: number;
10-
response: Record<string, any>;
15+
response: ProgramStatus | null;
1116
}
1217

1318
const initialState: ProgramStatusWrap = {
1419
error: false,
1520
errorCount: 0,
1621
errorMessage: '',
1722
lastUpdate: 0,
18-
response: {}
23+
response: null
1924
};
2025

2126
export const programStatusAtom = atom(initialState);

src/components/DashboardFetch.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect } from "react";
1+
import { useEffect } from "react";
22
// State Management
33
import { useAtomValue, useSetAtom } from 'jotai';
44
import { bigStateAtom, clientSettingsAtom, clientSettingsInitial } from '../atoms/settingsState';
@@ -10,7 +10,7 @@ import axios from 'axios';
1010
import { programStatusAtom } from "atoms/programAtom";
1111
import { handleFetchFail } from "helpers/axios";
1212
// Types
13-
import { CommentListObject, CommentListResponseObject } from "types/commentTypes";
13+
import { CommentListObject } from "types/commentTypes";
1414

1515
const DashboardFetch = () => {
1616

@@ -63,7 +63,7 @@ const DashboardFetch = () => {
6363
}
6464

6565
// Pluck out the commentlist result
66-
const commentlist: Record<string, CommentListResponseObject> = response.data.data.commentlist;
66+
const commentlist = _.get(response.data.data, 'commentlist', {});
6767

6868
// Massage the commentlist so we have one key per hostname
6969
const commentlistObject: CommentListObject = {
@@ -152,7 +152,7 @@ const DashboardFetch = () => {
152152
}
153153

154154
// Pluck out the hostgrouplist result
155-
const hostgroup = _.get(response.data, 'hostgrouplist', {});
155+
const hostgroup = _.get(response.data.data, 'hostgrouplist', {});
156156

157157
setHostgroup({
158158
error: false,
@@ -195,8 +195,8 @@ const DashboardFetch = () => {
195195
return;
196196
}
197197

198-
// Pluck out the hostgrouplist result
199-
const servicegroup = _.get(response.data, 'servicegrouplist', {});
198+
// Pluck out the servicegrouplist result
199+
const servicegroup = _.get(response.data.data, 'servicegrouplist', {});
200200

201201
setServicegroup({
202202
error: false,
@@ -239,12 +239,15 @@ const DashboardFetch = () => {
239239
return;
240240
}
241241

242+
// Pluck out the programstatus result
243+
const programstatus = _.get(response.data.data, 'programstatus', {});
244+
242245
setProgramStatus({
243246
error: false,
244247
errorCount: 0,
245248
errorMessage: '',
246249
lastUpdate: new Date().getTime(),
247-
response: response.data,
250+
response: programstatus,
248251
});
249252

250253
}).catch(error => {

src/components/summary/Summary.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export default function Summary() {
2525
const programStatus = useAtomValue(programStatusAtom);
2626

2727
// Extract a couple of fields out of programStatus that we are using: "program_start" and "version"
28-
const programStart = programStatus?.response?.data?.programstatus?.program_start;
29-
const programVersion = programStatus?.response?.data?.programstatus?.version;
28+
const programStart = programStatus?.response?.program_start;
29+
const programVersion = programStatus?.response?.version;
3030

3131
let quietForMs: number | null = null;
3232
if (alertState && alertState.responseArray && alertState.responseArray.length > 0) {

0 commit comments

Comments
 (0)