From d162bcc2a46d97b54d5ea8f9b3c71ef6594dfc8a Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Mon, 4 Jul 2022 04:13:04 -0700 Subject: [PATCH] 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 --- desktop/flipper-plugin/src/ui/data-table/DataTableManager.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop/flipper-plugin/src/ui/data-table/DataTableManager.tsx b/desktop/flipper-plugin/src/ui/data-table/DataTableManager.tsx index ecc3343c2..5a41ae937 100644 --- a/desktop/flipper-plugin/src/ui/data-table/DataTableManager.tsx +++ b/desktop/flipper-plugin/src/ui/data-table/DataTableManager.tsx @@ -502,7 +502,7 @@ export function getSelectedItems( 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[]; }