@pega/dx-component-builder-sdk 0.23.20 → 0.24.1

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 (72) hide show
  1. package/package.json +1 -1
  2. package/src/cli.js +1 -1
  3. package/src/constants.js +4 -0
  4. package/src/tasks/build-all/helper.js +6 -0
  5. package/src/tasks/build-comp/helper.js +6 -0
  6. package/src/tasks/bundle/builderAngular/webpack.config.js +14 -1
  7. package/src/tasks/bundle/builderAssociated/webpack.config.js +13 -0
  8. package/src/tasks/bundle/builderReact/webpack.config.js +14 -1
  9. package/src/tasks/create/templates/Constellation/field/Boolean/index.tsx.mustache +3 -2
  10. package/src/tasks/create/templates/Constellation/field/Icon-Button-URL/PConnProps.d.ts.mustache +46 -0
  11. package/src/tasks/create/templates/Constellation/field/Icon-Button-URL/config.json.mustache +64 -0
  12. package/src/tasks/create/templates/Constellation/field/Icon-Button-URL/demo.stories.tsx.mustache +99 -0
  13. package/src/tasks/create/templates/Constellation/field/Icon-Button-URL/index.tsx.mustache +204 -0
  14. package/src/tasks/create/templates/Constellation/field/Icon-Button-URL/mock.ts.mustache +5 -0
  15. package/src/tasks/create/templates/Constellation/field/Icon-Button-URL/styles.ts.mustache +8 -0
  16. package/src/tasks/create/templates/Constellation/field/Picklist-Autocomplete/index.tsx.mustache +11 -0
  17. package/src/tasks/create/templates/Constellation/field/Picklist-Autocomplete/utils.ts.mustache +3 -0
  18. package/src/tasks/create/templates/Constellation/field/Text/index.tsx.mustache +94 -4
  19. package/src/tasks/create/templates/Constellation/template/DETAILS/Avatar.tsx.mustache +78 -0
  20. package/src/tasks/create/templates/Constellation/template/DETAILS/DetailsRender.tsx.mustache +55 -0
  21. package/src/tasks/create/templates/Constellation/template/DETAILS/HighlightRender.tsx.mustache +49 -0
  22. package/src/tasks/create/templates/Constellation/template/DETAILS/Operator.tsx.mustache +218 -0
  23. package/src/tasks/create/templates/Constellation/template/DETAILS/demo.stories.tsx.mustache +77 -23
  24. package/src/tasks/create/templates/Constellation/template/DETAILS/index.tsx.mustache +51 -40
  25. package/src/tasks/create/templates/Constellation/template/DETAILS/mock.ts.mustache +78 -20
  26. package/src/tasks/create/templates/Constellation/template/DETAILS/styles.ts.mustache +16 -0
  27. package/src/tasks/create/templates/Constellation/template/DETAILS-region/Avatar.tsx.mustache +78 -0
  28. package/src/tasks/create/templates/Constellation/template/DETAILS-region/DetailsRender.tsx.mustache +55 -0
  29. package/src/tasks/create/templates/Constellation/template/DETAILS-region/HighlightRender.tsx.mustache +49 -0
  30. package/src/tasks/create/templates/Constellation/template/DETAILS-region/Operator.tsx.mustache +218 -0
  31. package/src/tasks/create/templates/Constellation/template/DETAILS-region/demo.stories.tsx.mustache +95 -26
  32. package/src/tasks/create/templates/Constellation/template/DETAILS-region/index.tsx.mustache +43 -40
  33. package/src/tasks/create/templates/Constellation/template/DETAILS-region/mock.ts.mustache +68 -10
  34. package/src/tasks/create/templates/Constellation/template/DETAILS-region/styles.ts.mustache +15 -0
  35. package/src/tasks/create/templates/Constellation/template/FORM/DetailsRender.tsx +59 -0
  36. package/src/tasks/create/templates/Constellation/template/FORM/index.tsx.mustache +31 -5
  37. package/src/tasks/create/templates/Constellation/template/FORM-region/DetailsRender.tsx +59 -0
  38. package/src/tasks/create/templates/Constellation/template/FORM-region/index.tsx.mustache +29 -7
  39. package/src/tasks/create/templates/Constellation/template/PAGE/GetNextWork.tsx.mustache +2 -1
  40. package/src/tasks/create/templates/Constellation/template/PAGE/localizations.json.mustache +4 -2
  41. package/src/tasks/create/templates/Constellation/widget/PAGE/demo.stories.tsx.mustache +87 -6
  42. package/src/tasks/create/templates/Constellation/widget/PAGE/index.tsx.mustache +67 -5
  43. package/src/tasks/create/templates/SDK-Angular/field/Icon-Button-URL/config.json.mustache +64 -0
  44. package/src/tasks/create/templates/SDK-Angular/field/Icon-Button-URL/demo.stories.tsx.mustache +42 -0
  45. package/src/tasks/create/templates/SDK-Angular/field/Icon-Button-URL/mock.ts.mustache +17 -0
  46. package/src/tasks/create/templates/SDK-Angular/field/Icon-Button-URL/text-url.component.html.mustache +29 -0
  47. package/src/tasks/create/templates/SDK-Angular/field/Icon-Button-URL/text-url.component.scss.mustache +20 -0
  48. package/src/tasks/create/templates/SDK-Angular/field/Icon-Button-URL/text-url.component.spec.ts.mustache +26 -0
  49. package/src/tasks/create/templates/SDK-Angular/field/Icon-Button-URL/text-url.component.ts.mustache +179 -0
  50. package/src/tasks/create/templates/SDK-React/field/Icon-Button-URL/config.json.mustache +64 -0
  51. package/src/tasks/create/templates/SDK-React/field/Icon-Button-URL/demo.stories.tsx.mustache +58 -0
  52. package/src/tasks/create/templates/SDK-React/field/Icon-Button-URL/index.tsx.mustache +79 -0
  53. package/src/tasks/create/templates/SDK-React/field/Icon-Button-URL/mock.ts.mustache +16 -0
  54. package/src/tasks/create/templates/SDK-React/field/Icon-Button-URL/styles.js.mustache +7 -0
  55. package/src/tasks/create/templates/SDK-React/template/DETAILS/index.tsx.mustache +1 -1
  56. package/src/tasks/create/templates/SDK-React/template/DETAILS-region/index.tsx.mustache +1 -1
  57. package/src/tasks/create-all/index.js +3 -0
  58. package/src/tasks/publish/helper.js +4 -0
  59. package/src/tasks/publish-all/helper.js +6 -2
  60. package/src/tasks/validator/index.js +7 -1
  61. package/tests/assets/sdk-r/components/create/override-sdk/designSystemExtension/CaseSummaryFields/CaseSummaryFields.tsx +2 -2
  62. package/tests/assets/sdk-r/components/create/override-sdk/designSystemExtension/FieldValueList/FieldValueList.tsx +10 -4
  63. package/tests/assets/sdk-r/components/create/override-sdk/field/RichText/RichText.tsx +2 -2
  64. package/tests/assets/sdk-r/components/create/override-sdk/infra/NavBar/NavBar.tsx +1 -1
  65. package/tests/assets/sdk-r/components/create/override-sdk/template/ListView/ListView.tsx +2 -2
  66. package/tests/assets/sdk-r/components/createAll/custom-sdk/template/Pega_DXIL_MyDetails/demo.stories.tsx +3 -0
  67. package/tests/assets/sdk-r/components/createAll/custom-sdk/template/Pega_DXIL_MyTwoColumnDetails/demo.stories.tsx +3 -0
  68. package/tests/assets/sdk-r/components/createAll/override-sdk/designSystemExtension/CaseSummaryFields/CaseSummaryFields.tsx +2 -2
  69. package/tests/assets/sdk-r/components/createAll/override-sdk/designSystemExtension/FieldValueList/FieldValueList.tsx +10 -4
  70. package/tests/assets/sdk-r/components/createAll/override-sdk/field/RichText/RichText.tsx +2 -2
  71. package/tests/assets/sdk-r/components/createAll/override-sdk/infra/NavBar/NavBar.tsx +1 -1
  72. package/tests/assets/sdk-r/components/createAll/override-sdk/template/ListView/ListView.tsx +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/dx-component-builder-sdk",
