Merge pull request #914 from palash-signoz/tsc-fix

chore: tsc fix are updated over frontend
This commit is contained in:
palash-signoz 2022-03-25 15:39:27 +05:30 committed by GitHub
commit 995232e057
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 128 additions and 43 deletions

View File

@ -1,5 +1,6 @@
import { Chart, ChartType, Plugin } from 'chart.js'; import { Chart, ChartType, Plugin } from 'chart.js';
import { colors } from 'lib/getRandomColor'; import { colors } from 'lib/getRandomColor';
import { get } from 'lodash-es';
const getOrCreateLegendList = ( const getOrCreateLegendList = (
chart: Chart, chart: Chart,
@ -40,9 +41,20 @@ export const legend = (id: string, isLonger: boolean): Plugin<ChartType> => {
} }
// Reuse the built-in legendItems generator // Reuse the built-in legendItems generator
const items = chart?.options?.plugins?.legend?.labels?.generateLabels(chart); const items = get(chart, [
'options',
'plugins',
'legend',
'labels',
'generateLabels',
])
? get(chart, ['options', 'plugins', 'legend', 'labels', 'generateLabels'])(
chart,
)
: null;
items?.forEach((item, index) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any
items?.forEach((item: Record<any, any>, index: number) => {
const li = document.createElement('li'); const li = document.createElement('li');
li.style.alignItems = 'center'; li.style.alignItems = 'center';
li.style.cursor = 'pointer'; li.style.cursor = 'pointer';
@ -66,8 +78,8 @@ export const legend = (id: string, isLonger: boolean): Plugin<ChartType> => {
// Color box // Color box
const boxSpan = document.createElement('span'); const boxSpan = document.createElement('span');
boxSpan.style.background = item.strokeStyle || colors[0]; boxSpan.style.background = `${item.strokeStyle}` || `${colors[0]}`;
boxSpan.style.borderColor = item?.strokeStyle; boxSpan.style.borderColor = `${item?.strokeStyle}`;
boxSpan.style.borderWidth = `${item.lineWidth}px`; boxSpan.style.borderWidth = `${item.lineWidth}px`;
boxSpan.style.display = 'inline-block'; boxSpan.style.display = 'inline-block';
boxSpan.style.minHeight = '20px'; boxSpan.style.minHeight = '20px';

View File

@ -1,3 +1,4 @@
import { expect } from '@jest/globals';
import { render } from '@testing-library/react'; import { render } from '@testing-library/react';
import React from 'react'; import React from 'react';
import { MemoryRouter } from 'react-router-dom'; import { MemoryRouter } from 'react-router-dom';

View File

@ -6,8 +6,8 @@ import styled, { FlattenSimpleInterpolation } from 'styled-components';
import { IStyledClass } from './types'; import { IStyledClass } from './types';
const styledClass = (props: IStyledClass): FlattenSimpleInterpolation => const styledClass = (props: IStyledClass): FlattenSimpleInterpolation | null =>
props.styledclass; props.styledclass || null;
type TStyledCol = AntD.ColProps & IStyledClass; type TStyledCol = AntD.ColProps & IStyledClass;
const StyledCol = styled(AntD.Col)<TStyledCol>` const StyledCol = styled(AntD.Col)<TStyledCol>`

View File

@ -1,6 +1,7 @@
import { css, FlattenSimpleInterpolation } from 'styled-components'; import { css, FlattenSimpleInterpolation } from 'styled-components';
const cssProprty = (key: string, value): FlattenSimpleInterpolation => // eslint-disable-next-line @typescript-eslint/no-explicit-any
const cssProperty = (key: any, value: any): FlattenSimpleInterpolation =>
key && key &&
value && value &&
css` css`
@ -15,8 +16,8 @@ export const Flex = ({
flexDirection, flexDirection,
flex, flex,
}: IFlexProps): FlattenSimpleInterpolation => css` }: IFlexProps): FlattenSimpleInterpolation => css`
${cssProprty('flex-direction', flexDirection)} ${cssProperty('flex-direction', flexDirection)}
${cssProprty('flex', flex)} ${cssProperty('flex', flex)}
`; `;
interface IDisplayProps { interface IDisplayProps {
@ -25,7 +26,7 @@ interface IDisplayProps {
export const Display = ({ export const Display = ({
display, display,
}: IDisplayProps): FlattenSimpleInterpolation => css` }: IDisplayProps): FlattenSimpleInterpolation => css`
${cssProprty('display', display)} ${cssProperty('display', display)}
`; `;
interface ISpacingProps { interface ISpacingProps {
@ -36,6 +37,6 @@ export const Spacing = ({
margin, margin,
padding, padding,
}: ISpacingProps): FlattenSimpleInterpolation => css` }: ISpacingProps): FlattenSimpleInterpolation => css`
${cssProprty('margin', margin)} ${cssProperty('margin', margin)}
${cssProprty('padding', padding)} ${cssProperty('padding', padding)}
`; `;

View File

@ -30,7 +30,7 @@ function Delete({ notifications, setChannels, id }: DeleteProps): JSX.Element {
} catch (error) { } catch (error) {
notifications.error({ notifications.error({
message: 'Error', message: 'Error',
description: error.toString() || 'Something went wrong', description: error instanceof Error ? error.toString() : 'Something went wrong',
}); });
setLoading(false); setLoading(false);
} }

View File

@ -33,7 +33,7 @@ function SpanLength(props: SpanLengthProps): JSX.Element {
leftOffset={leftOffset} leftOffset={leftOffset}
width={width} width={width}
/> />
<SpanText leftOffset={leftOffset}>{`${toFixed( <SpanText isDarkMode={isDarkMode} leftOffset={leftOffset}>{`${toFixed(
resolveTimeFromInterval(inMsCount, intervalUnit), resolveTimeFromInterval(inMsCount, intervalUnit),
2, 2,
)} ${intervalUnit.name}`}</SpanText> )} ${intervalUnit.name}`}</SpanText>

View File

@ -60,6 +60,7 @@ function EmptyGraph({
return ( return (
<Graph <Graph
name=""
{...{ {...{
type: 'line', type: 'line',
onClickHandler, onClickHandler,

View File

@ -154,7 +154,8 @@ function GridGraph(): JSX.Element {
}); });
} catch (error) { } catch (error) {
notification.error({ notification.error({
message: error.toString() || 'Something went wrong', message:
error instanceof Error ? error.toString() : 'Something went wrong',
}); });
} }
} }

View File

@ -2,8 +2,8 @@ import { Button, Divider } from 'antd';
import Input from 'components/Input'; import Input from 'components/Input';
import TextToolTip from 'components/TextToolTip'; import TextToolTip from 'components/TextToolTip';
import { timePreferance } from 'container/NewWidget/RightContainer/timeItems'; import { timePreferance } from 'container/NewWidget/RightContainer/timeItems';
import React, { useCallback, useState } from 'react'; import React, { useCallback, useMemo, useState } from 'react';
import { connect } from 'react-redux'; import { connect, useSelector } from 'react-redux';
import { useLocation } from 'react-router-dom'; import { useLocation } from 'react-router-dom';
import { bindActionCreators, Dispatch } from 'redux'; import { bindActionCreators, Dispatch } from 'redux';
import { ThunkDispatch } from 'redux-thunk'; import { ThunkDispatch } from 'redux-thunk';
@ -12,8 +12,11 @@ import {
UpdateQuery, UpdateQuery,
UpdateQueryProps, UpdateQueryProps,
} from 'store/actions/dashboard/updateQuery'; } from 'store/actions/dashboard/updateQuery';
import { AppState } from 'store/reducers';
import AppActions from 'types/actions'; import AppActions from 'types/actions';
import { DeleteQueryProps } from 'types/actions/dashboard'; import { DeleteQueryProps } from 'types/actions/dashboard';
import { Widgets } from 'types/api/dashboard/getAll';
import DashboardReducer from 'types/reducer/dashboards';
import { import {
ButtonContainer, ButtonContainer,
@ -32,10 +35,27 @@ function Query({
const [promqlQuery, setPromqlQuery] = useState(preQuery); const [promqlQuery, setPromqlQuery] = useState(preQuery);
const [legendFormat, setLegendFormat] = useState(preLegend); const [legendFormat, setLegendFormat] = useState(preLegend);
const { search } = useLocation(); const { search } = useLocation();
const { dashboards } = useSelector<AppState, DashboardReducer>(
(state) => state.dashboards,
);
const [selectedDashboards] = dashboards;
const { widgets } = selectedDashboards.data;
const query = new URLSearchParams(search); const query = new URLSearchParams(search);
const widgetId = query.get('widgetId') || ''; const widgetId = query.get('widgetId') || '';
const urlQuery = useMemo(() => {
return new URLSearchParams(search);
}, [search]);
const getWidget = useCallback(() => {
const widgetId = urlQuery.get('widgetId');
return widgets?.find((e) => e.id === widgetId);
}, [widgets, urlQuery]);
const selectedWidget = getWidget() as Widgets;
const onChangeHandler = useCallback( const onChangeHandler = useCallback(
(setFunc: React.Dispatch<React.SetStateAction<string>>, value: string) => { (setFunc: React.Dispatch<React.SetStateAction<string>>, value: string) => {
setFunc(value); setFunc(value);
@ -49,6 +69,7 @@ function Query({
legend: legendFormat, legend: legendFormat,
query: promqlQuery, query: promqlQuery,
widgetId, widgetId,
yAxisUnit: selectedWidget.yAxisUnit,
}); });
}; };

View File

@ -19,11 +19,11 @@ function YAxisUnitSelector({
fieldLabel, fieldLabel,
}: { }: {
defaultValue: string; defaultValue: string;
onSelect: (e: string | undefined) => void; onSelect: React.Dispatch<React.SetStateAction<string>>;
fieldLabel: string; fieldLabel: string;
}): JSX.Element { }): JSX.Element {
const onSelectHandler = (selectedValue: string): void => { const onSelectHandler = (selectedValue: string): void => {
onSelect(findCategoryByName(selectedValue)?.id); onSelect(findCategoryByName(selectedValue)?.id || '');
}; };
const options = flattenedCategories.map((options) => ({ const options = flattenedCategories.map((options) => ({
value: options.name, value: options.name,

View File

@ -1,4 +1,5 @@
import { StyledDiv } from 'components/Styled'; import { StyledDiv } from 'components/Styled';
import { ITraceMetaData } from 'container/GantChart';
import { IIntervalUnit, INTERVAL_UNITS } from 'container/TraceDetail/utils'; import { IIntervalUnit, INTERVAL_UNITS } from 'container/TraceDetail/utils';
import useThemeMode from 'hooks/useThemeMode'; import useThemeMode from 'hooks/useThemeMode';
import React, { useEffect, useRef, useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
@ -74,10 +75,9 @@ function Timeline({
{intervals && {intervals &&
intervals.map((interval, index) => ( intervals.map((interval, index) => (
<TimelineInterval <TimelineInterval
transform={`translate(${ transform={`translate(${TimelineHSpacing +
TimelineHSpacing +
(interval.percentage * (width - 2 * TimelineHSpacing)) / 100 (interval.percentage * (width - 2 * TimelineHSpacing)) / 100
},0)`} },0)`}
key={`${interval.label + interval.percentage + index}`} key={`${interval.label + interval.percentage + index}`}
> >
<text y={13} fill={isDarkMode ? 'white' : 'black'}> <text y={13} fill={isDarkMode ? 'white' : 'black'}>
@ -104,7 +104,7 @@ interface TimelineProps {
totalSpans: number; totalSpans: number;
levels: number; levels: number;
}; };
globalTraceMetadata: Record<string, number>; globalTraceMetadata: ITraceMetaData;
setIntervalUnit: React.Dispatch<React.SetStateAction<IIntervalUnit>>; setIntervalUnit: React.Dispatch<React.SetStateAction<IIntervalUnit>>;
} }

View File

@ -1,3 +1,4 @@
import { ITraceMetaData } from 'container/GantChart';
import { import {
IIntervalUnit, IIntervalUnit,
resolveTimeFromInterval, resolveTimeFromInterval,
@ -7,14 +8,12 @@ import { toFixed } from 'utils/toFixed';
import { Interval } from './types'; import { Interval } from './types';
type TMetaDataType = Record<string, never>;
export const getIntervalSpread = ({ export const getIntervalSpread = ({
localTraceMetaData, localTraceMetaData,
globalTraceMetadata, globalTraceMetadata,
}: { }: {
localTraceMetaData: TMetaDataType; localTraceMetaData: ITraceMetaData;
globalTraceMetadata: TMetaDataType; globalTraceMetadata: ITraceMetaData;
}): { }): {
baseInterval: number; baseInterval: number;
baseSpread: number; baseSpread: number;

View File

@ -69,6 +69,8 @@ export const getChartDataforGroupBy = (
const allGroupBy = Object.keys(items).map((e) => items[e].groupBy); const allGroupBy = Object.keys(items).map((e) => items[e].groupBy);
keys(allGroupBy).forEach((e: string): void => { keys(allGroupBy).forEach((e: string): void => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const { length } = keys(allGroupBy[e]); const { length } = keys(allGroupBy[e]);
if (length >= max) { if (length >= max) {

View File

@ -43,7 +43,7 @@ function TraceGraph(): JSX.Element {
} }
return ( return (
<Container ref={ref}> <Container ref={ref as never}>
<Graph <Graph
animate={false} animate={false}
data={ChartData} data={ChartData}

View File

@ -9,7 +9,7 @@ import {
StyledTypography, StyledTypography,
} from 'components/Styled'; } from 'components/Styled';
import * as StyledStyles from 'components/Styled/styles'; import * as StyledStyles from 'components/Styled/styles';
import GanttChart from 'container/GantChart'; import GanttChart, { ITraceMetaData } from 'container/GantChart';
import { getNodeById } from 'container/GantChart/utils'; import { getNodeById } from 'container/GantChart/utils';
import Timeline from 'container/Timeline'; import Timeline from 'container/Timeline';
import TraceFlameGraph from 'container/TraceFlameGraph'; import TraceFlameGraph from 'container/TraceFlameGraph';
@ -55,7 +55,7 @@ function TraceDetail({ response }: TraceDetailProps): JSX.Element {
/* eslint-enable */ /* eslint-enable */
}, [treeData, spanServiceColors]); }, [treeData, spanServiceColors]);
const [globalTraceMetadata] = useState<Record<string, number>>({ const [globalTraceMetadata] = useState<ITraceMetaData>({
...traceMetaData, ...traceMetaData,
}); });
@ -129,7 +129,6 @@ function TraceDetail({ response }: TraceDetailProps): JSX.Element {
<Timeline <Timeline
globalTraceMetadata={globalTraceMetadata} globalTraceMetadata={globalTraceMetadata}
traceMetaData={traceMetaData} traceMetaData={traceMetaData}
intervalUnit={intervalUnit}
setIntervalUnit={setIntervalUnit} setIntervalUnit={setIntervalUnit}
/> />
</StyledCol> </StyledCol>

View File

@ -1,9 +1,42 @@
import { expect } from '@jest/globals'; import { expect } from '@jest/globals';
import { render } from '@testing-library/react'; import { render } from '@testing-library/react';
import TraceFlameGraph from 'container/TraceFlameGraph'; import TraceFlameGraph from 'container/TraceFlameGraph';
import React from 'react'; import React, { useState } from 'react';
test('loads and displays greeting', async () => { test('loads and displays greeting', () => {
const { asFragment } = render(<TraceFlameGraph />); const onSpanHover = useState('');
const { asFragment } = render(
<TraceFlameGraph
{...{
hoveredSpanId: '',
intervalUnit: { multiplier: 0, name: 'm' },
onSpanHover: onSpanHover[1],
onSpanSelect: (): void => {},
selectedSpanId: '',
traceMetaData: {
globalEnd: 0,
globalStart: 0,
levels: 0,
spread: 0,
totalSpans: 0,
},
treeData: {
children: [],
id: '',
name: '',
serviceColour: '',
serviceName: '',
startTime: 0,
tags: [],
time: 0,
value: 0,
event: [],
hasError: false,
parent: undefined,
},
}}
/>,
);
expect(asFragment()).toMatchSnapshot(); expect(asFragment()).toMatchSnapshot();
}); });

View File

@ -173,6 +173,8 @@ function TraceFlameGraph(props: {
onSpanSelect={onSpanSelect} onSpanSelect={onSpanSelect}
hoveredSpanId={hoveredSpanId} hoveredSpanId={hoveredSpanId}
selectedSpanId={selectedSpanId} selectedSpanId={selectedSpanId}
level={0}
parentLeftOffset={0}
/> />
</TraceFlameGraphContainer> </TraceFlameGraphContainer>
); );

View File

@ -56,7 +56,7 @@ function useFetch<PayloadProps, FunctionParams>(
loading: false, loading: false,
success: false, success: false,
error: true, error: true,
errorMessage: error, errorMessage: error as string,
}); });
} }
return (): void => { return (): void => {

View File

@ -1,3 +1,4 @@
import { expect } from '@jest/globals';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import getStep, { DefaultStepSize } from 'lib/getStep'; import getStep, { DefaultStepSize } from 'lib/getStep';

View File

@ -5,6 +5,7 @@ import { Select, Space } from 'antd';
import Graph from 'components/Graph'; import Graph from 'components/Graph';
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { connect, useSelector } from 'react-redux'; import { connect, useSelector } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { GetService, getUsageData, UsageDataItem } from 'store/actions'; import { GetService, getUsageData, UsageDataItem } from 'store/actions';
import { AppState } from 'store/reducers'; import { AppState } from 'store/reducers';
import { GlobalTime } from 'types/actions/globalTime'; import { GlobalTime } from 'types/actions/globalTime';
@ -213,7 +214,9 @@ const mapStateToProps = (
}; };
}; };
export const UsageExplorer = connect(mapStateToProps, { export const UsageExplorer = withRouter(
getUsageData, connect(mapStateToProps, {
getServicesList: GetService, getUsageData,
})(_UsageExplorer); getServicesList: GetService,
})(_UsageExplorer),
);

View File

@ -74,7 +74,12 @@ function DashboardWidget({ getDashboard }: NewDashboardProps): JSX.Element {
); );
} }
return <NewWidget selectedGraph={selectedGraph} />; return (
<NewWidget
yAxisUnit={selectedWidget.yAxisUnit}
selectedGraph={selectedGraph}
/>
);
} }
export interface DashboardWidgetPageParams { export interface DashboardWidgetPageParams {

View File

@ -31,7 +31,8 @@ export const DeleteDashboard = ({
dispatch({ dispatch({
type: 'DELETE_DASHBOARD_ERROR', type: 'DELETE_DASHBOARD_ERROR',
payload: { payload: {
errorMessage: error.toString() || 'Something went wrong', errorMessage:
error instanceof Error ? error.toString() : 'Something went wrong',
}, },
}); });
} }

View File

@ -64,7 +64,8 @@ export const GetDashboard = ({
dispatch({ dispatch({
type: 'GET_DASHBOARD_ERROR', type: 'GET_DASHBOARD_ERROR',
payload: { payload: {
errorMessage: error.toString() || 'Something went wrong', errorMessage:
error instanceof Error ? error.toString() : 'Something went wrong',
}, },
}); });
} }

View File

@ -42,7 +42,8 @@ export const UpdateDashboardTitleDescriptionTags = ({
dispatch({ dispatch({
type: 'UPDATE_TITLE_DESCRIPTION_TAGS_ERROR', type: 'UPDATE_TITLE_DESCRIPTION_TAGS_ERROR',
payload: { payload: {
errorMessage: error.toString() || 'Something went wrong', errorMessage:
error instanceof Error ? error.toString() : 'Something went wrong',
}, },
}); });
} }

View File

@ -46,6 +46,7 @@ export const SelectedTraceFilter = (props: {
traces.selectedTags, traces.selectedTags,
traces.filter, traces.filter,
traces.isFilterExclude, traces.isFilterExclude,
traces.userSelectedFilter,
); );
}; };
}; };