Skip to content

Commit d29bd47

Browse files
committed
fixed deleting field
1 parent e5310ce commit d29bd47

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

app/helpers/miq_ae_class_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def schema_data(schema_data)
249249
cells.push({:text => ae_field.send(fname)})
250250
end
251251
end
252-
push_data({:id => index.to_s, :clickable => false, :cells => cells})
252+
push_data({:id => index.to_s, :field_id => ae_field.id, :clickable => false, :cells => cells})
253253
end
254254
end
255255

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@ export const ClassFieldsEditor = (props) => {
2828
const rowItems = [];
2929
const headers = schemaHeaders(true);
3030
fieldData.forEach(({
31-
cells, id, clickable, clickId,
31+
// eslint-disable-next-line camelcase
32+
id, field_id, cells, clickable,
3233
}) => {
3334
const reducedItems = cells.reduce((result, item, index) => {
3435
result[headers[index].name] = item;
3536
result.id = id;
36-
if (clickId) result.clickId = clickId;
37+
// eslint-disable-next-line camelcase
38+
result.field_id = field_id;
3739
result.clickable = clickable;
3840
return result;
3941
}, {});
40-
// reducedItems.id = id;
4142
rowItems.push(reducedItems);
4243
});
44+
4345
return rowItems;
4446
};
4547

@@ -59,9 +61,11 @@ export const ClassFieldsEditor = (props) => {
5961
setState((state) => ({ ...state, isModalOpen: false }));
6062
};
6163

62-
const formatFieldValues = (field, id) => {
64+
const formatFieldValues = (field, rowId) => {
6365
if (!field || typeof field !== 'object') return [];
64-
const getFieldName = () => `${field.display_name} (${field.name})`;
66+
67+
const getFieldName = () => ((field.display_name) ? `${field.display_name} (${field.name})` : `${field.name}`);
68+
6569
const getIconForValue = () => {
6670
const aeMatch = aeTypeOptions.find((option) => option[1] === field.aetype);
6771
const aeTypeIcon = (aeMatch && aeMatch[2] && aeMatch[2]['data-icon']) || '';
@@ -74,8 +78,11 @@ export const ClassFieldsEditor = (props) => {
7478
return [aeTypeIcon, dTypeIcon, subIcon];
7579
};
7680

81+
debugger
82+
7783
const row = {
78-
id: (field.id || id).toString(),
84+
id: field.id,
85+
row_id: rowId.toString(),
7986
name: {
8087
text: getFieldName(),
8188
icon: getIconForValue() || [],

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ const createSchemaEditSchema = (rows, setState, isSchemaModified) => {
1818
};
1919

2020
const handleFieldDelete = (index) => {
21-
// const rowId = parseInt(index, 10);
22-
http.post(`/miq_ae_class/field_delete?arr_id=${index}`, { skipErrors: [400] })
21+
const field = rows.find((field) => field.id === index);
22+
const fId = field.field_id || null;
23+
http.post(`/miq_ae_class/field_delete/${fId}?arr_id=${index}`, { skipErrors: [400] })
2324
.then(() => {
2425
setState((prev) => ({
2526
...prev,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { transformSelectOptions } from '../helper';
44
const createClassFieldsSchema = (aeClassId, selectedRowId, aeTypeOptions,
55
dTypeOptions, schemaField = {}, handleSchemaFieldChange, updateFieldValueInState) => {
66
const classField = schemaField;
7-
console.log("Class field -- ", classField);
87

98
const formatName = () => {
109
const fullName = classField.name.text;
@@ -122,8 +121,8 @@ const createClassFieldsSchema = (aeClassId, selectedRowId, aeTypeOptions,
122121
id: 'datatype',
123122
label: __('Data Type'),
124123
placeholder: __('<Choose>'),
125-
options: transformSelectOptions(dTypeOptions),
126124
includeEmpty: true,
125+
options: transformSelectOptions(dTypeOptions),
127126
initialValue: getType(dTypeOptions, getIcons(1)),
128127
...(selectedRowId && {
129128
onChange: (val) => {

0 commit comments

Comments
 (0)