Skip to content

Commit

Permalink
VolumeDialog: share numeric value between Fixed and Range (#1412)
Browse files Browse the repository at this point in the history
## Problem

#1277 - "Size entry gets reset when switching from Range to Fixed"

## Solution

In Add/Edit file system dialog (VolumeDialog), keep the numeric value
when switching between Fixed and Range sizing.

Do it by removing `size` and `sizeUnit` from `formData` and using
`minSize`, `minSizeUnit` for both roles.

## Testing

- [x] *Tested manually*
  • Loading branch information
mvidner committed Jun 28, 2024
2 parents 392bc42 + ca1d1ee commit 21f6b48
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 6 additions & 0 deletions web/package/agama-web-ui.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Jun 28 13:49:54 UTC 2024 - Martin Vidner <mvidner@suse.com>

- In Add/Edit file system dialog (VolumeDialog), keep the numeric value
when switching between Fixed and Range sizing (gh#openSUSE/agama#1277)

-------------------------------------------------------------------
Fri Jun 28 06:56:02 UTC 2024 - Martin Vidner <mvidner@suse.com>

Expand Down
7 changes: 1 addition & 6 deletions web/src/components/storage/VolumeDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ import {
* @property {VolumeFormErrors} errors
*
* @typedef {object} VolumeFormData
* @property {number|string} [size]
* @property {string} [sizeUnit]
* @property {number|string} [minSize]
* @property {string} [minSizeUnit]
* @property {number|string} [maxSize]
Expand Down Expand Up @@ -490,7 +488,6 @@ const sanitizeMountPath = (mountPath) => {
*/
const createUpdatedVolume = (volume, formData) => {
let sizeAttrs = {};
const size = parseToBytes(`${formData.size} ${formData.sizeUnit}`);
const minSize = parseToBytes(`${formData.minSize} ${formData.minSizeUnit}`);
const maxSize = parseToBytes(`${formData.maxSize} ${formData.maxSizeUnit}`);

Expand All @@ -499,7 +496,7 @@ const createUpdatedVolume = (volume, formData) => {
sizeAttrs = { minSize: undefined, maxSize: undefined, autoSize: true };
break;
case SIZE_METHODS.MANUAL:
sizeAttrs = { minSize: size, maxSize: size, autoSize: false };
sizeAttrs = { minSize, maxSize: minSize, autoSize: false };
break;
case SIZE_METHODS.RANGE:
sizeAttrs = { minSize, maxSize: formData.maxSize ? maxSize : undefined, autoSize: false };
Expand Down Expand Up @@ -543,8 +540,6 @@ const prepareFormData = (volume) => {
const { size: maxSize = "", unit: maxSizeUnit = minSizeUnit || DEFAULT_SIZE_UNIT } = splitSize(volume.maxSize);

return {
size: minSize,
sizeUnit: minSizeUnit,
minSize,
minSizeUnit,
maxSize,
Expand Down
10 changes: 5 additions & 5 deletions web/src/components/storage/VolumeFields.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ const SizeManual = ({ errors, formData, isDisabled, onChange }) => {
// (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
// or use the "globalize" JS library which can also parse the localized string back
// (https://github.com/globalizejs/globalize#number-module)
value={formData.size}
onChange={(size) => onChange({ size })}
validated={errors.size && 'error'}
value={formData.minSize}
onChange={(minSize) => onChange({ minSize })}
validated={errors.minSize && 'error'}
isDisabled={isDisabled}
/>
</InputGroupItem>
Expand All @@ -334,8 +334,8 @@ const SizeManual = ({ errors, formData, isDisabled, onChange }) => {
// TRANSLATORS: units selector (like KiB, MiB, GiB...)
aria-label={_("Size unit")}
units={Object.values(SIZE_UNITS)}
value={formData.sizeUnit}
onChange={(_, sizeUnit) => onChange({ sizeUnit })}
value={formData.minSizeUnit}
onChange={(_, minSizeUnit) => onChange({ minSizeUnit })}
isDisabled={isDisabled}
/>
</InputGroupItem>
Expand Down

0 comments on commit 21f6b48

Please sign in to comment.