@pega/custom-dx-components 2.0.16 → 2.0.17

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 (117) hide show
  1. package/package.json +2 -2
  2. package/src/cli.js +18 -0
  3. package/src/tasks/authenticate/index.js +3 -1
  4. package/src/tasks/build/helper.js +123 -0
  5. package/src/tasks/build/index.js +54 -0
  6. package/src/tasks/{publish/bundle → bundle}/builder/index.js +0 -0
  7. package/src/tasks/{publish/bundle → bundle}/builder/modules.js +0 -0
  8. package/src/tasks/{publish/bundle → bundle}/builder/paths.js +0 -0
  9. package/src/tasks/{publish/bundle → bundle}/builder/webpack.config.js +0 -2
  10. package/src/tasks/{publish/bundle → bundle}/index.js +2 -2
  11. package/src/tasks/create/index.js +6 -3
  12. package/src/tasks/create/templates/Constellation/Field/Boolean/boolean-format.js.mustache +1 -1
  13. package/src/tasks/create/templates/Constellation/Field/Boolean/demo.stories.jsx.mustache +29 -18
  14. package/src/tasks/create/templates/Constellation/Field/Boolean/index.jsx.mustache +1 -2
  15. package/src/tasks/create/templates/Constellation/Field/Boolean/mock.stories.js.mustache +21 -0
  16. package/src/tasks/create/templates/Constellation/Field/Date/DateFormatter.js.mustache +61 -0
  17. package/src/tasks/create/templates/Constellation/Field/Date/FormattedText.jsx.mustache +41 -0
  18. package/src/tasks/create/templates/Constellation/Field/Date/date.js.mustache +179 -67
  19. package/src/tasks/create/templates/Constellation/Field/Date/demo.stories.jsx.mustache +40 -16
  20. package/src/tasks/create/templates/Constellation/Field/Date/index.jsx.mustache +3 -1
  21. package/src/tasks/create/templates/Constellation/Field/Date/mock.stories.js.mustache +23 -0
  22. package/src/tasks/create/templates/Constellation/Field/DateTime/date-time.js.mustache +0 -1
  23. package/src/tasks/create/templates/Constellation/Field/DateTime/{date-utils.js → date-utils.js.mustache} +1 -0
  24. package/src/tasks/create/templates/Constellation/Field/DateTime/date.js.mustache +1 -0
  25. package/src/tasks/create/templates/Constellation/Field/DateTime/demo.stories.jsx.mustache +40 -15
  26. package/src/tasks/create/templates/Constellation/Field/DateTime/index.jsx.mustache +2 -0
  27. package/src/tasks/create/templates/Constellation/Field/DateTime/mock.stories.js.mustache +23 -0
  28. package/src/tasks/create/templates/Constellation/Field/Decimal/demo.stories.jsx.mustache +22 -17
  29. package/src/tasks/create/templates/Constellation/Field/Decimal/index.jsx.mustache +2 -1
  30. package/src/tasks/create/templates/Constellation/Field/Decimal/mock.stories.js.mustache +21 -0
  31. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/demo.stories.jsx.mustache +25 -17
  32. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/index.jsx.mustache +3 -4
  33. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/mock.stories.js.mustache +23 -0
  34. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/demo.stories.jsx.mustache +22 -17
  35. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/index.jsx.mustache +8 -2
  36. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/mock.stories.js.mustache +21 -0
  37. package/src/tasks/create/templates/Constellation/Field/Integer/demo.stories.jsx.mustache +22 -17
  38. package/src/tasks/create/templates/Constellation/Field/Integer/index.jsx.mustache +2 -1
  39. package/src/tasks/create/templates/Constellation/Field/Integer/mock.stories.js.mustache +21 -0
  40. package/src/tasks/create/templates/Constellation/Field/Picklist/demo.stories.jsx.mustache +42 -14
  41. package/src/tasks/create/templates/Constellation/Field/Picklist/index.jsx.mustache +44 -1
  42. package/src/tasks/create/templates/Constellation/Field/Picklist/mock.stories.js.mustache +67 -0
  43. package/src/tasks/create/templates/Constellation/Field/Text/demo.stories.jsx.mustache +21 -16
  44. package/src/tasks/create/templates/Constellation/Field/Text/mock.stories.js.mustache +13 -0
  45. package/src/tasks/create/templates/Constellation/Field/Text-Email/demo.stories.jsx.mustache +20 -16
  46. package/src/tasks/create/templates/Constellation/Field/Text-Email/index.jsx.mustache +44 -2
  47. package/src/tasks/create/templates/Constellation/Field/Text-Email/mock.stories.js.mustache +22 -0
  48. package/src/tasks/create/templates/Constellation/Field/Text-Input/{StatusWork.js → StatusWork.jsx} +0 -1
  49. package/src/tasks/create/templates/Constellation/Field/Text-Input/demo.stories.jsx.mustache +21 -17
  50. package/src/tasks/create/templates/Constellation/Field/Text-Input/index.jsx.mustache +46 -3
  51. package/src/tasks/create/templates/Constellation/Field/Text-Input/mock.stories.js.mustache +21 -0
  52. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/demo.stories.jsx.mustache +21 -17
  53. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/index.jsx.mustache +44 -2
  54. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/mock.stories.js.mustache +20 -0
  55. package/src/tasks/create/templates/Constellation/Field/Text-Phone/demo.stories.jsx.mustache +19 -17
  56. package/src/tasks/create/templates/Constellation/Field/Text-Phone/index.jsx.mustache +46 -2
  57. package/src/tasks/create/templates/Constellation/Field/Text-Phone/mock.stories.js.mustache +37 -0
  58. package/src/tasks/create/templates/Constellation/Field/Text-URL/demo.stories.jsx.mustache +19 -17
  59. package/src/tasks/create/templates/Constellation/Field/Text-URL/index.jsx.mustache +174 -3
  60. package/src/tasks/create/templates/Constellation/Field/Text-URL/mock.stories.js.mustache +22 -0
  61. package/src/tasks/create/templates/Constellation/Field/TimeofDay/demo.stories.jsx.mustache +24 -16
  62. package/src/tasks/create/templates/Constellation/Field/TimeofDay/mock.stories.js.mustache +20 -0
  63. package/src/tasks/create/templates/Constellation/Field/TimeofDay/time-of-day.js.mustache +1 -0
  64. package/src/tasks/create/templates/Constellation/Template/DETAILS/StatusWork.jsx.mustache +26 -0
  65. package/src/tasks/create/templates/Constellation/Template/DETAILS/demo.stories.jsx.mustache +110 -0
  66. package/src/tasks/create/templates/Constellation/Template/DETAILS/index.jsx.mustache +14 -29
  67. package/src/tasks/create/templates/Constellation/Template/DETAILS/mock.stories.js.mustache +179 -0
  68. package/src/tasks/create/templates/Constellation/Template/DETAILS/utils.js.mustache +3 -77
  69. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/StatusWork.jsx.mustache +26 -0
  70. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/demo.stories.jsx.mustache +118 -0
  71. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/index.jsx.mustache +14 -29
  72. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/mock.stories.js.mustache +215 -0
  73. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/utils.js.mustache +3 -74
  74. package/src/tasks/create/templates/Constellation/Template/FORM/demo.stories.jsx.mustache +89 -0
  75. package/src/tasks/create/templates/Constellation/Template/FORM/index.jsx.mustache +6 -10
  76. package/src/tasks/create/templates/Constellation/Template/FORM/mock.stories.js.mustache +125 -0
  77. package/src/tasks/create/templates/Constellation/Template/FORM-region/demo.stories.jsx.mustache +100 -0
  78. package/src/tasks/create/templates/Constellation/Template/FORM-region/index.jsx.mustache +10 -8
  79. package/src/tasks/create/templates/Constellation/Template/FORM-region/mock.stories.js.mustache +131 -0
  80. package/src/tasks/create/templates/Constellation/Template/PAGE/{GetNextWork.js.mustache → GetNextWork.jsx.mustache} +6 -0
  81. package/src/tasks/create/templates/Constellation/Template/PAGE/demo.stories.jsx.mustache +102 -0
  82. package/src/tasks/create/templates/Constellation/Template/PAGE/index.jsx.mustache +9 -7
  83. package/src/tasks/create/templates/Constellation/Template/PAGE/mock.stories.js.mustache +94 -0
  84. package/src/tasks/create/templates/Constellation/Template/PAGE/utils.js.mustache +4 -1
  85. package/src/tasks/create/templates/Constellation/Widget/CASE/demo.stories.jsx.mustache +78 -0
  86. package/src/tasks/create/templates/Constellation/Widget/CASE/index.jsx.mustache +1 -0
  87. package/src/tasks/create/templates/Constellation/Widget/CASE/mock.stories.js.mustache +389 -0
  88. package/src/tasks/create/templates/Constellation/Widget/PAGE/demo.stories.jsx.mustache +30 -0
  89. package/src/tasks/create/templates/Constellation/Widget/PAGE/index.jsx.mustache +8 -8
  90. package/src/tasks/create/templates/Constellation/Widget/PAGE/mock.stories.js.mustache +22 -0
  91. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/{Avatar.js.mustache → Avatar.jsx.mustache} +2 -0
  92. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/{Operator.js.mustache → Operator.jsx.mustache} +2 -1
  93. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/demo.stories.jsx.mustache +68 -0
  94. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/index.jsx.mustache +9 -9
  95. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/mock.stories.js.mustache +51 -0
  96. package/src/tasks/delete/helper.js +4 -0
  97. package/src/tasks/delete/index.js +4 -0
  98. package/src/tasks/delete-all/helper.js +175 -0
  99. package/src/tasks/delete-all/index.js +49 -0
  100. package/src/tasks/index.js +3 -0
  101. package/src/tasks/init/index.js +1 -1
  102. package/src/tasks/init/template/.eslintignore +8 -0
  103. package/src/tasks/init/template/.eslintrc.json +186 -5
  104. package/src/tasks/init/template/package.json.mustache +19 -4
  105. package/src/tasks/init/template/tasks.config.json +1 -0
  106. package/src/tasks/linter/index.js +46 -0
  107. package/src/tasks/list/index.js +4 -0
  108. package/src/tasks/publish/index.js +14 -1
  109. package/src/tasks/publish-all/helper.js +139 -0
  110. package/src/tasks/publish-all/index.js +84 -0
  111. package/src/util.js +10 -0
  112. package/src/tasks/create/templates/Constellation/Field/Picklist/picklist.js.mustache +0 -43
  113. package/src/tasks/create/templates/Constellation/Field/Text-Email/text-email.js.mustache +0 -43
  114. package/src/tasks/create/templates/Constellation/Field/Text-Input/text-input.js.mustache +0 -43
  115. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/text-paragraph.js.mustache +0 -43
  116. package/src/tasks/create/templates/Constellation/Field/Text-Phone/text-phone.js.mustache +0 -43
  117. package/src/tasks/create/templates/Constellation/Field/Text-URL/text-url.js.mustache +0 -172
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/custom-dx-components",
3
- "version": "2.0.16",
3
+ "version": "2.0.17",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
@@ -26,6 +26,7 @@
26
26
  "css-loader": "6.7.1",
