@pega/custom-dx-components 2.0.8 → 2.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/package.json +1 -1
  2. package/src/constants.js +29 -7
  3. package/src/tasks/create/index.js +46 -6
  4. package/src/tasks/create/templates/Constellation/Field/Boolean/Boolean.js.mustache +38 -0
  5. package/src/tasks/create/templates/Constellation/Field/Boolean/boolean-format.js.mustache +26 -0
  6. package/src/tasks/create/templates/Constellation/Field/Boolean/config.json.mustache +145 -0
  7. package/src/tasks/create/templates/Constellation/Field/Boolean/demo.stories.jsx.mustache +44 -0
  8. package/src/tasks/create/templates/Constellation/Field/Boolean/event-utils.js.mustache +18 -0
  9. package/src/tasks/create/templates/Constellation/Field/Boolean/index.jsx.mustache +171 -0
  10. package/src/tasks/create/templates/Constellation/Field/Boolean/styles.js.mustache +7 -0
  11. package/src/tasks/create/templates/Constellation/Field/Date/config.json.mustache +195 -0
  12. package/src/tasks/create/templates/Constellation/Field/Date/date.js.mustache +327 -0
  13. package/src/tasks/create/templates/Constellation/Field/Date/demo.stories.jsx.mustache +44 -0
  14. package/src/tasks/create/templates/Constellation/Field/Date/index.jsx.mustache +254 -0
  15. package/src/tasks/create/templates/Constellation/Field/Date/styles.js.mustache +7 -0
  16. package/src/tasks/create/templates/Constellation/Field/Date/suggestions-handler.js +10 -0
  17. package/src/tasks/create/templates/Constellation/Field/DateTime/config.json.mustache +256 -0
  18. package/src/tasks/create/templates/Constellation/Field/DateTime/date-time.js.mustache +93 -0
  19. package/src/tasks/create/templates/Constellation/Field/DateTime/date-utils.js +286 -0
  20. package/src/tasks/create/templates/Constellation/Field/DateTime/date.js.mustache +327 -0
  21. package/src/tasks/create/templates/Constellation/Field/DateTime/demo.stories.jsx.mustache +44 -0
  22. package/src/tasks/create/templates/Constellation/Field/DateTime/index.jsx.mustache +252 -0
  23. package/src/tasks/create/templates/Constellation/Field/DateTime/styles.js.mustache +7 -0
  24. package/src/tasks/create/templates/Constellation/Field/DateTime/suggestions-handler.js +10 -0
  25. package/src/tasks/create/templates/Constellation/Field/Decimal/config.json.mustache +278 -0
  26. package/src/tasks/create/templates/Constellation/Field/Decimal/demo.stories.jsx.mustache +44 -0
  27. package/src/tasks/create/templates/Constellation/Field/Decimal/event-utils.js.mustache +18 -0
  28. package/src/tasks/create/templates/Constellation/Field/Decimal/index.jsx.mustache +272 -0
  29. package/src/tasks/create/templates/Constellation/Field/Decimal/styles.js.mustache +7 -0
  30. package/src/tasks/create/templates/Constellation/Field/Decimal/suggestions-handler.js +10 -0
  31. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/config.json.mustache +291 -0
  32. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/demo.stories.jsx.mustache +44 -0
  33. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/event-utils.js.mustache +18 -0
  34. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/index.jsx.mustache +300 -0
  35. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/styles.js.mustache +7 -0
  36. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/suggestions-handler.js +10 -0
  37. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/config.json.mustache +93 -0
  38. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/demo.stories.jsx.mustache +44 -0
  39. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/event-utils.js.mustache +18 -0
  40. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/index.jsx.mustache +275 -0
  41. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/styles.js.mustache +7 -0
  42. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/suggestions-handler.js +10 -0
  43. package/src/tasks/create/templates/Constellation/Field/Integer/config.json.mustache +347 -0
  44. package/src/tasks/create/templates/Constellation/Field/Integer/demo.stories.jsx.mustache +44 -0
  45. package/src/tasks/create/templates/Constellation/Field/Integer/event-utils.js.mustache +18 -0
  46. package/src/tasks/create/templates/Constellation/Field/Integer/index.jsx.mustache +335 -0
  47. package/src/tasks/create/templates/Constellation/Field/Integer/styles.js.mustache +7 -0
  48. package/src/tasks/create/templates/Constellation/Field/Integer/suggestions-handler.js +10 -0
  49. package/src/tasks/create/templates/Constellation/Field/Picklist/config.json.mustache +114 -0
  50. package/src/tasks/create/templates/Constellation/Field/Picklist/demo.stories.jsx.mustache +44 -0
  51. package/src/tasks/create/templates/Constellation/Field/Picklist/event-utils.js.mustache +18 -0
  52. package/src/tasks/create/templates/Constellation/Field/Picklist/index.jsx.mustache +308 -0
  53. package/src/tasks/create/templates/Constellation/Field/Picklist/picklist.js.mustache +43 -0
  54. package/src/tasks/create/templates/Constellation/Field/Picklist/styles.js.mustache +7 -0
  55. package/src/tasks/create/templates/Constellation/Field/Picklist/suggestions-handler.js +10 -0
  56. package/src/tasks/create/templates/Constellation/Field/Text/config.json.mustache +62 -0
  57. package/src/tasks/create/templates/Constellation/Field/Text/demo.stories.jsx.mustache +44 -0
  58. package/src/tasks/create/templates/Constellation/Field/Text/index.jsx.mustache +60 -0
  59. package/src/tasks/create/templates/Constellation/Field/Text/styles.js.mustache +7 -0
  60. package/src/tasks/create/templates/Constellation/Field/Text-Email/config.json.mustache +111 -0
  61. package/src/tasks/create/templates/Constellation/Field/Text-Email/demo.stories.jsx.mustache +44 -0
  62. package/src/tasks/create/templates/Constellation/Field/Text-Email/event-utils.js.mustache +18 -0
  63. package/src/tasks/create/templates/Constellation/Field/Text-Email/index.jsx.mustache +189 -0
  64. package/src/tasks/create/templates/Constellation/Field/Text-Email/styles.js.mustache +7 -0
  65. package/src/tasks/create/templates/Constellation/Field/Text-Email/suggestions-handler.js +10 -0
  66. package/src/tasks/create/templates/Constellation/Field/Text-Email/text-email.js.mustache +43 -0
  67. package/src/tasks/create/templates/Constellation/Field/Text-Input/StatusWork.js +27 -0
  68. package/src/tasks/create/templates/Constellation/Field/Text-Input/config.json.mustache +111 -0
  69. package/src/tasks/create/templates/Constellation/Field/Text-Input/demo.stories.jsx.mustache +44 -0
  70. package/src/tasks/create/templates/Constellation/Field/Text-Input/event-utils.js.mustache +18 -0
  71. package/src/tasks/create/templates/Constellation/Field/Text-Input/index.jsx.mustache +196 -0
  72. package/src/tasks/create/templates/Constellation/Field/Text-Input/styles.js.mustache +7 -0
  73. package/src/tasks/create/templates/Constellation/Field/Text-Input/suggestions-handler.js +10 -0
  74. package/src/tasks/create/templates/Constellation/Field/Text-Input/text-input.js.mustache +43 -0
  75. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/config.json.mustache +111 -0
  76. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/demo.stories.jsx.mustache +44 -0
  77. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/event-utils.js.mustache +18 -0
  78. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/index.jsx.mustache +189 -0
  79. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/styles.js.mustache +7 -0
  80. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/suggestions-handler.js +10 -0
  81. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/text-paragraph.js.mustache +43 -0
  82. package/src/tasks/create/templates/Constellation/Field/Text-Phone/config.json.mustache +123 -0
  83. package/src/tasks/create/templates/Constellation/Field/Text-Phone/demo.stories.jsx.mustache +44 -0
  84. package/src/tasks/create/templates/Constellation/Field/Text-Phone/event-utils.js.mustache +18 -0
  85. package/src/tasks/create/templates/Constellation/Field/Text-Phone/index.jsx.mustache +223 -0
  86. package/src/tasks/create/templates/Constellation/Field/Text-Phone/styles.js.mustache +7 -0
  87. package/src/tasks/create/templates/Constellation/Field/Text-Phone/suggestions-handler.js +10 -0
  88. package/src/tasks/create/templates/Constellation/Field/Text-Phone/text-phone.js.mustache +43 -0
  89. package/src/tasks/create/templates/Constellation/Field/Text-URL/config.json.mustache +237 -0
  90. package/src/tasks/create/templates/Constellation/Field/Text-URL/demo.stories.jsx.mustache +44 -0
  91. package/src/tasks/create/templates/Constellation/Field/Text-URL/event-utils.js.mustache +18 -0
  92. package/src/tasks/create/templates/Constellation/Field/Text-URL/index.jsx.mustache +232 -0
  93. package/src/tasks/create/templates/Constellation/Field/Text-URL/styles.js.mustache +7 -0
  94. package/src/tasks/create/templates/Constellation/Field/Text-URL/suggestions-handler.js +10 -0
  95. package/src/tasks/create/templates/Constellation/Field/Text-URL/text-url.js.mustache +172 -0
  96. package/src/tasks/create/templates/Constellation/Field/TimeofDay/config.json.mustache +185 -0
  97. package/src/tasks/create/templates/Constellation/Field/TimeofDay/demo.stories.jsx.mustache +44 -0
  98. package/src/tasks/create/templates/Constellation/Field/TimeofDay/index.jsx.mustache +213 -0
  99. package/src/tasks/create/templates/Constellation/Field/TimeofDay/styles.js.mustache +7 -0
  100. package/src/tasks/create/templates/Constellation/Field/TimeofDay/suggestions-handler.js +10 -0
  101. package/src/tasks/create/templates/Constellation/Field/TimeofDay/time-of-day.js.mustache +286 -0
  102. package/src/tasks/create/templates/Constellation/Template/DETAILS/OneColumnDetails.svg +22 -0
  103. package/src/tasks/create/templates/Constellation/Template/DETAILS/config.json.mustache +35 -0
  104. package/src/tasks/create/templates/Constellation/Template/DETAILS/index.jsx.mustache +101 -0
  105. package/src/tasks/create/templates/Constellation/Template/DETAILS/styles.js.mustache +7 -0
  106. package/src/tasks/create/templates/Constellation/Template/DETAILS/utils.js.mustache +226 -0
  107. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/TwoColumnDetails.svg +28 -0
  108. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/config.json.mustache +42 -0
  109. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/index.jsx.mustache +101 -0
  110. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/styles.js.mustache +7 -0
  111. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/utils.js.mustache +226 -0
  112. package/src/tasks/create/templates/Constellation/Template/FORM/DefaultForm.svg +29 -0
  113. package/src/tasks/create/templates/Constellation/Template/FORM/config.json.mustache +45 -0
  114. package/src/tasks/create/templates/Constellation/Template/FORM/index.jsx.mustache +49 -0
  115. package/src/tasks/create/templates/Constellation/Template/FORM/styles.js.mustache +7 -0
  116. package/src/tasks/create/templates/Constellation/Template/FORM-region/TwoColumn.svg +38 -0
  117. package/src/tasks/create/templates/Constellation/Template/FORM-region/config.json.mustache +27 -0
  118. package/src/tasks/create/templates/Constellation/Template/FORM-region/index.jsx.mustache +43 -0
  119. package/src/tasks/create/templates/Constellation/Template/FORM-region/styles.js.mustache +7 -0
  120. package/src/tasks/create/templates/Constellation/Template/PAGE/GetNextWork.js.mustache +29 -0
  121. package/src/tasks/create/templates/Constellation/Template/PAGE/OneColumnPage.svg +36 -0
  122. package/src/tasks/create/templates/Constellation/Template/PAGE/config.json.mustache +32 -0
  123. package/src/tasks/create/templates/Constellation/Template/PAGE/index.jsx.mustache +68 -0
  124. package/src/tasks/create/templates/Constellation/Template/PAGE/localizations.json.mustache +4 -0
  125. package/src/tasks/create/templates/Constellation/Template/PAGE/styles.js.mustache +7 -0
  126. package/src/tasks/create/templates/Constellation/Template/PAGE/utils.js.mustache +226 -0
  127. package/src/tasks/create/templates/Constellation/Widget/CASE/OneColumnPage.svg +36 -0
  128. package/src/tasks/create/templates/Constellation/Widget/CASE/config.json.mustache +23 -0
  129. package/src/tasks/create/templates/Constellation/Widget/CASE/index.jsx.mustache +75 -0
  130. package/src/tasks/create/templates/Constellation/Widget/CASE/styles.js.mustache +7 -0
  131. package/src/tasks/create/templates/Constellation/Widget/PAGE/OneColumnPage.svg +36 -0
  132. package/src/tasks/create/templates/Constellation/Widget/PAGE/config.json.mustache +59 -0
  133. package/src/tasks/create/templates/Constellation/Widget/PAGE/index.jsx.mustache +48 -0
  134. package/src/tasks/create/templates/Constellation/Widget/PAGE/styles.js.mustache +7 -0
  135. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/Avatar.js.mustache +73 -0
  136. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/OneColumnPage.svg +36 -0
  137. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/Operator.js.mustache +239 -0
  138. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/config.json.mustache +66 -0
  139. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/index.jsx.mustache +110 -0
  140. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/styles.js.mustache +7 -0
  141. package/src/tasks/init/template/package.json.mustache +6 -1
  142. package/src/tasks/publish/bundle/builder/index.js +49 -5
  143. package/src/tasks/publish/bundle/builder/webpack.config.js +7 -3
  144. package/src/tasks/validator/index.js +107 -8
