@pega/dx-component-builder-sdk 0.1.30 → 0.1.32

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.
@@ -1,53 +1,89 @@
1
+ import React, { createElement } from "react";
2
+ import PropTypes from "prop-types";
3
+ import Grid from "@material-ui/core/Grid";
4
+ import FieldGroup from "@pega/react-sdk-components/lib/components/designSystemExtension/FieldGroup";
5
+ import createPConnectComponent from "@pega/react-sdk-components/lib/bridge/react_pconnect";
1
6
 
2
- import React from "react";
3
- // import PropTypes from "prop-types";
4
- import Grid from '@material-ui/core/Grid';
5
- import DetailsFields from '@pega/react-sdk-components/lib/components/designSystemExtension/DetailsFields';
6
-
7
- import Styled{{COMPONENT_CLASS_NAME}}Wrapper from './styles';
8
-
7
+ // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
8
+ import StyledYourOrgRequiredDxilDetailsWrapper from "./styles";
9
9
 
10
10
  // Duplicated runtime code from React SDK
11
11
 
12
12
  // props passed in combination of props from property panel (config.json) and run time props from Constellation
13
13
  // any default values in config.pros should be set in defaultProps at bottom of this file
14
14
  export default function {{COMPONENT_CLASS_NAME}}(props) {
15
- const { children } = props;
16
- const arFields: Array<any> = [];
15
+ const { label, showLabel, getPConnect, showHighlightedData } = props;
17
16
 
18
- for (const child of children) {
19
- const theChildPConn = child.props.getPConnect();
20
- const theChildrenOfChild = theChildPConn.getChildren();
21
- arFields.push(theChildrenOfChild);
22
- }
17
+ // Get the inherited props from the parent to determine label settings
18
+ const propsToUse = { label, showLabel, ...getPConnect().getInheritedProps() };
19
+
20
+ // Set display mode prop and re-create the children so this part of the dom tree renders
21
+ // in a readonly (display) mode instead of a editable
22
+ getPConnect().setInheritedProp("displayMode", "LABELS_LEFT");
23
+ getPConnect().setInheritedProp("readOnly", true);
24
+ const children = getPConnect()
25
+ .getChildren()
26
+ .map((configObject, index) =>
27
+ createElement(createPConnectComponent(), {
28
+ ...configObject,
29
+ // eslint-disable-next-line react/no-array-index-key
30
+ key: index.toString(),
31
+ })
32
+ );
23
33
 
24
- if (arFields.length !== 2) {
25
- // eslint-disable-next-line no-console
26
- console.error(`DetailsTwoColumn expects 2 children and received ${arFields.length}`);
34
+ // Set up highlighted data to pass in return if is set to show, need raw metadata to pass to createComponent
35
+ let highlightedDataArr = [];
36
+ if (showHighlightedData) {
37
+ const { highlightedData = [] } = getPConnect().getRawMetadata().config;
38
+ highlightedDataArr = highlightedData.map((field) => {
39
+ field.config.displayMode = "STACKED_LARGE_VAL";
40
+
41
+ // Mark as status display when using pyStatusWork
42
+ if (field.config.value === "@P .pyStatusWork") {
43
+ field.type = "TextInput";
44
+ field.config.displayAsStatus = true;
45
+ }
46
+
47
+ return getPConnect().createComponent(field);
48
+ });
27
49
  }
28
50
 
51
+ {{! pick new delimiteres for mustache }}
52
+ {{=<% %>=}}
29
53
 
30
54
  return (
31
- <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
32
- <div id="DetailsTwoColumn">
33
- <Grid container spacing={1}>
34
- <Grid item xs={6}>
35
- <DetailsFields fields={arFields[0]} />
36
- </Grid>
37
- <Grid item xs={6}>
38
- <DetailsFields fields={arFields[1]} />
55
+ <FieldGroup name={propsToUse.showLabel ? propsToUse.label : ""}>
56
+ {showHighlightedData && highlightedDataArr.length > 0 && (
57
+ <Grid container spacing={1} style={{ padding: "0 0 1em" }}>
58
+ {highlightedDataArr.map((child, i) => (
59
+ <Grid item xs={12} key={`hf-${i + 1}`}>
60
+ {child}
61
+ </Grid>
62
+ ))}
39
63
  </Grid>
64
+ )}
65
+ <Grid container spacing={1}>
66
+ {children.map((child, i) => (
67
+ <Grid item xs={6} key={`r-${i + 1}`}>
68
+ {child}
69
+ </Grid>
70
+ ))}
40
71
  </Grid>
41
- </div>
42
- </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
43
- )
44
-
72
+ </FieldGroup>
73
+ );
45
74
  }
