2022-03-09 10:43:02 +05:30
|
|
|
import { MinusSquareOutlined, PlusSquareOutlined } from '@ant-design/icons';
|
|
|
|
|
import { IIntervalUnit } from 'container/TraceDetail/utils';
|
2022-03-03 19:04:23 +05:30
|
|
|
import React, { useEffect, useState } from 'react';
|
2022-03-09 10:43:02 +05:30
|
|
|
import { ITraceTree } from 'types/api/trace/getTraceItem';
|
|
|
|
|
|
|
|
|
|
import { CardContainer, CardWrapper, CollapseButton, Wrapper } from './styles';
|
2022-03-03 19:04:23 +05:30
|
|
|
import Trace from './Trace';
|
|
|
|
|
import { getSpanPath } from './utils';
|
|
|
|
|
|
2022-03-22 12:10:31 +05:30
|
|
|
function GanttChart(props: GanttChartProps): JSX.Element {
|
2022-03-03 19:04:23 +05:30
|
|
|
const {
|
|
|
|
|
data,
|
|
|
|
|
traceMetaData,
|
|
|
|
|
activeHoverId,
|
|
|
|
|
setActiveHoverId,
|
|
|
|
|
activeSelectedId,
|
|
|
|
|
setActiveSelectedId,
|
|
|
|
|
spanId,
|
2022-03-09 10:43:02 +05:30
|
|
|
intervalUnit,
|
2022-03-03 19:04:23 +05:30
|
|
|
} = props;
|
|
|
|
|
|
|
|
|
|
const { globalStart, spread: globalSpread } = traceMetaData;
|
|
|
|
|
|
|
|
|
|
const [isExpandAll, setIsExpandAll] = useState<boolean>(false);
|
|
|
|
|
const [activeSpanPath, setActiveSpanPath] = useState<string[]>([]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-03-09 10:43:02 +05:30
|
|
|
setActiveSpanPath(getSpanPath(data, spanId));
|
2022-03-24 12:06:57 +05:30
|
|
|
}, [spanId, data]);
|
2022-03-03 19:04:23 +05:30
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-03-09 10:43:02 +05:30
|
|
|
setActiveSpanPath(getSpanPath(data, activeSelectedId));
|
2022-03-24 12:06:57 +05:30
|
|
|
}, [activeSelectedId, data]);
|
2022-03-03 19:04:23 +05:30
|
|
|
|
2022-03-24 12:06:57 +05:30
|
|
|
const handleCollapse = (): void => {
|
2022-03-03 19:04:23 +05:30
|
|
|
setIsExpandAll((prev) => !prev);
|
|
|
|
|
};
|
|
|
|
|
return (
|
2022-03-22 12:10:31 +05:30
|
|
|
<Wrapper>
|
|
|
|
|
<CardContainer>
|
|
|
|
|
<CollapseButton
|
|
|
|
|
onClick={handleCollapse}
|
|
|
|
|
title={isExpandAll ? 'Collapse All' : 'Expand All'}
|
|
|
|
|
>
|
|
|
|
|
{isExpandAll ? <MinusSquareOutlined /> : <PlusSquareOutlined />}
|
|
|
|
|
</CollapseButton>
|
|
|
|
|
<CardWrapper>
|
|
|
|
|
<Trace
|
|
|
|
|
activeHoverId={activeHoverId}
|
|
|
|
|
activeSpanPath={activeSpanPath}
|
|
|
|
|
setActiveHoverId={setActiveHoverId}
|
|
|
|
|
key={data.id}
|
2022-03-24 12:06:57 +05:30
|
|
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
2022-03-22 12:10:31 +05:30
|
|
|
{...{
|
|
|
|
|
...data,
|
|
|
|
|
globalSpread,
|
|
|
|
|
globalStart,
|
|
|
|
|
setActiveSelectedId,
|
|
|
|
|
activeSelectedId,
|
|
|
|
|
}}
|
|
|
|
|
level={0}
|
|
|
|
|
isExpandAll={isExpandAll}
|
|
|
|
|
intervalUnit={intervalUnit}
|
|
|
|
|
/>
|
|
|
|
|
</CardWrapper>
|
|
|
|
|
</CardContainer>
|
|
|
|
|
</Wrapper>
|
2022-03-03 19:04:23 +05:30
|
|
|
);
|
2022-03-22 12:10:31 +05:30
|
|
|
}
|
2022-03-03 19:04:23 +05:30
|
|
|
|
|
|
|
|
export interface ITraceMetaData {
|
|
|
|
|
globalEnd: number;
|
|
|
|
|
globalStart: number;
|
|
|
|
|
levels: number;
|
|
|
|
|
spread: number;
|
|
|
|
|
totalSpans: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface GanttChartProps {
|
|
|
|
|
data: ITraceTree;
|
|
|
|
|
traceMetaData: ITraceMetaData;
|
|
|
|
|
activeSelectedId: string;
|
|
|
|
|
activeHoverId: string;
|
|
|
|
|
setActiveHoverId: React.Dispatch<React.SetStateAction<string>>;
|
|
|
|
|
setActiveSelectedId: React.Dispatch<React.SetStateAction<string>>;
|
|
|
|
|
spanId: string;
|
2022-03-09 10:43:02 +05:30
|
|
|
intervalUnit: IIntervalUnit;
|
2022-03-03 19:04:23 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default GanttChart;
|