162 lines
4.0 KiB
TypeScript
Raw Normal View History

/* eslint-disable */
//@ts-nocheck
import { Card } from 'antd';
import Spinner from 'components/Spinner';
import React, { useEffect, useRef } from 'react';
import { ForceGraph2D } from 'react-force-graph';
2022-05-12 15:47:47 +05:30
import { connect, useSelector } from 'react-redux';
import { RouteComponentProps, withRouter } from 'react-router-dom';
import { getDetailedServiceMapItems, ServiceMapStore } from 'store/actions';
feat: Metrics (#281) * refactor: store is updated * temp * fix: eslint error is fixed * fix:eslint linting error is updated * chore: react-grid-layout is added * chore: linting changes are updated * chore: linting changes are updated * chore: @types/node is moved to devDependecies and @types/react-grid-layout is added * chore: tsconfig is updated * chore: updateUrl function is updated * feat: All Dashboard is updated * feat: All Dashboard page is updated * feat: New Dashboard is added * feat: App Layout is updated * feat: Add Tags is updated * chore: uuid package is added * chore: AppRoutes is updated * chore: UI components are updated * chore: baseUrl is added in the apiUrl and removed from other api request * chore: commonApi Response is updated * chore: ErrorResponse handler is updated * chore: useFetch hook is made * chore: axios instance is updated * chore:some of the changes are updated * chore: list of all dashboard types is updated * chore: logic is updated to the global state * chore: all dashboard data is fetched from the global state * chore: unnessary prop is removed * chore: changes are updated * chore: getAll and create is updated * chore: getDashboard is updated * chore: isEditMode is moved to the global state * chore: get,getAll is updated * chore: update title,tags,description is now fixed * chore: new widget is updated * chore: graph is updated * chore: input component accept input props * chore: name of the dashboard is updated * chore: Widgets page in WIP * chore: types for the error api is updated * chore: getQuery data is updated * chore: widget types is updated * default widget is updated * chore: getQuery is updated * chore: Add Query is updated * fix: creating new widget bug is resolved * chore: widget type is updated * chore: Query error is updated * chore: query error and success state is handled * chore: label of graph in WIP * chore: legend input placeholder is updated * chore: changes are updated * chore: no data component is updated and error component is rendered along with the data * chore: data fetching over the initial render is fixed over the initial mount * chore: convertDateToAndPm is updated * chore: x-axis label is now fixed * chore: label is updated * chore: labels name is updated * chore: labels name is updated * chore: labels color is updated * chore: values are parsed in float * chore: tags is updated * chore: datasets type is updated * chore: graph is updated * chore: more eslint rules are updated * chore: some of the linting changes and data is updated * chore: chart.js version is updated * chore: gitignore is updated * chore: graph component is updated * chore: apply functionality is updated * chore: dashboard is now saved * chore: getChartData is updated * feat: Dashboard graph is reflected * chore: some of the bugs is resolved * fix: aspect ratio is made false * chore: some small css are fixed * chore: widgetId and graphType is preAdded if present in the search params * chore: user is now able to change the time via global time and reflect new graph values * chore: query is updated * chore: onBlurHandler is updated * fix: usage explorer is now fixed * chore: bar element is updated * chore: chartjs adapter is added * chore: old instance for the charts are removed via re-chart * chore: re-chart is removed * chore: get chart data is updated * chore: added the counter in the useEffect * chore: history is added * chore: some of the features are updated * chore: history package is updated * chore: AppRoutes is updated * fix: some are components breaking while moving from BrowserRouter to Router * chore: Dashboard icon is updated * chore: Full screen component is updated * stepSize (optional) is added in the widgets type * fix: fetching query result is fixed * update: start and end time function is updated * fix: Alert color is updated * update: Query fetching is updated * fix: start and end time is fixed * fix: chartjs data is compatable for larger data set and no ajax call for empty query is fixed * fix: last 1 week selection is fixed * fix: legends is added * update: antd version is updated * feat: value graph is updated * feat: Title is added for the value graph * fix: Full Screen view is updated with refresh functionality and alignment is updated to flex-end * fix: Graph component is updated * fix: metric graph are fixed * feature: Delete widget functionality is updated * fix: empty value bug is resolved * fix: delete widget position is fixed * fix: resize functionality is fixed * fix: sumation of the query is fixed * update: default legend is removed * update: resize handlers is removed and service metric component is updated * fix: legends is updated * update: querySuccess reducer is updated * Modal component is updated * fix: ant-d tab css is updated of the tabs * update: stringToHTML is made * update: graph component is updated * fix: several component in the metric and traces are updated * wip: build error is fixed * fix: metric section is fixed * update: console.log are commented * fix: onClick graph re-render is stopped * fix: trace graph is updated * fix: updated the min,max time for the value type graph * getQueryMaxMin Time is updated * fix: trace chart is updated * fix: re-render is fixed * fix: localstorage persistance is there * update: if label is not present legend is not displayed * fix: graph is changed while updated the global time * fix: default title is updated while creation of the dashboard * update: external database call tabs are made of same size * fix: query graph max-min time is updated in the full screen mode * fix: Request per sec graph is fixed * fix: ErrorChart is fixed Co-authored-by: Palash gupta <palashgdev@gmail.com>
2021-09-23 15:43:43 +05:30
import { AppState } from 'store/reducers';
import styled from 'styled-components';
Fix(FE): global time (#332) * chore: Router provider is removed * update: localstorage set get is added * update: AppLayout is updated * fix: adapter type is fixed * fix: Metric and metric application is now fixed * fix: Metrics page application is updated * fix: Tracepage is made fix * fix: app layout is updated * fix: global Time reducer is updated * refactor: getService api is added * update: metrics reducer is added * update: service list is fixed * fix: Metrics page is updated * fix: api for the metrics application are done * fix: metrics reducer is updated * fix: metrics application is updated * fix: content layout shift is removed * fix: Metric application is updated * fix: metrics application is updated * fix: Metrics application is updated * fix: Application tab is updated * chore: graph is updated * chore: Metrics application is updated * fix: chart x-axis is label is now fixed * fix: application tab is updated * fix: Top end points is added and re-redering in stopped * fix: fixed the edge case when user changes the global time then updated data is fetched * fix: Settings page is updated * chore: AppLayout is updated * chore: AppLayout is updated * chore: applayout is updated * chore: changed default loading is true in the global time reducer * chore: Global Time option is fixed * chore: Signup and Applayout is updated * chore: Button text is updated * chore: Button in the metrics application is updated * chore: dashboard menu item position in the side nav is updated * fix: Logo is now redirecting to the Application page * fix: Application page is updated * fix: AppLayout is updated * fix: starting and ending time is fixed * fix: Metrics Application is updated to the previous chart data * update: getDateArrayFromStartAndEnd function is added * update: Empty graph data is added * fix: External Call and DB Call Tabs graph are updated when there is no data a empty data is rendered * fix: onboarding modal condition is fixed and new calling api every 50000 ms to fetch the data * fix: onBoarding condition modal is updated * fix: onBoarding condition modal is updated * fix: onBoarding condition modal is updated * fix: Application chart re rendering issue is fixed * fix: Application page is changed when we change the global time * chore: step size is increased from 30 to 60 * chore: build is now fixed * chore: metrics application page is updated * fix: empty graph is now fixed * fix: application metrics graph is now fixed * fix: Time selection for custom is fixed * fix: usage graph is fixed * fix: global time selector is fixed and empty graph on click handler is added * fix: metrics application is now fixed
2021-10-20 09:24:55 +05:30
import { GlobalTime } from 'types/actions/globalTime';
2022-05-12 15:47:47 +05:30
import AppReducer from 'types/reducer/app';
2021-05-17 17:43:04 +05:30
import SelectService from './SelectService';
import { getGraphData, getTooltip, getZoomPx, transformLabel } from './utils';
2021-05-09 22:51:08 +05:30
const Container = styled.div`
.force-graph-container .graph-tooltip {
background: black;
padding: 1px;
.keyval {
display: flex;
.key {
margin-right: 4px;
}
.val {
margin-left: auto;
}
}
}
`;
2021-05-09 14:44:14 +05:30
interface ServiceMapProps extends RouteComponentProps<any> {
serviceMap: ServiceMapStore;
2021-05-09 14:44:14 +05:30
globalTime: GlobalTime;
getDetailedServiceMapItems: (time: GlobalTime) => void;
2021-05-09 14:44:14 +05:30
}
interface graphNode {
id: string;
group: number;
}
interface graphLink {
source: string;
target: string;
value: number;
}
export interface graphDataType {
nodes: graphNode[];
links: graphLink[];
}
function ServiceMap(props: ServiceMapProps): JSX.Element {
2021-05-09 14:44:14 +05:30
const fgRef = useRef();
2022-05-12 15:47:47 +05:30
const { isDarkMode } = useSelector<AppState, AppReducer>((state) => state.app);
const { getDetailedServiceMapItems, globalTime, serviceMap } = props;
2021-05-09 14:44:14 +05:30
useEffect(() => {
2021-05-23 16:06:40 +05:30
/*
Call the apis only when the route is loaded.
Check this issue: https://github.com/SigNoz/signoz/issues/110
*/
Fix(FE): global time (#332) * chore: Router provider is removed * update: localstorage set get is added * update: AppLayout is updated * fix: adapter type is fixed * fix: Metric and metric application is now fixed * fix: Metrics page application is updated * fix: Tracepage is made fix * fix: app layout is updated * fix: global Time reducer is updated * refactor: getService api is added * update: metrics reducer is added * update: service list is fixed * fix: Metrics page is updated * fix: api for the metrics application are done * fix: metrics reducer is updated * fix: metrics application is updated * fix: content layout shift is removed * fix: Metric application is updated * fix: metrics application is updated * fix: Metrics application is updated * fix: Application tab is updated * chore: graph is updated * chore: Metrics application is updated * fix: chart x-axis is label is now fixed * fix: application tab is updated * fix: Top end points is added and re-redering in stopped * fix: fixed the edge case when user changes the global time then updated data is fetched * fix: Settings page is updated * chore: AppLayout is updated * chore: AppLayout is updated * chore: applayout is updated * chore: changed default loading is true in the global time reducer * chore: Global Time option is fixed * chore: Signup and Applayout is updated * chore: Button text is updated * chore: Button in the metrics application is updated * chore: dashboard menu item position in the side nav is updated * fix: Logo is now redirecting to the Application page * fix: Application page is updated * fix: AppLayout is updated * fix: starting and ending time is fixed * fix: Metrics Application is updated to the previous chart data * update: getDateArrayFromStartAndEnd function is added * update: Empty graph data is added * fix: External Call and DB Call Tabs graph are updated when there is no data a empty data is rendered * fix: onboarding modal condition is fixed and new calling api every 50000 ms to fetch the data * fix: onBoarding condition modal is updated * fix: onBoarding condition modal is updated * fix: onBoarding condition modal is updated * fix: Application chart re rendering issue is fixed * fix: Application page is changed when we change the global time * chore: step size is increased from 30 to 60 * chore: build is now fixed * chore: metrics application page is updated * fix: empty graph is now fixed * fix: application metrics graph is now fixed * fix: Time selection for custom is fixed * fix: usage graph is fixed * fix: global time selector is fixed and empty graph on click handler is added * fix: metrics application is now fixed
2021-10-20 09:24:55 +05:30
getDetailedServiceMapItems(globalTime);
}, [globalTime, getDetailedServiceMapItems]);
2021-05-09 14:44:14 +05:30
2021-05-09 23:45:42 +05:30
useEffect(() => {
fgRef.current && fgRef.current.d3Force('charge').strength(-400);
2021-05-09 23:45:42 +05:30
});
if (serviceMap.loading) {
return <Spinner size="large" tip="Loading..." />;
2021-05-09 14:44:14 +05:30
}
if (!serviceMap.loading && serviceMap.items.length === 0) {
return (
<Container>
<Card>No Service Found</Card>
</Container>
);
}
const zoomToService = (value: string): void => {
fgRef &&
fgRef.current &&
fgRef.current.zoomToFit(700, getZoomPx(), (e) => e.id === value);
};
2021-05-17 14:42:39 +05:30
const zoomToDefault = () => {
fgRef && fgRef.current && fgRef.current.zoomToFit(100, 120);
};
const { nodes, links } = getGraphData(serviceMap);
2021-05-09 14:44:14 +05:30
const graphData = { nodes, links };
2021-01-18 02:18:49 +05:30
return (
2021-05-09 22:51:08 +05:30
<Container>
<SelectService
services={serviceMap.services}
zoomToService={zoomToService}
2021-05-17 14:42:39 +05:30
zoomToDefault={zoomToDefault}
/>
2021-05-09 14:44:14 +05:30
<ForceGraph2D
ref={fgRef}
cooldownTicks={100}
graphData={graphData}
2021-05-16 15:08:31 +05:30
nodeLabel={getTooltip}
2021-05-09 14:44:14 +05:30
linkAutoColorBy={(d) => d.target}
linkDirectionalParticles="value"
linkDirectionalParticleSpeed={(d) => d.value}
nodeCanvasObject={(node, ctx, globalScale) => {
const label = transformLabel(node.id);
const { fontSize } = node;
2021-05-09 22:51:08 +05:30
ctx.font = `${fontSize}px Roboto`;
const { width } = node;
2021-05-09 22:51:08 +05:30
2021-05-09 14:44:14 +05:30
ctx.fillStyle = node.color;
2021-05-09 22:51:08 +05:30
ctx.beginPath();
ctx.arc(node.x, node.y, width, 0, 2 * Math.PI, false);
2022-05-25 10:48:53 +05:30
ctx.fillStyle = isDarkMode ? '#3C8618' : '#D5F2BB';
2021-05-09 22:51:08 +05:30
ctx.fill();
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
2022-05-12 15:47:47 +05:30
ctx.fillStyle = isDarkMode ? '#ffffff' : '#000000';
2021-05-09 14:44:14 +05:30
ctx.fillText(label, node.x, node.y);
}}
onNodeClick={(node) => {
const tooltip = document.querySelector('.graph-tooltip');
if (tooltip && node) {
2021-05-16 15:08:31 +05:30
tooltip.innerHTML = getTooltip(node);
}
}}
2021-05-09 14:44:14 +05:30
nodePointerAreaPaint={(node, color, ctx) => {
ctx.fillStyle = color;
2021-05-09 22:51:08 +05:30
ctx.beginPath();
ctx.arc(node.x, node.y, 5, 0, 2 * Math.PI, false);
ctx.fill();
2021-05-09 14:44:14 +05:30
}}
/>
2021-05-09 22:51:08 +05:30
</Container>
2021-01-18 02:18:49 +05:30
);
}
2021-01-03 18:15:44 +05:30
2021-05-09 14:44:14 +05:30
const mapStateToProps = (
feat: Metrics (#281) * refactor: store is updated * temp * fix: eslint error is fixed * fix:eslint linting error is updated * chore: react-grid-layout is added * chore: linting changes are updated * chore: linting changes are updated * chore: @types/node is moved to devDependecies and @types/react-grid-layout is added * chore: tsconfig is updated * chore: updateUrl function is updated * feat: All Dashboard is updated * feat: All Dashboard page is updated * feat: New Dashboard is added * feat: App Layout is updated * feat: Add Tags is updated * chore: uuid package is added * chore: AppRoutes is updated * chore: UI components are updated * chore: baseUrl is added in the apiUrl and removed from other api request * chore: commonApi Response is updated * chore: ErrorResponse handler is updated * chore: useFetch hook is made * chore: axios instance is updated * chore:some of the changes are updated * chore: list of all dashboard types is updated * chore: logic is updated to the global state * chore: all dashboard data is fetched from the global state * chore: unnessary prop is removed * chore: changes are updated * chore: getAll and create is updated * chore: getDashboard is updated * chore: isEditMode is moved to the global state * chore: get,getAll is updated * chore: update title,tags,description is now fixed * chore: new widget is updated * chore: graph is updated * chore: input component accept input props * chore: name of the dashboard is updated * chore: Widgets page in WIP * chore: types for the error api is updated * chore: getQuery data is updated * chore: widget types is updated * default widget is updated * chore: getQuery is updated * chore: Add Query is updated * fix: creating new widget bug is resolved * chore: widget type is updated * chore: Query error is updated * chore: query error and success state is handled * chore: label of graph in WIP * chore: legend input placeholder is updated * chore: changes are updated * chore: no data component is updated and error component is rendered along with the data * chore: data fetching over the initial render is fixed over the initial mount * chore: convertDateToAndPm is updated * chore: x-axis label is now fixed * chore: label is updated * chore: labels name is updated * chore: labels name is updated * chore: labels color is updated * chore: values are parsed in float * chore: tags is updated * chore: datasets type is updated * chore: graph is updated * chore: more eslint rules are updated * chore: some of the linting changes and data is updated * chore: chart.js version is updated * chore: gitignore is updated * chore: graph component is updated * chore: apply functionality is updated * chore: dashboard is now saved * chore: getChartData is updated * feat: Dashboard graph is reflected * chore: some of the bugs is resolved * fix: aspect ratio is made false * chore: some small css are fixed * chore: widgetId and graphType is preAdded if present in the search params * chore: user is now able to change the time via global time and reflect new graph values * chore: query is updated * chore: onBlurHandler is updated * fix: usage explorer is now fixed * chore: bar element is updated * chore: chartjs adapter is added * chore: old instance for the charts are removed via re-chart * chore: re-chart is removed * chore: get chart data is updated * chore: added the counter in the useEffect * chore: history is added * chore: some of the features are updated * chore: history package is updated * chore: AppRoutes is updated * fix: some are components breaking while moving from BrowserRouter to Router * chore: Dashboard icon is updated * chore: Full screen component is updated * stepSize (optional) is added in the widgets type * fix: fetching query result is fixed * update: start and end time function is updated * fix: Alert color is updated * update: Query fetching is updated * fix: start and end time is fixed * fix: chartjs data is compatable for larger data set and no ajax call for empty query is fixed * fix: last 1 week selection is fixed * fix: legends is added * update: antd version is updated * feat: value graph is updated * feat: Title is added for the value graph * fix: Full Screen view is updated with refresh functionality and alignment is updated to flex-end * fix: Graph component is updated * fix: metric graph are fixed * feature: Delete widget functionality is updated * fix: empty value bug is resolved * fix: delete widget position is fixed * fix: resize functionality is fixed * fix: sumation of the query is fixed * update: default legend is removed * update: resize handlers is removed and service metric component is updated * fix: legends is updated * update: querySuccess reducer is updated * Modal component is updated * fix: ant-d tab css is updated of the tabs * update: stringToHTML is made * update: graph component is updated * fix: several component in the metric and traces are updated * wip: build error is fixed * fix: metric section is fixed * update: console.log are commented * fix: onClick graph re-render is stopped * fix: trace graph is updated * fix: updated the min,max time for the value type graph * getQueryMaxMin Time is updated * fix: trace chart is updated * fix: re-render is fixed * fix: localstorage persistance is there * update: if label is not present legend is not displayed * fix: graph is changed while updated the global time * fix: default title is updated while creation of the dashboard * update: external database call tabs are made of same size * fix: query graph max-min time is updated in the full screen mode * fix: Request per sec graph is fixed * fix: ErrorChart is fixed Co-authored-by: Palash gupta <palashgdev@gmail.com>
2021-09-23 15:43:43 +05:30
state: AppState,
2021-05-09 14:44:14 +05:30
): {
serviceMap: serviceMapStore;
globalTime: GlobalTime;
} => {
return {
serviceMap: state.serviceMap,
globalTime: state.globalTime,
};
};
export default withRouter(
connect(mapStateToProps, {
getDetailedServiceMapItems,
})(ServiceMap),
);