Skip to content

Commit

Permalink
Feature/EPMUII-8047 'Save' option doesn't save any files (#218)
Browse files Browse the repository at this point in the history
* EPMUII-8047:
- fixed nifti file saving dialog appearance
- fixed file extension setting during first download
- fixed styles of nifti saving window
  • Loading branch information
rrodionov91 authored Feb 6, 2025
1 parent c35c963 commit 69bc873
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/ui/Button/Button.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,7 @@ button:hover,
.button_select_file svg {
margin-right: 10px;
}

.cancel {
border-radius: 4px;
}
4 changes: 4 additions & 0 deletions src/ui/Modals/Modals.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@
flex-direction: column;
}

.input_label_left {
margin-right: 5px;
}

.input {
flex-grow: 1;
border: 1px solid var(--dark-gray);
Expand Down
28 changes: 18 additions & 10 deletions src/ui/Modals/UiModalSaveNifti.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import React, { useState } from 'react';
import { useSelector } from 'react-redux';

import SaverNifti from '../../engine/savers/SaverNifti';
import { Modal, ModalBody, ModalHeader } from './ModalBase';
import { Modal, ModalBody, ModalFooter, ModalHeader } from './ModalBase';
import { UIButton } from '../Button/Button';
import buttonCss from '../Button/Button.module.css';
import modalCss from './Modals.module.css';

export function UiModalSaveNifti(props) {
const { stateVis, onHide } = props;
Expand Down Expand Up @@ -40,14 +42,17 @@ export function UiModalSaveNifti(props) {
const niiArr = SaverNifti.writeBuffer(volData, volSize);
const textToSaveAsBlob = new Blob([niiArr], { type: 'application/octet-stream' });
const textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
const goodSuffix = fileName.trim().endsWith('.nii');
if (!goodSuffix) {
setFileName((prev) => `${prev.trim()}.nii`);
const isExtensionValid = fileName.trim().endsWith('.nii');
let fileNameWithExtension = fileName;

if (!isExtensionValid) {
fileNameWithExtension = `${fileName}.nii`;
setFileName(fileNameWithExtension);
}
// console.log(`Save to file ${fileName}`);

const downloadLink = document.createElement('a');
downloadLink.download = fileName;
downloadLink.download = fileNameWithExtension;
downloadLink.innerHTML = 'Download File';
downloadLink.href = textToSaveAsURL;
downloadLink.onclick = (event) => document.body.removeChild(event.target);
Expand All @@ -68,23 +73,26 @@ export function UiModalSaveNifti(props) {
};

return (
<Modal show={stateVis} onHide={onHide}>
<Modal isOpen={stateVis} onHide={onHide}>
<ModalHeader title="Save to Nifty" />
<ModalBody>
<ModalHeader title="Save to Nifty" />
<label className={modalCss.input_label_left}>Enter file name:</label>
<input
required
type="text"
placeholder="Enter file name here"
className={modalCss.input}
value={fileName}
onChange={onTexChange}
onKeyUp={(evt) => {
handleFormSubmit(evt);
}}
/>
.nii
<UIButton handler={onSaveNifti} caption="Save" />
<UIButton handler={onHide} caption="Cancel" />
</ModalBody>
<ModalFooter>
<UIButton handler={onSaveNifti} caption="Save" mode={'accent'} cx={buttonCss.apply} />
<UIButton handler={onHide} caption="Cancel" cx={buttonCss.cancel} />
</ModalFooter>
</Modal>
);
}

0 comments on commit 69bc873

Please sign in to comment.