Skip to content

Commit 26df1e6

Browse files
committed
Refactor task deselection logic in WithTaskClusterMarkers to accumulate tasks with bundle conflicts and deselect them in a single operation, improving performance and state management.
1 parent dd73f8e commit 26df1e6

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/components/HOCs/WithTaskClusterMarkers/WithTaskClusterMarkers.jsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export const WithTaskClusterMarkers = function (WrappedComponent) {
3333
* Refreshes map marker data for the task clusters
3434
*/
3535
updateMapMarkers() {
36+
const tasksToDeselect = [];
37+
3638
const markers = _map(this.props.taskClusters, (cluster) => {
3739
const clusterStatus = cluster.status ?? cluster.taskStatus;
3840
const clusterId = cluster.id ?? cluster.taskId;
@@ -51,7 +53,7 @@ export const WithTaskClusterMarkers = function (WrappedComponent) {
5153
locked,
5254
);
5355

54-
// If this task has a bundle conflict and is currently selected, deselect it
56+
// If this task has a bundle conflict and is currently selected, add it to deselect list
5557
if (
5658
bundleConflict &&
5759
this.props.selectedTasks &&
@@ -64,10 +66,7 @@ export const WithTaskClusterMarkers = function (WrappedComponent) {
6466
!this.props.taskBundle?.taskIds?.includes(clusterId) &&
6567
!this.props.initialBundle?.taskIds?.includes(clusterId)
6668
) {
67-
// Use setTimeout to avoid state updates during render
68-
setTimeout(() => {
69-
this.props.deselectTasks([{ id: clusterId }]);
70-
}, 0);
69+
tasksToDeselect.push({ id: clusterId });
7170
}
7271

7372
return AsMappableCluster(cluster).mapMarker(
@@ -79,6 +78,14 @@ export const WithTaskClusterMarkers = function (WrappedComponent) {
7978
);
8079
});
8180

81+
// Deselect all tasks with bundle conflicts at once
82+
if (tasksToDeselect.length > 0 && this.props.deselectTasks) {
83+
// Use setTimeout to avoid state updates during render
84+
setTimeout(() => {
85+
this.props.deselectTasks(tasksToDeselect);
86+
}, 0);
87+
}
88+
8289
this.setState({ taskMarkers: markers });
8390
}
8491

0 commit comments

Comments
 (0)