@rh-support/manage 0.2.95 → 0.2.98

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 +1 @@
1
- {"version":3,"file":"BookmarkAccountSelector.d.ts","sourceRoot":"","sources":["../../../../src/components/ManageBookmarkedAccountsTab/BookmarkAccountSelector.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAGhF,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAQtD,UAAU,MAAM;IACZ,uBAAuB,EAAE,SAAS,EAAE,CAAC;IACrC,iBAAiB,CAAC,EAAE,kBAAkB,CAAC;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,yBAAyB,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,SAAS,EAAE,CAAC;IAC9B,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,eA2NpD;yBA3Ne,uBAAuB"}
1
+ {"version":3,"file":"BookmarkAccountSelector.d.ts","sourceRoot":"","sources":["../../../../src/components/ManageBookmarkedAccountsTab/BookmarkAccountSelector.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAGhF,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAUtD,UAAU,MAAM;IACZ,uBAAuB,EAAE,SAAS,EAAE,CAAC;IACrC,iBAAiB,CAAC,EAAE,kBAAkB,CAAC;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,yBAAyB,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,SAAS,EAAE,CAAC;IAC9B,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,eAwPpD;yBAxPe,uBAAuB"}
@@ -8,20 +8,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { accounts } from '@cee-eng/hydrajs';
11
- import { Label, Tooltip } from '@patternfly/react-core';
11
+ import { Chip, ChipGroup, Label, Select, SelectOption, SelectVariant, Tooltip } from '@patternfly/react-core';
12
12
  import InfoCircleIcon from '@patternfly/react-icons/dist/js/icons/info-circle-icon';
13
13
  import assign from 'lodash/assign';
14
14
  import compact from 'lodash/compact';
15
+ import debounce from 'lodash/debounce';
16
+ import find from 'lodash/find';
15
17
  import isEmpty from 'lodash/isEmpty';
18
+ import remove from 'lodash/remove';
16
19
  import React, { useEffect, useRef, useState } from 'react';
17
- import { AsyncTypeahead, Highlighter, Token } from 'react-bootstrap-typeahead';
18
20
  import { Trans, useTranslation } from 'react-i18next';
19
21
  export function BookmarkAccountSelector(props) {
20
22
  const [options, setOptions] = useState([]);
21
23
  const [isSearching, setIsSearching] = useState(false);
22
24
  const abortControllerRef = useRef(undefined);
23
- const typeaheadRef = useRef(null);
24
25
  const { t } = useTranslation();
26
+ const [isOpen, setIsOpen] = useState(false);
27
+ const [selected, setSelected] = useState([]);
28
+ const onToggle = (isOpen) => setIsOpen(isOpen);
29
+ const clearSelection = () => {
30
+ setIsOpen(false);
31
+ setSelected([]);
32
+ props.onBookMarkAccountSelected([]);
33
+ };
25
34
  const fetchAccounts = (query) => __awaiter(this, void 0, void 0, function* () {
26
35
  if (query == null)
27
36
  return;
@@ -69,20 +78,23 @@ export function BookmarkAccountSelector(props) {
69
78
  }
70
79
  }
71
80
  });
72
- const clear = () => {
73
- typeaheadRef.current.clear();
74
- };
75
- // this ref is used to call clear() outside component
76
- props.clearRef.current = clear;
77
- const handleChange = (selected) => {
78
- const selectedObj = selected.map((bookmark) => (Object.assign(Object.assign({}, bookmark), { bookmarkId: bookmark.bookmarkId || undefined, rootBookmarkId: bookmark.rootBookmarkId || undefined })));
79
- props.onBookMarkAccountSelected(selectedObj);
81
+ const onTypeaheadInputChanged = (input) => __awaiter(this, void 0, void 0, function* () {
82
+ yield fetchAccounts(input);
83
+ });
84
+ // this ref is used to call clearSelection() outside component
85
+ props.clearRef.current = clearSelection;
86
+ const debounceFn = debounce(onTypeaheadInputChanged, 500);
87
+ const onSelect = (event, currentSelected) => {
88
+ const alreadySelected = find(selected, (account) => account.accountNumber === currentSelected.accountNumber);
89
+ if (alreadySelected)
90
+ return;
91
+ const selectedAccounts = [
92
+ ...selected,
93
+ Object.assign(Object.assign({}, currentSelected), { bookmarkId: currentSelected.bookmarkId || undefined, rootBookmarkId: currentSelected.rootBookmarkId || undefined }),
94
+ ];
95
+ setSelected(selectedAccounts);
96
+ props.onBookMarkAccountSelected(selectedAccounts);
80
97
  };
81
- const getLabels = (account) => account.accountNumber
82
- ? account.name
83
- ? `${account.name} (${account.accountNumber})`
84
- : account.accountNumber
85
- : '';
86
98
  const duplicateAccounts = (props.selectedGroup &&
87
99
  props.addMode &&
88
100
  props.bookmarkedGroupAccounts
@@ -91,6 +103,21 @@ export function BookmarkAccountSelector(props) {
91
103
  })
92
104
  .map((a) => a.accountNumber)) ||
93
105
  [];
106
+ const removeAccountChip = (e, removedAccount) => {
107
+ const updatedSelectedAccounts = remove(selected, (account) => account.accountNumber !== removedAccount.accountNumber);
108
+ setSelected(updatedSelectedAccounts);
109
+ props.onBookMarkAccountSelected(updatedSelectedAccounts);
110
+ };
111
+ const chipGroupComponent = () => {
112
+ return (React.createElement(ChipGroup, { numChips: 2 }, (selected || []).map((currentChip) => (React.createElement(Chip, { key: currentChip.accountNumber, onClick: (event) => removeAccountChip(event, currentChip), isOverflowChip: false },
113
+ currentChip.name,
114
+ " (",
115
+ currentChip.accountNumber,
116
+ ")")))));
117
+ };
118
+ useEffect(() => {
119
+ setSelected(props.defaultSelected || []);
120
+ }, [props.defaultSelected]);
94
121
  // when a group is added or removed from account we need to update dropdown
95
122
  // options to show correct group
96
123
  useEffect(() => {
@@ -109,18 +136,23 @@ export function BookmarkAccountSelector(props) {
109
136
  setOptions(newOptions);
110
137
  // eslint-disable-next-line react-hooks/exhaustive-deps
111
138
  }, [props.bookmarkedGroupAccounts]);
139
+ const titleId = 'multi-typeahead-bookmark-chip-group-props-id';
112
140
  return (React.createElement(React.Fragment, null,
113
- React.createElement(AsyncTypeahead, { defaultSelected: props.defaultSelected || [], clearButton: true, positionFixed: true, "data-tracking-id": props.labelId, id: props.labelId, isLoading: isSearching, labelKey: getLabels, minLength: 0, onSearch: fetchAccounts, options: options, delay: 0, placeholder: t('Search for account names or numbers'), multiple: true, isInvalid: props.isInValid, disabled: props.isDisabled || false, renderMenuItemChildren: (account, props) => (React.createElement("div", null,
114
- React.createElement(Highlighter, { key: account.bookmarkId, search: props.text }, getLabels(account)),
141
+ React.createElement("span", { id: titleId, hidden: true }, "Select a state"),
142
+ React.createElement(Select, Object.assign({ chipGroupComponent: chipGroupComponent(), variant: SelectVariant.typeaheadMulti, typeAheadAriaLabel: t('Search for account names or numbers'), onToggle: onToggle, onSelect: onSelect, onClear: clearSelection, "data-tracking-id": props.labelId, selections: selected, isOpen: isOpen, "aria-labelledby": titleId, placeholderText: t('Search for account names or numbers'), hasInlineFilter: false, onTypeaheadInputChanged: debounceFn, onFilter: () => undefined, "aria-describedby": "clusterID-validate-helper" }, (isSearching && { loadingVariant: 'spinner' })), options.map((account, index) => (React.createElement(SelectOption, { value: account, key: index },
143
+ React.createElement("div", null,
144
+ React.createElement("div", { className: "pf-u-color-100 pf-u-font-size-sm" },
145
+ account.name,
146
+ " (",
147
+ account.accountNumber,
148
+ ")"),
115
149
  React.createElement("div", null, account.bookmarkGroupName.length === 0 ? (React.createElement("span", { className: "pf-u-color-400" },
116
150
  React.createElement(Trans, null, "This account has not been bookmarked."))) : account.bookmarkGroupName.length > 2 ? (React.createElement("div", null,
117
151
  React.createElement(Tooltip, { isContentLeftAligned: true, content: account.bookmarkGroupName.map((group) => (React.createElement("div", null, group))) },
118
152
  React.createElement(Label, { color: "purple", icon: React.createElement(InfoCircleIcon, null), key: `${account.accountNumber}${account.bookmarkGroupName}` },
119
153
  "Bookmarked ",
120
154
  account.bookmarkGroupName.length,
121
- " times")))) : (account.bookmarkGroupName.map((group) => !isEmpty(group) && (React.createElement(Label, { color: "purple", key: `${account.accountNumber}-${group}` }, group))))))), renderToken: (option, { onRemove }, index) => (React.createElement(Token, { key: index, onRemove: onRemove, option: option, style: duplicateAccounts.includes(option.accountNumber)
122
- ? { backgroundColor: '#fdf7e7', color: '#795600' }
123
- : {} }, getLabels(option))), useCache: false, onChange: handleChange, ref: typeaheadRef }),
155
+ " times")))) : (account.bookmarkGroupName.map((group) => !isEmpty(group) && (React.createElement(Label, { color: "purple", key: `${account.accountNumber}-${group}` }, group)))))))))),
124
156
  props.isInValid && (React.createElement("p", { className: "form-instructions form-invalid" },
125
157
  React.createElement(Trans, null, "Select one or more accounts to bookmark"))),
