Skip to content

Commit 749bffd

Browse files
committed
updated
1 parent 8c9381b commit 749bffd

File tree

10 files changed

+222
-84
lines changed

10 files changed

+222
-84
lines changed

app/javascript/components/service-dialog-form/dynamic-fields/dynamic-checkbox.jsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState } from 'react';
22
import PropTypes from 'prop-types';
33
import { Checkbox } from 'carbon-components-react';
4-
import { dynamicFieldDataProps, SD_ACTIONS } from '../helper';
4+
import { dynamicFieldDataProps, SD_ACTIONS, getFieldValues } from '../helper';
55
import DynamicFieldActions from '../dynamic-field-actions';
66
import {
77
fieldInformation, advanced, overridableOptions, fieldTab, dynamicFields,
@@ -20,22 +20,18 @@ const DynamicCheckbox = ({ dynamicFieldData: { section, field, fieldPosition },
2020
.filter((field) => field.showRefresh)
2121
.map((field) => ({ value: field.label, label: field.label }));
2222

23-
// Initialize field state with values from the field prop or defaults
23+
// Initialize field state with values from the helper function
24+
const fieldValues = getFieldValues(field);
2425
const [fieldState, setFieldState] = useState({
25-
type: field.type || 'DialogFieldCheckBox',
26+
...fieldValues,
2627
position: fieldPosition,
27-
label: field.label || __('Check Box'),
28-
required: field.required || false,
29-
name: field.name || inputId,
30-
visible: field.visible !== undefined ? field.visible : true,
31-
checked: field.default_value || field.value || false,
32-
readOnly: field.read_only || false,
33-
dynamic: field.dynamic || false,
28+
name: fieldValues.name || inputId,
3429
fieldsToRefresh: refreshEnabledFields,
3530
});
3631

3732
// Log the field data for debugging
3833
console.log('Field data in DynamicCheckbox:', field);
34+
console.log('Field values from helper:', fieldValues);
3935
console.log('Field state initialized as:', fieldState);
4036

4137
const handleFieldUpdate = (event, updatedFields) => {

app/javascript/components/service-dialog-form/dynamic-fields/dynamic-date-picker.jsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState } from 'react';
22
import PropTypes from 'prop-types';
33
import { DatePicker, DatePickerInput } from 'carbon-components-react';
4-
import { dynamicFieldDataProps, SD_ACTIONS } from '../helper';
4+
import { dynamicFieldDataProps, SD_ACTIONS, getFieldValues } from '../helper';
55
import DynamicFieldActions from '../dynamic-field-actions';
66
import {
77
fieldInformation, advanced, overridableOptions, fieldTab, dynamicFields,
@@ -19,13 +19,12 @@ const DynamicDatePicker = ({ dynamicFieldData: { section, field, fieldPosition }
1919
.filter((field) => field.showRefresh)
2020
.map((field) => ({ value: field.label, label: field.label }));
2121

22+
// Initialize field state with values from the helper function
23+
const fieldValues = getFieldValues(field);
2224
const [fieldState, setFieldState] = useState({
23-
type: 'DialogFieldDateControl',
25+
...fieldValues,
2426
position: fieldPosition,
25-
label: __('Datepicker'),
26-
name: inputId,
27-
visible: true,
28-
value: '',
27+
name: fieldValues.name || inputId,
2928
fieldsToRefresh: refreshEnabledFields,
3029
});
3130

app/javascript/components/service-dialog-form/dynamic-fields/dynamic-dropdown.jsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState } from 'react';
22
import PropTypes from 'prop-types';
33
import { MultiSelect } from 'carbon-components-react';
4-
import { dynamicFieldDataProps, SD_ACTIONS } from '../helper';
4+
import { dynamicFieldDataProps, SD_ACTIONS, getFieldValues } from '../helper';
55
import DynamicFieldActions from '../dynamic-field-actions';
66
import { defaultDropdownOptions } from '../edit-field-modal/fields.schema';
77
import {
@@ -21,27 +21,19 @@ const DynamicDropdown = ({ dynamicFieldData: { section, field, fieldPosition },
2121
.filter((field) => field.showRefresh)
2222
.map((field) => ({ value: field.label, label: field.label }));
2323

24-
// Initialize field state with values from the field prop or defaults
24+
// Initialize field state with values from the helper function
25+
const fieldValues = getFieldValues(field);
2526
const [fieldState, setFieldState] = useState({
26-
type: field.type || 'DialogFieldDropDownList',
27+
...fieldValues,
2728
position: fieldPosition,
28-
label: field.label || __('Selection Dropdown'),
29-
required: field.required || false,
30-
name: field.name || inputId,
31-
visible: field.visible !== undefined ? field.visible : true,
32-
items: field.values ? field.values.map(([value, description]) => ({ value, description })) : defaultDropdownOptions,
33-
multiselect: field.force_multi_value || false,
34-
value: field.default_value || field.value || [],
35-
readOnly: field.read_only || false,
36-
dynamic: field.dynamic || false,
29+
name: fieldValues.name || inputId,
3730
fieldsToRefresh: refreshEnabledFields,
38-
sortBy: (field.options && field.options.sort_by) || 'description',
39-
sortOrder: (field.options && field.options.sort_order) || 'ascending',
4031
automationType: 'embedded_automate',
4132
});
4233

4334
// Log the field data for debugging
4435
console.log('Field data in DynamicDropdown:', field);
36+
console.log('Field values from helper:', fieldValues);
4537
console.log('Field state initialized as:', fieldState);
4638

4739
const handleFieldUpdate = (event, updatedFields) => {

app/javascript/components/service-dialog-form/dynamic-fields/dynamic-radio-button.jsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState } from 'react';
22
import PropTypes from 'prop-types';
33
import { RadioButtonGroup, RadioButton } from 'carbon-components-react';
4-
import { dynamicFieldDataProps, SD_ACTIONS } from '../helper';
4+
import { dynamicFieldDataProps, SD_ACTIONS, getFieldValues } from '../helper';
55
import { defaultRadioButtonOptions } from '../edit-field-modal/fields.schema';
66
import DynamicFieldActions from '../dynamic-field-actions';
77
import {
@@ -20,18 +20,15 @@ const DynamicRadioButton = ({ dynamicFieldData: { section, field, fieldPosition
2020
.filter((field) => field.showRefresh)
2121
.map((field) => ({ value: field.label, label: field.label }));
2222

23+
// Initialize field state with values from the helper function
24+
const fieldValues = getFieldValues(field);
2325
const [fieldState, setFieldState] = useState({
24-
type: 'DialogFieldRadioButton',
26+
...fieldValues,
2527
position: fieldPosition,
26-
label: __('Radio Button'),
27-
required: false,
28-
name: inputId,
29-
visible: true,
30-
items: defaultRadioButtonOptions,
31-
value: '',
28+
name: fieldValues.name || inputId,
3229
fieldsToRefresh: refreshEnabledFields,
33-
sortBy: 'description',
34-
sortOrder: 'ascending',
30+
sortBy: fieldValues.sortBy || 'description',
31+
sortOrder: fieldValues.sortOrder || 'ascending',
3532
});
3633

3734
const handleFieldUpdate = (event, updatedFields) => {

app/javascript/components/service-dialog-form/dynamic-fields/dynamic-tag-control.jsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22
import PropTypes from 'prop-types';
33
import { Select, SelectItem } from 'carbon-components-react';
4-
import { dynamicFieldDataProps, SD_ACTIONS } from '../helper';
4+
import { dynamicFieldDataProps, SD_ACTIONS, getFieldValues } from '../helper';
55
import DynamicFieldActions from '../dynamic-field-actions';
66
import {
77
fieldInformation, advanced, fieldTab, dynamicFields,
@@ -20,20 +20,25 @@ const DynamicTagControl = ({ dynamicFieldData: { section, field, fieldPosition }
2020
.filter((field) => field.showRefresh)
2121
.map((field) => ({ value: field.label, label: field.label }));
2222

23+
// Initialize field state with values from the helper function
24+
const fieldValues = getFieldValues(field);
2325
const [fieldState, setFieldState] = useState({
24-
type: 'DialogFieldTagControl',
26+
...fieldValues,
2527
position: fieldPosition,
26-
label: __('Tag Control'),
27-
name: inputId,
28-
visible: true,
28+
name: fieldValues.name || inputId,
2929
categories: [],
3030
selectedCategory: [],
3131
subCategories: [],
3232
fieldsToRefresh: refreshEnabledFields,
33-
sortBy: 'description',
34-
sortOrder: 'ascending',
33+
sortBy: fieldValues.sortBy || 'description',
34+
sortOrder: fieldValues.sortOrder || 'ascending',
3535
});
3636

37+
// Log the field data for debugging
38+
console.log('Field data in DynamicTagControl:', field);
39+
console.log('Field values from helper:', fieldValues);
40+
console.log('Field state initialized as:', fieldState);
41+
3742
useEffect(() => {
3843
if (fieldState.categories.length === 0) {
3944
tagControlCategories().then((fetchedCategories) => {
@@ -68,7 +73,15 @@ const DynamicTagControl = ({ dynamicFieldData: { section, field, fieldPosition }
6873
categories: prevState.categories, // this is required to retain the options in the dropdown (not the selected category)
6974
}));
7075

71-
onFieldAction({ event, type: editActionType, fieldPosition, inputProps: { ...fieldState, ...updatedFields } });
76+
onFieldAction({
77+
event,
78+
type: editActionType,
79+
fieldPosition,
80+
inputProps: {
81+
...fieldState,
82+
...updatedFields
83+
}
84+
});
7285
};
7386

7487
const fieldActions = (event, inputProps) => {

app/javascript/components/service-dialog-form/dynamic-fields/dynamic-text-area.jsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React, { useState } from 'react';
22
import PropTypes from 'prop-types';
33
import { TextArea } from 'carbon-components-react';
4-
import { dynamicFieldDataProps, SD_ACTIONS } from '../helper';
4+
// import { dynamicFieldDataProps, SD_ACTIONS } from '../helper';
5+
import { dynamicFieldDataProps, SD_ACTIONS, getFieldValues } from '../helper';
56
import DynamicFieldActions from '../dynamic-field-actions';
67
import {
78
fieldInformation, advanced, overridableOptions, fieldTab, dynamicFields,
@@ -19,18 +20,20 @@ const DynamicTextArea = ({ dynamicFieldData: { section, field, fieldPosition },
1920
.filter((field) => field.showRefresh)
2021
.map((field) => ({ value: field.label, label: field.label }));
2122

23+
// Initialize field state with values from the helper function
24+
const fieldValues = getFieldValues(field);
2225
const [fieldState, setFieldState] = useState({
23-
type: 'DialogFieldTextAreaBox',
26+
...fieldValues,
2427
position: fieldPosition,
25-
label: __('Text Area'),
26-
placeholder: '',
27-
required: false,
28-
name: inputId,
29-
visible: true,
30-
value: '',
28+
name: fieldValues.name || inputId,
3129
fieldsToRefresh: refreshEnabledFields,
3230
});
3331

32+
// Log the field data for debugging
33+
console.log('Field data in DynamicTextArea:', field);
34+
console.log('Field values from helper:', fieldValues);
35+
console.log('Field state initialized as:', fieldState);
36+
3437
const handleFieldUpdate = (event, updatedFields) => {
3538
setFieldState((prevState) => ({ ...prevState, ...updatedFields }));
3639
onFieldAction({ event, type: editActionType, fieldPosition, inputProps: { ...fieldState, ...updatedFields } });

app/javascript/components/service-dialog-form/dynamic-fields/dynamic-text-input.jsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState } from 'react';
22
import PropTypes from 'prop-types';
33
import { TextInput } from 'carbon-components-react';
4-
import { dynamicFieldDataProps, SD_ACTIONS } from '../helper';
4+
import { dynamicFieldDataProps, SD_ACTIONS, getFieldValues } from '../helper';
55
import DynamicFieldActions from '../dynamic-field-actions';
66
import {
77
fieldInformation, advanced, overridableOptions, fieldTab, dynamicFields,
@@ -18,22 +18,18 @@ const DynamicTextInput = ({ dynamicFieldData: { section, field, fieldPosition },
1818
.filter((field) => field.showRefresh)
1919
.map((field) => ({ value: field.label, label: field.label }));
2020

21-
// Initialize field state with values from the field prop or defaults
21+
// Initialize field state with values from the helper function
22+
const fieldValues = getFieldValues(field);
2223
const [fieldState, setFieldState] = useState({
23-
type: field.type || 'DialogFieldTextBox',
24+
...fieldValues,
2425
position: fieldPosition,
25-
label: field.label || __('Text Box'),
26-
name: field.name || inputId,
27-
visible: field.visible !== undefined ? field.visible : true,
28-
value: field.default_value || field.value || '',
29-
dynamic: field.dynamic || false,
30-
required: field.required || false,
31-
readOnly: field.read_only || false,
26+
name: fieldValues.name || inputId,
3227
fieldsToRefresh: refreshEnabledFields,
3328
});
3429

3530
// Log the field data for debugging
3631
console.log('Field data in DynamicTextInput:', field);
32+
console.log('Field values from helper:', fieldValues);
3733
console.log('Field state initialized as:', fieldState);
3834

3935
const handleFieldUpdate = (event, updatedFields) => {

0 commit comments

Comments
 (0)