@pega/custom-dx-components 0.242.48 → 0.242.50

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 (25) hide show
  1. package/package.json +1 -1
  2. package/src/constants.js +3 -1
  3. package/src/tasks/create/templates/Constellation/Template/DETAILS/Avatar.tsx.mustache +4 -4
  4. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/Avatar.tsx.mustache +4 -4
  5. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/Avatar.tsx.mustache +4 -4
  6. package/src/tasks/create/templates/Launchpad/Widget/PAGE-CASE/Avatar.tsx.mustache +4 -4
  7. package/src/tasks/export-archive/helper.js +21 -4
  8. package/src/tasks/import-archive/helper.js +25 -16
  9. package/src/tasks/init/template/package.json.mustache +2 -2
  10. package/src/util.js +25 -5
  11. package/tests/assets/library/components/{createAll/Constellation/Pega_DXIL_MyDetails → create/shared}/Avatar.tsx +5 -5
  12. package/tests/assets/library/components/{createAll/Constellation/Pega_DXIL_MyDetails → create/shared}/Operator.tsx +1 -1
  13. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyDetails/demo.stories.tsx +1 -1
  14. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPageCaseWidget/index.tsx +1 -1
  15. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails/demo.stories.tsx +1 -1
  16. package/tests/assets/library/components/createAll/Constellation/{Pega_DXIL_MyPageCaseWidget → shared}/Avatar.tsx +8 -7
  17. package/tests/assets/library/components/createAll/Constellation/{Pega_DXIL_MyPageCaseWidget → shared}/Operator.tsx +3 -3
  18. package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyDetails/Avatar.tsx +4 -4
  19. package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyPageCaseWidget/Avatar.tsx +4 -4
  20. package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails/Avatar.tsx +4 -4
  21. package/tests/assets/original/components/createAll/Launchpad/Pega_DXIL_MyDetails/Avatar.tsx +4 -4
  22. package/tests/assets/original/components/createAll/Launchpad/Pega_DXIL_MyPageCaseWidget/Avatar.tsx +4 -4
  23. package/tests/assets/original/components/createAll/Launchpad/Pega_DXIL_MyTwoColumnDetails/Avatar.tsx +4 -4
  24. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails/Avatar.tsx +0 -76
  25. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails/Operator.tsx +0 -215
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/custom-dx-components",
3
- "version": "0.242.48",
3
+ "version": "0.242.50",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
package/src/constants.js CHANGED
@@ -68,7 +68,9 @@ export const AUTHENTICATE_DEFAULTS = {
68
68
  export const SHARED_FILE_NAMES = [
69
69
  "suggestions-handler.ts",
70
70
  "PConnProps.d.ts",
71
- "create-nonce.ts"
71
+ "create-nonce.ts",
72
+ "Operator.tsx",
73
+ "Avatar.tsx"
72
74
  ];
73
75
 
74
76
  export const AUTHENTICATE_SCHEMA = {
@@ -16,14 +16,14 @@ interface {{COMPONENT_CLASS_NAME}}AvatarProps extends PConnFieldProps {
16
16
  function Avatar(props: {{COMPONENT_CLASS_NAME}}AvatarProps) {
17
17
  const { metaObj, showStatus = false } = props;
18
18
  const [imageBlobUrl, setImageBlobUrl] = useState(null);
19
- let userName: any;
20
- let userIdentifier: any;
19
+ let userName: string;
20
+ let userIdentifier: string;
21
21
 
22
22
  // TODO Below if conditions can be removed once we have apis to get worklist/mywork info
23
23
  // This is non CaseView case (Dashboard, MyWork etc)
24
24
  if (!metaObj) {
25
- userName = PCore.getEnvironmentInfo().getOperatorName();
26
- userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier();
25
+ userName = PCore.getEnvironmentInfo().getOperatorName() ?? "";
26
+ userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier() ?? "";
27
27
  } else {
28
28
  userName = metaObj.name;
29
29
  userIdentifier = metaObj.ID;
@@ -16,14 +16,14 @@ interface {{COMPONENT_CLASS_NAME}}AvatarProps extends PConnFieldProps {
16
16
  function Avatar(props: {{COMPONENT_CLASS_NAME}}AvatarProps) {
17
17
  const { metaObj, showStatus = false } = props;
18
18
  const [imageBlobUrl, setImageBlobUrl] = useState(null);
19
- let userName: any;
20
- let userIdentifier: any;
19
+ let userName: string;
20
+ let userIdentifier: string;
21
21
 
22
22
  // TODO Below if conditions can be removed once we have apis to get worklist/mywork info
23
23
  // This is non CaseView case (Dashboard, MyWork etc)
24
24
  if (!metaObj) {
25
- userName = PCore.getEnvironmentInfo().getOperatorName();
26
- userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier();
25
+ userName = PCore.getEnvironmentInfo().getOperatorName() ?? "";
26
+ userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier() ?? "";
27
27
  } else {
28
28
  userName = metaObj.name;
29
29
  userIdentifier = metaObj.ID;
@@ -16,14 +16,14 @@ interface {{COMPONENT_CLASS_NAME}}AvatarProps extends PConnFieldProps {
16
16
  function Avatar(props: {{COMPONENT_CLASS_NAME}}AvatarProps) {
17
17
  const { metaObj, showStatus = false } = props;
18
18
  const [imageBlobUrl, setImageBlobUrl] = useState(null);
19
- let userName: any;
20
- let userIdentifier: any;
19
+ let userName: string;
20
+ let userIdentifier: string;
21
21
 
22
22
  // TODO Below if conditions can be removed once we have apis to get worklist/mywork info
23
23
  // This is non CaseView case (Dashboard, MyWork etc)
24
24
  if (!metaObj) {
25
- userName = PCore.getEnvironmentInfo().getOperatorName();
26
- userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier();
25
+ userName = PCore.getEnvironmentInfo().getOperatorName() ?? "";
26
+ userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier() ?? "";
27
27
  } else {
28
28
  userName = metaObj.name;
29
29
  userIdentifier = metaObj.ID;
@@ -16,14 +16,14 @@ interface {{COMPONENT_CLASS_NAME}}AvatarProps extends PConnFieldProps {
16
16
  function Avatar(props: {{COMPONENT_CLASS_NAME}}AvatarProps) {
17
17
  const { metaObj, showStatus = false } = props;
18
18
  const [imageBlobUrl, setImageBlobUrl] = useState(null);
19
- let userName: any;
20
- let userIdentifier: any;
19
+ let userName: string;
20
+ let userIdentifier: string;
21
21
 
22
22
  // TODO Below if conditions can be removed once we have apis to get worklist/mywork info
23
23
  // This is non CaseView case (Dashboard, MyWork etc)
24
24
  if (!metaObj) {
25
- userName = PCore.getEnvironmentInfo().getOperatorName();
26
- userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier();
25
+ userName = PCore.getEnvironmentInfo().getOperatorName() ?? "";
26
+ userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier() ?? "";
27
27
  } else {
28
28
  userName = metaObj.name;
29
29
  userIdentifier = metaObj.ID;
@@ -93,15 +93,32 @@ export const updateSavedExportFilePath = async(filePath) => {
93
93
 
94
94
  let defaultPath = join(path.sep, arPathParts[0], arPathParts[1], arPathParts[2]);
95
95
 
96
- if (filePath.indexOf(defaultPath) === 0) {
97
- // same starting path, so we can save the relative
98
- const relativePath = filePath.replace(defaultPath.concat("/"), "");
96
+ if (path.sep != "/") {
97
+ // windows
98
+ if (defaultPath.indexOf(path.sep) === 0) {
99
+ // if start with \\, then remove
100
+ defaultPath = defaultPath.substring(1);
101
+ }
102
+
103
+ if (filePath.indexOf(defaultPath) === 0) {
104
+ // same starting path, so we can save the relative
105
+ const relativePath = filePath.replace(defaultPath.concat(path.sep), "");
99
106
 
100
- if (relativePath != configDef.importRelativePath) {
101
107
  await setConfigExportRelativePath(relativePath);
102
108
  await forceDefaultsUpdate();
109
+
103
110
  }
111
+ }
112
+ else {
113
+ // mac
114
+ if (filePath.indexOf(defaultPath) === 0) {
115
+ // same starting path, so we can save the relative
116
+ const relativePath = filePath.replace(defaultPath.concat("/"), "");
104
117
 
118
+ await setConfigExportRelativePath(relativePath);
119
+ await forceDefaultsUpdate();
105
120
 
121
+ }
106
122
  }
123
+
107
124
  }
@@ -190,17 +190,6 @@ export const updateTempArchive = async(libraryName, version, devBuild) => {
190
190
  // remove -dev if exists
191
191
  const justVersion = version.replace("-dev", "");
192
192
 
193
- // open tasks.config and update it
194
- // await setTasksConfig(libraryName, justVersion, devBuild, tempStoreDirectory);
195
-
196
- // open package.json, update org
197
- // await setPackageOrg(configDef.organization, tempStoreDirectory);
198
-
199
- // update all the components
200
- // const compDir = join(tempStoreDirectory, "src", "components");
201
- // const compList = await getComponents(compDir);
202
-
203
- // await renameComponents(compList, libraryName, version, compDir);
204
193
 
205
194
  const tasks = new Listr(
206
195
  [
@@ -290,12 +279,32 @@ export const updateSavedFilePath = async(filePath) => {
290
279
 
291
280
  let defaultPath = join(path.sep, arPathParts[0], arPathParts[1], arPathParts[2]);
292
281
 
293
- if (filePath.indexOf(defaultPath) === 0) {
294
- // same starting path, so we can save the relative
295
- const relativePath = filePath.replace(defaultPath.concat("/"), "");
282
+ if (path.sep != "/") {
283
+ // windows
284
+ if (defaultPath.indexOf(path.sep) === 0) {
285
+ // if start with \\, then remove
286
+ defaultPath = defaultPath.substring(1);
287
+ }
288
+
289
+ if (filePath.indexOf(defaultPath) === 0) {
290
+ // same starting path, so we can save the relative
291
+ const relativePath = filePath.replace(defaultPath.concat(path.sep), "");
292
+
293
+ await setConfigImportRelativePath(relativePath);
294
+ await forceDefaultsUpdate();
296
295
 
297
- await setConfigImportRelativePath(relativePath);
298
- await forceDefaultsUpdate();
296
+ }
297
+ }
298
+ else {
299
+ // mac
300
+ if (filePath.indexOf(defaultPath) === 0) {
301
+ // same starting path, so we can save the relative
302
+ const relativePath = filePath.replace(defaultPath.concat("/"), "");
299
303
 
304
+ await setConfigImportRelativePath(relativePath);
305
+ await forceDefaultsUpdate();
306
+
307
+ }
300
308
  }
309
+
301
310
  }
@@ -48,7 +48,7 @@
48
48
  "_internal-test-coverage": "node --input-type=module --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand node_modules/@pega/custom-dx-component --ci --testResultsProcessor='jest-junit' --coverage",
49
49
  "_internal-test": "echo 'Running functional and unit tests will DELETE existing local components, proceed (y/n)?' && read proceed && if test \"$proceed\" = \"y\"; then npm run _internal-test-full; fi ",
50
50
  "_internal-test-full": "npm run _internal-test-functional && npm run _internal-test-unit",
51
- "_internal-test-functional": "echo '\nMake sure you authenticate!!\n' && npm run test:functional:local --prefix node_modules/@pega/custom-dx-components",
51
+ "_internal-test-functional": "echo 'Make sure you authenticate!!' && npm run test:functional:local --prefix node_modules/@pega/custom-dx-components",
52
52
  "_internal-test-unit": "npm run test:unit:local --prefix node_modules/@pega/custom-dx-components",
53
53
  "_internal-build-jest-assets": "custom-dx-components buildJestAssets",
54
54
  "_internal-buildLibrary": "custom-dx-components buildLibrary",
@@ -100,7 +100,7 @@
100
100
  },
101
101
  "devDependencies": {
102
102
  "@pega/configs": "^0.15.1",
103
- "@pega/custom-dx-components": "~0.242.48",
103
+ "@pega/custom-dx-components": "~0.242.50",
104
104
  "@pega/pcore-pconnect-typedefs": "~3.2.0-alpha.1",
105
105
  "@storybook/addon-actions": "^7.6.19",
106
106
  "@storybook/addon-essentials": "^7.6.19",
package/src/util.js CHANGED
@@ -1508,6 +1508,28 @@ export const unZipFromArchive = async (fileName) => {
1508
1508
  };
1509
1509
 
1510
1510
 
1511
+ export const updateComponentTaskConfig = async () => {
1512
+ const currentDirectory = process.cwd();
1513
+ const tempDirectory = join(currentDirectory, TEMP_PATH);
1514
+
1515
+ const tempConfigPath = join(tempDirectory, TASKS_CONFIG_JSON_FILENAME);
1516
+ const currentConfigPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
1517
+
1518
+ const contents = fs.readFileSync(tempConfigPath);
1519
+ const originalContents = fs.readFileSync(currentConfigPath);
1520
+
1521
+ let contentsData = JSON.parse(contents);
1522
+ let originalContentsData = JSON.parse(originalContents);
1523
+
1524
+ // only copy "components" from archived task.config and "devBuild"
1525
+ // that way, your current tasks.config isn't messed up
1526
+ originalContentsData["server-config"].devBuild = contentsData["server-config"].devBuild;
1527
+ originalContentsData["component"] = contentsData["component"];
1528
+
1529
+ fs.writeFileSync(currentConfigPath, JSON.stringify(originalContentsData, null, 4), { encoding: 'utf8' });
1530
+
1531
+ }
1532
+
1511
1533
  export const restoreDependenciesFromPackage = async () => {
1512
1534
  const currentDirectory = process.cwd();
1513
1535
  const tempDirectory = join(currentDirectory, TEMP_PATH);
@@ -1598,16 +1620,14 @@ export const restoreFromArchive = async (fileName, orgLibName, version) => {
1598
1620
 
1599
1621
  await unZipFromArchive(archFileName);
1600
1622
 
1601
- const tempConfigPath = join(tempDirectory, TASKS_CONFIG_JSON_FILENAME);
1602
- const currentConfigPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
1623
+
1603
1624
  const tempPackagePath = join (tempDirectory, PACKAGE_JSON_FILENAME);
1604
1625
  const currentPackagePath = join(currentDirectory, PACKAGE_JSON_FILENAME);
1605
1626
  const tempDirectoryComponents = join(tempDirectory, "src", "components");
1606
1627
  const currentComponentsPath = join(currentDirectory, "src", "components");
1607
1628
 
1608
-
1609
- let contents = fs.readFileSync(tempConfigPath);
1610
- fs.writeFileSync(currentConfigPath, contents);
1629
+ // take your current tasks.config and update with component and devBuild from saved tasks.config
1630
+ await updateComponentTaskConfig();
1611
1631
 
1612
1632
  // restore package json dependencies
1613
1633
  await restoreDependenciesFromPackage();
@@ -2,7 +2,7 @@
2
2
  import React from 'react';
3
3
  import { useEffect, useState } from 'react';
4
4
  import { Avatar as CosmosAvatar, withConfiguration } from '@pega/cosmos-react-core';
5
- import type { PConnFieldProps } from '../shared/PConnProps';
5
+ import type { PConnFieldProps } from './PConnProps';
6
6
 
7
7
 
8
8
  // interface for props
@@ -16,14 +16,14 @@ interface PegaDxilMyDetailsAvatarProps extends PConnFieldProps {
16
16
  function Avatar(props: PegaDxilMyDetailsAvatarProps) {
17
17
  const { metaObj, showStatus = false } = props;
18
18
  const [imageBlobUrl, setImageBlobUrl] = useState(null);
19
- let userName: any;
20
- let userIdentifier: any;
19
+ let userName: string;
20
+ let userIdentifier: string;
21
21
 
22
22
  // TODO Below if conditions can be removed once we have apis to get worklist/mywork info
23
23
  // This is non CaseView case (Dashboard, MyWork etc)
24
24
  if (!metaObj) {
25
- userName = PCore.getEnvironmentInfo().getOperatorName();
26
- userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier();
25
+ userName = PCore.getEnvironmentInfo().getOperatorName() ?? "";
26
+ userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier() ?? "";
27
27
  } else {
28
28
  userName = metaObj.name;
29
29
  userIdentifier = metaObj.ID;
@@ -14,7 +14,7 @@ import {
14
14
  import { Glimpse } from '@pega/cosmos-react-work';
15
15
  import { EmailDisplay } from '@pega/cosmos-react-core';
16
16
 
17
- import type { PConnFieldProps } from '../shared/PConnProps';
17
+ import type { PConnFieldProps } from './PConnProps';
18
18
 
19
19
  import Avatar from './Avatar';
20
20
 
@@ -5,7 +5,7 @@ import { Text, FieldValueList, Button, DateTimeDisplay, useTheme } from '@pega/c
5
5
  import PegaDxilMyDetails from './index';
6
6
  import { pyReviewRaw, pyReviewResolved, regionChildrenResolved, operatorDetails, configProps } from './mock';
7
7
  import StatusWorkRenderer from './StatusWork';
8
- import Operator from './Operator';
8
+ import Operator from '../shared/Operator';
9
9
  import type C11nEnv from '@pega/pcore-pconnect-typedefs/interpreter/c11n-env';
10
10
 
11
11
  const meta: Meta<typeof PegaDxilMyDetails> = {
@@ -6,7 +6,7 @@ import { DateTimeDisplay, Card, CardHeader, CardContent, Flex, withConfiguration
6
6
  import type { PConnFieldProps } from '../shared/PConnProps';
7
7
 
8
8
  // includes in bundle
9
- import Operator from './Operator';
9
+ import Operator from '../shared/Operator';
10
10
 
11
11
  import StyledPegaDxilMyPageCaseWidgetWrapper from './styles';
12
12
 
@@ -4,7 +4,7 @@ import { Text, FieldValueList, Button, DateTimeDisplay, useTheme } from '@pega/c
4
4
  import PegaDxilMyTwoColumnDetails from './index';
5
5
  import { pyReviewRaw, pyReviewResolved, regionChildrenResolved, operatorDetails, configProps } from './mock';
6
6
  import StatusWorkRenderer from './StatusWork';
7
- import Operator from './Operator';
7
+ import Operator from '../shared/Operator';
8
8
  import type C11nEnv from '@pega/pcore-pconnect-typedefs/interpreter/c11n-env';
9
9
 
10
10
  const meta: Meta<typeof PegaDxilMyTwoColumnDetails> = {
@@ -2,28 +2,28 @@
2
2
  import React from 'react';
3
3
  import { useEffect, useState } from 'react';
4
4
  import { Avatar as CosmosAvatar, withConfiguration } from '@pega/cosmos-react-core';
5
- import type { PConnFieldProps } from '../shared/PConnProps';
5
+ import type { PConnFieldProps } from './PConnProps';
6
6
 
7
7
 
8
8
  // interface for props
9
- interface PegaDxilMyPageCaseWidgetAvatarProps extends PConnFieldProps {
9
+ interface PegaDxilMyDetailsAvatarProps extends PConnFieldProps {
10
10
  // If any, enter additional props that only exist on TextInput here
11
11
  metaObj: any;
12
12
  showStatus: boolean;
13
13
 
14
14
  }
15
15
 
16
- function Avatar(props: PegaDxilMyPageCaseWidgetAvatarProps) {
16
+ function Avatar(props: PegaDxilMyDetailsAvatarProps) {
17
17
  const { metaObj, showStatus = false } = props;
18
18
  const [imageBlobUrl, setImageBlobUrl] = useState(null);
19
- let userName: any;
20
- let userIdentifier: any;
19
+ let userName: string;
20
+ let userIdentifier: string;
21
21
 
22
22
  // TODO Below if conditions can be removed once we have apis to get worklist/mywork info
23
23
  // This is non CaseView case (Dashboard, MyWork etc)
24
24
  if (!metaObj) {
25
- userName = PCore.getEnvironmentInfo().getOperatorName();
26
- userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier();
25
+ userName = PCore.getEnvironmentInfo().getOperatorName() ?? "";
26
+ userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier() ?? "";
27
27
  } else {
28
28
  userName = metaObj.name;
29
29
  userIdentifier = metaObj.ID;
@@ -59,6 +59,7 @@ function Avatar(props: PegaDxilMyPageCaseWidgetAvatarProps) {
59
59
  PCore.getMessagingServiceManager().getUserPresence().unsubscribe(userIdentifier, subId);
60
60
  };
61
61
  }, [userIdentifier, handleUserStateChange]);
62
+
62
63
  return <CosmosAvatar name={userName} imageSrc={imageBlobUrl as React.SetStateAction<any>} status={userState} />;
63
64
  }
64
65
 
@@ -14,13 +14,13 @@ import {
14
14
  import { Glimpse } from '@pega/cosmos-react-work';
15
15
  import { EmailDisplay } from '@pega/cosmos-react-core';
16
16
 
17
- import type { PConnFieldProps } from '../shared/PConnProps';
17
+ import type { PConnFieldProps } from './PConnProps';
18
18
 
19
19
  import Avatar from './Avatar';
20
20
 
21
21
 
22
22
  // interface for props
23
- interface PegaDxilMyPageCaseWidgetOperatorProps extends PConnFieldProps {
23
+ interface PegaDxilMyDetailsOperatorProps extends PConnFieldProps {
24
24
  // If any, enter additional props that only exist on TextInput here
25
25
  name: string;
26
26
  id: string;
@@ -31,7 +31,7 @@ interface PegaDxilMyPageCaseWidgetOperatorProps extends PConnFieldProps {
31
31
 
32
32
  let pTarget = null;
33
33
 
34
- function Operator(props: PegaDxilMyPageCaseWidgetOperatorProps) {
34
+ function Operator(props: PegaDxilMyDetailsOperatorProps) {
35
35
  const { id, name, label, testId, helperText, externalUser, metaObj } = props;
36
36
  const [isOpen, setIsOpen] = useState(false);
37
37
  const [isLoading, setIsLoading] = useState(true);
@@ -16,14 +16,14 @@ interface PegaDxilMyDetailsAvatarProps extends PConnFieldProps {
16
16
  function Avatar(props: PegaDxilMyDetailsAvatarProps) {
17
17
  const { metaObj, showStatus = false } = props;
18
18
  const [imageBlobUrl, setImageBlobUrl] = useState(null);
19
- let userName: any;
20
- let userIdentifier: any;
19
+ let userName: string;
20
+ let userIdentifier: string;
21
21
 
22
22
  // TODO Below if conditions can be removed once we have apis to get worklist/mywork info
23
23
  // This is non CaseView case (Dashboard, MyWork etc)
24
24
  if (!metaObj) {
25
- userName = PCore.getEnvironmentInfo().getOperatorName();
26
- userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier();
25
+ userName = PCore.getEnvironmentInfo().getOperatorName() ?? "";
26
+ userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier() ?? "";
27
27
  } else {
28
28
  userName = metaObj.name;
29
29
  userIdentifier = metaObj.ID;
@@ -16,14 +16,14 @@ interface PegaDxilMyPageCaseWidgetAvatarProps extends PConnFieldProps {
16
16
  function Avatar(props: PegaDxilMyPageCaseWidgetAvatarProps) {
17
17
  const { metaObj, showStatus = false } = props;
18
18
  const [imageBlobUrl, setImageBlobUrl] = useState(null);
19
- let userName: any;
20
- let userIdentifier: any;
19
+ let userName: string;
20
+ let userIdentifier: string;
21
21
 
22
22
  // TODO Below if conditions can be removed once we have apis to get worklist/mywork info
23
23
  // This is non CaseView case (Dashboard, MyWork etc)
24
24
  if (!metaObj) {
25
- userName = PCore.getEnvironmentInfo().getOperatorName();
26
- userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier();
25
+ userName = PCore.getEnvironmentInfo().getOperatorName() ?? "";
26
+ userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier() ?? "";
27
27
  } else {
28
28
  userName = metaObj.name;
29
29
  userIdentifier = metaObj.ID;
@@ -16,14 +16,14 @@ interface PegaDxilMyTwoColumnDetailsAvatarProps extends PConnFieldProps {
16
16
  function Avatar(props: PegaDxilMyTwoColumnDetailsAvatarProps) {
17
17
  const { metaObj, showStatus = false } = props;
18
18
  const [imageBlobUrl, setImageBlobUrl] = useState(null);
19
- let userName: any;
20
- let userIdentifier: any;
19
+ let userName: string;
20
+ let userIdentifier: string;
21
21
 
22
22
  // TODO Below if conditions can be removed once we have apis to get worklist/mywork info
23
23
  // This is non CaseView case (Dashboard, MyWork etc)
24
24
  if (!metaObj) {
25
- userName = PCore.getEnvironmentInfo().getOperatorName();
26
- userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier();
25
+ userName = PCore.getEnvironmentInfo().getOperatorName() ?? "";
26
+ userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier() ?? "";
27
27
  } else {
28
28
  userName = metaObj.name;
29
29
  userIdentifier = metaObj.ID;
@@ -16,14 +16,14 @@ interface PegaDxilMyDetailsAvatarProps extends PConnFieldProps {
16
16
  function Avatar(props: PegaDxilMyDetailsAvatarProps) {
17
17
  const { metaObj, showStatus = false } = props;
18
18
  const [imageBlobUrl, setImageBlobUrl] = useState(null);
19
- let userName: any;
20
- let userIdentifier: any;
19
+ let userName: string;
20
+ let userIdentifier: string;
21
21
 
22
22
  // TODO Below if conditions can be removed once we have apis to get worklist/mywork info
23
23
  // This is non CaseView case (Dashboard, MyWork etc)
24
24
  if (!metaObj) {
25
- userName = PCore.getEnvironmentInfo().getOperatorName();
26
- userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier();
25
+ userName = PCore.getEnvironmentInfo().getOperatorName() ?? "";
26
+ userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier() ?? "";
27
27
  } else {
28
28
  userName = metaObj.name;
29
29
  userIdentifier = metaObj.ID;
@@ -16,14 +16,14 @@ interface PegaDxilMyPageCaseWidgetAvatarProps extends PConnFieldProps {
16
16
  function Avatar(props: PegaDxilMyPageCaseWidgetAvatarProps) {
17
17
  const { metaObj, showStatus = false } = props;
18
18
  const [imageBlobUrl, setImageBlobUrl] = useState(null);
19
- let userName: any;
20
- let userIdentifier: any;
19
+ let userName: string;
20
+ let userIdentifier: string;
21
21
 
22
22
  // TODO Below if conditions can be removed once we have apis to get worklist/mywork info
23
23
  // This is non CaseView case (Dashboard, MyWork etc)
24
24
  if (!metaObj) {
25
- userName = PCore.getEnvironmentInfo().getOperatorName();
26
- userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier();
25
+ userName = PCore.getEnvironmentInfo().getOperatorName() ?? "";
26
+ userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier() ?? "";
27
27
  } else {
28
28
  userName = metaObj.name;
29
29
  userIdentifier = metaObj.ID;
@@ -16,14 +16,14 @@ interface PegaDxilMyTwoColumnDetailsAvatarProps extends PConnFieldProps {
16
16
  function Avatar(props: PegaDxilMyTwoColumnDetailsAvatarProps) {
17
17
  const { metaObj, showStatus = false } = props;
18
18
  const [imageBlobUrl, setImageBlobUrl] = useState(null);
19
- let userName: any;
20
- let userIdentifier: any;
19
+ let userName: string;
20
+ let userIdentifier: string;
21
21
 
22
22
  // TODO Below if conditions can be removed once we have apis to get worklist/mywork info
23
23
  // This is non CaseView case (Dashboard, MyWork etc)
24
24
  if (!metaObj) {
25
- userName = PCore.getEnvironmentInfo().getOperatorName();
26
- userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier();
25
+ userName = PCore.getEnvironmentInfo().getOperatorName() ?? "";
26
+ userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier() ?? "";
27
27
  } else {
28
28
  userName = metaObj.name;
29
29
  userIdentifier = metaObj.ID;
@@ -1,76 +0,0 @@
1
- /* eslint-disable react-hooks/rules-of-hooks */
2
- import React from 'react';
3
- import { useEffect, useState } from 'react';
4
- import { Avatar as CosmosAvatar, withConfiguration } from '@pega/cosmos-react-core';
5
- import type { PConnFieldProps } from '../shared/PConnProps';
6
-
7
-
8
- // interface for props
9
- interface PegaDxilMyTwoColumnDetailsAvatarProps extends PConnFieldProps {
10
- // If any, enter additional props that only exist on TextInput here
11
- metaObj: any;
12
- showStatus: boolean;
13
-
14
- }
15
-
16
- function Avatar(props: PegaDxilMyTwoColumnDetailsAvatarProps) {
17
- const { metaObj, showStatus = false } = props;
18
- const [imageBlobUrl, setImageBlobUrl] = useState(null);
19
- let userName: any;
20
- let userIdentifier: any;
21
-
22
- // TODO Below if conditions can be removed once we have apis to get worklist/mywork info
23
- // This is non CaseView case (Dashboard, MyWork etc)
24
- if (!metaObj) {
25
- userName = PCore.getEnvironmentInfo().getOperatorName();
26
- userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier();
27
- } else {
28
- userName = metaObj.name;
29
- userIdentifier = metaObj.ID;
30
- }
31
- if (!userName && userIdentifier) {
32
- userName = userIdentifier;
33
- }
34
-
35
- useEffect(() => {
36
- const imageKey = !metaObj ? PCore.getEnvironmentInfo().getOperatorImageInsKey() : metaObj.image;
37
- if (imageKey) {
38
- PCore.getAssetLoader()
39
- .getSvcImage(imageKey)
40
- .then((blob) => window.URL.createObjectURL(blob))
41
- .then((imagePath) => setImageBlobUrl(imagePath as React.SetStateAction<any>));
42
- }
43
- }, [metaObj]);
44
-
45
- if (showStatus) {
46
- const currentState = PCore.getMessagingServiceManager().getUserPresence().getUserState(userIdentifier);
47
- const [userState, setUserState]: any = useState(currentState === 'online' ? 'active' : 'inactive');
48
-
49
- const handleUserStateChange = ({ state } : any) => {
50
- setUserState(state === 'online' ? 'active' : 'inactive');
51
- };
52
-
53
- useEffect(() => {
54
- const subId = PCore.getMessagingServiceManager()
55
- .getUserPresence()
56
- // @ts-ignore
57
- .subscribe(userIdentifier, handleUserStateChange);
58
-
59
- return function cleanup() {
60
- PCore.getMessagingServiceManager().getUserPresence().unsubscribe(userIdentifier, subId);
61
- };
62
- }, [userIdentifier, handleUserStateChange]);
63
- return <CosmosAvatar name={userName} imageSrc={imageBlobUrl as React.SetStateAction<any>} status={userState} />;
64
- }
65
-
66
- // Do not render when userName does not exists
67
- // TODO : In CNR case, pxRequestor is not available, please remove this condition once it populates
68
- if (!userName) {
69
- return null;
70
- }
71
-
72
- return <CosmosAvatar name={userName} imageSrc={imageBlobUrl as React.SetStateAction<any>} />;
73
- }
74
-
75
-
76
- export default withConfiguration(Avatar);
@@ -1,215 +0,0 @@
1
- // @ts-nocheck
2
- import { useState, useEffect, Fragment } from 'react';
3
- import {
4
- Link,
5
- Button,
6
- Popover,
7
- useOuterEvent,
8
- useElement,
9
- Progress,
10
- FormField,
11
- useTheme,
12
- withConfiguration
13
- } from '@pega/cosmos-react-core';
14
- import { Glimpse } from '@pega/cosmos-react-work';
15
- import { EmailDisplay } from '@pega/cosmos-react-core';
16
-
17
- import type { PConnFieldProps } from '../shared/PConnProps';
18
-
19
- import Avatar from './Avatar';
20
-
21
-
22
- // interface for props
23
- interface PegaDxilMyTwoColumnDetailsOperatorProps extends PConnFieldProps {
24
- // If any, enter additional props that only exist on TextInput here
25
- name: string;
26
- id: string;
27
- label: string;
28
- metaObj: any;
29
- externalUser: any;
30
- }
31
-
32
- let pTarget = null;
33
-
34
- function Operator(props: PegaDxilMyTwoColumnDetailsOperatorProps) {
35
- const { id, name, label, testId, helperText, externalUser, metaObj } = props;
36
- const [isOpen, setIsOpen] = useState(false);
37
- const [isLoading, setIsLoading] = useState(true);
38
- const [popoverEl, setPopoverEl] = useElement(null);
39
- const [popoverContent, setpopoverContent] = useState(null);
40
- const theme: any = useTheme();
41
-
42
- /* If the id has changed, we need to reset the popover */
43
- useEffect(() => {
44
- pTarget = null;
45
- }, [id]);
46
-
47
-
48
-
49
- const OperatorPreview = () => {
50
- const localizedVal = PCore.getLocaleUtils().getLocaleValue;
51
- const localeCategory = 'Operator';
52
- setpopoverContent(
53
- <Progress variant='ring' message={localizedVal('Loading operator...', localeCategory)} placement='local' />
54
- );
55
- if (externalUser && externalUser.classID !== 'Data-Party-Operator') {
56
- const fields = [
57
- {
58
- id: 'pyFirstName',
59
- name: localizedVal('Name', localeCategory),
60
- value: externalUser.name
61
- },
62
- {
63
- id: 'pyEmail1',
64
- name: localizedVal('Email', localeCategory),
65
- value:
66
- externalUser.email !== '' ? <Link href={`mailto:${externalUser.email}`}>{externalUser.email}</Link> : ''
67
- },
68
- {
69
- id: 'pyPhoneNumber',
70
- name: localizedVal('Phone', localeCategory),
71
- value: externalUser.phone !== '' ? <Link href={`tel:${externalUser.phone}`}>{externalUser.phone}</Link> : ''
72
- }
73
- ];
74
- setIsLoading(false);
75
- setpopoverContent(
76
- <Glimpse
77
- visual={
78
- <Avatar
79
- metaObj={{
80
- name: externalUser.name
81
- }}
82
- />
83
- }
84
- primary={externalUser.name}
85
- secondary={[externalUser.position]}
86
- fields={fields}
87
- target={pTarget}
88
- />
89
- );
90
- } else {
91
- return PCore.getUserApi()
92
- .getOperatorDetails(id, true)
93
- .then(res => {
94
- if (res.data?.pyOperatorInfo) {
95
- const fields = [];
96
- const data = res.data;
97
- if (data.pyOperatorInfo && data.pyOperatorInfo.pyUserName) {
98
- fields.push({
99
- id: 'Name',
100
- name: localizedVal('Name', localeCategory),
101
- value: data.pyOperatorInfo.pyUserName
102
- });
103
- }
104
- if (data.pyOperatorInfo && data.pyOperatorInfo.pyEmailAddress) {
105
- fields.push({
106
- id: 'Email',
107
- name: localizedVal('Email address', localeCategory),
108
- value: <EmailDisplay value={data.pyOperatorInfo.pyEmailAddress} />
109
- });
110
- }
111
- const opAvatar = (
112
- <Avatar
113
- metaObj={{
114
- image: '',
115
- name: data.pyOperatorInfo.pyUserName
116
- }}
117
- />
118
- );
119
-
120
- setIsLoading(false);
121
- setpopoverContent(
122
- <Glimpse
123
- heading={{
124
- primary: data.pyOperatorInfo.pyUserName,
125
- secondary: data.pyOperatorInfo.pyEmailAddress,
126
- visual: opAvatar
127
- }}
128
- fields={fields}
129
- target={pTarget}
130
- onDismiss={() => {pTarget = null;}}
131
- />
132
- );
133
- }
134
- });
135
- }
136
- };
137
-
138
-
139
- const clickAction = (e: any) => {
140
-
141
- setIsOpen(!isOpen);
142
- if (pTarget === null) {
143
- pTarget = e.currentTarget;
144
- OperatorPreview();
145
- }
146
- };
147
-
148
- const hidePopover = () => {
149
- if (isOpen) {
150
- setIsOpen(false);
151
- }
152
- };
153
-
154
- useOuterEvent('mousedown', [popoverEl], hidePopover); // Call the method on clicking outside these elements
155
-
156
- const hideOnEscape = (e: any) => {
157
- if (e.key === 'Escape') hidePopover(); // Call the method when Escape key is pressed
158
- };
159
-
160
- const comp = (
161
- <Fragment>
162
- {metaObj ? (
163
- <Button
164
- variant='text'
165
- aria-haspopup
166
- aria-expanded={isOpen}
167
- onClick={clickAction}
168
- onKeyDown={hideOnEscape}
169
- data-test-id={testId}
170
- style={label !== null ? { width: 'max-content', height: theme.components.input.height } : undefined}
171
- >
172
- <Avatar {...props} />
173
- </Button>
174
- ) : (
175
- <Button
176
- variant='link'
177
- aria-haspopup
178
- aria-expanded={isOpen}
179
- onClick={clickAction}
180
- onKeyDown={hideOnEscape}
181
- data-test-id={testId}
182
- style={label !== null ? { width: 'max-content', height: theme.components.input.height } : undefined}
183
- >
184
- {name}
185
- </Button>
186
- )}
187
-
188
- {isOpen && (
189
- <Popover
190
- ref={setPopoverEl}
191
- groupId='operator'
192
- target={pTarget}
193
- placement='bottom-start'
194
- style={isLoading ? { position: 'relative', width: '10rem', minHeight: '4rem' } : undefined}
195
- strategy='fixed'
196
- >
197
- {popoverContent}
198
- </Popover>
199
- )}
200
- </Fragment>
201
- );
202
-
203
- if (label !== null) {
204
- return (
205
- <FormField label={label} info={helperText}>
206
- {comp}
207
- </FormField>
208
- );
209
- }
210
-
211
- return comp;
212
- };
213
-
214
-
215
- export default withConfiguration(Operator);