Fix sorting order of selection during exports

Summary:
See https://fb.workplace.com/100051336486185/videos/469885544533059/

I couldn't reproduce it myself, but it is reported that when copying logs, the order of the selection is not preserve. Diving into the example there is a block of rows (around the 1.09 timestamp) that appear 'too early' in the output.

In flipper we sort the selection before copying the data by row index. This is to make sure if the user has multiple selections, they appear in the order of the logs (including any applied sorting), rather than in the order of which the user selected them.

However, when sorting numbers, JavaScript by coerces them to strings first (wtf JS), so the issue can be prevented by explicitly providing a sort function. Proof: {F749329864}

Reviewed By: lblasa

Differential Revision: D37596975

fbshipit-source-id: 820e03350034e7af8148200a58a8c858b358acd8
This commit is contained in:
Michel Weststrate
2022-07-04 04:13:04 -07:00
committed by Facebook GitHub Bot
parent 1353e0630b
commit d162bcc2a4

View File

@@ -502,7 +502,7 @@ export function getSelectedItems<T>(
selection: Selection,
): T[] {
return [...selection.items]
.sort()
.sort((a, b) => a - b) // https://stackoverflow.com/a/15765283/1983583
.map((i) => dataSource.view.get(i))
.filter(Boolean) as any[];
}