Skip to content

Commit 4ff5f94

Browse files
- implemented #1376
- also fixed bug in download structures dialog where only first download got added to the dropdown menu
1 parent 66a98f3 commit 4ff5f94

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

js/components/snapshot/modals/downloadStructuresDialog.js

+36-11
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,13 @@ export const DownloadStructureDialog = memo(({}) => {
470470
}
471471
};
472472

473+
const resetDownloadOnChange = () => {
474+
setSelectedDownload(newDownload);
475+
setDownloadTagUrl(null);
476+
setFileSize(null);
477+
setDownloadUrl(null);
478+
};
479+
473480
const copyPOSTJson = () => {
474481
const requestObject = prepareRequestObject();
475482
const jsonString = JSON.stringify(requestObject);
@@ -563,7 +570,14 @@ export const DownloadStructureDialog = memo(({}) => {
563570
<FormControlLabel
564571
key={flag}
565572
value={flag}
566-
control={<Radio disabled={zipPreparing} />}
573+
control={
574+
<Radio
575+
disabled={zipPreparing}
576+
onChange={() => {
577+
resetDownloadOnChange();
578+
}}
579+
/>
580+
}
567581
label={text}
568582
/>
569583
);
@@ -578,11 +592,12 @@ export const DownloadStructureDialog = memo(({}) => {
578592
control={
579593
<Checkbox
580594
checked={mapFiles[flag]}
581-
onChange={() =>
595+
onChange={() => {
582596
setMapFiles(prevState => {
583597
return { ...prevState, [flag]: !prevState[flag] };
584-
})
585-
}
598+
});
599+
resetDownloadOnChange();
600+
}}
586601
disabled={zipPreparing}
587602
/>
588603
}
@@ -599,11 +614,12 @@ export const DownloadStructureDialog = memo(({}) => {
599614
control={
600615
<Checkbox
601616
checked={crystallographicFiles[flag]}
602-
onChange={() =>
617+
onChange={() => {
603618
setCrystallographicFiles(prevState => {
604619
return { ...prevState, [flag]: !prevState[flag] };
605-
})
606-
}
620+
});
621+
resetDownloadOnChange();
622+
}}
607623
disabled={zipPreparing || disabled}
608624
/>
609625
}
@@ -626,14 +642,22 @@ export const DownloadStructureDialog = memo(({}) => {
626642
name="radio-group-download-type"
627643
onChange={event => {
628644
setLinkType(event.currentTarget.value);
645+
resetDownloadOnChange();
629646
}}
630647
>
631648
{PERMALINK_OPTIONS.map(({ flag, text }) => {
632649
return (
633650
<FormControlLabel
634651
key={flag}
635652
value={flag}
636-
control={<Radio disabled={zipPreparing} />}
653+
control={
654+
<Radio
655+
disabled={zipPreparing}
656+
onChange={() => {
657+
resetDownloadOnChange();
658+
}}
659+
/>
660+
}
637661
label={text}
638662
/>
639663
);
@@ -648,11 +672,12 @@ export const DownloadStructureDialog = memo(({}) => {
648672
control={
649673
<Checkbox
650674
checked={other[flag]}
651-
onChange={() =>
675+
onChange={() => {
652676
setOthers(prevState => {
653677
return { ...prevState, [flag]: !prevState[flag] };
654-
})
655-
}
678+
});
679+
resetDownloadOnChange();
680+
}}
656681
disabled={zipPreparing}
657682
/>
658683
}

js/reducers/api/apiReducers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ export default function apiReducers(state = INITIAL_STATE, action = {}) {
266266
return { ...state, downloadTags: [...action.downloadTags] };
267267

268268
case constants.APPEND_TO_DOWNLOAD_TAGS:
269-
if (!state.downloadTags.find(dt => action.tag.tag)) {
270-
return { ...state, downloadTags: [...state.downloadTags, action.tag] };
269+
if (!state.downloadTags.find(dt => dt.tag === action.tag.tag)) {
270+
return { ...state, downloadTags: [...state.downloadTags, { ...action.tag }] };
271271
} else {
272272
return state;
273273
}

0 commit comments

Comments
 (0)