bug: no service and loading check are added (#934)

This commit is contained in:
palash-signoz 2022-04-01 17:59:44 +05:30 committed by GitHub
parent d085506d3e
commit a566b5dc97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 38 deletions

View File

@ -1,12 +1,13 @@
/* eslint-disable */ /* eslint-disable */
//@ts-nocheck //@ts-nocheck
import { Card } from 'antd';
import Spinner from 'components/Spinner'; import Spinner from 'components/Spinner';
import React, { useEffect, useRef } from 'react'; import React, { useEffect, useRef } from 'react';
import { ForceGraph2D } from 'react-force-graph'; import { ForceGraph2D } from 'react-force-graph';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { RouteComponentProps, withRouter } from 'react-router-dom'; import { RouteComponentProps, withRouter } from 'react-router-dom';
import { getDetailedServiceMapItems, getServiceMapItems } from 'store/actions'; import { getDetailedServiceMapItems, ServiceMapStore } from 'store/actions';
import { AppState } from 'store/reducers'; import { AppState } from 'store/reducers';
import styled from 'styled-components'; import styled from 'styled-components';
import { GlobalTime } from 'types/actions/globalTime'; import { GlobalTime } from 'types/actions/globalTime';
@ -31,9 +32,8 @@ const Container = styled.div`
`; `;
interface ServiceMapProps extends RouteComponentProps<any> { interface ServiceMapProps extends RouteComponentProps<any> {
serviceMap: serviceMapStore; serviceMap: ServiceMapStore;
globalTime: GlobalTime; globalTime: GlobalTime;
getServiceMapItems: (time: GlobalTime) => void;
getDetailedServiceMapItems: (time: GlobalTime) => void; getDetailedServiceMapItems: (time: GlobalTime) => void;
} }
interface graphNode { interface graphNode {
@ -53,29 +53,32 @@ export interface graphDataType {
function ServiceMap(props: ServiceMapProps): JSX.Element { function ServiceMap(props: ServiceMapProps): JSX.Element {
const fgRef = useRef(); const fgRef = useRef();
const { const { getDetailedServiceMapItems, globalTime, serviceMap } = props;
getDetailedServiceMapItems,
getServiceMapItems,
globalTime,
serviceMap,
} = props;
useEffect(() => { useEffect(() => {
/* /*
Call the apis only when the route is loaded. Call the apis only when the route is loaded.
Check this issue: https://github.com/SigNoz/signoz/issues/110 Check this issue: https://github.com/SigNoz/signoz/issues/110
*/ */
getServiceMapItems(globalTime);
getDetailedServiceMapItems(globalTime); getDetailedServiceMapItems(globalTime);
}, [globalTime, getServiceMapItems, getDetailedServiceMapItems]); }, [globalTime, getDetailedServiceMapItems]);
useEffect(() => { useEffect(() => {
fgRef.current && fgRef.current.d3Force('charge').strength(-400); fgRef.current && fgRef.current.d3Force('charge').strength(-400);
}); });
if (!serviceMap.items.length || !serviceMap.services.length) {
if (serviceMap.loading) {
return <Spinner size="large" tip="Loading..." />; return <Spinner size="large" tip="Loading..." />;
} }
if (!serviceMap.loading && serviceMap.items.length === 0) {
return (
<Container>
<Card>No Service Found</Card>
</Container>
);
}
const zoomToService = (value: string): void => { const zoomToService = (value: string): void => {
fgRef && fgRef &&
fgRef.current && fgRef.current &&
@ -149,7 +152,6 @@ const mapStateToProps = (
export default withRouter( export default withRouter(
connect(mapStateToProps, { connect(mapStateToProps, {
getServiceMapItems,
getDetailedServiceMapItems, getDetailedServiceMapItems,
})(ServiceMap), })(ServiceMap),
); );

View File

@ -7,6 +7,7 @@ import { ActionTypes } from './types';
export interface ServiceMapStore { export interface ServiceMapStore {
items: ServicesMapItem[]; items: ServicesMapItem[];
services: ServicesItem[]; services: ServicesItem[];
loading: boolean;
} }
export interface ServicesItem { export interface ServicesItem {
@ -37,38 +38,39 @@ export interface ServicesAction {
payload: ServicesItem[]; payload: ServicesItem[];
} }
export const getServiceMapItems = (globalTime: GlobalTime) => { export interface ServiceMapLoading {
return async (dispatch: Dispatch): Promise<void> => { type: ActionTypes.serviceMapLoading;
dispatch<ServiceMapItemAction>({ payload: {
type: ActionTypes.getServiceMapItems, loading: ServiceMapStore['loading'];
payload: [],
});
const requestString = `/serviceMapDependencies?start=${globalTime.minTime}&end=${globalTime.maxTime}`;
const response = await api.get<ServicesMapItem[]>(requestString);
dispatch<ServiceMapItemAction>({
type: ActionTypes.getServiceMapItems,
payload: response.data,
});
};
}; };
}
export const getDetailedServiceMapItems = (globalTime: GlobalTime) => { export const getDetailedServiceMapItems = (globalTime: GlobalTime) => {
return async (dispatch: Dispatch): Promise<void> => { return async (dispatch: Dispatch): Promise<void> => {
dispatch<ServicesAction>({
type: ActionTypes.getServices,
payload: [],
});
const requestString = `/services?start=${globalTime.minTime}&end=${globalTime.maxTime}`; const requestString = `/services?start=${globalTime.minTime}&end=${globalTime.maxTime}`;
const response = await api.get<ServicesItem[]>(requestString); const serviceMapDependencies = `/serviceMapDependencies?start=${globalTime.minTime}&end=${globalTime.maxTime}`;
const [serviceMapDependenciesResponse, response] = await Promise.all([
api.get<ServicesMapItem[]>(serviceMapDependencies),
api.get<ServicesItem[]>(requestString),
]);
dispatch<ServicesAction>({ dispatch<ServicesAction>({
type: ActionTypes.getServices, type: ActionTypes.getServices,
payload: response.data, payload: response.data,
}); });
dispatch<ServiceMapItemAction>({
type: ActionTypes.getServiceMapItems,
payload: serviceMapDependenciesResponse.data,
});
dispatch<ServiceMapLoading>({
type: ActionTypes.serviceMapLoading,
payload: {
loading: false,
},
});
}; };
}; };

View File

@ -1,14 +1,22 @@
import { ServiceMapItemAction, ServicesAction } from './serviceMap'; import {
ServiceMapItemAction,
ServiceMapLoading,
ServicesAction,
} from './serviceMap';
import { GetUsageDataAction } from './usage'; import { GetUsageDataAction } from './usage';
export enum ActionTypes { export enum ActionTypes {
updateTraceFilters = 'UPDATE_TRACES_FILTER',
updateTimeInterval = 'UPDATE_TIME_INTERVAL', updateTimeInterval = 'UPDATE_TIME_INTERVAL',
getServiceMapItems = 'GET_SERVICE_MAP_ITEMS', getServiceMapItems = 'GET_SERVICE_MAP_ITEMS',
getServices = 'GET_SERVICES', getServices = 'GET_SERVICES',
getUsageData = 'GET_USAGE_DATE', getUsageData = 'GET_USAGE_DATE',
fetchTraces = 'FETCH_TRACES', fetchTraces = 'FETCH_TRACES',
fetchTraceItem = 'FETCH_TRACE_ITEM', fetchTraceItem = 'FETCH_TRACE_ITEM',
serviceMapLoading = 'UPDATE_SERVICE_MAP_LOADING',
} }
export type Action = GetUsageDataAction | ServicesAction | ServiceMapItemAction; export type Action =
| GetUsageDataAction
| ServicesAction
| ServiceMapItemAction
| ServiceMapLoading;

View File

@ -3,6 +3,7 @@ import { Action, ActionTypes, ServiceMapStore } from 'store/actions';
const initialState: ServiceMapStore = { const initialState: ServiceMapStore = {
items: [], items: [],
services: [], services: [],
loading: true,
}; };
export const ServiceMapReducer = ( export const ServiceMapReducer = (
@ -20,6 +21,12 @@ export const ServiceMapReducer = (
...state, ...state,
services: action.payload, services: action.payload,
}; };
case ActionTypes.serviceMapLoading: {
return {
...state,
loading: action.payload.loading,
};
}
default: default:
return state; return state;
} }