Skip to content

Commit 2f12bcc

Browse files
theibhirbhufmann
authored andcommitted
Fix pin row bug when id is 2
move reusable code to the parent Signed-off-by: Yassine Ibhir <[email protected]>
1 parent 0018417 commit 2f12bcc

File tree

3 files changed

+41
-40
lines changed

3 files changed

+41
-40
lines changed

local-libs/traceviewer-libs/react-components/src/components/abstract-gantt-output-component.tsx

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export abstract class AbstractGanttOutputComponent<
121121
this.chartLayer.updateChart(this.filterExpressionsMap());
122122
}, 500);
123123

124-
static NEW_ID_KEY = -3;
124+
private NEW_ID_KEY = -3;
125125

126126
constructor(props: P) {
127127
super(props);
@@ -447,7 +447,7 @@ export abstract class AbstractGanttOutputComponent<
447447
const { collapsedNodes, emptyNodes } = this.state;
448448

449449
// Convert duplicate ID back to original ID for checking
450-
const originalId = entry.id < -1 ? AbstractGanttOutputComponent.getOriginalId(entry.id) : entry.id;
450+
const originalId = entry.id < -1 ? this.getOriginalId(entry.id) : entry.id;
451451

452452
// Check for empty nodes
453453
if (this.shouldHideEmptyNodes && emptyNodes.includes(originalId)) {
@@ -1028,9 +1028,7 @@ export abstract class AbstractGanttOutputComponent<
10281028

10291029
// Add pinned rows at the beginning
10301030
const pinnedRowIds = pinnedRows
1031-
? pinnedRows
1032-
.filter(id => chartTree.some(entry => entry.id === id))
1033-
.map(id => AbstractGanttOutputComponent.createNewId(id))
1031+
? pinnedRows.filter(id => chartTree.some(entry => entry.id === id)).map(id => this.createNewId(id))
10341032
: [];
10351033
const rowIds = [...pinnedRowIds, ...regularRowIds];
10361034

@@ -1054,7 +1052,7 @@ export abstract class AbstractGanttOutputComponent<
10541052

10551053
const strategy = additionalProperties?.filter_query_parameters?.strategy;
10561054
const ids = rowIds ? rowIds : this.getTimegraphRowIds().rowIds;
1057-
const originalIds = ids.map(id => (id < -1 ? AbstractGanttOutputComponent.getOriginalId(id) : id));
1055+
const originalIds = ids.map(id => (id < -1 ? this.getOriginalId(id) : id));
10581056

10591057
const { start, end } = range;
10601058
const newRange: TimelineChart.TimeGraphRange = range;
@@ -1501,7 +1499,7 @@ export abstract class AbstractGanttOutputComponent<
15011499
* @param {number} id TreeNode id number
15021500
*/
15031501
public onRowClick = (id: number): void => {
1504-
const originalId = id < -1 ? AbstractGanttOutputComponent.getOriginalId(id) : id;
1502+
const originalId = id < -1 ? this.getOriginalId(id) : id;
15051503
const rowIndex = getIndexOfNode(
15061504
originalId,
15071505
listToTree(this.state.chartTree, this.state.columns),
@@ -1634,7 +1632,7 @@ export abstract class AbstractGanttOutputComponent<
16341632
public onPin = (id: number): void => {
16351633
const rows = this.state.pinnedRows ? this.state.pinnedRows.slice() : [];
16361634
// Handle both original ID and duplicate ID
1637-
const originalId = id < -1 ? AbstractGanttOutputComponent.getOriginalId(id) : id;
1635+
const originalId = id < -1 ? this.getOriginalId(id) : id;
16381636
const index = rows.indexOf(originalId);
16391637
if (index === -1) {
16401638
rows.push(originalId);
@@ -1647,11 +1645,38 @@ export abstract class AbstractGanttOutputComponent<
16471645
});
16481646
};
16491647

1650-
static createNewId(originalId: number) {
1651-
return originalId ^ this.NEW_ID_KEY;
1648+
private getLastEntryId() {
1649+
const lastEntryIndex = this.state.chartTree.length - 1;
1650+
const lastEntry = this.state.chartTree[lastEntryIndex];
1651+
return lastEntry.id;
16521652
}
16531653

1654-
static getOriginalId(newId: number) {
1655-
return newId ^ this.NEW_ID_KEY;
1654+
protected createNewId(originalId: number) {
1655+
const newId = originalId ^ this.NEW_ID_KEY;
1656+
return newId === -1 ? (this.getLastEntryId() + 1) ^ this.NEW_ID_KEY : newId;
1657+
}
1658+
1659+
protected getOriginalId(newId: number) {
1660+
const original1 = newId ^ this.NEW_ID_KEY;
1661+
const original2 = original1 === this.getLastEntryId() + 1 ? -1 ^ this.NEW_ID_KEY : original1;
1662+
return original2;
1663+
}
1664+
1665+
protected getEntriesWithPinned() {
1666+
const pinnedEntries = this.state.pinnedRows
1667+
? this.state.pinnedRows
1668+
.map(id => this.state.chartTree.find(entry => entry.id === id))
1669+
.filter(entry => entry !== undefined)
1670+
.map(entry => ({ ...entry, id: this.createNewId(entry.id), parentId: -1 }))
1671+
: [];
1672+
const entriesWithPinned = [...pinnedEntries, ...this.state.chartTree];
1673+
return entriesWithPinned;
1674+
}
1675+
1676+
protected getExtendedPinnedRows() {
1677+
const extendedPinnedRows = this.state.pinnedRows
1678+
? [...this.state.pinnedRows, ...this.state.pinnedRows.map(id => this.createNewId(id))]
1679+
: [];
1680+
return extendedPinnedRows;
16561681
}
16571682
}

local-libs/traceviewer-libs/react-components/src/components/gantt-chart-output-component.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,9 @@ export class GanttChartOutputComponent extends AbstractGanttOutputComponent<
6363
this.onOrderReset = this.onOrderReset.bind(this);
6464

6565
// Add pinned entries at the top, maintaining tree order
66-
const pinnedEntries = this.state.pinnedRows
67-
? this.state.pinnedRows
68-
.map(id => this.state.chartTree.find(entry => entry.id === id))
69-
.filter(entry => entry !== undefined)
70-
.map(entry => ({ ...entry, id: AbstractGanttOutputComponent.createNewId(entry.id), parentId: -1 }))
71-
: [];
72-
const entriesWithPinned = [...pinnedEntries, ...this.state.chartTree];
73-
66+
const entriesWithPinned = this.getEntriesWithPinned();
7467
// Show pin icons on both original and duplicate rows
75-
const extendedPinnedRows = this.state.pinnedRows
76-
? [
77-
...this.state.pinnedRows,
78-
...this.state.pinnedRows.map(id => AbstractGanttOutputComponent.createNewId(id))
79-
]
80-
: [];
68+
const extendedPinnedRows = this.getExtendedPinnedRows();
8169

8270
// TODO Show header, when we can have entries in-line with timeline-chart
8371
return (

local-libs/traceviewer-libs/react-components/src/components/timegraph-output-component.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,9 @@ export class TimegraphOutputComponent extends AbstractGanttOutputComponent {
3838
this.onOrderReset = this.onOrderReset.bind(this);
3939

4040
// Add pinned entries at the top, maintaining tree order
41-
const pinnedEntries = this.state.pinnedRows
42-
? this.state.pinnedRows
43-
.map(id => this.state.chartTree.find(entry => entry.id === id))
44-
.filter(entry => entry !== undefined)
45-
.map(entry => ({ ...entry, id: AbstractGanttOutputComponent.createNewId(entry.id), parentId: -1 }))
46-
: [];
47-
const entriesWithPinned = [...pinnedEntries, ...this.state.chartTree];
48-
41+
const entriesWithPinned = this.getEntriesWithPinned();
4942
// Show pin icons on both original and duplicate rows
50-
const extendedPinnedRows = this.state.pinnedRows
51-
? [
52-
...this.state.pinnedRows,
53-
...this.state.pinnedRows.map(id => AbstractGanttOutputComponent.createNewId(id))
54-
]
55-
: [];
43+
const extendedPinnedRows = this.getExtendedPinnedRows();
5644

5745
return (
5846
<>

0 commit comments

Comments
 (0)