Skip to content

Commit

Permalink
- implemented #1376
Browse files Browse the repository at this point in the history
- also fixed bug in download structures dialog where only first download got added to the dropdown menu
  • Loading branch information
boriskovar-m2ms committed Mar 12, 2024
1 parent 66a98f3 commit 4ff5f94
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
47 changes: 36 additions & 11 deletions js/components/snapshot/modals/downloadStructuresDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,13 @@ export const DownloadStructureDialog = memo(({}) => {
}
};

const resetDownloadOnChange = () => {
setSelectedDownload(newDownload);
setDownloadTagUrl(null);
setFileSize(null);
setDownloadUrl(null);
};

const copyPOSTJson = () => {
const requestObject = prepareRequestObject();
const jsonString = JSON.stringify(requestObject);
Expand Down Expand Up @@ -563,7 +570,14 @@ export const DownloadStructureDialog = memo(({}) => {
<FormControlLabel
key={flag}
value={flag}
control={<Radio disabled={zipPreparing} />}
control={
<Radio
disabled={zipPreparing}
onChange={() => {
resetDownloadOnChange();
}}
/>
}
label={text}
/>
);
Expand All @@ -578,11 +592,12 @@ export const DownloadStructureDialog = memo(({}) => {
control={
<Checkbox
checked={mapFiles[flag]}
onChange={() =>
onChange={() => {
setMapFiles(prevState => {
return { ...prevState, [flag]: !prevState[flag] };
})
}
});
resetDownloadOnChange();
}}
disabled={zipPreparing}
/>
}
Expand All @@ -599,11 +614,12 @@ export const DownloadStructureDialog = memo(({}) => {
control={
<Checkbox
checked={crystallographicFiles[flag]}
onChange={() =>
onChange={() => {
setCrystallographicFiles(prevState => {
return { ...prevState, [flag]: !prevState[flag] };
})
}
});
resetDownloadOnChange();
}}
disabled={zipPreparing || disabled}
/>
}
Expand All @@ -626,14 +642,22 @@ export const DownloadStructureDialog = memo(({}) => {
name="radio-group-download-type"
onChange={event => {
setLinkType(event.currentTarget.value);
resetDownloadOnChange();
}}
>
{PERMALINK_OPTIONS.map(({ flag, text }) => {
return (
<FormControlLabel
key={flag}
value={flag}
control={<Radio disabled={zipPreparing} />}
control={
<Radio
disabled={zipPreparing}
onChange={() => {
resetDownloadOnChange();
}}
/>
}
label={text}
/>
);
Expand All @@ -648,11 +672,12 @@ export const DownloadStructureDialog = memo(({}) => {
control={
<Checkbox
checked={other[flag]}
onChange={() =>
onChange={() => {
setOthers(prevState => {
return { ...prevState, [flag]: !prevState[flag] };
})
}
});
resetDownloadOnChange();
}}
disabled={zipPreparing}
/>
}
Expand Down
4 changes: 2 additions & 2 deletions js/reducers/api/apiReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ export default function apiReducers(state = INITIAL_STATE, action = {}) {
return { ...state, downloadTags: [...action.downloadTags] };

case constants.APPEND_TO_DOWNLOAD_TAGS:
if (!state.downloadTags.find(dt => action.tag.tag)) {
return { ...state, downloadTags: [...state.downloadTags, action.tag] };
if (!state.downloadTags.find(dt => dt.tag === action.tag.tag)) {
return { ...state, downloadTags: [...state.downloadTags, { ...action.tag }] };
} else {
return state;
}
Expand Down

0 comments on commit 4ff5f94

Please sign in to comment.