Skip to content

Commit 77cea7d

Browse files
Added a shared constants file for fields and tests
1 parent ec6beee commit 77cea7d

File tree

3 files changed

+84
-99
lines changed

3 files changed

+84
-99
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Field IDs/names used in both the application and tests
2+
export const FIELD_IDS = {
3+
NAME: 'name',
4+
DESCRIPTION: 'description',
5+
ACTIVE: 'enabled',
6+
ACTION_TYPE: 'action_typ',
7+
FILTER_TYPE: 'filter_typ',
8+
FILTER_VALUE: 'filter_value',
9+
TIMER_TYPE: 'timer_typ',
10+
TIMER_VALUE: 'timer_value',
11+
TIME_ZONE: 'time_zone',
12+
START_DATE: 'start_date',
13+
START_TIME: 'start_time',
14+
ZONE: 'zone_id',
15+
SYSTEM: 'instance_name',
16+
MESSAGE: 'message',
17+
REQUEST: 'request',
18+
OBJECT_TYPE: 'target_class',
19+
OBJECT_ITEM: 'target_id',
20+
ATTRIBUTE_PREFIX: 'attribute_',
21+
STARTING_OBJECT: 'starting_object',
22+
VALUE_PREFIX: 'value_',
23+
};

app/javascript/components/schedule-form/schedule-form-fields.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { componentTypes, validatorTypes } from '@@ddf';
22
import {
33
actionChange, runOptionChange, runOptions, subActionChange, objectTypeChange, restructureOptions,
44
} from './helper';
5+
import { FIELD_IDS } from './schedule-form-constants';
56

67
export const attributeValueLimit = 5;
78

