changed alarm count gql

This commit is contained in:
Sean Macfarlane
2020-07-16 17:03:03 -04:00
parent 0f7433b49f
commit caeaf8bdf5
2 changed files with 8 additions and 39 deletions

View File

@@ -1,9 +1,9 @@
import React, { useContext, useMemo } from 'react';
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import { useLocation } from 'react-router-dom';
import { useApolloClient, useQuery } from '@apollo/react-hooks';
import { GET_ALL_STATUS_ALARMS } from 'graphql/queries';
import { GET_ALARM_COUNT } from 'graphql/queries';
import { AppLayout as Layout } from '@tip-wlan/wlan-cloud-ui-library';
@@ -19,27 +19,10 @@ const MasterLayout = ({ children }) => {
const client = useApolloClient();
const location = useLocation();
const { data } = useQuery(GET_ALL_STATUS_ALARMS, {
variables: { customerId, statusDataTypes: ['CUSTOMER_DASHBOARD'] },
const { data } = useQuery(GET_ALARM_COUNT, {
variables: { customerId },
});
const alarmsCount = useMemo(() => {
const alarmsArr =
(data &&
data.getAllStatus &&
data.getAllStatus.items[0] &&
data.getAllStatus.items[0].alarmsCount &&
data.getAllStatus.items[0].alarmsCount.totalCountsPerAlarmCodeMap) ||
{};
let totalAlarms = 0;
if (alarmsArr) {
Object.keys(alarmsArr).forEach(i => {
totalAlarms += alarmsArr[i];
});
}
return totalAlarms;
}, [data]);
const handleLogout = () => {
removeItem(AUTH_TOKEN);
client.resetStore();
@@ -117,7 +100,7 @@ const MasterLayout = ({ children }) => {
locationState={location}
menuItems={menuItems}
mobileMenuItems={mobileMenuItems}
totalAlarms={alarmsCount}
totalAlarms={data && data.getAlarmCount}
>
{children}
</Layout>

View File

@@ -224,22 +224,8 @@ export const GET_ALL_STATUS = gql`
}
`;
export const GET_ALL_STATUS_ALARMS = gql`
query GetAllStatus($customerId: Int!, $statusDataTypes: [String]) {
getAllStatus(customerId: $customerId, statusDataTypes: $statusDataTypes) {
items {
customerId
detailsJSON
details {
equipmentCountPerOui
clientCountPerOui
}
alarmsCount
}
context {
lastPage
cursor
}
}
export const GET_ALARM_COUNT = gql`
query GetAlarmCount($customerId: Int!) {
getAlarmCount(customerId: $customerId)
}
`;