3
- "version": "0.23.20",
3
+ "version": "0.24.1",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
package/src/cli.js CHANGED
@@ -41,7 +41,7 @@ const TASKS = {
41
41
  VALIDATE_SCHEMA: 'validateSchema',
42
42
  UPDATE: 'update',
43
43
  DELETE: 'delete',
44
- DELETE_ALL: "deleteAll",
44
+ DELETE_ALL: 'deleteAll',
45
45
  AUTHENTICATE: 'authenticate',
46
46
  UPGRADE: 'upgrade',
47
47
  SCAN_AND_FIX: 'scanAndFix'
package/src/constants.js CHANGED
@@ -164,6 +164,10 @@ export const COMPONENT_SCHEMA = {
164
164
  name: 'URL',
165
165
  value: 'Text-URL'
166
166
  },
167
+ {
168
+ name: 'Icon Button URL',
169
+ value: 'Icon-Button-URL'
170
+ },
167
171
  {
168
172
  name: 'Integer',
169
173
  value: 'Integer'
@@ -71,11 +71,17 @@ export const zipComponent = async (componentKey, category = CATEGORY_CUSTOM) =>
71
71
  const srcDirectory = await getComponentDirectoryPath(componentKey, category);
72
72
  const buildDirectory = await path.join(path.resolve(), 'dist/components', componentKey);
73
73
  const configJson = `${srcDirectory}/config.json`;
74
+ const localizationJson = `${srcDirectory}/localizations.json`;
74
75
 
75
76
  const zip = new AdmZip();
76
77
 
77
78
  zip.addLocalFolder(srcDirectory, 'src/');
78
79
  zip.addLocalFile(configJson);
80
+
81
+ if (fs.existsSync(localizationJson)) {
82
+ zip.addLocalFile(localizationJson);
83
+ }
84
+
79
85
  zip.addLocalFolder(buildDirectory);
80
86
  const zipContent = zip.toBuffer().toString('base64');
81
87
 
@@ -89,11 +89,17 @@ export const zipComponent = async (componentKey, category = CATEGORY_CUSTOM) =>
89
89
  const srcDirectory = await getComponentDirectoryPath(componentKey, category);
90
90
  const buildDirectory = await path.join(path.resolve(), 'dist/components', componentKey);
91
91
  const configJson = `${srcDirectory}/config.json`;
92
+ const localizationJson = `${srcDirectory}/localizations.json`;
92
93
 
93
94
  const zip = new AdmZip();
94
95
 
95
96
  zip.addLocalFolder(srcDirectory, 'src/');
96
97
  zip.addLocalFile(configJson);
98
+
99
+ if (fs.existsSync(localizationJson)) {
100
+ zip.addLocalFile(localizationJson);
101
+ }
102
+
97
103
  zip.addLocalFolder(buildDirectory);
98
104
  const zipContent = zip.toBuffer().toString('base64');
99
105
 
@@ -266,7 +266,7 @@ export default (
266
266
  {
267
267
  test: /\.(map)$/, /* latest react-sdk-components needs to ignore compiling .d.ts and .map files */
268
268
  loader: 'null-loader',
269
- },
269
+ },
270
270
  // "file" loader makes sure those assets get served by WebpackDevServer.
271
271
  // When you `import` an asset, you get its (virtual) filename.
272
272
  // In production, they would get copied to the `build` folder.
@@ -330,6 +330,19 @@ export default (
330
330
  contextRegExp: /@pega\\cosmos-react-core\\lib\\components\\Icon$/
331
331
  }),
332
332
 
333
+ /* cosmos 6.x and above */
334
+ /* Ignore cosmos icons */
335
+ new webpack.IgnorePlugin({
336
+ resourceRegExp: /^\.\/.*\/.*\.icon$/,
337
+ contextRegExp: /@pega\/cosmos-react-core\/lib\/components\/Icon$/
338
+ }),
339
+
340
+ /* Ignore cosmos icons - windows */
341
+ new webpack.IgnorePlugin({
342
+ resourceRegExp: /^\.\/.*\/.*\.icon$/,
343
+ contextRegExp: /@pega\\cosmos-react-core\\lib\\components\\Icon$/
344
+ }),
345
+
333
346
  new webpack.optimize.LimitChunkCountPlugin({
334
347
  maxChunks: 1
335
348
  }),
@@ -318,6 +318,19 @@ export default (
318
318
  contextRegExp: /@pega\\cosmos-react-core\\lib\\components\\Icon$/
319
319
  }),