89
export const nameField = () => ({
910
component: componentTypes.TEXT_FIELD,
10-
name: 'name',
11+
name: FIELD_IDS.NAME,
1112
label: __('Name'),
1213
maxLength: 50,
1314
isRequired: true,
@@ -17,7 +18,7 @@ export const nameField = () => ({
1718

1819
export const descriptionField = () => ({
1920
component: componentTypes.TEXT_FIELD,
20-
name: 'description',
21+
name: FIELD_IDS.DESCRIPTION,
2122
label: __('Description'),
2223
isRequired: true,
2324
maxLength: 100,
@@ -26,14 +27,14 @@ export const descriptionField = () => ({
2627

2728
export const activeField = () => ({
2829
component: componentTypes.CHECKBOX,
29-
name: 'enabled',
30+
name: FIELD_IDS.ACTIVE,
3031
label: __('Active'),
3132
});
3233

3334
export const actionField = (actionOptions, filterOptions, setData, data) => ({
3435
component: componentTypes.SELECT,
3536
id: 'action',
36-
name: 'action_typ',
37+
name: FIELD_IDS.ACTION_TYPE,
3738
label: __('Action'),
3839
initialValue: 'vm',
3940
onChange: (value) => actionChange(value, filterOptions, setData, data),
@@ -44,7 +45,7 @@ export const actionField = (actionOptions, filterOptions, setData, data) => ({
4445
export const filterField = (setData, data) => ({
4546
component: componentTypes.SELECT,
4647
id: 'filter_type',
47-
name: 'filter_typ',
48+
name: FIELD_IDS.FILTER_TYPE,
4849
label: __('Filter'),
4950
onChange: (value) => subActionChange(value, setData, data),
5051
hideField: data.displayFields.filterType,
@@ -55,7 +56,7 @@ export const filterField = (setData, data) => ({
5556
export const targetField = (data) => ({
5657
component: componentTypes.SELECT,
5758
id: 'filter_value',
58-
name: 'filter_value',
59+
name: FIELD_IDS.FILTER_VALUE,
5960
label: __('Filter Item'),
6061
hideField: data.displayFields.target,
6162
options: data.options.target,
@@ -66,7 +67,7 @@ export const targetField = (data) => ({
6667
export const zoneField = (data) => ({
6768
component: componentTypes.SELECT,
6869
id: 'zone',
69-
name: 'zone_id',
70+
name: FIELD_IDS.ZONE,
7071
label: __('Zone'),
7172
placeholder: __('<Choose>'),
7273
includeEmpty: true,
@@ -87,7 +88,7 @@ export const plainField = (name, text, data) => ({
8788
export const systemField = (data) => ({
8889
component: componentTypes.SELECT,
8990
id: 'system',
90-
name: 'instance_name',
91+
name: FIELD_IDS.SYSTEM,
9192
label: __('System/Process'),
9293
hideField: data.displayFields.automationFields,
9394
options: data.options.request,
@@ -99,7 +100,7 @@ export const systemField = (data) => ({
99100

100101
export const objectMessageField = (data) => ({
101102
component: componentTypes.TEXT_FIELD,
102-
id: 'message',
103+
id: FIELD_IDS.MESSAGE,
103104
name: 'object_message',
104105
label: __('Message'),
105106
hideField: data.displayFields.automationFields,
@@ -109,7 +110,7 @@ export const objectMessageField = (data) => ({
109110

110111
export const objectRequestField = (data) => ({
111112
component: componentTypes.TEXT_FIELD,
112-
id: 'request',
113+
id: FIELD_IDS.REQUEST,
113114
name: 'object_request',
114115
label: __('Request'),
115116
hideField: data.displayFields.automationFields,
@@ -120,7 +121,7 @@ export const objectRequestField = (data) => ({
120121
export const objectTypeField = (setData, data) => ({
121122
component: componentTypes.SELECT,
122123
id: 'object_type',
123-
name: 'target_class',
124+
name: FIELD_IDS.OBJECT_TYPE,
124125
onChange: (value) => objectTypeChange(value, setData, data),
125126
hideField: data.displayFields.automationFields,
126127
placeholder: __('<Choose>'),
@@ -137,7 +138,7 @@ export const objectTypeField = (setData, data) => ({
137138
export const objectItemField = (data) => ({
138139
component: componentTypes.SELECT,
139140
id: 'object_item',
140-
name: 'target_id',
141+
name: FIELD_IDS.OBJECT_ITEM,
141142
hideField: data.displayFields.objectItem,
142143
options: data.options.objectItem,
143144
placeholder: __('<Choose>'),
@@ -165,14 +166,14 @@ const attributeValueField = (count) => ({
165166
},
166167
{
167168
component: componentTypes.TEXT_FIELD,
168-
id: `attribute_${count}`,
169+
id: `${FIELD_IDS.ATTRIBUTE_PREFIX}${count}`,
169170
name: `attribute_${count}`,
170171
label: __(' '),
171172
className: 'attribute-value-row-attribute',
172173
},
173174
{
174175
component: componentTypes.TEXT_FIELD,
175-
id: `value_${count}`,
176+
id: `${FIELD_IDS.VALUE_PREFIX}${count}`,
176177
name: `value_${count}`,
177178
label: __(' '),
178179
className: 'attribute-value-row-value',
@@ -194,7 +195,7 @@ export const attributeValueFields = (data, limit) => ({
194195
fields: [[...Array(limit)].map((_item, i) => attributeValueField(i + 1)),
195196
{
196197
component: componentTypes.TEXT_FIELD,
197-
id: `starting_object`,
198+
id: FIELD_IDS.STARTING_OBJECT,
198199
name: `starting_object`,
199200
label: __(' '),
200201
value: 'SYSTEM/PROCESS',
@@ -206,7 +207,7 @@ export const attributeValueFields = (data, limit) => ({
206207
export const runField = (setData, data) => ({
207208
component: componentTypes.SELECT,
208209
id: 'run',
209-
name: 'timer_typ',
210+
name: FIELD_IDS.TIMER_TYPE,
210211
label: __('Run'),
211212
initialValue: 'Once',
212213
isRequired: true,
@@ -217,7 +218,7 @@ export const runField = (setData, data) => ({
217218
export const timerValueField = (data) => ({
218219
component: componentTypes.SELECT,
219220
id: 'timer_value',
220-
name: 'timer_value',
221+
name: FIELD_IDS.TIMER_VALUE,
221222
label: __('Every'),
222223
hideField: data.displayFields.everyTime,
223224
options: data.options.everyTime,
@@ -229,7 +230,7 @@ export const timerValueField = (data) => ({
229230
export const timezoneField = (data) => ({
230231
component: componentTypes.SELECT,
231232
id: 'time_zone',
232-
name: 'time_zone',
233+
name: FIELD_IDS.TIME_ZONE,
233234
isRequired: true,
234235
placeholder: __('<Choose>'),
235236
includeEmpty: true,
@@ -243,7 +244,7 @@ export const timezoneField = (data) => ({
243244

244245
export const startDateField = () => ({
245246
component: componentTypes.DATE_PICKER,
246-
name: 'start_date',
247+
name: FIELD_IDS.START_DATE,
247248
label: __('Starting Date'),
248249
datePickerType: 'single',
249250
isRequired: true,
@@ -252,7 +253,7 @@ export const startDateField = () => ({
252253

253254
export const startTimeField = () => ({
254255
component: componentTypes.TIME_PICKER,
255-
id: 'start_time',
256+
id: FIELD_IDS.START_TIME,
256257
name: 'start_hour',
257258
label: __('Starting Time'),
258259
isRequired: true,

0 commit comments

Comments
 (0)