Skip to content

Commit 2a2d5af

Browse files
authored
Merge pull request #8702 from Autosde/split_volume_create_capabilities_to_seperate_single_select_fields
split volume create capabilities to separate single select fields
2 parents d64e9c8 + d9c3f2b commit 2a2d5af

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
lines changed

app/javascript/components/cloud-volume-form/cloud-volume-form.schema.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const createSchema = (fields, edit, ems, loadSchema, emptySchema) => {
8989
component: componentTypes.SUB_FORM,
9090
name: 'resource_type_selection',
9191
id: 'resource_type_selection',
92-
condition: { when: 'required_capabilities', isNotEmpty: true },
92+
condition: { when: 'compression', isNotEmpty: true },
9393
fields: [
9494
{
9595
component: 'enhanced-select',
@@ -101,12 +101,18 @@ const createSchema = (fields, edit, ems, loadSchema, emptySchema) => {
101101
isRequired: true,
102102
validate: [
103103
{ type: validatorTypes.REQUIRED },
104-
{ type: validatorTypes.PATTERN, pattern: '^(?!-)', message: 'Required' },
104+
{ type: validatorTypes.PATTERN, pattern: '^(?!-)', message: 'No storage service supports all selected capabilities' },
105105
async(value) => validateServiceHasResources(value),
106106
],
107107
resolveProps: (_props, _field, { getState }) => {
108-
const capabilityValues = getState().values.required_capabilities.map(({ value }) => value);
109-
const emsId = getState().values.ems_id;
108+
const stateValues = getState().values;
109+
const emsId = stateValues.ems_id;
110+
const capabilityValues = [];
111+
112+
const capabilityNames = fields.find((object) => object.id === 'required_capabilities')
113+
.fields.map((capability) => capability.id);
114+
capabilityNames.forEach((capabilityName) => capabilityValues.push(stateValues[capabilityName]));
115+
110116
return {
111117
key: JSON.stringify(capabilityValues),
112118
loadOptions: async() => {
@@ -120,19 +126,25 @@ const createSchema = (fields, edit, ems, loadSchema, emptySchema) => {
120126
component: 'enhanced-select',
121127
name: 'storage_resource_id',
122128
id: 'storage_resource_id',
123-
label: __('Storage Resources (if no option appears then no storage resource with selected capabilities was found)'),
129+
label: __('Storage Resource(s)'),
124130
condition: { when: 'mode', is: 'Advanced' },
125131
onInputChange: () => null,
126132
isRequired: true,
127-
helperText: __('Select storage resources to attach to the new service. The new Volume(s) will be created on these resources.'),
133+
helperText: __('Select storage resources to attach to the service. The new Volume(s) will be created on these resources.'),
128134
validate: [
129135
{ type: validatorTypes.REQUIRED },
130136
{ type: validatorTypes.PATTERN, pattern: '^(?!-)', message: 'Required' },
131137
],
132138
isMulti: true,
133139
resolveProps: (_props, _field, { getState }) => {
134-
const capabilityValues = getState().values.required_capabilities.map(({ value }) => value);
135-
const emsId = getState().values.ems_id;
140+
const stateValues = getState().values;
141+
const emsId = stateValues.ems_id;
142+
const capabilityValues = [];
143+
144+
const capabilityNames = fields.find((object) => object.id === 'required_capabilities')
145+
.fields.map((capability) => capability.id);
146+
capabilityNames.forEach((capabilityName) => capabilityValues.push(stateValues[capabilityName]));
147+
136148
return {
137149
key: JSON.stringify(capabilityValues),
138150
loadOptions: async() => {

app/javascript/components/cloud-volume-form/index.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const CloudVolumeForm = ({ recordId, storageManagerId }) => {
4040
}
4141
}, [recordId, storageManagerId]);
4242

43+
const redirectUrl = storageManagerId ? `/ems_storage/${storageManagerId}?display=cloud_volumes#/` : '/cloud_volume/show_list';
44+
4345
const onSubmit = ({ edit: _edit, ...values }) => {
4446
if (values.ems_id !== '-1') {
4547
miqSparkleOn();
@@ -52,7 +54,7 @@ const CloudVolumeForm = ({ recordId, storageManagerId }) => {
5254
: __('Add of Cloud Volume "%s" has been successfully queued.'),
5355
values.name,
5456
);
55-
miqRedirectBack(message, undefined, '/cloud_volume/show_list');
57+
miqRedirectBack(message, undefined, redirectUrl);
5658
}).catch(miqSparkleOff);
5759
}
5860
};
@@ -64,7 +66,7 @@ const CloudVolumeForm = ({ recordId, storageManagerId }) => {
6466
: __('Add of new Cloud Volume was cancelled by the user.'),
6567
initialValues && initialValues.name,
6668
);
67-
miqRedirectBack(message, 'warning', '/cloud_volume/show_list');
69+
miqRedirectBack(message, 'warning', redirectUrl);
6870
};
6971

7072
const validation = (values) => {

app/javascript/helpers/storage_manager/filter-by-capabilities-utils.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/** function that use to filter the services/resources by capabilities. */
2-
const arrayIncludes = (including, included) => including.length >= included.length
3-
&& included.every((includedItem) => including.includes(includedItem));
2+
const arrayIncludes = (including, included) => included.every((includedItem) => including.includes(includedItem));
43

54
const getCapabilityUuid = (providerCapabilities, capabilityName, capabilityValue) => {
65
const capVals = providerCapabilities[capabilityName];

app/javascript/helpers/storage_manager/filter-resources-by-capabilities.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const filterResourcesByCapabilities = async(filterArray, providerCapabilities) =
1111
resourceCapsUuids.push(getCapabilityUuid(providerCapabilities, capabilityName, capabilityValue));
1212
});
1313
});
14+
resourceCapsUuids.push('-1'); // to filter-in the N/A option of capabilities
15+
1416
if (arrayIncludes(resourceCapsUuids, filterArray)) {
1517
valueArray.push(resource);
1618
}

app/javascript/helpers/storage_manager/filter-service-by-capabilities.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const filterServicesByCapabilities = async(filterArray, providerCapabilities) =>
99
Object.keys(resource.capabilities).forEach((key) => {
1010
capsToFilter.push(getCapabilityUuid(providerCapabilities, key, resource.capabilities[key]));
1111
});
12+
capsToFilter.push('-1'); // to filter-in the N/A option of capabilities
13+
1214
if (arrayIncludes(capsToFilter, filterArray)) {
1315
valueArray.push(resource);
1416
}
@@ -17,7 +19,7 @@ const filterServicesByCapabilities = async(filterArray, providerCapabilities) =>
1719
const options = valueArray.map(({ name, id }) => ({ label: name, value: id }));
1820

1921
if (options.length === 0) {
20-
options.unshift({ label: sprintf(__('No storage service with selected capabilities.')), value: '-1' });
22+
options.unshift({ label: sprintf(__('Not found')), value: '-1' });
2123
}
2224

2325
options.unshift({ label: `<${__('Choose')}>`, value: '-2' });

0 commit comments

Comments
 (0)