From 5cd9a8738a069a7453a5674dec65f7beebb6c510 Mon Sep 17 00:00:00 2001 From: YanJin Date: Sun, 20 Dec 2020 18:13:12 +0100 Subject: [PATCH] ui/volumes: Fix the defaults path start from the input path The recommend default device path should start from the global one Refs: #2964 --- ui/src/containers/CreateVolume.js | 5 +---- ui/src/services/utils.js | 2 ++ ui/src/services/utils.test.js | 9 +++++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ui/src/containers/CreateVolume.js b/ui/src/containers/CreateVolume.js index 66f465f1ee..192989c8be 100644 --- a/ui/src/containers/CreateVolume.js +++ b/ui/src/containers/CreateVolume.js @@ -269,10 +269,7 @@ const CreateVolume = (props) => { } } else if (fieldname === 'path') { if (values.path.trim() !== '' && touched.path) { - setFieldValue( - name, - linuxDrivesNamingIncrement(values.path, index + 1), - ); + setFieldValue(name, linuxDrivesNamingIncrement(values.path, index)); } } }, [ diff --git a/ui/src/services/utils.js b/ui/src/services/utils.js index 2e28cc6e4f..f5d65f7e0f 100644 --- a/ui/src/services/utils.js +++ b/ui/src/services/utils.js @@ -473,6 +473,8 @@ export const linuxDrivesNamingIncrement = (devicePath, increment) => { } } return devicePath; + } else if (devicePath.match(/^\/dev\/vd[a-z]/) && increment === 0) { + return devicePath; } else { return ''; } diff --git a/ui/src/services/utils.test.js b/ui/src/services/utils.test.js index c3665ccba9..c4b83d0366 100644 --- a/ui/src/services/utils.test.js +++ b/ui/src/services/utils.test.js @@ -285,6 +285,11 @@ it('should return /dev/vdaa after /dev/vdz', () => { expect(result).toEqual('/dev/vdaa'); }); +it('should return the original path if the increment is 0', () => { + const result = linuxDrivesNamingIncrement('/dev/vdc', 0); + expect(result).toEqual('/dev/vdc'); +}); + it('should return an empty string if the driver is not virtualization-aware disk driver', () => { const result = linuxDrivesNamingIncrement('/dev/sda', 2); expect(result).toEqual(''); @@ -295,7 +300,7 @@ it('should return an empty string if the device path is empty', () => { expect(result).toEqual(''); }); -it('should return an empty string if the increment is smaller than 1', () => { - const result = linuxDrivesNamingIncrement('/dev/vda', 0); +it('should return an empty string if the increment is smaller than 0', () => { + const result = linuxDrivesNamingIncrement('/dev/vda', -1); expect(result).toEqual(''); });