46
75
 
47
- {{COMPONENT_CLASS_NAME}}.defaultProps = {
76
+ <%={{ }}=%> {{! revert delimiteres for mustache }}
48
77
 
78
+ {{COMPONENT_CLASS_NAME}}.defaultProps = {
79
+ label: undefined,
80
+ showLabel: true,
81
+ showHighlightedData: false,
49
82
  };
50
83
 
51
84
  {{COMPONENT_CLASS_NAME}}.propTypes = {
52
-
85
+ showLabel: PropTypes.bool,
86
+ label: PropTypes.string,
87
+ getPConnect: PropTypes.func.isRequired,
88
+ showHighlightedData: PropTypes.bool,
53
89
  };
@@ -1,34 +1,290 @@
1
1
  const operatorDetails = {
2
2
  data: {
3
- "pzLoadTime": "March 13, 2023 10:58:15 AM EDT",
4
- "pzPageNameHash": "_pa134221491644431pz",
5
- "pyOperatorInfo": {
6
- "pyUserName": "User DigV2",
7
- "pyPosition": "",
8
- "pyImageInsKey": "",
9
- "pySkills": [
10
- {
11
- "pySkillName": "",
12
- "pzIndexOwnerKey": "DATA-ADMIN-OPERATOR-ID USER.DIGV2",
13
- "pySkillRating": 0
14
- }
15
- ],
16
- "pyReportToUserName": "",
17
- "pyReportTo": "",
18
- "pyOrganization": "DXIL",
19
- "pyTitle": "",
20
- "pyLabel": "User.DigV2",
21
- "pyEmailAddress": "User@DigV2",
22
- "pyTelephone": ""
23
- }
3
+ pzLoadTime: "January 18, 2023 10:33:19 AM EST",
4
+ pzPageNameHash: "_pa1519192551088960pz",
5
+ pyOperatorInfo: {
6
+ pyUserName: "french DigV2",
7
+ pyPosition: "",
8
+ pyImageInsKey: "",
9
+ pySkills: [
10
+ {
11
+ pySkillName: "",
12
+ pzIndexOwnerKey: "DATA-ADMIN-OPERATOR-ID FRENCHTEST.DIGV2",
13
+ pySkillRating: 0,
14
+ },
15
+ ],
16
+ pyReportToUserName: "",
17
+ pyReportTo: "",
18
+ pyOrganization: "DXIL",
19
+ pyTitle: "",
20
+ pyLabel: "frenchTest.DigV2",
21
+ pyEmailAddress: "User@DigV2",
22
+ pyTelephone: "",
23
+ },
24
24
  },
25
25
  status: 200,
26
- statusText: '',
26
+ statusText: "",
27
27
  headers: {
28
- 'content-length': '435',
29
- 'content-type': 'application/json;charset=UTF-8'
28
+ "content-length": "435",
29
+ "content-type": "application/json;charset=UTF-8",
30
30
  },
31
- request: {}
31
+ request: {},
32
32
  };
33
33
 
34
34
  export default operatorDetails;
35
+
36
+ export const pyReviewRaw = {
37
+ name: "pyReview",
38
+ type: "View",
39
+ config: {
40
+ template: "Details",
41
+ ruleClass: "MyCo-MyCompon-Work-MyComponents",
42
+ showLabel: true,
43
+ label: "@L Details",
44
+ localeReference: "@LR MYCO-MYCOMPON-WORK-MYCOMPONENTS!VIEW!PYREVIEW",
45
+ showHighlightedData: true,
46
+ highlightedData: [
47
+ {
48
+ type: "TextInput",
49
+ config: {
50
+ value: "@P .pyStatusWork",
51
+ label: "@L Work Status",
52
+ displayMode: "STACKED_LARGE_VAL",
53
+ displayAsStatus: true,
54
+ },
55
+ },
56
+ {
57
+ type: "TextInput",
58
+ config: {
59
+ value: "@P .pyID",
60
+ label: "@L Case ID",
61
+ displayMode: "STACKED_LARGE_VAL",
62
+ },
63
+ },
64
+ {
65
+ type: "DateTime",
66
+ config: {
67
+ value: "@P .pxCreateDateTime",
68
+ label: "@L Create date/time",
69
+ displayMode: "STACKED_LARGE_VAL",
70
+ },
71
+ },
72
+ {
73
+ type: "UserReference",
74
+ config: {
75
+ label: "@L Create Operator",
76
+ value: "@USER .pxCreateOperator",
77
+ placeholder: "Select...",
78
+ displayMode: "STACKED_LARGE_VAL",
79
+ },
80
+ },
81
+ ],
82
+ inheritedProps: [
83
+ {
84
+ prop: "label",
85
+ value: "@L Details",
86
+ },
87
+ {
88
+ prop: "showLabel",
89
+ value: true,
90
+ },
91
+ ],
92
+ },
93
+ children: [
94
+ {
95
+ name: "A",
96
+ type: "Region",
97
+ getPConnect: () => {
98
+ return {
99
+ getRawMetadata: () => {
100
+ return pyReviewRaw.children[0];
101
+ },
102
+ };
103
+ },
104
+ children: [
105
+ {
106
+ readOnly: undefined,
107
+ placeholder: "First Name",
108
+ value: "John",
109
+ label: "First Name",
110
+ hasSuggestions: false,
111
+ displayMode: "LABELS_LEFT",
112
+ },
113
+ {
114
+ readOnly: undefined,
115
+ placeholder: "Middle Name",
116
+ value: "",
117
+ label: "Middle Name",
118
+ hasSuggestions: false,
119
+ displayMode: "LABELS_LEFT",
120
+ },
121
+ {
122
+ readOnly: undefined,
123
+ placeholder: "Last Name",
124
+ value: "Doe",
125
+ label: "Last Name",
126
+ hasSuggestions: false,
127
+ displayMode: "LABELS_LEFT",
128
+ },
129
+ {
130
+ value: "john@doe.com",
131
+ label: "Email",
132
+ required: true,
133
+ testId: "CE8AE9DA5B7CD6C3DF2929543A9AF92D",
134
+ hasSuggestions: false,
135
+ displayMode: "LABELS_LEFT",
136
+ },
137
+ {
138
+ readOnly: undefined,
139
+ value: "+16397975093",
140
+ label: "Phone",
141
+ displayMode: "LABELS_LEFT",
142
+ hasSuggestions: false,
143
+ },
144
+ {
145
+ readOnly: undefined,
146
+ placeholder: "Price",
147
+ value: "90.99",
148
+ label: "Price",
149
+ hasSuggestions: false,
150
+ displayMode: "LABELS_LEFT",
151
+ getPConnect: () => {
152
+ return {
153
+ getActionsApi: () => {/* nothing */},
154
+ getStateProps: () => {
155
+ return {
156
+ value: "",
157
+ };
158
+ },
159
+ getComponentName: () => {
160
+ return "currency";
161
+ },
162
+ };
163
+ },
164
+ },
165
+ {
166
+ readOnly: undefined,
167
+ value: "100 Mbps",
168
+ label: "Internet Plan",
169
+ hasSuggestions: false,
170
+ displayMode: "LABELS_LEFT",
171
+ getPConnect: () => {
172
+ return {
173
+ getActionsApi: () => {/* nothing */},
174
+ getStateProps: () => {
175
+ return {
176
+ value: "",
177
+ };
178
+ },
179
+ getComponentName: () => {
180
+ return "radio";
181
+ },
182
+ getConfigProps: () => {
183
+ return {};
184
+ },
185
+ getDataObject: () => {
186
+ return {};
187
+ },
188
+ };
189
+ },
190
+ },
191
+ {
192
+ readOnly: undefined,
193
+ placeholder: "Middle Name",
194
+ value: "",
195
+ label: "Middle Name",
196
+ hasSuggestions: false,
197
+ displayMode: "LABELS_LEFT",
198
+ },
199
+ {
200
+ readOnly: undefined,
201
+ placeholder: "Last Name",
202
+ value: "Doe",
203
+ label: "Last Name",
204
+ hasSuggestions: false,
205
+ displayMode: "LABELS_LEFT",
206
+ },
207
+ {
208
+ value: "john@doe.com",
209
+ label: "Email",
210
+ required: true,
211
+ testId: "CE8AE9DA5B7CD6C3DF2929543A9AF92D",
212
+ hasSuggestions: false,
213
+ displayMode: "LABELS_LEFT",
214
+ },
215
+ {
216
+ readOnly: undefined,
217
+ value: "+16397975093",
218
+ label: "Phone",
219
+ displayMode: "LABELS_LEFT",
220
+ hasSuggestions: false,
221
+ },
222
+ {
223
+ readOnly: undefined,
224
+ placeholder: "Price",
225
+ value: "90.89",
226
+ label: "Price",
227
+ hasSuggestions: false,
228
+ displayMode: "LABELS_LEFT",
229
+ getPConnect: () => {
230
+ return {
231
+ getActionsApi: () => {/* nothing */},
232
+ getStateProps: () => {
233
+ return {
234
+ value: "",
235
+ };
236
+ },
237
+ getComponentName: () => {
238
+ return "currency";
239
+ },
240
+ };
241
+ },
242
+ },
243
+ {
244
+ readOnly: undefined,
245
+ value: "100 Mbps",
246
+ label: "Internet Plan",
247
+ hasSuggestions: false,
248
+ displayMode: "LABELS_LEFT",
249
+ getPConnect: () => {
250
+ return {
251
+ getActionsApi: () => {/* nothing */},
252
+ getStateProps: () => {
253
+ return {
254
+ value: "",
255
+ };
256
+ },
257
+ getComponentName: () => {
258
+ return "radio";
259
+ },
260
+ getConfigProps: () => {
261
+ return {};
262
+ },
263
+ getDataObject: () => {
264
+ return {};
265
+ },
266
+ };
267
+ },
268
+ },
269
+ {
270
+ caseOpConfig: {
271
+ label: "Create operator",
272
+ createLabel: "Created",
273
+ updateLabel: "Updated",
274
+ updateDateTime: "2023-03-10T15:45:56.919Z",
275
+ createDateTime: "2023-03-10T15:45:40.154Z",
276
+ updateOperator: {
277
+ userId: "rep@mediaco",
278
+ userName: "representative",
279
+ },
280
+ createOperator: {
281
+ userId: "rep@mediaco",
282
+ userName: "representative",
283
+ },
284
+ },
285
+ },
286
+ ],
287
+ },
288
+ ],
289
+ classID: "MyCo-MyCompon-Work-MyComponents",
290
+ };
@@ -14,13 +14,19 @@ if (!window.PCore) {
14
14
  window.PCore = {};
15
15
  }
16
16
 
17
- window.PCore = {
18
- getErrorHandler() {
17
+ window.PCore.getErrorHandler = () => {
19
18
  return {
20
19
  getGenericFailedMessage() {
21
20
  /* nothing */
22
21
  }
23
22
  };
23
+ };
24
+
25
+ window.PCore.getConstants = () => {
26
+ return {
27
+ CASE_INFO: {
28
+ INSTRUCTIONS: ""
29
+ }
24
30
  }
25
31
  };
26
32
 
@@ -187,6 +193,15 @@ export const Base{{COMPONENT_CLASS_NAME}} = () => {
187
193
  }
188
194
  }
189
195
  ];
196
+ },
197
+ getValue: (val) => {
198
+ return val;
199
+ },
200
+ getCurrentView: () => {
201
+ return "";
202
+ },
203
+ getCurrentClassID: () => {
204
+ return "";
190
205
  }
