Skip to content

Commit 518f547

Browse files
committed
fixes substitute icon issue
1 parent c01a06e commit 518f547

File tree

3 files changed

+39
-36
lines changed

3 files changed

+39
-36
lines changed

app/controllers/miq_ae_class_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ def field_accept
14811481
# byebug
14821482
render :json => {
14831483
:message => 'Accepted',
1484-
:data => {:icons => [ae_field_fonticon(params[:aetype]), ae_field_fonticon(params[:datatype])]}
1484+
:status => 200,
14851485
}
14861486
end
14871487

app/javascript/components/data-tables/datastore/schema/class-fields-editor.jsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const ClassFieldsEditor = (props) => {
5959
setState((state) => ({ ...state, isModalOpen: false }));
6060
};
6161

62-
const formatFieldValues = (field, id, data = {}) => {
62+
const formatFieldValues = (field, id) => {
6363
if (!field || typeof field !== 'object') return [];
6464
const getFieldName = () => `${field.display_name} (${field.name})`;
6565
const getIconForValue = () => {
@@ -69,7 +69,9 @@ export const ClassFieldsEditor = (props) => {
6969
const dtypeMatch = dTypeOptions.find((option) => option[1] === field.datatype);
7070
const dTypeIcon = (dtypeMatch && dtypeMatch[2] && dtypeMatch[2]['data-icon']) || '';
7171

72-
return [aeTypeIcon, dTypeIcon];
72+
const subIcon = (field.substitute) ? 'pficon pficon-ok' : 'pficon pficon-close';
73+
74+
return [aeTypeIcon, dTypeIcon, subIcon];
7375
};
7476

7577
const row = {
@@ -128,8 +130,8 @@ export const ClassFieldsEditor = (props) => {
128130
updateState(data);
129131
} else {
130132
http.post(`/miq_ae_class/field_accept?button=accept`, values, { skipErrors: [400] })
131-
.then((response) => {
132-
const data = formatFieldValues(values, state.rows.length, response.data);
133+
.then(() => {
134+
const data = formatFieldValues(values, state.rows.length);
133135
updateState(data);
134136
})
135137
.catch((error) => {
@@ -153,7 +155,6 @@ export const ClassFieldsEditor = (props) => {
153155
}
154156
return row;
155157
});
156-
debugger
157158

158159
return {
159160
...prevState,
@@ -215,7 +216,6 @@ export const ClassFieldsEditor = (props) => {
215216
};
216217

217218
// const onCancel = () => {
218-
// debugger
219219
// miqSparkleOn();
220220
// const message = __('Edit of schema field was cancelled by the user');
221221
// miqRedirectBack(message, 'warning', '/miq_ae_class/explorer');
@@ -234,9 +234,7 @@ export const ClassFieldsEditor = (props) => {
234234
}).catch((error) => {
235235
console.error('Failed to cancel schema updates:', error);
236236
});
237-
}
238-
239-
// debugger
237+
};
240238

241239
return (
242240
<>

app/javascript/components/data-tables/datastore/schema/modal-form.schema.js

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@ import { transformSelectOptions } from '../helper';
44
const createClassFieldsSchema = (aeClassId, selectedRowId, aeTypeOptions,
55
dTypeOptions, schemaField = {}, handleSchemaFieldChange, updateFieldValueInState) => {
66
const classField = schemaField;
7-
8-
// const formatName = () => {
9-
// const fullName = classField.name.text;
10-
// const match = fullName.match(/^(.+?)\s*\(([^)]+)\)$/);
11-
// return {
12-
// display_name: match[1],
13-
// name: match[2],
14-
// };
15-
// };
7+
console.log("Class field -- ", classField);
168

179
const formatName = () => {
1810
const fullName = classField.name.text;
@@ -30,6 +22,25 @@ const createClassFieldsSchema = (aeClassId, selectedRowId, aeTypeOptions,
3022
};
3123
};
3224

25+
const getIcons = (index) => {
26+
if (
27+
classField
28+
&& typeof classField === 'object'
29+
&& Object.keys(classField).length > 0
30+
&& classField.name
31+
&& 'icon' in classField.name
32+
) {
33+
let icons = classField.name.icon;
34+
if (icons.length === 2) {
35+
// icons come in the order [aetype, dtype, substitute]
36+
// aetype and substitute will be present always; so rearrange index 1 and 2
37+
icons = [icons[0], '', icons[1]];
38+
}
39+
return icons[index];
40+
}
41+
return '';
42+
};
43+
3344
const getInitialValue = (field, defaultVal = '') => {
3445
if (
3546
classField
@@ -38,10 +49,19 @@ const createClassFieldsSchema = (aeClassId, selectedRowId, aeTypeOptions,
3849
) {
3950
if (selectedRowId) {
4051
if (field === 'name' || field === 'display_name') {
41-
// debugger
4252
const formatted = formatName();
4353
return formatted[field] || defaultVal;
4454
}
55+
if (field === 'substitute') {
56+
if (classField[field] && 'text' in classField[field]) {
57+
return classField[field].text !== undefined && classField[field].text !== null
58+
? classField[field].text
59+
: defaultVal;
60+
}
61+
const icon = getIcons(2);
62+
return icon === 'pficon pficon-ok';
63+
}
64+
return classField[field].text || defaultVal;
4565
}
4666

4767
if (classField[field] && 'text' in classField[field]) {
@@ -52,20 +72,6 @@ const createClassFieldsSchema = (aeClassId, selectedRowId, aeTypeOptions,
5272
return defaultVal;
5373
};
5474

55-
56-
const getIcons = (index) => {
57-
if (
58-
classField
59-
&& typeof classField === 'object'
60-
&& Object.keys(classField).length > 0
61-
&& classField.name
62-
&& 'icon' in classField.name
63-
) {
64-
return classField.name.icon[index];
65-
}
66-
return '';
67-
};
68-
6975
const getType = (options, icon) => {
7076
const match = options.find(
7177
(item) => item[2] && item[2]['data-icon'] === icon
@@ -175,8 +181,7 @@ const createClassFieldsSchema = (aeClassId, selectedRowId, aeTypeOptions,
175181
label: __('Sub'),
176182
initialValue: getInitialValue('substitute', true),
177183
...(selectedRowId && {
178-
onChange: (e) => {
179-
const val = e.target.value;
184+
onChange: (val) => {
180185
updateFieldValueInState('substitute', val);
181186
handleSchemaFieldChange(aeClassId, val, 'substitute');
182187
},

0 commit comments

Comments
 (0)