27
27
  "css-minimizer-webpack-plugin": "^4.1.0",
28
28
  "execa": "^6.1.0",
29
+ "eslint": "^8.4.1",
29
30
  "file-loader": "6.2.0",
30
31
  "fs-extra": "^10.1.0",
31
32
  "gitignore": "^0.7.0",
@@ -61,7 +62,6 @@
61
62
  "devDependencies": {
62
63
  "@pega/configs": "^0.3.3",
63
64
  "cspell": "^6.9.0",
64
- "eslint": "^8.23.1",
65
65
  "prettier": "2.7.1"
66
66
  }
67
67
  }
package/src/cli.js CHANGED
@@ -3,11 +3,14 @@ import chalk from 'chalk';
3
3
 
4
4
  import {
5
5
  authenticate,
6
+ buildComponent,
6
7
  createComponent,
7
8
  deleteComponent,
9
+ deleteAllComponents,
8
10
  initProject,
9
11
  listComponents,
10
12
  publishComponent,
13
+ publishAllComponents,
11
14
  updateComponent,
12
15
  validate,
13
16
  upgrade
@@ -16,11 +19,14 @@ import {
16
19
  const TASKS = {
17
20
  INIT: 'init',
18
21
  CREATE: 'create',
22
+ BUILD: 'buildComponent',
19
23
  PUBLISH: 'publish',
24
+ PUBLISH_All: 'publishAll',
20
25
  LIST: 'list',
21
26
  VALIDATE_SCHEMA: 'validateSchema',
22
27
  UPDATE: 'update',
23
28
  DELETE: 'delete',
29
+ DELETE_ALL: "deleteAll",
24
30
  AUTHENTICATE: 'authenticate',
25
31
  UPGRADE: 'upgrade'
26
32
  };
@@ -60,6 +66,14 @@ export default async (args = []) => {
60
66
  publishComponent(options);
61
67
  break;
62
68
  }
69
+ case TASKS.PUBLISH_All: {
70
+ publishAllComponents(options);
71
+ break;
72
+ }
73
+ case TASKS.BUILD: {
74
+ buildComponent(options);
75
+ break;
76
+ }
63
77
  case TASKS.LIST: {
64
78
  listComponents(options);
65
79
  break;
@@ -76,6 +90,10 @@ export default async (args = []) => {
76
90
  deleteComponent(options);
77
91
  break;
78
92
  }
93
+ case TASKS.DELETE_ALL: {
94
+ deleteAllComponents(options);
95
+ break;
96
+ }
79
97
  case TASKS.AUTHENTICATE: {
80
98
  authenticate(options);
81
99
  break;
@@ -6,7 +6,7 @@ import chalk from 'chalk';
6
6
  import inquirer from 'inquirer';
7
7
  import fetch from 'node-fetch';
8
8
 
9
- import { checkPathAccess, getTokenUrl } from '../../util.js';
9
+ import { checkPathAccess, getTokenUrl, showVersion } from '../../util.js';
10
10
  import { TOKEN_PATH } from '../../constants.js';
11
11
 
12
12
  import { getAuthQuestions } from './helper.js';
@@ -57,6 +57,8 @@ const generateAccessToken = async config => {
57
57
  };
58
58
 
59
59
  export default async options => {
60
+ showVersion();
61
+
60
62
  await checkPathAccess(pegaConfigJsonPath);
61
63
 
62
64
  let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
@@ -0,0 +1,123 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import https from 'https';
4
+
5
+ import fetch from 'node-fetch';
6
+ import AdmZip from 'adm-zip';
7
+ import chalk from 'chalk';
8
+
9
+ import {
10
+ constructCompleteUrl,
11
+ getComponentDirectoryPath,
12
+ getComponents,
13
+ getPegaServerConfig,
14
+ validateRulesetVersion
15
+ } from '../../util.js';
16
+ import { PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH } from '../../constants.js';
17
+
18
+ export const getPublishComponentQuestions = async () => {
19
+ const components = await getComponents();
20
+ const defaultPegaConfig = await getPegaServerConfig();
21
+
22
+ return [
23
+ {
24
+ name: 'componentKey',
25
+ type: 'rawlist',
26
+ message: 'Select component to build',
27
+ choices: components
28
+ },
29
+ {
30
+ name: 'sourceMap',
31
+ message: 'Generate source map ?',
32
+ default: defaultPegaConfig.sourceMap,
33
+ when: () => false && !process.env.SOURCE_MAP
34
+ },
35
+ {
36
+ name: 'devBuild',
37
+ message: 'Generate development build ?',
38
+ default: defaultPegaConfig.devBuild
39
+ }
40
+ ];
41
+ };
42
+
43
+ export const zipComponent = async componentKey => {
44
+ const srcDirectory = await getComponentDirectoryPath(componentKey);
45
+ const buildDirectory = await path.join(path.resolve(), 'dist/components', componentKey);
46
+ const configJson = `${srcDirectory}/config.json`;
47
+
48
+ const zip = new AdmZip();
49
+
50
+ zip.addLocalFolder(srcDirectory, 'src/');
51
+ zip.addLocalFile(configJson);
52
+ zip.addLocalFolder(buildDirectory);
53
+ const zipContent = zip.toBuffer().toString('base64');
54
+
55
+ const configContent = Buffer.from(fs.readFileSync(`${srcDirectory}/config.json`)).toString();
56
+ fs.rmdir('dist', { recursive: true }, err => {
57
+ if (err) {
58
+ throw err;
59
+ }
60
+ });
61
+ return { zipContent, configContent };
62
+ };
63
+
64
+ export const publishComponentToServer = async data => {
65
+ const { configContent, zipContent, componentKey, rulesetName, rulesetVersion } = data;
66
+
67
+ const apiBody = {
68
+ configContent,
69
+ zipContent,
70
+ componentKey: JSON.parse(configContent).componentKey,
71
+ publishFor: 'constellation',
72
+ rulesetName,
73
+ rulesetVersion,
74
+ category: ''
75
+ };
76
+ const defaultPegaConfig = await getPegaServerConfig();
77
+ const url = constructCompleteUrl(
78
+ defaultPegaConfig.server,
79
+ PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT
80
+ );
81
+ try {
82
+ const OauthData = fs.readFileSync(TOKEN_PATH, 'utf8');
83
+ if (OauthData) {
84
+ const {
85
+ access_token: accessToken,
86
+ token_type: tokenType,
87
+ refresh_token: refreshToken
88
+ } = JSON.parse(OauthData);
89
+ let status = 500;
90
+ fetch(url, {
91
+ method: 'POST',
92
+ agent: new https.Agent({ rejectUnauthorized: false }),
93
+ headers: {
94
+ Authorization: `${tokenType} ${accessToken}`
95
+ },
96
+ body: JSON.stringify(apiBody)
97
+ })
98
+ .then(response => {
99
+ status = response.status;
100
+ return response.text();
101
+ })
102
+ .then(resp => {
103
+ const respData = JSON.parse(resp);
104
+ if (status === 401) {
105
+ throw new Error(
106
+ 'Error occured in authentication. Please regenerate using authenticate'
107
+ );
108
+ // console.log(accessTokenUri, refreshToken);
109
+ /* TODO - Handle refresh_token */
110
+ } else if (status == 200) {
111
+ console.log(chalk.bold.green(`Success : ${respData.message}`));
112
+ } else {
113
+ throw new Error(`${respData.message}`);
114
+ }
115
+ })
116
+ .catch(e => Promise.reject(`${chalk.bold.red(e)}`));
117
+ } else {
118
+ throw new Error(`Error occured in authentication. Please regenerate using authenticate`);
119
+ }
120
+ } catch (err) {
121
+ throw new Error(`Error occured in authentication. Please regenerate using authenticate`);
122
+ }
123
+ };
@@ -0,0 +1,54 @@
1
+ import inquirer from 'inquirer';
2
+ import Listr from 'listr';
3
+ import chalk from 'chalk';
4
+
5
+ import validate from '../validator/index.js';
6
+
7
+ import bundleComponent from '../bundle/index.js';
8
+ import lintComponent from '../linter/index.js';
9
+ import { getPublishComponentQuestions, publishComponentToServer, zipComponent } from './helper.js';
10
+ import { getComponentDirectoryPath, showVersion } from '../../util.js';
11
+
12
+ export default async options => {
13
+ showVersion();
14
+
15
+ const questions = await getPublishComponentQuestions();
16
+ const answers = await inquirer.prompt(questions);
17
+ const { componentKey, sourceMap, devBuild } = answers;
18
+
19
+ let content = {
20
+ ...answers
21
+ };
22
+
23
+ const tasks = new Listr(
24
+ [
25
+ {
26
+ title: 'Validate config schema',
27
+ task: async () => {
28
+ await validate(componentKey);
29
+ }
30
+ },
31
+ {
32
+ title: 'Lint component',
33
+ task: async () => {
34
+ const targetDirectory = await getComponentDirectoryPath(componentKey);
35
+ // console.log(`in buildComponent Lint component task: componentKey: ${componentKey} targetDirectory: ${targetDirectory}`);
36
+ await lintComponent(targetDirectory);
37
+ }
38
+ },
39
+ {
40
+ title: 'Bundle Component',
41
+ task: async () => await bundleComponent(componentKey, sourceMap, devBuild),
42
+ skip: () => (options.skipBundle ? 'Skipped bundling component' : undefined)
43
+ }
44
+ ],
45
+ {
46
+ exitOnError: true
47
+ }
48
+ );
49
+
50
+ await tasks.run().catch(err => {
51
+ console.log(chalk.bold.red(err.toString()));
52
+ });
53
+ return true;
54
+ };
@@ -306,14 +306,12 @@ export default (
306
306
  contextRegExp: /moment$/
307
307
  }),
308
308
  /* Ignore cosmos icons */
309
-
310
309
  new webpack.IgnorePlugin({
311
310
  resourceRegExp: /^\.\/icons$/,
312
311
  contextRegExp: /@pega\/cosmos-react-core\/lib\/components\/Icon$/
313
312
  }),
314
313
 
315
314
  /* Ignore cosmos icons - windows */
316
-
317
315
  new webpack.IgnorePlugin({
318
316
  resourceRegExp: /^\.\/icons$/,
319
317
  contextRegExp: /@pega\\cosmos-react-core\\lib\\components\\Icon$/
@@ -2,8 +2,8 @@ import path from 'path';
2
2
  import fs from 'fs';
3
3
  import { stat } from 'fs/promises';
4
4
 
5
- import { BUILD_CONFIG_JSON_FILENAME } from '../../../constants.js';
6
- import { getComponentDirectoryPath } from '../../../util.js';
5
+ import { BUILD_CONFIG_JSON_FILENAME } from '../../constants.js';
6
+ import { getComponentDirectoryPath } from '../../util.js';
7
7
 
8
8
  import buildComponent from './builder/index.js';
9
9
 
@@ -14,7 +14,8 @@ import {
14
14
  getComponents,
15
15
  getComponentDefaults,
16
16
  sanitize,
17
- validateSemver
17
+ validateSemver,
18
+ showVersion
18
19
  } from '../../util.js';
19
20
  import { COMPONENT_SCHEMA } from '../../constants.js';
20
21
 
@@ -87,7 +88,7 @@ const compileMustacheTemplates = async (
87
88
  ALLOWEDAPPS: JSON.stringify(allowedApplications),
88
89
  TYPE: type,
89
90
  SUB_TYPE: JSON.stringify(mustacheSubType),
90
- DESCRIPTION: description,
91
+ DESCRIPTION: description || componentLabel,
91
92
  IS_TEMPLATE: isTemplate,
92
93
  IS_PICKLIST: isPicklist,
93
94
  IS_BOOLEAN: isBool,
@@ -172,6 +173,8 @@ const validateCompile = async (
172
173
  };
173
174
 
174
175
  export default async options => {
176
+ showVersion();
177
+
175
178
  if (options.params[10]) {
176
179
  const componentName = options.params[3];
177
180
  const componentLabel = options.params[4];
@@ -226,6 +229,7 @@ export default async options => {
226
229
  {
227
230
  name: 'version',
228
231
  message: 'Enter component version',
232
+ default: componentDefaults.version,
229
233
  validate: value => {
230
234
  if (validateSemver(value)) {
231
235
  return true;
@@ -312,7 +316,6 @@ export default async options => {
312
316
  }
313
317
  ];
314
318
 
315
- console.log(chalk.green("DX Component Builder v2.0.16"));
316
319
  await inquirer.prompt(questions).then(async answers => {
317
320
  const {
318
321
  componentName,
@@ -7,7 +7,7 @@ export default {
7
7
 
8
8
 
9
9
 
10
- export function format(value, type, options) {
10
+ export function format(value, type) {
11
11
  let formattedValue;
12
12
 
13
13
  switch (type?.toLowerCase()) {
@@ -1,7 +1,8 @@
1
- import { useState } from 'react';
2
- import { withKnobs, text, boolean } from '@storybook/addon-knobs';
1
+ import { withKnobs } from '@storybook/addon-knobs';
3
2
 
4
- import {{COMPONENT_CLASS_NAME}} from './index.jsx';
3
+ import { configProps, stateProps } from './mock.stories';
4
+
5
+ import {{COMPONENT_CLASS_NAME}} from './index';
5
6
 
6
7
  export default {
7
8
  title: '{{COMPONENT_CLASS_NAME}}',
@@ -10,30 +11,40 @@ export default {
10
11
  };
11
12
 
12
13
  export const base{{COMPONENT_CLASS_NAME}} = () => {
13
- const [value, setValue] = useState('test value');
14
-
15
14
  const props = {
15
+ value: configProps.value,
16
+ label: configProps.label,
17
+ helperText: configProps.helperText,
18
+ caption: configProps.caption,
19
+ validatemessage: configProps.validatemessage,
20
+ hideLabel: configProps.hideLabel,
21
+ testId: configProps.testId,
22
+ additionalProps: configProps.additionalProps,
23
+ displayMode: configProps.displayMode,
24
+ variant: configProps.variant,
25
+ trueLabel: configProps.trueLabel,
26
+ falseLabel: configProps.falseLabel,
27
+ disabled: configProps.disabled,
28
+ readOnly: configProps.readOnly,
29
+ required: configProps.required,
16
30
  getPConnect: () => {
17
31
  return {
32
+ getStateProps: () => {
33
+ return stateProps;
34
+ },
18
35
  getActionsApi: () => {
19
36
  return {
20
- updateFieldValue: (propName, value) => {
21
- setValue(value);
22
- }
37
+ updateFieldValue: () => { /* nothing */},
38
+ triggerFieldChange: () => { /* nothing */}
23
39
  };
24
40
  },
25
- getStateProps: () => {
26
- return { value: '.name' };
41
+ getValidationApi: () => {
42
+ return {
43
+ validate: () => { /* nothing */}
44
+ };
27
45
  }
28
46
  };
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')
47
+ }
37
48
  };
38
49
 
39
50
  return (
@@ -7,7 +7,6 @@ import {
7
7
  import PropTypes from "prop-types";
8
8
 
9
9
  // includes in bundle
10
- import { format } from "./boolean-format";
11
10
  import handleEvent from "./event-utils";
12
11
 
13
12
  import Styled{{COMPONENT_CLASS_NAME}}Wrapper from './styles';
@@ -70,7 +69,7 @@ const {{COMPONENT_CLASS_NAME}} = props => {
70
69
 
71
70
  let displayComponent;
72
71
  if (displayMode) {
73
- displayComponent = <BooleanDisplay value={value} trueLabel={trueLabel} falseLabel={falseLabel}></BooleanDisplay>;
72
+ displayComponent = <{{COMPONENT_CLASS_NAME}} value={value} trueLabel={trueLabel} falseLabel={falseLabel} />;
74
73
  }
75
74
 
76
75
  if (displayMode === 'DISPLAY_ONLY') {
@@ -0,0 +1,21 @@
1
+ export const configProps = {
2
+ value: true,
3
+ label: 'Boolean label',
4
+ helperText: 'Test helper text',
5
+ caption: 'Boolean caption',
6
+ validatemessage: '',
7
+ hideLabel: false,
8
+ testId: '12345678',
9
+ additionalProps: {},
10
+ displayMode: '',
11
+ variant: '',
12
+ trueLabel: 'True',
13
+ falseLabel: 'False',
14
+ disabled: false,
15
+ readOnly: false,
16
+ required: true
17
+ };
18
+
19
+ export const stateProps = {
20
+ value: '.Test'
21
+ };
@@ -0,0 +1,61 @@
1
+ import dayjs from 'dayjs';
2
+ import relativeTime from 'dayjs/plugin/relativeTime';
3
+ import localizedFormat from 'dayjs/plugin/localizedFormat';
4
+ import utc from 'dayjs/plugin/utc';
5
+ import tzone from 'dayjs/plugin/timezone';
6
+
7
+ dayjs.extend(relativeTime);
8
+ dayjs.extend(localizedFormat);
9
+ dayjs.extend(utc);
10
+ dayjs.extend(tzone);
11
+
12
+ const types = ['fromNow', 'customFormat'];
13
+
14
+
15
+
16
+ // value should be in ISO 8601 format.
17
+ function DateFormatter(
18
+ value,
19
+ { type = types[1], format = "DD/MM/YYYY", timezone } = {}
20
+ ) {
21
+ if (!value) return value;
22
+ switch (type) {
23
+ case types[1]:
24
+ if (timezone) return dayjs(value).tz(timezone).format(format);
25
+ return dayjs(value).format(format);
26
+ case types[0]:
27
+ return dayjs(value).from(dayjs());
28
+ default:
29
+ return value;
30
+ }
31
+ }
32
+
33
+ // value should be in hh:mm:ss format (00:00:00 - 23:59:59).
34
+ function TimeFormatter(value, options) {
35
+ if (!value) return value;
36
+ const { locale = "en-US" } = options;
37
+ const timeOnlyRegex = /^(?:[01]\d|2[0123]):(?:[012345]\d):(?:[012345]\d)$/;
38
+ if (value.length === 8 && timeOnlyRegex.test(value)) {
39
+ const tempDate = new Date();
40
+ const hours = parseInt(value.substr(0, 2), 10);
41
+ const minutes = parseInt(value.substr(3, 2), 10);
42
+ const seconds = parseInt(value.substr(6, 2), 10);
43
+ tempDate.setHours(hours);
44
+ tempDate.setMinutes(minutes);
45
+ tempDate.setSeconds(seconds);
46
+ return tempDate.toLocaleTimeString(locale);
47
+ }
48
+ return DateFormatter(value, options);
49
+ }
50
+
51
+ export default {
52
+ Date: (value, options) => DateFormatter(value, { type: 'customFormat', ...options }),
53
+ 'Date-Time-Default': (value, options) =>
54
+ DateFormatter(value, { ...options, type: 'customFormat', format: 'lll' }),
55
+ 'Time-Default': (value, options) =>
56
+ TimeFormatter(value, {
57
+ ...options,
58
+ type: 'customFormat',
59
+ format: 'hh:mm A'
60
+ })
61
+ };
@@ -0,0 +1,41 @@
1
+ import { FieldValueList } from '@pega/cosmos-react-core';
2
+ import PropTypes from 'prop-types';
3
+
4
+ import { format } from './date.js';
5
+
6
+ export default function FormattedText(props) {
7
+ const { formatType, label, value, testId, hideLabel, variant, additionalProps } = props;
8
+
9
+ let text = value;
10
+
11
+ text = format(text, formatType, additionalProps);
12
+
13
+ const fields = [
14
+ {
15
+ id: label.toLowerCase(),
16
+ name: hideLabel ? '' : label,
17
+ value: text
18
+ }
19
+ ];
20
+ return <FieldValueList variant={variant} fields={fields} data-testid={testId} />;
21
+ }
22
+
23
+ FormattedText.defaultProps = {
24
+ formatType: 'none',
25
+ variant: 'stacked',
26
+ value: undefined,
27
+ label: '',
28
+ testId: null,
29
+ hideLabel: false,
30
+ additionalProps: {}
31
+ };
32
+
33
+ FormattedText.propTypes = {
34
+ formatType: PropTypes.string,
35
+ variant: PropTypes.oneOf(['inline', 'stacked']),
36
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
37
+ label: PropTypes.string,
38
+ testId: PropTypes.string,
39
+ additionalProps: PropTypes.objectOf(PropTypes.any),
40
+ hideLabel: PropTypes.bool
41
+ };