191
206
  };
192
207
  }
@@ -1,63 +1,63 @@
1
-
1
+ /* eslint-disable react/no-array-index-key */
2
2
  import React, { createElement } from "react";
3
- import PropTypes from 'prop-types';
4
-
5
- import createPConnectComponent from '@pega/react-sdk-components/lib/bridge/react_pconnect';
6
- import './DefaultForm.css';
3
+ import PropTypes from "prop-types";
7
4
 
8
- import Styled{{COMPONENT_CLASS_NAME}}Wrapper from './styles';
5
+ import { getInstructions } from "./utils";
6
+ import createPConnectComponent from "@pega/react-sdk-components/lib/bridge/react_pconnect";
7
+ import "./DefaultForm.css";
9
8
 
9
+ import Styled{{COMPONENT_CLASS_NAME}}Wrapper from "./styles";
10
10
 
11
11
  // Duplicated runtime code from React SDK
12
12
 
13
13
  // props passed in combination of props from property panel (config.json) and run time props from Constellation
14
14
  // any default values in config.pros should be set in defaultProps at bottom of this file
15
15
  export default function {{COMPONENT_CLASS_NAME}}(props) {
16
-
17
-
18
16
  const { getPConnect, NumCols } = props;
17
+ const instructions = getInstructions(getPConnect(), props.instructions);
18
+ const instructionText = instructions?.replace(/<\/?[^>]+(>|$)/g, "");
19
19
 
20
20
  let divClass: string;
21
21
 
22
22
  const numCols = NumCols || "1";
23
23
  switch (numCols) {
24
- case "1" :
24
+ case "1":
25
25
  divClass = "psdk-default-form-one-column";
26
26
  break;
27
- case "2" :
27
+ case "2":
28
28
  divClass = "psdk-default-form-two-column";
29
29
  break;
30
- case "3" :
30
+ case "3":
31
31
  divClass = "psdk-default-form-three-column";
32
32
  break;
33
- default :
33
+ default:
34
34
  divClass = "psdk-default-form-one-column";
35
35
  break;
36
36
  }
37
37
 
38
-
39
38
  // repoint the children because they are in a region and we need to not render the region
40
39
  // to take the children and create components for them, put in an array and pass as the
41
40
  // defaultForm kids
42
41
  const arChildren = getPConnect().getChildren()[0].getPConnect().getChildren();
43
- // eslint-disable-next-line react/no-array-index-key
44
- const dfChildren = arChildren.map((kid, idx) => createElement(createPConnectComponent(), {...kid, key: idx}));
42
+ const dfChildren = arChildren.map((kid, idx) =>
43
+ createElement(createPConnectComponent(), { ...kid, key: idx })
44
+ );
45
45
 
46
46
  return (
47
47
  <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
48
- <div className={divClass}>
49
- {dfChildren}
50
- </div>
48
+ <div className={divClass}>
49
+ <div>{instructionText}</div>
50
+ {dfChildren}
51
+ </div>
51
52
  </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
52
- )
53
-
53
+ );
54
54
  }
