@pega/dx-component-builder-sdk 0.1.6 → 0.1.8

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 (111) hide show
  1. package/package.json +1 -1
  2. package/src/constants.js +8 -4
  3. package/src/tasks/build/helper.js +5 -23
  4. package/src/tasks/build/index.js +54 -7
  5. package/src/tasks/bundle/index.js +2 -2
  6. package/src/tasks/create/index.js +13 -5
  7. package/src/tasks/create/templates/Constellation/Field/Boolean/boolean-format.js.mustache +1 -1
  8. package/src/tasks/create/templates/Constellation/Field/Boolean/demo.stories.jsx.mustache +60 -0
  9. package/src/tasks/create/templates/Constellation/Field/Boolean/index.jsx.mustache +1 -2
  10. package/src/tasks/create/templates/Constellation/Field/Boolean/mock.stories.js.mustache +21 -0
  11. package/src/tasks/create/templates/Constellation/Field/Date/DateFormatter.js.mustache +61 -0
  12. package/src/tasks/create/templates/Constellation/Field/Date/FormattedText.jsx.mustache +41 -0
  13. package/src/tasks/create/templates/Constellation/Field/Date/date.js.mustache +179 -67
  14. package/src/tasks/create/templates/Constellation/Field/Date/demo.stories.jsx.mustache +40 -16
  15. package/src/tasks/create/templates/Constellation/Field/Date/index.jsx.mustache +3 -1
  16. package/src/tasks/create/templates/Constellation/Field/Date/mock.stories.js.mustache +23 -0
  17. package/src/tasks/create/templates/Constellation/Field/DateTime/date-time.js.mustache +0 -1
  18. package/src/tasks/create/templates/Constellation/Field/DateTime/{date-utils.js → date-utils.js.mustache} +1 -0
  19. package/src/tasks/create/templates/Constellation/Field/DateTime/date.js.mustache +1 -0
  20. package/src/tasks/create/templates/Constellation/Field/DateTime/demo.stories.jsx.mustache +40 -15
  21. package/src/tasks/create/templates/Constellation/Field/DateTime/index.jsx.mustache +2 -0
  22. package/src/tasks/create/templates/Constellation/Field/DateTime/mock.stories.js.mustache +23 -0
  23. package/src/tasks/create/templates/Constellation/Field/Decimal/demo.stories.jsx.mustache +22 -17
  24. package/src/tasks/create/templates/Constellation/Field/Decimal/index.jsx.mustache +2 -1
  25. package/src/tasks/create/templates/Constellation/Field/Decimal/mock.stories.js.mustache +21 -0
  26. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/demo.stories.jsx.mustache +25 -17
  27. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/index.jsx.mustache +3 -4
  28. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/mock.stories.js.mustache +23 -0
  29. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/demo.stories.jsx.mustache +22 -17
  30. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/index.jsx.mustache +8 -2
  31. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/mock.stories.js.mustache +21 -0
  32. package/src/tasks/create/templates/Constellation/Field/Integer/demo.stories.jsx.mustache +22 -17
  33. package/src/tasks/create/templates/Constellation/Field/Integer/index.jsx.mustache +2 -1
  34. package/src/tasks/create/templates/Constellation/Field/Integer/mock.stories.js.mustache +21 -0
  35. package/src/tasks/create/templates/Constellation/Field/Picklist/demo.stories.jsx.mustache +42 -14
  36. package/src/tasks/create/templates/Constellation/Field/Picklist/index.jsx.mustache +44 -1
  37. package/src/tasks/create/templates/Constellation/Field/Picklist/mock.stories.js.mustache +67 -0
  38. package/src/tasks/create/templates/Constellation/Field/Text/demo.stories.jsx.mustache +21 -16
  39. package/src/tasks/create/templates/Constellation/Field/Text/mock.stories.js.mustache +13 -0
  40. package/src/tasks/create/templates/Constellation/Field/Text-Email/demo.stories.jsx.mustache +20 -16
  41. package/src/tasks/create/templates/Constellation/Field/Text-Email/index.jsx.mustache +44 -2
  42. package/src/tasks/create/templates/Constellation/Field/Text-Email/mock.stories.js.mustache +22 -0
  43. package/src/tasks/create/templates/Constellation/Field/Text-Input/{StatusWork.js → StatusWork.jsx} +0 -1
  44. package/src/tasks/create/templates/Constellation/Field/Text-Input/demo.stories.jsx.mustache +21 -17
  45. package/src/tasks/create/templates/Constellation/Field/Text-Input/index.jsx.mustache +46 -3
  46. package/src/tasks/create/templates/Constellation/Field/Text-Input/mock.stories.js.mustache +21 -0
  47. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/demo.stories.jsx.mustache +21 -17
  48. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/index.jsx.mustache +44 -2
  49. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/mock.stories.js.mustache +20 -0
  50. package/src/tasks/create/templates/Constellation/Field/Text-Phone/demo.stories.jsx.mustache +19 -17
  51. package/src/tasks/create/templates/Constellation/Field/Text-Phone/index.jsx.mustache +46 -2
  52. package/src/tasks/create/templates/Constellation/Field/Text-Phone/mock.stories.js.mustache +37 -0
  53. package/src/tasks/create/templates/Constellation/Field/Text-URL/demo.stories.jsx.mustache +19 -17
  54. package/src/tasks/create/templates/Constellation/Field/Text-URL/index.jsx.mustache +174 -3
  55. package/src/tasks/create/templates/Constellation/Field/Text-URL/mock.stories.js.mustache +22 -0
  56. package/src/tasks/create/templates/Constellation/Field/TimeofDay/demo.stories.jsx.mustache +24 -16
  57. package/src/tasks/create/templates/Constellation/Field/TimeofDay/mock.stories.js.mustache +20 -0
  58. package/src/tasks/create/templates/Constellation/Field/TimeofDay/time-of-day.js.mustache +1 -0
  59. package/src/tasks/create/templates/Constellation/Template/DETAILS/StatusWork.jsx.mustache +26 -0
  60. package/src/tasks/create/templates/Constellation/Template/DETAILS/demo.stories.jsx.mustache +110 -0
  61. package/src/tasks/create/templates/Constellation/Template/DETAILS/index.jsx.mustache +3 -5
  62. package/src/tasks/create/templates/Constellation/Template/DETAILS/mock.stories.js.mustache +179 -0
  63. package/src/tasks/create/templates/Constellation/Template/DETAILS/utils.js.mustache +3 -6
  64. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/StatusWork.jsx.mustache +26 -0
  65. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/demo.stories.jsx.mustache +118 -0
  66. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/index.jsx.mustache +3 -5
  67. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/mock.stories.js.mustache +215 -0
  68. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/utils.js.mustache +3 -3
  69. package/src/tasks/create/templates/Constellation/Template/FORM/demo.stories.jsx.mustache +89 -0
  70. package/src/tasks/create/templates/Constellation/Template/FORM/index.jsx.mustache +6 -10
  71. package/src/tasks/create/templates/Constellation/Template/FORM/mock.stories.js.mustache +125 -0
  72. package/src/tasks/create/templates/Constellation/Template/FORM-region/demo.stories.jsx.mustache +100 -0
  73. package/src/tasks/create/templates/Constellation/Template/FORM-region/index.jsx.mustache +5 -11
  74. package/src/tasks/create/templates/Constellation/Template/FORM-region/mock.stories.js.mustache +131 -0
  75. package/src/tasks/create/templates/Constellation/Template/PAGE/{GetNextWork.js.mustache → GetNextWork.jsx.mustache} +6 -0
  76. package/src/tasks/create/templates/Constellation/Template/PAGE/demo.stories.jsx.mustache +102 -0
  77. package/src/tasks/create/templates/Constellation/Template/PAGE/index.jsx.mustache +9 -7
  78. package/src/tasks/create/templates/Constellation/Template/PAGE/mock.stories.js.mustache +94 -0
  79. package/src/tasks/create/templates/Constellation/Template/PAGE/utils.js.mustache +4 -1
  80. package/src/tasks/create/templates/Constellation/Widget/CASE/demo.stories.jsx.mustache +78 -0
  81. package/src/tasks/create/templates/Constellation/Widget/CASE/index.jsx.mustache +1 -0
  82. package/src/tasks/create/templates/Constellation/Widget/CASE/mock.stories.js.mustache +389 -0
  83. package/src/tasks/create/templates/Constellation/Widget/PAGE/demo.stories.jsx.mustache +30 -0
  84. package/src/tasks/create/templates/Constellation/Widget/PAGE/mock.stories.js.mustache +22 -0
  85. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/{Avatar.js.mustache → Avatar.jsx.mustache} +2 -0
  86. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/{Operator.js.mustache → Operator.jsx.mustache} +2 -1
  87. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/demo.stories.jsx.mustache +68 -0
  88. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/index.jsx.mustache +9 -9
  89. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/mock.stories.js.mustache +51 -0
  90. package/src/tasks/create/templates/SDK-React/Template/PAGE/demo.stories.jsx.mustache +79 -0
  91. package/src/tasks/create/templates/SDK-React/Template/PAGE/mock.stories.js.mustache +115 -0
  92. package/src/tasks/delete/helper.js +7 -25
  93. package/src/tasks/delete/index.js +2 -3
  94. package/src/tasks/delete-all/helper.js +7 -24
  95. package/src/tasks/delete-all/index.js +2 -3
  96. package/src/tasks/list/helper.js +3 -21
  97. package/src/tasks/list/index.js +2 -3
  98. package/src/tasks/map/map.js +4 -10
  99. package/src/tasks/override/index.js +50 -21
  100. package/src/tasks/publish/helper.js +77 -15
  101. package/src/tasks/publish/index.js +103 -15
  102. package/src/tasks/publish-all/helper.js +77 -13
  103. package/src/tasks/publish-all/index.js +109 -25
  104. package/src/tasks/validator/index.js +7 -5
  105. package/src/util.js +56 -10
  106. package/src/tasks/create/templates/Constellation/Field/Picklist/picklist.js.mustache +0 -43
  107. package/src/tasks/create/templates/Constellation/Field/Text-Email/text-email.js.mustache +0 -43
  108. package/src/tasks/create/templates/Constellation/Field/Text-Input/text-input.js.mustache +0 -43
  109. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/text-paragraph.js.mustache +0 -43
  110. package/src/tasks/create/templates/Constellation/Field/Text-Phone/text-phone.js.mustache +0 -43
  111. package/src/tasks/create/templates/Constellation/Field/Text-URL/text-url.js.mustache +0 -172
