nmrium icon indicating copy to clipboard operation
nmrium copied to clipboard

Stability of sorting

Open lpatiny opened this issue 2 years ago • 6 comments

I would expect that the order is stable. This means that if I cancel the ordering of a column I should go back to the original order.

2023-11-02 10 44 05

lpatiny avatar Nov 02 '23 09:11 lpatiny

We could add an index object and the original order should be based on this number, or we could save the original order in a local state

hamed-musallam avatar Nov 08 '23 08:11 hamed-musallam

Does the sorting affect the array in the global state? It really shouldn't

targos avatar Nov 08 '23 08:11 targos

In our case, it should, as it affects the order of the spectra and other places such as the multiple spectra analysis list Screenshot 2023-11-08 at 09 50 35

hamed-musallam avatar Nov 08 '23 08:11 hamed-musallam

I believe there's an alternative approach we can explore, but it would require more adjustments. We could store the order as 'Ascending' or 'Descending' in the state, and then use that information to sort spectra in all locations without modifying the global state array

hamed-musallam avatar Nov 08 '23 08:11 hamed-musallam

I believe that making changes to the original array is the simplest way to accomplish this without introducing additional complexities

hamed-musallam avatar Nov 08 '23 08:11 hamed-musallam

There are other less intrusive alternatives. I recommend to create derived state dynamically (after the useReducer call) that you pass in a context provider. We don't want the sorted array to be saved when we export the data.

targos avatar Nov 08 '23 10:11 targos