55
55
 
56
56
  {{COMPONENT_CLASS_NAME}}.defaultProps = {
57
- NumCols: "1"
57
+ NumCols: "1",
58
58
  };
59
59
 
60
60
  {{COMPONENT_CLASS_NAME}}.propTypes = {
61
61
  // children: PropTypes.arrayOf(PropTypes.node).isRequired,
62
- NumCols: PropTypes.string
62
+ NumCols: PropTypes.string,
63
63
  };
@@ -0,0 +1,76 @@
1
+ // This file is adapted from React components/Templates/utils.js
2
+ declare const PCore: any;
3
+ export function getAllFields(pConnect: any) {
4
+ const metadata = pConnect.getRawMetadata();
5
+ let allFields = [];
6
+ if (metadata.children && metadata.children.map) {
7
+ allFields = metadata.children.map((fields) => {
8
+ const children = fields.children instanceof Array ? fields.children : [];
9
+ return children.map((field) => field.config);
10
+ });
11
+ }
12
+ return allFields;
13
+ }
14
+
15
+ export function filterForFieldValueList(fields : any) {
16
+ return fields
17
+ .filter(({ visibility }) => visibility !== false)
18
+ .map(({ value, label }) => ({
19
+ id: label.toLowerCase(),
20
+ name: label,
21
+ value
22
+ }));
23
+ }
24
+
25
+ /**
26
+ * Determine if the current view is the view of the case step/assignment.
27
+ * @param {Function} pConnect PConnect object for the component
28
+ */
29
+ export function getIsAssignmentView(pConnect) {
30
+ // Get caseInfo content from the store which contains the view info about the current assignment/step
31
+ // TODO To be replaced with pConnect.getCaseInfo().getCurrentAssignmentView when it's available
32
+ const assignmentViewClass = pConnect.getValue(PCore.getConstants().CASE_INFO.CASE_INFO_CLASSID);
33
+ const assignmentViewName = pConnect.getValue(PCore.getConstants().CASE_INFO.ASSIGNMENTACTION_ID);
34
+
35
+ const assignmentViewId = `${assignmentViewName}!${assignmentViewClass}`;
36
+
37
+ // Get the info about the current view from pConnect
38
+ const currentViewId = `${pConnect.getCurrentView()}!${pConnect.getCurrentClassID()}`;
39
+
40
+ return assignmentViewId === currentViewId;
41
+ }
42
+
43
+ /**
44
+ * A hook that gets the instructions content for a view.
45
+ * @param {Function} pConnect PConnect object for the component
46
+ * @param {string} [instructions="casestep"] 'casestep', 'none', or the html content of a Rule-UI-Paragraph rule (processed via core's paragraph annotation handler)
47
+ */
48
+ export function getInstructions(pConnect, instructions = 'casestep') {
49
+ const caseStepInstructions = pConnect.getValue(PCore.getConstants().CASE_INFO.INSTRUCTIONS);
50
+
51
+ // Determine if this view is the current assignment/step view
52
+ const isCurrentAssignmentView = getIsAssignmentView(pConnect);
53
+
54
+ // Case step instructions
55
+ if (instructions === 'casestep' && isCurrentAssignmentView && caseStepInstructions?.length) {
56
+ return caseStepInstructions;
57
+ }
58
+
59
+ // No instructions
60
+ if (instructions === 'none') {
61
+ return undefined;
62
+ }
63
+
64
+ // If the annotation wasn't processed correctly, don't return any instruction text
65
+ if (instructions?.startsWith('@PARAGRAPH')) {
66
+ return undefined;
67
+ }
68
+
69
+ // Custom instructions from the view
70
+ // The raw metadata for `instructions` will be something like '@PARAGRAPH .SomeParagraphRule' but
71
+ // it is evaluated by core logic to the content
72
+ if (instructions !== 'casestep' && instructions !== 'none') {
73
+ return instructions;
74
+ }
75
+ return undefined;
76
+ }
@@ -1,6 +1,6 @@
1
1
  import { withKnobs } from '@storybook/addon-knobs';
2
2
 
3
- import AppAnnouncement from '@pega/react-sdk-components/lib/components/widgets/AppAnnouncement';
3
+ import AppAnnouncement from "@pega/react-sdk-components/lib/components/widget/AppAnnouncement";
4
4
 
5
5
  import { pyHome1Resolved, pyHome1Raw } from './mock.stories';
6
6
 
@@ -27,7 +27,14 @@ window.PCore.getUserApi = () => {
27
27
  export const Base{{COMPONENT_CLASS_NAME}} = () => {
28
28
 
29
29
  const props = {
30
- caseOpConfig: configProps,
30
+ label: configProps.label,
31
+ createLabel: configProps.createLabel,
32
+ updateLabel: configProps.updateLabel,
33
+ createOperator: configProps.createOperator,
34
+ updateOperator: configProps.updateOperator,
35
+ createDateTime: configProps.createDateTime,
36
+ updateDateTime: configProps.updateDateTime,
37
+ hideLabel: configProps.hideLabel,
31
38
 
32
39
  getPConnect: () => {
33
40
  return {