320
320
 
321
+ /* cosmos 6.x and above */
322
+ /* Ignore cosmos icons */
323
+ new webpack.IgnorePlugin({
324
+ resourceRegExp: /^\.\/.*\/.*\.icon$/,
325
+ contextRegExp: /@pega\/cosmos-react-core\/lib\/components\/Icon$/
326
+ }),
327
+
328
+ /* Ignore cosmos icons - windows */
329
+ new webpack.IgnorePlugin({
330
+ resourceRegExp: /^\.\/.*\/.*\.icon$/,
331
+ contextRegExp: /@pega\\cosmos-react-core\\lib\\components\\Icon$/
332
+ }),
333
+
321
334
  new webpack.optimize.LimitChunkCountPlugin({
322
335
  maxChunks: 1
323
336
  }),
@@ -262,7 +262,7 @@ export default (
262
262
  {
263
263
  test: /\.(map)$/, /* latest react-sdk-components needs to ignore compiling .d.ts and .map files */
264
264
  loader: 'null-loader',
265
- },
265
+ },
266
266
  // "file" loader makes sure those assets get served by WebpackDevServer.
267
267
  // When you `import` an asset, you get its (virtual) filename.
268
268
  // In production, they would get copied to the `build` folder.
@@ -326,6 +326,19 @@ export default (
326
326
  contextRegExp: /@pega\\cosmos-react-core\\lib\\components\\Icon$/
327
327
  }),
