mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-11 17:59:09 +08:00
fix(FE): onFocusSelected bug is resolved (#258)
* fix: onFocusSelected bug is resolved * dependecies array is updated * updated the dependency array * fix: TraceGantt chart is updated Co-authored-by: Ankit Nayan <ankit@signoz.io>
This commit is contained in:
parent
0055eaf656
commit
4817a17320
@ -20,7 +20,7 @@ interface TraceGanttChartProps {
|
|||||||
treeData: pushDStree[];
|
treeData: pushDStree[];
|
||||||
clickedSpan: pushDStree;
|
clickedSpan: pushDStree;
|
||||||
selectedSpan: pushDStree;
|
selectedSpan: pushDStree;
|
||||||
resetZoom: () => {};
|
resetZoom: (value: boolean) => {};
|
||||||
setSpanTagsInfo: (p: { data: any }) => {};
|
setSpanTagsInfo: (p: { data: any }) => {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,14 +32,16 @@ const TraceGanttChart = ({
|
|||||||
setSpanTagsInfo,
|
setSpanTagsInfo,
|
||||||
}: TraceGanttChartProps) => {
|
}: TraceGanttChartProps) => {
|
||||||
let checkStrictly = true;
|
let checkStrictly = true;
|
||||||
const [selectedRows, setSelectedRows] = useState([]);
|
const [selectedRows, setSelectedRows] = useState<string[]>([]);
|
||||||
const [clickedSpanData, setClickedSpanData] = useState(clickedSpan);
|
const [clickedSpanData, setClickedSpanData] = useState(clickedSpan);
|
||||||
const [defaultExpandedRows, setDefaultExpandedRows] = useState([]);
|
const [defaultExpandedRows, setDefaultExpandedRows] = useState<string[]>([]);
|
||||||
const [sortedTreeData, setSortedTreeData] = useState(treeData);
|
const [sortedTreeData, setSortedTreeData] = useState(treeData);
|
||||||
const [isReset, setIsReset] = useState(false);
|
const [isReset, setIsReset] = useState(false);
|
||||||
const [tabsContainerWidth, setTabsContainerWidth] = useState(0);
|
const [tabsContainerWidth, setTabsContainerWidth] = useState(0);
|
||||||
const tableRef = useRef("");
|
const tableRef = useRef("");
|
||||||
let tabsContainer = document.querySelector("#collapsable .ant-tabs-nav-list");
|
let tabsContainer = document.querySelector<HTMLElement>(
|
||||||
|
"#collapsable .ant-tabs-nav-list",
|
||||||
|
);
|
||||||
|
|
||||||
let tabs = document.querySelectorAll("#collapsable .ant-tabs-tab");
|
let tabs = document.querySelectorAll("#collapsable .ant-tabs-tab");
|
||||||
|
|
||||||
@ -55,7 +57,9 @@ const TraceGanttChart = ({
|
|||||||
if (clickedSpan) {
|
if (clickedSpan) {
|
||||||
setClickedSpanData(clickedSpan);
|
setClickedSpanData(clickedSpan);
|
||||||
}
|
}
|
||||||
setTabsContainerWidth(tabsContainer?.offsetWidth);
|
if (tabsContainer) {
|
||||||
|
setTabsContainerWidth(tabsContainer.offsetWidth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
handleScroll(selectedSpan?.id);
|
handleScroll(selectedSpan?.id);
|
||||||
}, [sortedTreeData, treeData, clickedSpan]);
|
}, [sortedTreeData, treeData, clickedSpan]);
|
||||||
@ -69,12 +73,13 @@ const TraceGanttChart = ({
|
|||||||
) {
|
) {
|
||||||
setSelectedRows([clickedSpan.id]);
|
setSelectedRows([clickedSpan.id]);
|
||||||
getParentKeys(clickedSpan);
|
getParentKeys(clickedSpan);
|
||||||
handleFocusOnSelectedPath("", [clickedSpan.id], clickedSpan);
|
handleFocusOnSelectedPath("", [clickedSpan.id]);
|
||||||
}
|
}
|
||||||
}, [clickedSpan, selectedRows, isReset, clickedSpanData]);
|
}, [clickedSpan, selectedRows, isReset, clickedSpanData]);
|
||||||
|
|
||||||
let parentKeys = [];
|
let parentKeys: string[] = [];
|
||||||
let childrenKeys = [];
|
let childrenKeys: string[] = [];
|
||||||
|
|
||||||
const getParentKeys = (obj) => {
|
const getParentKeys = (obj) => {
|
||||||
if (has(obj, "parent")) {
|
if (has(obj, "parent")) {
|
||||||
parentKeys.push(obj.parent.id);
|
parentKeys.push(obj.parent.id);
|
||||||
@ -82,7 +87,7 @@ const TraceGanttChart = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getChildrenKeys = (obj) => {
|
const getChildrenKeys = (obj: pushDStree) => {
|
||||||
if (has(obj, "children")) {
|
if (has(obj, "children")) {
|
||||||
childrenKeys.push(obj.id);
|
childrenKeys.push(obj.id);
|
||||||
if (!isEmpty(obj.children)) {
|
if (!isEmpty(obj.children)) {
|
||||||
@ -105,7 +110,7 @@ const TraceGanttChart = ({
|
|||||||
setDefaultExpandedRows([treeData?.[0]?.id]);
|
setDefaultExpandedRows([treeData?.[0]?.id]);
|
||||||
// /.setSpanTagsInfo({data: treeData?.[0]})
|
// /.setSpanTagsInfo({data: treeData?.[0]})
|
||||||
}
|
}
|
||||||
}, [selectedSpan, treeData]);
|
}, [selectedSpan, treeData, clickedSpan]);
|
||||||
|
|
||||||
const getMaxEndTime = (treeData) => {
|
const getMaxEndTime = (treeData) => {
|
||||||
if (treeData.length > 0) {
|
if (treeData.length > 0) {
|
||||||
@ -169,7 +174,7 @@ const TraceGanttChart = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
let paddingLeft = 0;
|
let paddingLeft = 0;
|
||||||
let startTime = parseFloat(record.startTime);
|
let startTime = parseFloat(record.startTime.toString());
|
||||||
let duration = parseFloat((record.time / 1000000).toFixed(2));
|
let duration = parseFloat((record.time / 1000000).toFixed(2));
|
||||||
paddingLeft = parseInt(
|
paddingLeft = parseInt(
|
||||||
getPaddingLeft(
|
getPaddingLeft(
|
||||||
@ -200,7 +205,17 @@ const TraceGanttChart = ({
|
|||||||
|
|
||||||
const handleFocusOnSelectedPath = (event, selectedRowsList = selectedRows) => {
|
const handleFocusOnSelectedPath = (event, selectedRowsList = selectedRows) => {
|
||||||
if (!isEmpty(selectedRowsList)) {
|
if (!isEmpty(selectedRowsList)) {
|
||||||
let node = {};
|
// initializing the node
|
||||||
|
let node: pushDStree = {
|
||||||
|
children: [],
|
||||||
|
id: "",
|
||||||
|
name: "",
|
||||||
|
startTime: 0,
|
||||||
|
tags: [],
|
||||||
|
time: 0,
|
||||||
|
value: 0,
|
||||||
|
};
|
||||||
|
|
||||||
traverseTreeData(treeData, (item: pushDStree) => {
|
traverseTreeData(treeData, (item: pushDStree) => {
|
||||||
if (item.id === selectedRowsList[0]) {
|
if (item.id === selectedRowsList[0]) {
|
||||||
node = item;
|
node = item;
|
||||||
@ -214,13 +229,20 @@ const TraceGanttChart = ({
|
|||||||
console.error("Node not found in Tree Data.");
|
console.error("Node not found in Tree Data.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the parent of the node
|
||||||
getParentKeys(node);
|
getParentKeys(node);
|
||||||
|
|
||||||
|
// get the children of the node
|
||||||
getChildrenKeys(node);
|
getChildrenKeys(node);
|
||||||
|
|
||||||
let rows = document.querySelectorAll("#collapsable table tbody tr");
|
let rows = document.querySelectorAll("#collapsable table tbody tr");
|
||||||
Array.from(rows).map((row) => {
|
rows.forEach((row) => {
|
||||||
let attribKey = row.getAttribute("data-row-key");
|
let attribKey = row.getAttribute("data-row-key") || "";
|
||||||
if (!selectedRowsList.includes(attribKey)) {
|
if (
|
||||||
|
!isEmpty(attribKey) &&
|
||||||
|
!selectedRowsList.includes(attribKey) &&
|
||||||
|
!childrenKeys.includes(attribKey)
|
||||||
|
) {
|
||||||
row.classList.add("hide");
|
row.classList.add("hide");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -230,7 +252,7 @@ const TraceGanttChart = ({
|
|||||||
|
|
||||||
const handleResetFocus = () => {
|
const handleResetFocus = () => {
|
||||||
const rows = document.querySelectorAll("#collapsable table tbody tr");
|
const rows = document.querySelectorAll("#collapsable table tbody tr");
|
||||||
Array.from(rows).map((row) => {
|
rows.forEach((row) => {
|
||||||
row.classList.remove("hide");
|
row.classList.remove("hide");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -256,13 +278,13 @@ const TraceGanttChart = ({
|
|||||||
setIsReset(false);
|
setIsReset(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSelect: (record) => {
|
onSelect: (record: pushDStree) => {
|
||||||
handleRowOnClick(record);
|
handleRowOnClick(record);
|
||||||
},
|
},
|
||||||
selectedRowKeys: selectedRows,
|
selectedRowKeys: selectedRows,
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRowOnClick = (record) => {
|
const handleRowOnClick = (record: pushDStree) => {
|
||||||
let node = {};
|
let node = {};
|
||||||
traverseTreeData(treeData, (item: pushDStree) => {
|
traverseTreeData(treeData, (item: pushDStree) => {
|
||||||
if (item.id === record.id) {
|
if (item.id === record.id) {
|
||||||
@ -286,7 +308,7 @@ const TraceGanttChart = ({
|
|||||||
setSelectedRows([record.id]);
|
setSelectedRows([record.id]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOnExpandedRowsChange = (item) => {
|
const handleOnExpandedRowsChange = (item: string[]) => {
|
||||||
setDefaultExpandedRows(item);
|
setDefaultExpandedRows(item);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -303,8 +325,7 @@ const TraceGanttChart = ({
|
|||||||
>
|
>
|
||||||
<Col>
|
<Col>
|
||||||
<StyledButton onClick={handleFocusOnSelectedPath}>
|
<StyledButton onClick={handleFocusOnSelectedPath}>
|
||||||
{" "}
|
Focus on selected path
|
||||||
Focus on selected path{" "}
|
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
</Col>
|
</Col>
|
||||||
<Col>
|
<Col>
|
||||||
@ -320,14 +341,18 @@ const TraceGanttChart = ({
|
|||||||
dataSource={sortedTreeData}
|
dataSource={sortedTreeData}
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
sticky={true}
|
sticky={true}
|
||||||
onRow={(record, rowIndex) => {
|
onRow={(record) => {
|
||||||
return {
|
return {
|
||||||
onClick: () => handleRowOnClick(record, rowIndex), // click row
|
onClick: () => handleRowOnClick(record), // click row
|
||||||
};
|
};
|
||||||
}}
|
}}
|
||||||
expandedRowKeys={defaultExpandedRows}
|
onExpandedRowsChange={(keys) =>
|
||||||
onExpandedRowsChange={handleOnExpandedRowsChange}
|
handleOnExpandedRowsChange(keys.map((e) => e.toString()))
|
||||||
|
}
|
||||||
pagination={false}
|
pagination={false}
|
||||||
|
expandable={{
|
||||||
|
expandedRowKeys: defaultExpandedRows,
|
||||||
|
}}
|
||||||
scroll={{ y: 540 }}
|
scroll={{ y: 540 }}
|
||||||
rowClassName="row-styles"
|
rowClassName="row-styles"
|
||||||
filterMultiple={false}
|
filterMultiple={false}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user