package/src/util.js CHANGED
@@ -34,7 +34,9 @@ import {
34
34
  COMPONENT_PREFIX_TEMPLATES_PATH,
35
35
  COMPONENT_PREFIX_WIDGETS_PATH,
36
36
  COMPONENT_PREFIX_DSE_PATH,
37
- COMPONENT_PREFIX_INFRA_PATH
37
+ COMPONENT_PREFIX_INFRA_PATH,
38
+ CATEGORY_CUSTOM,
39
+ CATEGORY_OVERRIDE
38
40
  } from './constants.js';
39
41
 
40
42
 
@@ -54,7 +56,7 @@ export const checkPathAccess = async (path, options = {}) => {
54
56
  }
55
57
  };
56
58
 
57
- export const deleteLocalComponent = async (componentKey, category = "custom") => {
59
+ export const deleteLocalComponent = async (componentKey, category = CATEGORY_CUSTOM) => {
58
60
  const currentDirectory = process.cwd();
59
61
  const pegaConfigJsonPath = join(currentDirectory, DXCB_CONFIG_JSON_FILENAME);
60
62
  const categoryDirectory = join("/", category.toLowerCase());
@@ -128,7 +130,26 @@ export const deleteServerComponent = async componentKey => {
128
130
  }
129
131
  };
130
132
 
131
- export const getComponents = async (showSeparator = false, category = "custom") => {
133
+ export const getOptionsCategory = (options) => {
134
+ let categoryType = null;
135
+ if (options.params[3]) {
136
+ let catType = options.params[3];
137
+
138
+ switch (catType.toLowerCase()) {
139
+ case "override" :
140
+ case "o" :
141
+ categoryType = "override";
142
+ break;
143
+ case "custom" :
144
+ case "c" :
145
+ categoryType = "custom";
146
+ break;
147
+ }
148
+ }
149
+ return categoryType;
150
+ }
151
+
152
+ export const getComponents = async (showSeparator = false, category = CATEGORY_CUSTOM) => {
132
153
  const currentDirectory = process.cwd();
133
154
  const pegaConfigJsonPath = join(currentDirectory, DXCB_CONFIG_JSON_FILENAME);
134
155
  const categoryDirectory = join("/", category.toLowerCase());
@@ -150,7 +171,7 @@ export const getComponents = async (showSeparator = false, category = "custom")
150
171
  let compList = new Array();
151
172
 
152
173
  switch (category) {
153
- case "custom":
174
+ case CATEGORY_CUSTOM:
154
175
  const fieldComps = await getSubComponents(directory, FIELD_PATH);
155
176
  const templateComps = await getSubComponents(directory, TEMPLATE_PATH);
156
177
  const widgetComps = await getSubComponents(directory, WIDGET_PATH);
@@ -172,7 +193,7 @@ export const getComponents = async (showSeparator = false, category = "custom")
172
193
  compList.push(...widgetComps);
173
194
  }
174
195
  break;
175
- case "override":
196
+ case CATEGORY_OVERRIDE:
176
197
  const formsComps = await getSubComponents(directory, FORMS_PATH);
177
198
  const templatesComps = await getSubComponents(directory, TEMPLATES_PATH);
178
199
  const widgetsComps = await getSubComponents(directory, WIDGETS_PATH);
@@ -223,7 +244,30 @@ export const getSubComponents = async (directory, type) => {
223
244
  .map(dirent => dirent.name);
224
245
  }
225
246
 
226
- export const getComponentsObj = async (showSeparator = false, category = "custom") => {
247
+
248
+ export const getDirectoryFiles = async (directory) => {
249
+ return fs
250
+ .readdirSync(directory, { withFileTypes: true })
251
+ .filter(dirent => !dirent.isDirectory())
252
+ .map(dirent => dirent.name);
253
+ }
254
+
255
+ /*
256
+ export const createBlankConfigExt = async (directory, name) => {
257
+
258
+ let fileData = "{";
259
+ fileData = fileData.concat("\n\t");
260
+ fileData = fileData.concat("\"name\" : \"");
261
+ fileData = fileData.concat(`${name}`);
262
+ fileData = fileData.concat("\", \n\t");
263
+ fileData = fileData.concat("\"properties\" : [ ] \n");
264
+ fileData = fileData.concat("}");
265
+ return fs.writeFileSync( join(directory, "/config-ext.json"), fileData, { encoding: 'utf8' });
266
+ }
267
+ */
268
+
269
+
270
+ export const getComponentsObj = async (showSeparator = false, category = CATEGORY_CUSTOM) => {
227
271
  const currentDirectory = process.cwd();
228
272
  const pegaConfigJsonPath = join(currentDirectory, DXCB_CONFIG_JSON_FILENAME);
229
273
  const categoryDirectory = join("/", category.toLowerCase());
@@ -244,7 +288,7 @@ export const getComponentsObj = async (showSeparator = false, category = "custom
244
288
  let compList = new Array();
245
289
 
246
290
  switch (category) {
247
- case "custom":
291
+ case CATEGORY_CUSTOM:
248
292
  const fieldComps = await getSubComponents(directory, FIELD_PATH);
249
293
  const templateComps = await getSubComponents(directory, TEMPLATE_PATH);
250
294
  const widgetComps = await getSubComponents(directory, WIDGET_PATH);
@@ -289,7 +333,7 @@ export const getComponentsObj = async (showSeparator = false, category = "custom
289
333
  ));
290
334
  }
291
335
  break;
292
- case "override":
336
+ case CATEGORY_OVERRIDE:
293
337
  const formsComps = await getSubComponents(directory, FORMS_PATH);
294
338
  const templatesComps = await getSubComponents(directory, TEMPLATES_PATH);
295
339
  const widgetsComps = await getSubComponents(directory, WIDGETS_PATH);
@@ -381,7 +425,9 @@ export const getSubComponentsAndDir = async (directory, type) => {
381
425
  .map(dirent => prefix + dirent.name);
382
426
  }
383
427
 
384
- export const getComponentsAndSubDirectory = async (category = "custom") => {
428
+
429
+
430
+ export const getComponentsAndSubDirectory = async (category = CATEGORY_CUSTOM) => {
385
431
  const currentDirectory = process.cwd();
386
432
  const pegaConfigJsonPath = join(currentDirectory, DXCB_CONFIG_JSON_FILENAME);
387
433
  const categoryDirectory = join("/", category.toLowerCase());
@@ -465,7 +511,7 @@ export const getComponentDefaults = async () => {
465
511
  return config.component;
466
512
  };
467
513
 
468
- export const getComponentDirectoryPath = async (componentKey, category = "custom") => {
514
+ export const getComponentDirectoryPath = async (componentKey, category = CATEGORY_CUSTOM) => {
469
515
  const currentDirectory = process.cwd();
470
516
  const pegaConfigJsonPath = join(currentDirectory, DXCB_CONFIG_JSON_FILENAME);
471
517
  const categoryDirectory = join("/", category.toLowerCase());
@@ -1,43 +0,0 @@
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
- };
@@ -1,43 +0,0 @@
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
- };
@@ -1,43 +0,0 @@
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
- };
@@ -1,43 +0,0 @@
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
- };
@@ -1,43 +0,0 @@
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
- };
@@ -1,172 +0,0 @@
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
- const urlLabelVal = (urlLabelSelection, btnVal, urlLabel, propUrlLabel) => {
21
- if ((urlLabel !== '' || propUrlLabel !== '') && btnVal !== null) {
22
- switch (urlLabelSelection) {
23
- case 'constant': {
24
- btnVal = urlLabel;
25
- break;
26
- }
27
- case 'propertyRef': {
28
- btnVal = propUrlLabel;
29
- break;
30
- }
31
- // no default
32
- }
33
- }
34
- return btnVal;
35
- };
36
-
37
- const isImage = (url) => /\.(jpg|jpeg|png|webp|avif|gif|svg)$/.test(url);
38
-
39
- const TableImage = (imageProps) => {
40
- const { value, altText, altTextOfImage, propaltTextOfImage, urlLabelSelection, urlLabel, propUrlLabel } = imageProps;
41
- const demoButtonRef = useRef(null);
42
- let imageDisplayComp = null;
43
- const [images, setImages] = useState(null);
44
- const imgDescription = {
45
- id: 'url',
46
- name: urlLabelSelection === 'constant' ? urlLabel : propUrlLabel,
47
- description: altText === 'constant' ? altTextOfImage : propaltTextOfImage,
48
- src: value
49
- };
50
- const onClick = () => {
51
- setImages([imgDescription]);
52
- };
53
- const onItemDownload = async (id) => {
54
- const a = document.createElement('a');
55
- a.href = await fetch(images[0].src)
56
- .then((response) => {
57
- return response.blob();
58
- })
59
- .then((blob) => {
60
- return URL.createObjectURL(blob);
61
- });
62
- a.download = images?.find((image) => image.id === id)?.name ?? id;
63
- document.body.appendChild(a);
64
- a.click();
65
- document.body.removeChild(a);
66
- };
67
- let btnVal = value;
68
- btnVal = urlLabelVal(urlLabelSelection, btnVal, urlLabel, propUrlLabel);
69
- imageDisplayComp = (
70
- <React.Fragment>
71
- {btnVal !== null && (
72
- <Button ref={demoButtonRef} variant='link' compact={false} onClick={onClick} autoFocus>
73
- {btnVal}
74
- </Button>
75
- )}
76
- {images && (
77
- <Lightbox
78
- items={images}
79
- cycle={false}
80
- onAfterClose={() => {
81
- setImages(null);
82
- demoButtonRef.current?.focus();
83
- }}
84
- onItemDownload={isImage(images[0].src) ? onItemDownload : undefined}
85
- />
86
- )}
87
- </React.Fragment>
88
- );
89
- return imageDisplayComp;
90
- };
91
-
92
- export const textFormatter = (formatter,value) => {
93
- let displayComponent = null;
94
- switch(formatter){
95
- case "TextInput" : {
96
- displayComponent = value;
97
- break;
98
- }
99
- case "Email" : {
100
- displayComponent = (<EmailDisplay value={value} displayText={value} variant="link" />);
101
- break;
102
- }
103
- case "Phone" : {
104
- displayComponent = (<PhoneDisplay value={value} variant="link" />);
105
- break;
106
- }
107
- case "URL" : {
108
- displayComponent = (<URLDisplay target="_blank" value={value} displayText={value} variant="link" />);
109
- break;
110
- }
111
- // no default
112
- }
113
- return displayComponent;
114
- };
115
-
116
- /**
117
- * Returns a URL display component based on the options
118
- * @function urlFormatter
119
- * @param {string} value value
120
- * @param {object} options options for formatting
121
- * { displayAs,tableDisplayAs,isTableFormatter,altText,altTextOfImage,propaltTextOfImage,urlLabelSelection, urlLabel,propUrlLabel, widthSel, customWidth}
122
- */
123
- export const urlFormatter = (value, options) => {
124
- const {
125
- displayAs,
126
- tableDisplayAs,
127
- isTableFormatter,
128
- altText,
129
- altTextOfImage,
130
- propaltTextOfImage,
131
- urlLabelSelection,
132
- urlLabel,
133
- propUrlLabel,
134
- widthSel,
135
- customWidth
136
- } = options;
137
-
138
- let urlFormatComp = null;
139
- if (
140
- (displayAs === 'labelText' || (isTableFormatter && tableDisplayAs === 'link')) &&
141
- (urlLabel !== '' || propUrlLabel !== '')
142
- ) {
143
- urlFormatComp = (
144
- <URLDisplay
145
- target='_blank'
146
- value={value}
147
- displayText={urlLabelSelection === 'constant' ? urlLabel : propUrlLabel}
148
- variant='link'
149
- />
150
- );
151
- } else if ((displayAs === 'Image' || tableDisplayAs === 'Image') && !!value) {
152
- if (isTableFormatter) {
153
- urlFormatComp = TableImage({
154
- value,
155
- altText,
156
- altTextOfImage,
157
- propaltTextOfImage,
158
- urlLabelSelection,
159
- urlLabel,
160
- propUrlLabel
161
- });
162
- } else {
163
- const width = widthSel === 'widthpx' ? customWidth : null;
164
- urlFormatComp = (
165
- <Image src={value} width={width} alt={altText === 'constant' ? altTextOfImage : propaltTextOfImage} />
166
- );
167
- }
168
- } else {
169
- urlFormatComp = <URLDisplay target='_blank' value={value} displayText={value} variant='link' />;
170
- }
171
- return urlFormatComp;
172
- };