328
328
 
329
+ /* cosmos 6.x and above */
330
+ /* Ignore cosmos icons */
331
+ new webpack.IgnorePlugin({
332
+ resourceRegExp: /^\.\/.*\/.*\.icon$/,
333
+ contextRegExp: /@pega\/cosmos-react-core\/lib\/components\/Icon$/
334
+ }),
335
+
336
+ /* Ignore cosmos icons - windows */
337
+ new webpack.IgnorePlugin({
338
+ resourceRegExp: /^\.\/.*\/.*\.icon$/,
339
+ contextRegExp: /@pega\\cosmos-react-core\\lib\\components\\Icon$/
340
+ }),
341
+
329
342
  new webpack.optimize.LimitChunkCountPlugin({
330
343
  maxChunks: 1
331
344
  }),
@@ -3,7 +3,8 @@ import {
3
3
  CheckboxGroup,
4
4
  FieldValueList,
5
5
  Text,
6
- withConfiguration
6
+ withConfiguration,
7
+ BooleanDisplay
7
8
  } from "@pega/cosmos-react-core";
8
9
 
9
10
  import type { PConnFieldProps } from './PConnProps';
@@ -99,7 +100,7 @@ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
99
100
  // @ts-ignore
100
101
  displayComponent = (
101
102
  // @ts-ignore
102
- <{{COMPONENT_CLASS_NAME}} value={value} trueLabel={trueLabel} falseLabel={falseLabel} />
103
+ <BooleanDisplay value={value} trueLabel={trueLabel} falseLabel={falseLabel} />
103
104
  );
104
105
  }
105
106
 
