Skip to content

Commit 6029c95

Browse files
Minor fixes
1 parent d359d80 commit 6029c95

File tree

5 files changed

+278
-102
lines changed

5 files changed

+278
-102
lines changed

app/controllers/miq_ae_class_controller.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,11 +1884,12 @@ def class_update_create
18841884
begin
18851885
class_rec.save!
18861886
rescue StandardError
1887+
errors = []
18871888
class_rec.errors.each do |error|
1888-
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
1889+
errors.push("#{error.attribute.to_s.capitalize} #{error.message}")
18891890
end
18901891
@changed = true
1891-
javascript_flash
1892+
render :json => {:error => errors, :status => 500}
18921893
else
18931894
edit_hash = {}
18941895
edit_hash[:new] = {:name => params[:name],
@@ -1902,7 +1903,7 @@ def class_update_create
19021903
end
19031904
AuditEvent.success(build_saved_audit(class_rec, edit_hash))
19041905
@edit = session[:edit] = nil # clean out the saved info
1905-
replace_right_cell(:nodetype => x_node, :replace_trees => [:ae])
1906+
render :json => {:status => 200}
19061907
end
19071908
end
19081909
end

app/javascript/components/miq-ae-class/class-form.schema.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { componentTypes, validatorTypes } from '@@ddf';
1+
import { componentTypes } from '@@ddf';
22

33
const createSchema = (fqname) => ({
44
fields: [
@@ -13,7 +13,7 @@ const createSchema = (fqname) => ({
1313
name: 'name',
1414
label: __('Name'),
1515
maxLength: 128,
16-
validate: [{ type: validatorTypes.REQUIRED }],
16+
validate: [{ type: 'customValidatorForNameField' }],
1717
isRequired: true,
1818
},
1919
{

app/javascript/components/miq-ae-class/index.jsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import MiqFormRenderer, { useFormApi } from '@@ddf';
55
import PropTypes from 'prop-types';
66
import createSchema from './class-form.schema';
77
import miqRedirectBack from '../../helpers/miq-redirect-back';
8+
import miqFlash from '../../helpers/miq-flash';
89

910
const MiqAeClass = ({ classRecord, fqname }) => {
1011
const [data, setData] = useState({
@@ -49,9 +50,14 @@ const MiqAeClass = ({ classRecord, fqname }) => {
4950
: http.post(`/miq_ae_class/class_update/`, params);
5051

5152
request
52-
.then(() => {
53-
const confirmation = isEdit ? __(`Class "${values.name}" was saved`) : __(`Class "${values.name}" was added`);
54-
miqRedirectBack(sprintf(confirmation, values.name), 'success', '/miq_ae_class/explorer');
53+
.then((response) => {
54+
if (response.status === 200) {
55+
const confirmation = isEdit ? __(`Class "${values.name}" was saved`) : __(`Class "${values.name}" was added`);
56+
miqRedirectBack(sprintf(confirmation, values.name), 'success', '/miq_ae_class/explorer');
57+
} else {
58+
miqSparkleOff();
59+
miqFlash('error', response.error);
60+
}
5561
})
5662
.catch(miqSparkleOff);
5763
};
@@ -65,12 +71,25 @@ const MiqAeClass = ({ classRecord, fqname }) => {
6571
miqRedirectBack(message, 'warning', '/miq_ae_class/explorer');
6672
};
6773

74+
const customValidatorMapper = {
75+
customValidatorForNameField: () => (value) => {
76+
if (!value) {
77+
return __('Required');
78+
}
79+
if (!value.match('^[a-zA-Z0-9_.-]*$')) {
80+
return __('Name may contain only alphanumeric and _ . - characters');
81+
}
82+
return false;
83+
},
84+
};
85+
6886
return (!data.isLoading
6987
? (
7088
<div className="dialog-provision-form">
7189
<MiqFormRenderer
7290
schema={createSchema(fqname)}
7391
initialValues={data.initialValues}
92+
validatorMapper={customValidatorMapper}
7493
onSubmit={onSubmit}
7594
onCancel={onCancel}
7695
canReset={!!classRecord.id}

cypress.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = defineConfig({
77
baseUrl: 'http://localhost:3000',
88
viewportHeight: 800,
99
viewportWidth: 1800,
10-
numTestsKeptInMemory: 0,
10+
numTestsKeptInMemory: 5,
1111
videoCompression: false,
1212
// eslint-disable-next-line no-unused-vars
1313
setupNodeEvents(on, config) {

0 commit comments

Comments
 (0)