Skip to content

Commit

Permalink
fix: order
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoalee committed Jan 22, 2025
1 parent abca406 commit 49af43d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ const ThresholdSlider: React.FC<{
}}
></Slider>
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
{/* no mechanism exists yet to allow for soft threshold AND adjustable cal_min. Uncomment this if we want to add an adjustable min in the future, the useEffect infrastructure to do so already exists above */}
{/* <TextField
sx={{
width: '60px',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ export interface INeurovault {
function useGetNeurovaultImages(neurovaultImages: string[]) {
return useQuery({
queryKey: ['neurovault-images', ...neurovaultImages],

queryFn: async () => {
const res = await Promise.all<AxiosResponse<INeurovault>>(neurovaultImages.map((url) => axios.get(url)));

return res.map((x) => ({
...x.data,
file: (x.data.file || '').replace(/http/, 'https'), // without this, link will redirect but result in an error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ const caseMKDAChi2: Partial<INeurovault>[] = [
{ id: 5, name: 'z_desc-associationMass' },
];

const caseNotZAlphabetical: Partial<INeurovault>[] = [
{ id: 2, name: 'p_desc-DEF' },
{ id: 1, name: 'p_desc-ABC' },
];

const caseMoreSegments: Partial<INeurovault>[] = [
{ id: 2, name: 'z_desc-association_level-voxel_corr-FDR_method-indep.nii.gz' },
{ id: 1, name: 'z_desc-association.nii.gz' },
Expand Down Expand Up @@ -148,6 +153,20 @@ describe('DisplayMetaAnalysisResults', () => {
expect(buttons[4].textContent).toBe('z_desc-ZZZ');
});

it('should show the correctly sorted list for non z maps', () => {
(useGetNeurovaultImages as Mock).mockReturnValue({
data: caseNotZAlphabetical,
isLoading: false,
isError: false,
});

render(<DisplayMetaAnalysisResults metaAnalysis={mockMetaAnalysisReturn()} />);
const buttons = screen.getAllByRole('button');
expect(buttons.length).toEqual(caseNotZAlphabetical.length);
expect(buttons[0].textContent).toBe('p_desc-ABC');
expect(buttons[1].textContent).toBe('p_desc-DEF');
});

it('should show the correctly sorted list if one file name is larger than the other', () => {
(useGetNeurovaultImages as Mock).mockReturnValue({
data: caseMoreSegments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const DisplayMetaAnalysisResults: React.FC<{
if (!neurovaultFiles || !metaAnalysis || !(metaAnalysis?.specification as Specification).estimator?.type)
return [];

const orderMap = new Map(NimareOutputs.map((output, index) => [output.key, index]));
const orderMap = new Map(NimareOutputs.reverse().map((output, index) => [output.key, index]));
// We want the order of the files to be very specific:
// if algorithm is MKDAChi2, then set 1st image to be z_desc-associationMass
// set 2nd image to be z_desc-uniformityMass
Expand All @@ -51,8 +51,8 @@ const DisplayMetaAnalysisResults: React.FC<{
const segmentB = filenameB[i];

if (!segmentA && !segmentB) return 0;
else if (!segmentA) return -1;
else if (!segmentB) return 1;
else if (!segmentA) return 1;
else if (!segmentB) return -1;

const orderA = orderMap.get(segmentA.key) ?? Infinity;
const orderB = orderMap.get(segmentB.key) ?? Infinity;
Expand All @@ -61,7 +61,7 @@ const DisplayMetaAnalysisResults: React.FC<{
if (segmentA.value === segmentB.value) continue;
return segmentA.value.localeCompare(segmentB.value);
} else {
return orderB - orderA;
return orderA - orderB;
}
}
return 0;
Expand All @@ -85,7 +85,7 @@ const DisplayMetaAnalysisResults: React.FC<{
}
}

return sorted.reverse();
return sorted;
}, [neurovaultFiles, metaAnalysis]);

useEffect(() => {
Expand Down

0 comments on commit 49af43d

Please sign in to comment.