@@ -0,0 +1,46 @@
1
+ import {PConnect } from '@pega/pcore-pconnect-typedefs';
2
+
3
+ // PConnProps.d.ts
4
+ // This gives us a place to have each component (which is most DX Components) that is
5
+ // expected to have a getPConnect extend its props (from BaseProps)
6
+ // such that every component will be expected to have a getPConnect() function
7
+ // that returns a PConnect object. (new/better way of doing .propTypes).
8
+ // This PConnProps can be extended to include other props that we know are in every component
9
+ export interface PConnProps {
10
+ // getPConnect should exist for every C11n component. (add @ts-ignore in special cases where it isn't)
11
+ getPConnect: () => typeof PConnect;
12
+
13
+ // Allow any/all other key/value pairs in the BaseProps for now
14
+ // TODO: refine which other props are always expected for various component
15
+ // types and consider further interface "subclassing". For example, we may
16
+ // want to create a "BasePropsForm" that gives guidance on required, readonly, etc.
17
+ // and any other props that every Form component expects.
18
+ // For example, see the PConnFieldProps below.
19
+ // NOTE: if you uncomment the line below, the PConnProps type will allow
20
+ // otherwise undefined types to appear. This can be helpful for debugging
21
+ // or when adding new components whose types aren't yet known.
22
+ // [key: string]: any;
23
+ }
24
+
25
+
26
+ // PConnFieldProps extends PConnProps to bring in the common properties that are
27
+ // associated with most field components (ex: Dropdown, TextInput, etc.) in the
28
+ // components/field directory
29
+ export interface PConnFieldProps extends PConnProps {
30
+ label: string,
31
+ required: boolean,
32
+ disabled: boolean,
33
+ value: any,
34
+ validatemessage: string,
35
+ status?: string,
36
+ onChange?: any,
37
+ onBlur?: any,
38
+ readOnly: boolean,
39
+ testId: string,
40
+ helperText: string,
41
+ displayMode?: string,
42
+ hideLabel: boolean,
43
+ placeholder?: string,
44
+ fieldMetadata?: any,
45
+ additionalProps?: any
46
+ }
@@ -0,0 +1,64 @@
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-url-active.svg",
13
+ "properties": [
14
+ {
15
+ "format": "SELECT",
16
+ "name": "countryCode",
17
+ "label": "Country code",
18
+ "defaultValue": "USA",
19
+ "source": [
20
+ {
21
+ "key": "USA",
22
+ "value": "United States"
23
+ },
24
+ {
25
+ "key": "CAN",
26
+ "value": "Canada"
27
+ },
28
+ {
29
+ "key": "AUS",
30
+ "value": "Australia"
31
+ },
32
+ {
33
+ "key": "JPN",
34
+ "value": "Japan"
35
+ },
36
+ {
37
+ "key": "IND",
38
+ "value": "India"
39
+ },
40
+ {
41
+ "key": "TUR",
42
+ "value": "Turkey"
43
+ }
44
+ ]
45
+ },
46
+ {
47
+ "label": "Advanced",
48
+ "format": "GROUP",
49
+ "collapsible": true,
50
+ "properties": [
51
+ {
52
+ "name": "testId",
53
+ "label": "Test ID",
54
+ "format": "TEXT",
55
+ "ignorePattern": "[^-_\\p{N}\\p{L}]",
56
+ "includeAnnotations": false
57
+ }
58
+ ]
59
+ }
60
+ ],
61
+ "defaultConfig": {
62
+ "label": "@L $this.label"
63
+ }
64
+ }
@@ -0,0 +1,99 @@
1
+
2
+ /* eslint-disable react/jsx-no-useless-fragment */
3
+ // @ts-nocheck
4
+ import type { Meta, StoryObj } from '@storybook/react';
5
+
6
+ import {{COMPONENT_CLASS_NAME}} from './index';
7
+ import { stateProps, configProps } from './mock';
8
+
9
+ const meta: Meta<typeof {{COMPONENT_CLASS_NAME}}> = {
10
+ title: '{{COMPONENT_CLASS_NAME}}',
11
+ component: {{COMPONENT_CLASS_NAME}},
12
+ excludeStories: /.*Data$/
13
+ };
14
+
15
+ export default meta;
16
+ type Story = StoryObj<typeof {{COMPONENT_CLASS_NAME}}>;
17
+
18
+ if (!window.PCore) {
19
+ window.PCore = {};
20
+ }
21
+
22
+ const statelistData = {
23
+ data: [
24
+ {
25
+ pyLabel: 'Massachusetts',
26
+ pyStateCode: 'MA'
27
+ },
28
+ {
29
+ pyLabel: 'Rhode Island',
30
+ pyStateCode: 'RI'
31
+ },
32
+ {
33
+ pyLabel: 'Connecticut',
34
+ pyStateCode: 'CT'
35
+ }
36
+ ]
37
+ };
38
+
39
+ window.PCore.getDataPageUtils = () => {
40
+ return {
41
+ getDataAsync: () => {
42
+ return new Promise(resolve => {
43
+ resolve(statelistData);
44
+ });
45
+ }
46
+ };
47
+ };
48
+
49
+ export const Base{{COMPONENT_CLASS_NAME}}: Story = args => {
50
+
51
+ const props = {
52
+ countryCode: configProps.countryCode,
53
+ getPConnect: () => {
54
+ return {
55
+ getValue: value => {
56
+ return value;
57
+ },
58
+ getContextName: () => {
59
+ return 'app/primary_1';
60
+ },
61
+ getLocalizedValue: value => {
62
+ return value;
63
+ },
64
+ getActionsApi: () => {
65
+ return {
66
+ updateFieldValue: () => {
67
+ /* nothing */
68
+ },
69
+ triggerFieldChange: () => {
70
+ /* nothing */
71
+ }
72
+ };
73
+ },
74
+ ignoreSuggestion: () => {
75
+ /* nothing */
76
+ },
77
+ acceptSuggestion: () => {
78
+ /* nothing */
79
+ },
80
+ setInheritedProps: () => {
81
+ /* nothing */
82
+ },
83
+ resolveConfigProps: () => {
84
+ /* nothing */
85
+ }
86
+ };
87
+ }
88
+ };
89
+
90
+ return (
91
+ <>
92
+ <{{COMPONENT_CLASS_NAME}} {...props} {...args} />
93
+ </>
94
+ );
95
+ };
96
+
97
+ Base{{COMPONENT_CLASS_NAME}}.args = {
98
+ countryCode: configProps.countryCode
99
+ };
@@ -0,0 +1,204 @@
1
+ import { useEffect, useState } from 'react';
2
+ import {
3
+ Icon,
4
+ Button,
5
+ withConfiguration,
6
+ registerIcon,
7
+ Table,
8
+ Label,
9
+ Link,
10
+ URLDisplay
11
+ } from '@pega/cosmos-react-core';
12
+ import type { PConnFieldProps } from './PConnProps';
13
+
14
+ // IMPORTANT
15
+ // To use Icons, need to individually import the icon file form @pega/cosmos-react-core (see path below)
16
+ // Icons filename is kabab case (file-name), where as the icon you import is camel case (fileName)
17
+ // Icons need to be registered (camel case), and then used (kabab case)
18
+ import * as listNumber from '@pega/cosmos-react-core/lib/components/Icon/icons/list-number.icon';
19
+ import * as arrowRight from '@pega/cosmos-react-core/lib/components/Icon/icons/arrow-right.icon';
20
+ import * as globe from '@pega/cosmos-react-core/lib/components/Icon/icons/globe.icon';
21
+
22
+ import Styled{{COMPONENT_CLASS_NAME}}Wrapper from './styles';
23
+
24
+ // interface for props
25
+ interface {{COMPONENT_CLASS_NAME}}Props extends PConnFieldProps {
26
+ // If any, enter additional props that only exist on TextInput here
27
+ countryCode: string;
28
+ }
29
+
30
+ export const textFormatter = (value: string) => {
31
+ return <URLDisplay target='_blank' value={value} displayText={value} variant='link' />;
32
+ };
33
+
34
+
35
+ // *************
36
+ // This component is meant to be an example of usage (Icon, Button, Link, etc.) and NOT meant to be
37
+ // used "as is"
38
+ //
39
+ // In this example, Icon is shown on its own and inside a Button
40
+ // Though an Icon can have an "onClick" event is it recommended if you want to click on it,
41
+ // to put it in a Button (shown below), so you can have a tooltip and hover style or put it
42
+ // in a Link (shown below) as a URL.
43
+ //
44
+ // For the button, the click will get a list of states for a given country and display in a
45
+ // table below. The table display will toggle with the click of the button icon. Example shows
46
+ // how to handle click, retrieve data from PCore and display it.
47
+ //
48
+ // Globe icon is an icon placed in a Link element. The Link element to use an icon internally. (NOTE: In general
49
+ // the Link element shows the open icon to the left of the link text, but here we are using
50
+ // another icon, so with "icon" specified in the Link element, the open icon doesn't show)
51
+ // Link elements do not handle bad urls well, so we have a simple validator to prevent the Link element
52
+ // from getting most bad urls.
53
+ //
54
+ // NOTE: because icons have to be imported and registered, you can NOT put the icon name
55
+ // inside the config.json and let the user pick it, if it is not already part of your
56
+ // import and registration (can't be done on the fly)
57
+ // **************
58
+
59
+ // props passed in combination of props from property panel (config.json) and run time props from Constellation
60
+ // any default values in config.pros should be set in defaultProps at bottom of this file
61
+ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
62
+ const { value, displayMode, countryCode = 'USA', getPConnect, testId } = props;
63
+ const [statelist, setStatelist] = useState([]);
64
+ const [showTable, setShowTable] = useState(false);
65
+ const [validUrl, setValidUrl] = useState('about:blank');
66
+ const PConnect = getPConnect();
67
+
68
+ // IMPORTANT: need to register icons used in camel case
69
+ registerIcon(listNumber, arrowRight, globe);
70
+
71
+
72
+ // setting up columns for the work list table
73
+ const columns = [
74
+ { renderer: 'stateName', label: PConnect.getLocalizedValue('State name', '', '') },
75
+ { renderer: 'stateCode', label: PConnect.getLocalizedValue('State code', '', '') }
76
+ ];
77
+
78
+ // toggle showing table and getting table data
79
+ function showHideTable() {
80
+ setShowTable(prevShowTable => !prevShowTable);
81
+ }
82
+
83
+ // check if url is valid (simple)
84
+ function validateUrl(href: string) {
85
+ return /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(
86
+ href
87
+ );
88
+ }
89
+
90
+ // Testing to see if value entered is valid url, if not can't use it.
91
+ // Reason for this code is that you can NOT pass to Link component
92
+ // a bad url, or it will error out.
93
+ // For example: Since the value is the property field,
94
+ // it could be entered from another component and thus as it is
95
+ // entered (typed in), it won't be valid until it is all entered.
96
+ // NOTE: can't have a blank value for the url as the Link element will error out
97
+ // in App studio preview
98
+ useEffect(() => {
99
+ if (validateUrl(value)) {
100
+ setValidUrl(value);
101
+ } else {
102
+ setValidUrl('about:blank');
103
+ }
104
+ }, [value]);
105
+
106
+ // going to get data for worklist to put into a table
107
+ // data comes from calling a PCore function to get
108
+ // get data from a data page and a PConnect function
109
+ // to get getContextName
110
+ useEffect(() => {
111
+ const dataViewName = 'D_pyStateList';
112
+ const context = PConnect.getContextName();
113
+ const params = { pyCountry: countryCode };
114
+
115
+ // only retrieve table data if table is shown
116
+ if (showTable) {
117
+ PCore.getDataPageUtils()
118
+ .getDataAsync(dataViewName, context, params, null, null)
119
+ // @ts-ignore
120
+ .then((response: any) => {
121
+ // table requires an index or will get setExtraStackFrame error
122
+ setStatelist(
123
+ response.data.map((entry: any, index: number) => {
124
+ // mapping the data into the column names
125
+ // MUST have an id/index or will get a setExtraStackFrame error
126
+ // put a key in the table
127
+ return {
128
+ stateName: entry.pyLabel,
129
+ stateCode: entry.pyStateCode,
130
+ id: index
131
+ };
132
+ })
133
+ );
134
+ })
135
+ .catch((error: any) => {
136
+ console.log(error);
137
+ });
138
+ }
139
+ }, [PConnect, countryCode, showTable]);
140
+
141
+ // when DISPLAY_ONLY, in this example we will just show the URL.
142
+ if (displayMode === 'DISPLAY_ONLY') {
143
+ const displayComp = textFormatter(validUrl);
144
+ return (
145
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper> {displayComp} </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
146
+ );
147
+ }
148
+
149
+ return (
150
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
151
+ {{! pick new delimiters for mustache }}
152
+ {{=<% %>=}}
153
+ <div style={{ display: 'flex' }} data-testid={testId}>
154
+ <Icon
155
+ style={{ height: '1.5rem', width: '1.5rem' }}
156
+ // icon name is kabab case
157
+ name='arrow-right'
158
+ role='img'
159
+ aria-label='arrow right'
160
+ />
161
+ <Label style={{ margin: '0.1rem' }}>
162
+ {' '}
163
+ {PConnect.getLocalizedValue('State list for', '', '')}{' '}
164
+ {PConnect.getLocalizedValue(`${countryCode}`, '', '')}{' '}
165
+ </Label>
166
+ <Button
167
+ icon
168
+ label={PConnect.getLocalizedValue('Click to show/hide state list', '', '')}
169
+ variant='link'
170
+ compact={false}
171
+ onClick={showHideTable}
172
+ >
173
+ <Icon
174
+ style={{ height: '1.5rem', width: '1.5rem' }}
175
+ // icon name is kabab case
176
+ name='list-number'
177
+ role='img'
178
+ aria-label='numbered list'
179
+ />
180
+ </Button>
181
+ <Link href={validUrl} variant='link' label={validUrl} icon>
182
+ <Icon
183
+ style={{ height: '1.5rem', width: '1.5rem' }}
184
+ // icon name is kabab case
185
+ name='globe'
186
+ role='img'
187
+ aria-label='open link'
188
+ />
189
+ </Link>
190
+ </div>
191
+ {showTable && (
192
+ <Table
193
+ title={PConnect.getLocalizedValue('State list', '', '')}
194
+ columns={columns}
195
+ data={statelist}
196
+ />
197
+ )}
198
+ <%={{ }}=%> {{! revert delimiters for mustache }}
199
+ </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
200
+ );
201
+ }
202
+
203
+
204
+ export default withConfiguration({{COMPONENT_CLASS_NAME}});
@@ -0,0 +1,5 @@
1
+
2
+ // @ts-nocheck
3
+ export const configProps = {
4
+ countryCode: 'USA'
5
+ };
@@ -0,0 +1,8 @@
1
+ // individual style, comment out above, and uncomment here and add styles
2
+ import styled, { css } from 'styled-components';
3
+
4
+ export default styled.div(() => {
5
+ return css`
6
+ margin: 0px 0;
7
+ `;
8
+ });
@@ -645,12 +645,14 @@ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
645
645
  PCore.getDataApi()