126
158
  duplicateAccounts.length !== 0 && (React.createElement("p", { className: "form-instructions" },
@@ -1 +1 @@
1
- {"version":3,"file":"PreferencesCaseCreate.d.ts","sourceRoot":"","sources":["../../../../../src/components/ManagePreferences/sections/PreferencesCaseCreate.tsx"],"names":[],"mappings":"AAaA,UAAU,MAAM;CAAG;AACnB,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,eA0HlD"}
1
+ {"version":3,"file":"PreferencesCaseCreate.d.ts","sourceRoot":"","sources":["../../../../../src/components/ManagePreferences/sections/PreferencesCaseCreate.tsx"],"names":[],"mappings":"AAkBA,UAAU,MAAM;CAAG;AACnB,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,eAgIlD"}
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { Card, CardBody, CardHeader, SelectOption } from '@patternfly/react-core';
11
11
  import { languageConst, ToastNotification } from '@rh-support/components';
12
- import { GlobalMetadataStateContext } from '@rh-support/react-context';
12
+ import { fetchCaseGroupsForSSO, GlobalMetadataDispatchContext, GlobalMetadataStateContext, } from '@rh-support/react-context';
13
+ import { haventLoadedMetadata } from '@rh-support/utils';
13
14
  import { invert } from 'lodash';
14
15
  import isEmpty from 'lodash/isEmpty';
15
16
  import React, { useContext, useEffect, useState } from 'react';
@@ -18,7 +19,8 @@ import { useUserPreferences } from '../../../hooks/useUserPreferences';
18
19
  import { PreferenceSelect } from '../components/PreferenceSelect';
19
20
  export function PreferencesCaseCreate(props) {
20
21
  const { t } = useTranslation();
21
- const { globalMetadataState: { caseGroups }, } = useContext(GlobalMetadataStateContext);
22
+ const { globalMetadataState: { caseGroups, loggedInUserJwtToken }, } = useContext(GlobalMetadataStateContext);
23
+ const dispatchToGlobalMetadataReducer = useContext(GlobalMetadataDispatchContext);
22
24
  const [originalPreferredLanguage, setOriginalPreferredLanguage] = useState('');
23
25
  const [originalDefaultGroup, setOriginalDefaultGroup] = useState('');
24
26
  const [groupDictionary, setGroupDictionary] = useState({});
@@ -37,24 +39,6 @@ export function PreferencesCaseCreate(props) {
37
39
  const selectionKey = invert(groupDictionary)[selection];
38
40
  yield updateDefaultGroup(selectionKey);
39
41
  });
40
- const userOriginalPreferredLanguage = () => __awaiter(this, void 0, void 0, function* () {
41
- try {
42
- const retrievedLanguage = yield getPreferredLanguage();
43
- setOriginalPreferredLanguage(languageConst[retrievedLanguage]);
44
- }
45
- catch (_a) {
46
- ToastNotification.addWarningMessage(t('Failed to fetch original preference'));
47
- }
48
- });
49
- const userOriginalDefaultGroup = () => __awaiter(this, void 0, void 0, function* () {
50
- try {
51
- const retrievedGroupId = yield getDefaultGroup();
52
- setOriginalDefaultGroup(groupDictionary[retrievedGroupId]);
53
- }
54
- catch (_b) {
55
- ToastNotification.addWarningMessage(t('Failed to fetch original preference'));
56
- }
57
- });
58
42
  const createCaseGroupStruct = (caseGroups) => {
59
43
  const defaultGroupDictionary = {};
60
44
  for (let i = 0; i < caseGroups.data.length; i++) {
@@ -62,26 +46,50 @@ export function PreferencesCaseCreate(props) {
62
46
  }
63
47
  return defaultGroupDictionary;
64
48
  };
65
- const refreshParsedGroups = () => {
66
- var _a;
67
- if (!isEmpty(caseGroups) && ((_a = caseGroups === null || caseGroups === void 0 ? void 0 : caseGroups.data) === null || _a === void 0 ? void 0 : _a.length) > 0) {
68
- let updatedDictionary = createCaseGroupStruct(caseGroups);
69
- setGroupDictionary(updatedDictionary);
70
- const parsedDefaultGroupNames = [];
71
- for (let groupId in updatedDictionary) {
72
- parsedDefaultGroupNames.push(updatedDictionary[groupId]);
73
- }
74
- setUserDefaultGroupList(parsedDefaultGroupNames);
75
- }
76
- };
49
+ //use effect to retrieve original pref values.
77
50
  useEffect(() => {
51
+ const userOriginalPreferredLanguage = () => __awaiter(this, void 0, void 0, function* () {
52
+ try {
53
+ const retrievedLanguage = yield getPreferredLanguage();
54
+ setOriginalPreferredLanguage(languageConst[retrievedLanguage]);
55
+ }
56
+ catch (_a) {
57
+ ToastNotification.addWarningMessage(t('Failed to fetch original preference'));
58
+ }
59
+ });
60
+ const userOriginalDefaultGroup = () => __awaiter(this, void 0, void 0, function* () {
61
+ try {
62
+ const retrievedGroupId = yield getDefaultGroup();
63
+ setOriginalDefaultGroup(groupDictionary[retrievedGroupId]);
64
+ }
65
+ catch (_b) {
66
+ ToastNotification.addWarningMessage(t('Failed to fetch original preference'));
67
+ }
68
+ });
78
69
  userOriginalPreferredLanguage();
79
70
  userOriginalDefaultGroup();
80
- });
71
+ // eslint-disable-next-line react-hooks/exhaustive-deps
72
+ }, []);
73
+ // used to build the groups object
81
74
  useEffect(() => {
75
+ const refreshParsedGroups = () => __awaiter(this, void 0, void 0, function* () {
76
+ var _a;
77
+ if (haventLoadedMetadata(caseGroups, (data) => data === undefined)) {
78
+ yield fetchCaseGroupsForSSO(dispatchToGlobalMetadataReducer, loggedInUserJwtToken.username);
79
+ }
80
+ if (!isEmpty(caseGroups) && ((_a = caseGroups === null || caseGroups === void 0 ? void 0 : caseGroups.data) === null || _a === void 0 ? void 0 : _a.length) > 0) {
81
+ let updatedDictionary = createCaseGroupStruct(caseGroups);
82
+ setGroupDictionary(updatedDictionary);
83
+ const parsedDefaultGroupNames = [];
84
+ for (let groupId in updatedDictionary) {
85
+ parsedDefaultGroupNames.push(updatedDictionary[groupId]);
86
+ }
87
+ setUserDefaultGroupList(parsedDefaultGroupNames);
88
+ }
89
+ });
82
90
  refreshParsedGroups();
83
91
  // eslint-disable-next-line react-hooks/exhaustive-deps
84
- }, [caseGroups]);
92
+ }, [caseGroups, dispatchToGlobalMetadataReducer, loggedInUserJwtToken]);
85
93
  return (React.createElement(Card, { className: "preference-card" },
86
94
  React.createElement(CardHeader, null,
87
95
  React.createElement("h3", null,
@@ -1 +1 @@
1
- {"version":3,"file":"PreferencesCaseView.d.ts","sourceRoot":"","sources":["../../../../../src/components/ManagePreferences/sections/PreferencesCaseView.tsx"],"names":[],"mappings":"AAcA,UAAU,MAAM;CAAG;AAEnB,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,eAgKhD"}
1
+ {"version":3,"file":"PreferencesCaseView.d.ts","sourceRoot":"","sources":["../../../../../src/components/ManagePreferences/sections/PreferencesCaseView.tsx"],"names":[],"mappings":"AAcA,UAAU,MAAM;CAAG;AAEnB,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,eAiKhD"}
@@ -83,7 +83,7 @@ export function PreferencesCaseView(props) {
83
83
  });
84
84
  const titleId = 'default-comment-preference-select';
85
85
  const canUseHostName = ability.can(resourceActions.PATCH, resources.CASE_CREATE, CaseListFields.HOSTNAME);
86
- const { globalMetadataState: { loggedInUsersAccount }, } = useContext(GlobalMetadataStateContext);
86
+ const { globalMetadataState: { loggedInUsersAccount, loggedInUserRights }, } = useContext(GlobalMetadataStateContext);
87
87
  const { request: fetchHostnameDefault } = useFetch(accounts.getIsSharingHostname);
88
88
  const accountNumber = loggedInUsersAccount.data.accountNumber;
89
89
  const { request: updateShareHostnames } = useFetch(accounts.updateIsSharingHostname);
@@ -92,14 +92,15 @@ export function PreferencesCaseView(props) {
92
92
  return __awaiter(this, void 0, void 0, function* () {
93
93
  try {
94
94
  const fetchedHostnameStatus = yield fetchHostnameDefault(accountNumber);
95
- setIsSharingHostNames(fetchedHostnameStatus.shareHostnameWithRHT);
95
+ (fetchedHostnameStatus === null || fetchedHostnameStatus === void 0 ? void 0 : fetchedHostnameStatus.shareHostnameWithRHT) &&
96
+ setIsSharingHostNames(fetchedHostnameStatus.shareHostnameWithRHT);
96
97
  }
97
98
  catch (error) {
98
99
  console.log(error);
99
100
  }
100
101
  });
101
102
  }
102
- userOriginalHostnameValue();
103
+ !loggedInUserRights.data.isInternal && userOriginalHostnameValue();
103
104
  // eslint-disable-next-line react-hooks/exhaustive-deps
104
105
  }, []);
105
106
  const onShareHostNamesSwitch = () => __awaiter(this, void 0, void 0, function* () {
@@ -113,14 +113,14 @@
113
113
  align-items: flex-start;
114
114
 
115
115
  .toolbar-left {
116
- flex: 0 1 50%;
117
- width: 50%;
116
+ flex: 0 1 70%;
117
+ width: 70%;
118
118
  margin-bottom: 0;
119
119
  }
120
120
 
121
121
  .toolbar-right {
122
- flex: 1 1 35%;
123
- max-width: 35%;
122
+ flex: 1 1 28%;
123
+ max-width: 28%;
124
124
  margin-left: auto;
125
125
  }
126
126
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rh-support/manage",
3
- "version": "0.2.95",
3
+ "version": "0.2.98",
4
4
  "description": "Customer Support Manage App",
5
5
  "author": "Jordan Eudy <jeudy100@gmail.com>",
6
6
  "homepage": "",
@@ -78,7 +78,6 @@
78
78
  "@types/i18next": "^12.1.0",
79
79
  "@types/lodash": "^4.14.136",
80
80
  "@types/react": "^17.0.14",
81
- "@types/react-bootstrap-typeahead": "^5.1.3",
82
81
  "@types/react-dom": "^17.0.9",
83
82
  "@types/react-i18next": "^8.1.0",
84
83
  "@types/react-router-dom": "^5.1.2",
@@ -97,9 +96,9 @@
97
96
  "@patternfly/react-core": "4.202.16",
98
97
  "@patternfly/react-table": "4.71.16",
99
98
  "@rh-support/api": "0.3.24",
100
- "@rh-support/components": "1.1.76",
99
+ "@rh-support/components": "1.1.79",
101
100
  "@rh-support/configs": "0.2.5",
102
- "@rh-support/react-context": "0.2.82",
101
+ "@rh-support/react-context": "0.2.85",
103
102
  "@rh-support/types": "0.2.0",
104
103
  "@rh-support/user-permissions": "0.2.63",
105
104
  "@rh-support/utils": "0.2.46",
@@ -108,10 +107,9 @@
108
107
  "lodash": ">=4.17.15",
109
108
  "react": "17.0.2",
110
109
  "react-beautiful-dnd": "^13.0.0",
111
- "react-bootstrap-typeahead": "^5.1.4",
112
110
  "react-dom": "17.0.2",
113
111
  "react-i18next": ">=10.11.0",
114
112
  "react-router-dom": ">=5.1.2"
115
113
  },
116
- "gitHead": "1359173d6efb7ece2bd1d0760c001e053bc29893"
114
+ "gitHead": "acb137236b62e31aba70cda91755b3b94f0cb7da"
117
115
  }