@@ -0,0 +1,308 @@
1
+ import { useState, useEffect, useRef } from 'react';
2
+ import { Select, Option, FieldValueList, Text } from '@pega/cosmos-react-core';
3
+ import PropTypes from 'prop-types';
4
+
5
+ // includes in bundle
6
+ import {formatExists,textFormatter} from "./picklist";
7
+ import handleEvent from "./event-utils";
8
+ import { suggestionsHandler } from './suggestions-handler';
9
+
10
+ import Styled{{COMPONENT_CLASS_NAME}}Wrapper from './styles';
11
+
12
+ export const setDefaultValue = (dropdownOptions, pConnect, propName) => {
13
+ // calculate the default option and set it to dropdown
14
+ const option = (dropdownOptions && dropdownOptions[0]) || {};
15
+ const defaultValue = option.key ? option.props.value : '';
16
+ pConnect.setValue(propName, defaultValue, defaultValue);
17
+ };
18
+
19
+ const pushPlaceholderOption = (placeholder, listSourceItems, items, pConnect) => {
20
+ // If we have a placeholder, push that option in the list of items
21
+ if (placeholder) {
22
+ items.push(
23
+ <Option key={placeholder} value=''>
24
+ {pConnect.getLocalizedValue(placeholder)}
25
+ </Option>
26
+ );
27
+ } else if (!listSourceItems) {
28
+ // If we don't have a placeholder and our list source is empty, push a blank row option in the list of items
29
+ items.push(<Option key='' value='' />);
30
+ }
31
+ };
32
+
33
+
34
+ // Duplicated runtime code from Constellation Design System Component
35
+
36
+ // props passed in combination of props from property panel (config.json) and run time props from Constellation
37
+ // any default values in config.pros should be set in defaultProps at bottom of this file
38
+ const {{COMPONENT_CLASS_NAME}} = props => {
39
+ const {
40
+ getPConnect,
41
+ value,
42
+ label,
43
+ hideLabel,
44
+ placeholder,
45
+ datasource,
46
+ listType,
47
+ validatemessage,
48
+ testId,
49
+ helperText,
50
+ additionalProps,
51
+ displayMode,
52
+ onRecordChange,
53
+ variant,
54
+ fieldMetadata,
55
+ isTableFormatter,
56
+ hasSuggestions
57
+ } = props;
58
+ const { formatter } = props;
59
+ const pConnect = getPConnect();
60
+ const actions = pConnect.getActionsApi();
61
+ const propName = pConnect.getStateProps().value;
62
+ const className = pConnect.getCaseInfo().getClassName();
63
+ const refName = propName?.slice(propName.lastIndexOf('.') + 1);
64
+
65
+ let { readOnly, required, disabled } = props;
66
+ [readOnly, required, disabled] = [readOnly, required, disabled].map(
67
+ (prop) => prop === true || (typeof prop === 'string' && prop === 'true')
68
+ );
69
+
70
+ const [status, setStatus] = useState(hasSuggestions ? 'pending' : undefined);
71
+
72
+ const useIsMount = () => {
73
+ const isMountRef = useRef(true);
74
+ useEffect(() => {
75
+ isMountRef.current = false;
76
+ }, []);
77
+ return isMountRef.current;
78
+ };
79
+
80
+ const isMount = useIsMount();
81
+
82
+ const metaData = Array.isArray(fieldMetadata)
83
+ ? fieldMetadata.filter((field) => field?.classID === className)[0]
84
+ : fieldMetadata;
85
+ let displayName = metaData?.datasource?.propertyForDisplayText;
86
+ displayName = displayName?.slice(displayName.lastIndexOf('.') + 1);
87
+ const localeContext = metaData?.datasource?.tableType === 'DataPage' ? 'datapage' : 'associated';
88
+ const localeClass = localeContext === 'datapage' ? '@baseclass' : className;
89
+ const localeName = localeContext === 'datapage' ? metaData?.datasource?.name : refName;
90
+ const localePath = localeContext === 'datapage' ? displayName : '';
91
+
92
+ const configProps = pConnect.getConfigProps();
93
+ const items = [];
94
+ const isDatapage = listType === 'datapage';
95
+ let listSourceItems = isDatapage ? configProps.listOutput : datasource;
96
+
97
+ if (isDatapage && typeof datasource === 'object' && !Array.isArray(listSourceItems)) {
98
+ listSourceItems = datasource.source ? datasource.source : [];
99
+ }
100
+
101
+ useEffect(() => {
102
+ if (validatemessage !== '') {
103
+ setStatus('error');
104
+ }
105
+ if (hasSuggestions) {
106
+ setStatus('pending');
107
+ } else if (!hasSuggestions && status !== 'success') {
108
+ setStatus(validatemessage !== '' ? 'error' : undefined);
109
+ }
110
+ }, [validatemessage, hasSuggestions]);
111
+
112
+ pushPlaceholderOption(placeholder, listSourceItems, items, pConnect);
113
+
114
+ // Loop through all of our list source items that make up the values of the dropdown
115
+
116
+ let selectedLabel = '';
117
+ (listSourceItems || []).forEach((item) => {
118
+ selectedLabel =
119
+ value !== undefined &&
120
+ value !== null &&
121
+ item.key !== undefined &&
122
+ item.key !== null &&
123
+ value.toString() === item.key.toString()
124
+ ? item.text || item.value
125
+ : selectedLabel;
126
+ items.push(
127
+ <Option key={item.key} value={item.key}>
128
+ {isDatapage
129
+ ? pConnect.getLocalizedValue(
130
+ item.text,
131
+ localePath,
132
+ pConnect.getLocaleRuleNameFromKeys(localeClass, localeContext, localeName)
133
+ )
134
+ : pConnect.getLocalizedValue(
135
+ item.value,
136
+ localePath,
137
+ pConnect.getLocaleRuleNameFromKeys(localeClass, localeContext, localeName)
138
+ )}
139
+ </Option>
140
+ );
141
+ });
142
+
143
+ const isDisplayModeEnabled =
144
+ displayMode === 'LABELS_LEFT' || displayMode === 'STACKED_LARGE_VAL' || displayMode === 'DISPLAY_ONLY';
145
+ let firstOptionKey = '';
146
+ let firstOptionValue = '';
147
+ if (!placeholder && listSourceItems?.length > 0) {
148
+ // First option isn't going to change as long as placeholder is present. Incase placeholder is not there
149
+ // check for new option
150
+ firstOptionKey = listSourceItems[0].key;
151
+ firstOptionValue = listSourceItems[0].text || listSourceItems[0].value;
152
+ }
153
+ useEffect(() => {
154
+ // placeholder - placeholder option configured to be shown with dropdown, empty string if not configured
155
+ // value - value of the dropdown if set to something prior (either by pre-activity or default value etc.), empty string if nothing is set
156
+ // selectedLabel - is value(the one above) if it is one of the option in the dropdown datasource, empty string if not
157
+ // below code does this -
158
+ // set dropdown value to first option if placeholder is NOT present and ((value is empty) or (value is not empty and selectedLabel is empty))
159
+ // set dropdown value to empty if placeholder is present and value is not empty and selectedLabel is empty
160
+ // Broken down first option(key, value) to be as dependency instead of entire items array which creates new reference on every render
161
+ // First option is kept as dependency as setDefaultValue sets only first value from options
162
+ if (!isDisplayModeEnabled && ((!placeholder && !value) || (!isMount && value && !selectedLabel))) {
163
+ setDefaultValue(items, pConnect, propName);
164
+ }
165
+ }, [firstOptionKey, firstOptionValue, placeholder, selectedLabel, value, propName]);
166
+
167
+ if (displayMode === 'LABELS_LEFT' || displayMode === 'DISPLAY_ONLY') {
168
+ let displayComp = selectedLabel;
169
+ if (isTableFormatter && formatExists(formatter)) {
170
+ displayComp = textFormatter(formatter, selectedLabel);
171
+ }
172
+ if (selectedLabel === '') {
173
+ displayComp = value || <span aria-hidden='true'>&ndash;&ndash;</span>;
174
+ }
175
+
176
+ return displayMode === 'DISPLAY_ONLY' ? (
177
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
178
+ displayComp
179
+ </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
180
+ ) : (
181
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
182
+ <FieldValueList
183
+ variant={hideLabel ? 'stacked' : variant}
184
+ data-testid={testId}
185
+ fields={[
186
+ {
187
+ id: '1',
188
+ name: hideLabel ? '' : label,
189
+ value: displayComp
190
+ }
191
+ ]}
192
+ />
193
+ </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
194
+ );
195
+ }
196
+
197
+ if (displayMode === 'STACKED_LARGE_VAL') {
198
+ selectedLabel = selectedLabel === '' ? value : selectedLabel;
199
+ const isValDefined = typeof selectedLabel !== 'undefined' && selectedLabel !== '';
200
+ const val = isValDefined ? (
201
+ <Text variant='h1' as='span'>
202
+ {selectedLabel}
203
+ </Text>
204
+ ) : (
205
+ ''
206
+ );
207
+ return (
208
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
209
+ <FieldValueList
210
+ variant='stacked'
211
+ data-testid={testId}
212
+ fields={[{ id: '2', name: hideLabel ? '' : label, value: val }]}
213
+ />
214
+ </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
215
+ );
216
+ }
217
+
218
+ const onResolveSuggestionHandler = (accepted) => {
219
+ suggestionsHandler(accepted, pConnect, setStatus);
220
+ };
221
+
222
+ return (
223
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
224
+ <Select
225
+ {...additionalProps}
226
+ label={label}
227
+ labelHidden={hideLabel}
228
+ info={validatemessage || helperText}
229
+ status={status}
230
+ data-testid={testId}
231
+ key={getPConnect().getRawMetadata().config.value}
232
+ value={value}
233
+ disabled={disabled}
234
+ required={required}
235
+ readOnly={readOnly}
236
+ onChange={(event) => {
237
+ handleEvent(actions, 'changeNblur', propName, event.target.value);
238
+ if (hasSuggestions) {
239
+ pConnect.ignoreSuggestion();
240
+ setStatus(undefined);
241
+ }
242
+ if (onRecordChange) {
243
+ onRecordChange(event);
244
+ }
245
+ }}
246
+ onBlur={(event) => {
247
+ pConnect.getValidationApi().validate(event.target.value);
248
+ }}
249
+ onResolveSuggestion={onResolveSuggestionHandler}
250
+ >
251
+ {items}
252
+ </Select>
253
+ </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
254
+ );
255
+ }
256
+
257
+ {{COMPONENT_CLASS_NAME}}.defaultProps = {
258
+ value: '',
259
+ placeholder: '',
260
+ validatemessage: '',
261
+ hideLabel: false,
262
+ disabled: false,
263
+ readOnly: false,
264
+ required: false,
265
+ testId: null,
266
+ helperText: '',
267
+ datasource: [],
268
+ listType: '',
269
+ additionalProps: {},
270
+ fieldMetadata: {},
271
+ displayMode: null,
272
+ onRecordChange: null,
273
+ variant: 'inline',
274
+ formatter: '',
275
+ isTableFormatter: false,
276
+ hasSuggestions: false
277
+ };
278
+
279
+ {{COMPONENT_CLASS_NAME}}.propTypes = {
280
+ getPConnect: PropTypes.func.isRequired,
281
+ value: PropTypes.string,
282
+ placeholder: PropTypes.string,
283
+ label: PropTypes.string.isRequired,
284
+ hideLabel: PropTypes.bool,
285
+ datasource: PropTypes.oneOfType([
286
+ PropTypes.arrayOf(PropTypes.any),
287
+ PropTypes.shape({
288
+ source: PropTypes.arrayOf(PropTypes.any)
289
+ })
290
+ ]),
291
+ listType: PropTypes.string,
292
+ validatemessage: PropTypes.string,
293
+ disabled: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
294
+ readOnly: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
295
+ required: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
296
+ testId: PropTypes.string,
297
+ helperText: PropTypes.string,
298
+ additionalProps: PropTypes.objectOf(PropTypes.any),
299
+ fieldMetadata: PropTypes.objectOf(PropTypes.any),
300
+ displayMode: PropTypes.string,
301
+ onRecordChange: PropTypes.func,
302
+ variant: PropTypes.string,
303
+ formatter: PropTypes.string,
304
+ isTableFormatter: PropTypes.bool,
305
+ hasSuggestions: PropTypes.bool
306
+ };
307
+
308
+ export default {{COMPONENT_CLASS_NAME}};
@@ -0,0 +1,43 @@
1
+ import {EmailDisplay, PhoneDisplay, URLDisplay } from "@pega/cosmos-react-core";
2
+
3
+ export const formatExists = (formatterVal) => {
4
+ const formatterValues = [
5
+ "TextInput",
6
+ "WorkStatus",
7
+ "RichText",
8
+ "Email",
9
+ "Phone",
10
+ "URL",
11
+ "Operator"
12
+ ];
13
+ let isformatter = false;
14
+ if (formatterValues.includes(formatterVal)) {
15
+ isformatter = true;
16
+ }
17
+ return isformatter;
18
+ };
19
+
20
+
21
+ export const textFormatter = (formatter,value) => {
22
+ let displayComponent = null;
23
+ switch(formatter){
24
+ case "TextInput" : {
25
+ displayComponent = value;
26
+ break;
27
+ }
28
+ case "Email" : {
29
+ displayComponent = (<EmailDisplay value={value} displayText={value} variant="link" />);
30
+ break;
31
+ }
32
+ case "Phone" : {
33
+ displayComponent = (<PhoneDisplay value={value} variant="link" />);
34
+ break;
35
+ }
36
+ case "URL" : {
37
+ displayComponent = (<URLDisplay target="_blank" value={value} displayText={value} variant="link" />);
38
+ break;
39
+ }
40
+ // no default
41
+ }
42
+ return displayComponent;
43
+ };
@@ -0,0 +1,7 @@
1
+ import styled, { css } from 'styled-components';
2
+
3
+ export default styled.div(() => {
4
+ return css`
5
+ margin: 8px 0;
6
+ `;
7
+ });
@@ -0,0 +1,10 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ export const suggestionsHandler = (accepted, pConn, setStatus) => {
3
+ if (accepted) {
4
+ pConn.acceptSuggestion();
5
+ setStatus('success');
6
+ } else {
7
+ pConn.ignoreSuggestion();
8
+ setStatus(undefined);
9
+ }
10
+ };
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "{{COMPONENT_KEY}}",
3
+ "label": "{{COMPONENT_LABEL}}",
4
+ "description": "{{DESCRIPTION}}",
5
+ "organization": "{{ORGANIZATION}}",
6
+ "version": "{{VERSION}}",
7
+ "library": "{{LIBRARY}}",
8
+ "allowedApplications": {{{ALLOWEDAPPS}}},
9
+ "componentKey": "{{COMPONENT_KEY}}",
10
+ "type": "{{TYPE}}",
11
+ "subtype": {{{SUB_TYPE}}},
12
+ {{#IS_TEMPLATE}}
13
+ "icon": "images/pz-text-input-active.svg",
14
+ {{/IS_TEMPLATE}}
15
+ "properties": [
16
+ {
17
+ "name": "label",
18
+ "label": "Label value",
19
+ "format": "TEXT"
20
+ },
21
+ {
22
+ "name": "placeholder",
23
+ "label": "Placeholder",
24
+ "format": "TEXT"
25
+ },
26
+ {
27
+ "name": "visibility",
28
+ "label": "Visible",
29
+ "format": "VISIBILITY"
30
+ },
31
+ {
32
+ "name": "disabled",
33
+ "label": "Disabled",
34
+ "format": "DISABLED"
35
+ },
36
+ {
37
+ "name": "required",
38
+ "label": "Required",
39
+ "format": "REQUIRED"
40
+ }
41
+ ],
42
+ "defaultConfig": {
43
+ {{#IS_PICKLIST}}
44
+ "label": "@L $this.label",
45
+ "placeholder": "@L Select...",
46
+ "listType": "associated",
47
+ "datasource": "@ASSOCIATED .$this.name"
48
+ {{/IS_PICKLIST}}
49
+ {{#IS_BOOLEAN}}
50
+ "trueText": "True",
51
+ "falseText": "False"
52
+ {{/IS_BOOLEAN}}
53
+ {{#IS_PHONE}}
54
+ "datasource": {
55
+ "source": "@DATASOURCE D_pyCountryCallingCodeList.pxResults",
56
+ "fields": {
57
+ "value": "@P .pyCallingCode"
58
+ }
59
+ }
60
+ {{/IS_PHONE}}
61
+ }
62
+ }
@@ -0,0 +1,44 @@
1
+ import { useState } from 'react';
2
+ import { withKnobs, text, boolean } from '@storybook/addon-knobs';
3
+
4
+ import {{COMPONENT_CLASS_NAME}} from './index.jsx';
5
+
6
+ export default {
7
+ title: '{{COMPONENT_CLASS_NAME}}',
8
+ decorators: [withKnobs],
9
+ component: {{COMPONENT_CLASS_NAME}}
10
+ };
11
+
12
+ export const base{{COMPONENT_CLASS_NAME}} = () => {
13
+ const [value, setValue] = useState('test value');
14
+
15
+ const props = {
16
+ getPConnect: () => {
17
+ return {
18
+ getActionsApi: () => {
19
+ return {
20
+ updateFieldValue: (propName, value) => {
21
+ setValue(value);
22
+ }
23
+ };
24
+ },
25
+ getStateProps: () => {
26
+ return { value: '.name' };
27
+ }
28
+ };
29
+ },
30
+ value,
31
+ placeholder: text('Placeholder', 'Test placeholder'),
32
+ disabled: boolean('Disabled', false),
33
+ readOnly: boolean('Disabled', false),
34
+ required: boolean('Disabled', false),
35
+ label: text('Label', 'Sample Label'),
36
+ testId: text('Test id', 'text-12344566')
37
+ };
38
+
39
+ return (
40
+ <>
41
+ <{{COMPONENT_CLASS_NAME}} {...props} />
42
+ </>
43
+ );
44
+ };
@@ -0,0 +1,60 @@
1
+ import PropTypes from 'prop-types';
2
+ import { Input, Label } from '@pega/cosmos-react-core';
3
+
4
+ import Styled{{COMPONENT_CLASS_NAME}}Wrapper from './styles';
5
+
6
+
7
+ // Duplicated runtime code from Constellation Design System Component
8
+
9
+ // props passed in combination of props from property panel (config.json) and run time props from Constellation
10
+ // any default values in config.pros should be set in defaultProps at bottom of this file
11
+ const {{COMPONENT_CLASS_NAME}} = props => {
12
+ const { getPConnect, value, placeholder, disabled, readOnly, required, label, testId } = props;
13
+
14
+ const pConn = getPConnect();
15
+ const actions = pConn.getActionsApi();
16
+ const propName = pConn?.getStateProps()?.value;
17
+
18
+ const handleOnChange = event => {
19
+ const { value: updatedValue } = event.target;
20
+ actions.updateFieldValue(propName, updatedValue);
21
+ };
22
+
23
+ return (
24
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
25
+ <Label>{label}</Label>
26
+ <Input
27
+ type='text'
28
+ value={value}
29
+ placeholder={placeholder}
30
+ disabled={disabled}
31
+ readOnly={readOnly}
32
+ required={required}
33
+ onChange={handleOnChange}
34
+ testId={testId}
35
+ />
36
+ </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
37
+ );
38
+ };
39
+
40
+ {{COMPONENT_CLASS_NAME}}.defaultProps = {
41
+ value: '',
42
+ placeholder: '',
43
+ disabled: false,
44
+ readOnly: false,
45
+ required: false,
46
+ testId: null
47
+ };
48
+
49
+ {{COMPONENT_CLASS_NAME}}.propTypes = {
50
+ label: PropTypes.string,
51
+ value: PropTypes.string,
52
+ placeholder: PropTypes.string,
53
+ getPConnect: PropTypes.func.isRequired,
54
+ disabled: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
55
+ readOnly: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
56
+ required: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
57
+ testId: PropTypes.string
58
+ };
59
+
60
+ export default {{COMPONENT_CLASS_NAME}};
@@ -0,0 +1,7 @@
1
+ import styled, { css } from 'styled-components';
2
+
3
+ export default styled.div(() => {
4
+ return css`
5
+ margin: 8px 0;
6
+ `;
7
+ });
@@ -0,0 +1,111 @@
1
+ {
2
+ "name": "{{COMPONENT_KEY}}",
3
+ "label": "{{COMPONENT_LABEL}}",
4
+ "description": "{{DESCRIPTION}}",
5
+ "organization": "{{ORGANIZATION}}",
6
+ "version": "{{VERSION}}",
7
+ "library": "{{LIBRARY}}",
8
+ "allowedApplications": {{{ALLOWEDAPPS}}},
9
+ "componentKey": "{{COMPONENT_KEY}}",
10
+ "type": "{{TYPE}}",
11
+ "subtype": {{{SUB_TYPE}}},
12
+ "icon": "images/pz-email-active.svg",
13
+ "properties": [
14
+ {
15
+ "name": "label",
16
+ "label": "Field label",
17
+ "format": "TEXT",
18
+ "required": true
19
+ },
20
+ {
21
+ "name": "readOnly",
22
+ "label": "Edit mode",
23
+ "format": "READONLY"
24
+ },
25
+ {
26
+ "label": "Column settings",
27
+ "format": "GROUP",
28
+ "visibility": "@VIEWTYPE == 'MultiRecordDisplayAsTable'",
29
+ "properties": [
30
+ {
31
+ "name": "columnWidth",
32
+ "label": "Column width",
33
+ "format": "SELECT",
34
+ "source": [
35
+ {
36
+ "key": "auto",
37
+ "value": "Auto"
38
+ },
39
+ {
40
+ "key": "custom",
41
+ "value": "Custom"
42
+ }
43
+ ]
44
+ },
45
+ {
46
+ "name": "width",
47
+ "label": "Width (px)",
48
+ "format": "NUMBER",
49
+ "visibility": "$this.columnWidth == 'custom'"
50
+ }
51
+ ]
52
+ },
53
+ {
54
+ "label": "Input settings",
55
+ "format": "GROUP",
56
+ "visibility": "(!readOnly = true)",
57
+ "properties": [
58
+ {
59
+ "name": "placeholder",
60
+ "label": "Placeholder",
61
+ "format": "TEXT"
62
+ },
63
+ {
64
+ "name": "helperText",
65
+ "label": "Helper text",
66
+ "format": "TEXT"
67
+ }
68
+ ]
69
+ },
70
+ {
71
+ "label": "Conditions",
72
+ "format": "GROUP",
73
+ "properties": [
74
+ {
75
+ "name": "required",
76
+ "label": "Required",
77
+ "format": "REQUIRED",
78
+ "visibility": "(!readOnly = true)"
79
+ },
80
+ {
81
+ "name": "disabled",
82
+ "label": "Disabled",
83
+ "format": "DISABLED",
84
+ "visibility": "(!readOnly = true)"
85
+ },
86
+ {
87
+ "name": "visibility",
88
+ "label": "Visibility",
89
+ "format": "VISIBILITY"
90
+ }
91
+ ]
92
+ },
93
+ {
94
+ "label": "Advanced",
95
+ "format": "GROUP",
96
+ "collapsible": true,
97
+ "properties": [
98
+ {
99
+ "name": "testId",
100
+ "label": "Test ID",
101
+ "format": "TEXT",
102
+ "ignorePattern": "[^-_\\p{N}\\p{L}]",
103
+ "includeAnnotations": false
104
+ }
105
+ ]
106
+ }
107
+ ],
108
+ "defaultConfig": {
109
+ "label": "@L $this.label"
110
+ }
111
+ }