646
646
  .init(dataConfig, contextName)
647
647
  .then(dataObj => {
648
+ // @ts-ignore
648
649
  setDataApiObj(dataObj);
649
650
  // To avoid calling doSearch if someone types/pastes value before the API call is made
650
651
  if (!filterValue)
651
652
  doSearch(
652
653
  '',
653
654
  getDisplayFieldsMetaData(dataConfig.columns),
655
+ // @ts-ignore
654
656
  dataObj,
655
657
  setItems as any,
656
658
  setLoading,
@@ -677,6 +679,7 @@ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
677
679
  PCore.getDataApi()
678
680
  .init(dataConfig, contextName)
679
681
  .then(dataObj => {
682
+ // @ts-ignore
680
683
  setDataApiObj(dataObj);
681
684
  // To avoid calling doSearch if someone types/pastes value before the API call is made
682
685
  if (!filterValue) {
@@ -692,6 +695,7 @@ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
692
695
  doSearch(
693
696
  '',
694
697
  getDisplayFieldsMetaData(dataConfig.columns),
698
+ // @ts-ignore
695
699
  dataObj,
696
700
  setItems as any,
697
701
  setLoading,
@@ -711,6 +715,7 @@ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
711
715
  doSearch(
712
716
  '',
713
717
  getDisplayFieldsMetaData(dataConfig.columns),
718
+ // @ts-ignore
714
719
  dataObj,
715
720
  setItems as any,
716
721
  setLoading,
@@ -770,10 +775,14 @@ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
770
775
  PCore.getDataApi()
771
776
  .init(dataConfig, contextName)
772
777
  .then(dataObj => {
778
+ // @ts-ignore
773
779
  setDataApiObj(dataObj);
780
+ // @ts-ignore
774
781
  buildColumnForDisplayValue(dataObj);
775
782
  // SET matchPosition to EQUALS to return exact matching record
783
+ // @ts-ignore
776
784
  dataObj.matchPosition = 'equals';
785
+ // @ts-ignore
777
786
  dataObj
778
787
  .fetchData(value)
779
788
  .then((displayResponse: { data: Array<never> }) => {
@@ -822,11 +831,13 @@ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
822
831
  setSelected(searchedItem[0]);
823
832
  setActualValue(value);
824
833
  // RESET matchPosition
834
+ // @ts-ignore
825
835
  dataObj.matchPosition = dataConfig.matchPosition;
826
836
  })
827
837
  .catch(() => {
828
838
  setActualValue(value);
829
839
  // RESET matchPosition
840
+ // @ts-ignore
830
841
  dataObj.matchPosition = dataConfig.matchPosition;
831
842
  });
832
843
  });