@rh-support/manage 0.2.90 → 0.2.93

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.
package/README.md CHANGED
@@ -9,5 +9,3 @@ const manage = require('manage');
9
9
 
10
10
  // TODO: DEMONSTRATE API
11
11
  ```
12
-
13
- .
@@ -1 +1 @@
1
- {"version":3,"file":"PreferenceSwitch.d.ts","sourceRoot":"","sources":["../../../../../src/components/ManagePreferences/components/PreferenceSwitch.tsx"],"names":[],"mappings":"AAKA,UAAU,MAAM;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IACnD,SAAS,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,gBAAgB,CAAC,EAAE,cAAc,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,MAAM,eA6B3F"}
1
+ {"version":3,"file":"PreferenceSwitch.d.ts","sourceRoot":"","sources":["../../../../../src/components/ManagePreferences/components/PreferenceSwitch.tsx"],"names":[],"mappings":"AAKA,UAAU,MAAM;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IACnD,SAAS,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,gBAAgB,CAAC,EAAE,cAAc,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,MAAM,eA+B3F"}
@@ -29,5 +29,6 @@ export function PreferenceSwitch({ onSwitchChange, className, id, label, isCheck
29
29
  setIsSwitchLoading(false);
30
30
  }
31
31
  });
32
- return (React.createElement(Switch, { className: className, id: id, label: t(label), isChecked: isCheckedLocal, onChange: onChangeLocal, isDisabled: isSwitchLoading }));
32
+ return (React.createElement("div", null,
33
+ React.createElement(Switch, { className: className, id: id, label: t(label), isChecked: isCheckedLocal, onChange: onChangeLocal, isDisabled: isSwitchLoading })));
33
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PreferencesCaseSearch.d.ts","sourceRoot":"","sources":["../../../../../src/components/ManagePreferences/sections/PreferencesCaseSearch.tsx"],"names":[],"mappings":"AAYA,UAAU,MAAM;CAAG;AAEnB,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,eAwHlD"}
1
+ {"version":3,"file":"PreferencesCaseSearch.d.ts","sourceRoot":"","sources":["../../../../../src/components/ManagePreferences/sections/PreferencesCaseSearch.tsx"],"names":[],"mappings":"AAYA,UAAU,MAAM;CAAG;AAEnB,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,eA0GlD"}
@@ -10,17 +10,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { Card, CardBody, CardHeader, SelectOption } from '@patternfly/react-core';
11
11
  import { ToastNotification } from '@rh-support/components';
12
12
  import { UserPreferencesKeys } from '@rh-support/react-context';
13
+ import { isEmpty } from 'lodash';
13
14
  import find from 'lodash/find';
14
15
  import React, { useEffect, useState } from 'react';
15
16
  import { Trans, useTranslation } from 'react-i18next';
16
17
  import { useUserPreferences } from '../../../hooks/useUserPreferences';
17
18
  import { PreferenceSelect } from '../components/PreferenceSelect';
18
- import { PreferenceSwitch } from '../components/PreferenceSwitch';
19
19
  export function PreferencesCaseSearch(props) {
20
20
  const { t } = useTranslation();
21
- const { getAutoRestoreSavedSearchPreference, updateAutoRestoreSavedSearchPreference, getAutoRestoreLastSearchPreference, updateAutoRestoreLastSearchPreference, getAutoSaveSelectedColumnsPreference, updateAutoSaveSelectedColumnsPreference, hydraUserPreferences, } = useUserPreferences();
22
- const [isAutoRestoreChecked, setIsAutoRestoreChecked] = useState(false);
23
- const [isAutoSaveChecked, setIsAutoSaveChecked] = useState(false);
21
+ const { getAutoRestoreSavedSearchPreference, updateAutoRestoreSavedSearchPreference, getAutoRestoreLastSearchPreference, updateAutoRestoreLastSearchPreference, hydraUserPreferences, } = useUserPreferences();
24
22
  const [bookmarkedSearches, setBookmarkedSearches] = useState([]);
25
23
  const [originalSavedSearch, setOriginalSavedSearch] = useState('');
26
24
  const parseToBoolean = (value) => {
@@ -36,47 +34,55 @@ export function PreferencesCaseSearch(props) {
36
34
  }, [hydraUserPreferences.data]);
37
35
  const userOriginalSavedSearch = () => __awaiter(this, void 0, void 0, function* () {
38
36
  try {
39
- const originalSearch = yield getAutoRestoreSavedSearchPreference();
40
- setOriginalSavedSearch(originalSearch);
41
- }
42
- catch (_a) {
43
- ToastNotification.addWarningMessage(t('Failed to fetch original preference'));
44
- }
45
- });
46
- const userOriginalAutoRestoreLastSearch = () => __awaiter(this, void 0, void 0, function* () {
47
- try {
37
+ let originalSearch = yield getAutoRestoreSavedSearchPreference();
38
+ if (isEmpty(originalSearch)) {
39
+ originalSearch = emptySearchPlaceholderText;
40
+ }
48
41
  const originalLastSearchPref = yield getAutoRestoreLastSearchPreference();
49
42
  const parsedLastSearchPref = parseToBoolean(originalLastSearchPref);
50
- setIsAutoRestoreChecked(parsedLastSearchPref);
51
- }
52
- catch (_b) {
53
- ToastNotification.addWarningMessage(t('Failed to fetch original preference'));
54
- }
55
- });
56
- const userOriginalAutoSaveColumns = () => __awaiter(this, void 0, void 0, function* () {
57
- try {
58
- const originalColumnsPref = yield getAutoSaveSelectedColumnsPreference();
59
- const parsedColumnPref = parseToBoolean(originalColumnsPref);
60
- setIsAutoSaveChecked(parsedColumnPref);
43
+ if (parsedLastSearchPref) {
44
+ setOriginalSavedSearch(restoreLatestText);
45
+ }
46
+ else {
47
+ setOriginalSavedSearch(originalSearch);
48
+ }
61
49
  }
62
- catch (_c) {
50
+ catch (_a) {
63
51
  ToastNotification.addWarningMessage(t('Failed to fetch original preference'));
64
52
  }
65
53
  });
66
54
  useEffect(() => {
67
55
  userOriginalSavedSearch();
68
- userOriginalAutoRestoreLastSearch();
69
- userOriginalAutoSaveColumns();
70
56
  });
71
57
  const onSelect = (event, selection, isPlaceholder) => __awaiter(this, void 0, void 0, function* () {
72
- yield updateAutoRestoreSavedSearchPreference(selection);
73
- });
74
- const onAutoRestoreSwitchChange = (checked) => __awaiter(this, void 0, void 0, function* () {
75
- yield updateAutoRestoreLastSearchPreference(checked);
76
- });
77
- const onAutoSaveSwitchChange = (checked) => __awaiter(this, void 0, void 0, function* () {
78
- yield updateAutoSaveSelectedColumnsPreference(checked);
79
- });
58
+ if (selection !== restoreLatestText) {
59
+ try {
60
+ yield updateAutoRestoreSavedSearchPreference(selection);
61
+ yield updateAutoRestoreLastSearchPreference(false);
62
+ }
63
+ catch (error) {
64
+ console.log(error);
65
+ }
66
+ }
67
+ else if (selection === restoreLatestText) {
68
+ try {
69
+ yield updateAutoRestoreLastSearchPreference(true);
70
+ yield updateAutoRestoreSavedSearchPreference(restoreLatestText);
71
+ }
72
+ catch (error) {
73
+ console.log(error);
74
+ }
75
+ }
76
+ }); // if the getAutoRestoreLastSearchPreference is false, then we will use this check in bookmarkedsearchesselector to not use the getAutoRestoresavedSearchPref.
77
+ const restoreLatestText = 'Restore latest';
78
+ const emptySearchPlaceholderText = 'Select an option';
79
+ let emptyPlaceHolderOption = React.createElement(SelectOption, { key: 0, value: emptySearchPlaceholderText });
80
+ const appendRestoreLatest = () => {
81
+ let selectRestoreOptions = bookmarkedSearches.map((option, index) => (React.createElement(SelectOption, { key: 1 + index, value: option })));
82
+ selectRestoreOptions.push(React.createElement(SelectOption, { key: bookmarkedSearches.length + 1, value: restoreLatestText }));
83
+ let emptyPlaceHolderList = [emptyPlaceHolderOption].concat(selectRestoreOptions);
84
+ return emptyPlaceHolderList;
85
+ }; // we are now adding "restore last" as the last of the array and "select a saved search" as the first option.
80
86
  const titleId = 'auto-restore-preference-dropdown';
81
87
  return (React.createElement(Card, { className: "preference-card" },
82
88
  React.createElement(CardHeader, null,
@@ -85,8 +91,5 @@ export function PreferencesCaseSearch(props) {
85
91
  React.createElement(CardBody, null,
86
92
  React.createElement("form", null,
87
93
  React.createElement("div", { className: "form-group" },
88
- React.createElement(PreferenceSelect, { label: "Auto-restore my saved search", id: titleId, onSelect: onSelect, selections: originalSavedSearch }, bookmarkedSearches.map((option, index) => (React.createElement(SelectOption, { key: index, value: option }))))),
89
- React.createElement("div", { className: "form-group" },
90
- React.createElement(PreferenceSwitch, { className: "preference-page-switches", id: "auto-restore-last-search-switch", label: "Auto-restore last search", onSwitchChange: onAutoRestoreSwitchChange, isChecked: isAutoRestoreChecked }),
91
- React.createElement(PreferenceSwitch, { className: "preference-page-switches", id: "auto-save-columns-switch", label: "Auto-save selected table columns", onSwitchChange: onAutoSaveSwitchChange, isChecked: isAutoSaveChecked }))))));
94
+ React.createElement(PreferenceSelect, { label: "Auto-restore my saved search", id: titleId, onSelect: onSelect, selections: originalSavedSearch }, appendRestoreLatest()))))));
92
95
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PreferencesCaseView.d.ts","sourceRoot":"","sources":["../../../../../src/components/ManagePreferences/sections/PreferencesCaseView.tsx"],"names":[],"mappings":"AAUA,UAAU,MAAM;CAAG;AAEnB,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,eAiJhD"}
1
+ {"version":3,"file":"PreferencesCaseView.d.ts","sourceRoot":"","sources":["../../../../../src/components/ManagePreferences/sections/PreferencesCaseView.tsx"],"names":[],"mappings":"AAaA,UAAU,MAAM;CAAG;AAEnB,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,eA6JhD"}
@@ -7,17 +7,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { accounts } from '@cee-eng/hydrajs';
10
11
  import { Card, CardBody, CardHeader, SelectOption, Spinner, TextArea } from '@patternfly/react-core';
11
- import { EditorMode, ToastNotification } from '@rh-support/components';
12
+ import { EditorMode, ToastNotification, useFetch } from '@rh-support/components';
13
+ import { GlobalMetadataStateContext } from '@rh-support/react-context';
14
+ import { ability, CaseListFields, resourceActions, resources } from '@rh-support/user-permissions';
12
15
  import debounce from 'lodash/debounce';
13
- import React, { useEffect, useState } from 'react';
16
+ import React, { useContext, useEffect, useState } from 'react';
14
17
  import { Trans, useTranslation } from 'react-i18next';
15
18
  import { useUserPreferences } from '../../../hooks/useUserPreferences';
16
19
  import { PreferenceSelect } from '../components/PreferenceSelect';
17
20
  import { PreferenceSwitch } from '../components/PreferenceSwitch';
18
21
  export function PreferencesCaseView(props) {
19
22
  const { t } = useTranslation();
20
- const { updateCommentType, getCommentTypeFromPreference, getCommentSignature, updateCommentSignature, getShareHostNames, updateShareHostNames, } = useUserPreferences();
23
+ const { updateCommentType, getCommentTypeFromPreference, getCommentSignature, updateCommentSignature } = useUserPreferences();
21
24
  const [isSharingHostNames, setIsSharingHostNames] = useState(false);
22
25
  const [localCommentSignature, setLocalCommentSignature] = useState('');
23
26
  const [originalCommentType, setOriginalCommentType] = useState('');
@@ -25,25 +28,12 @@ export function PreferencesCaseView(props) {
25
28
  const [commentValidated, setCommentValidated] = useState('default');
26
29
  const [isCommentSignatureLoading, setIsCommentSignatureLoading] = useState(false);
27
30
  const commentTypes = [EditorMode.PLAIN, EditorMode.MARKDOWN];
28
- const parseToBoolean = (value) => {
29
- return value === 'true';
30
- };
31
- const userOriginalShareHostNames = () => __awaiter(this, void 0, void 0, function* () {
32
- try {
33
- const retrievedShareHostNames = yield getShareHostNames();
34
- const parsedShareHostNames = parseToBoolean(retrievedShareHostNames);
35
- setIsSharingHostNames(parsedShareHostNames);
36
- }
37
- catch (_a) {
38
- ToastNotification.addWarningMessage(t('Failed to fetch original preference'));
39
- }
40
- });
41
31
  const userOriginalCommentType = () => __awaiter(this, void 0, void 0, function* () {
42
32
  try {
43
33
  const retrievedComment = yield getCommentTypeFromPreference();
44
34
  setOriginalCommentType(retrievedComment);
45
35
  }
46
- catch (_b) {
36
+ catch (_a) {
47
37
  ToastNotification.addWarningMessage(t('Failed to fetch original preference'));
48
38
  }
49
39
  });
@@ -52,14 +42,13 @@ export function PreferencesCaseView(props) {
52
42
  const retrievedSignature = yield getCommentSignature();
53
43
  setOriginalCommentSignature(retrievedSignature);
54
44
  }
55
- catch (_c) {
45
+ catch (_b) {
56
46
  ToastNotification.addWarningMessage(t('Failed to fetch original preference'));
57
47
  }
58
48
  });
59
49
  useEffect(() => {
60
50
  userOriginalCommentSignature();
61
51
  userOriginalCommentType();
62
- userOriginalShareHostNames();
63
52
  });
64
53
  useEffect(() => {
65
54
  if (localCommentSignature === '' && commentValidated !== 'error') {
@@ -85,13 +74,39 @@ export function PreferencesCaseView(props) {
85
74
  setLocalCommentSignature(value);
86
75
  setIsCommentSignatureLoading(false);
87
76
  });
88
- const onShareHostNamesSwitch = (checked) => __awaiter(this, void 0, void 0, function* () {
89
- yield updateShareHostNames(checked);
90
- });
91
77
  const onSelect = (event, selection, isPlaceholder) => __awaiter(this, void 0, void 0, function* () {
92
78
  yield updateCommentType(selection);
93
79
  });
94
80
  const titleId = 'default-comment-preference-select';
81
+ const canUseHostName = ability.can(resourceActions.PATCH, resources.CASE_CREATE, CaseListFields.HOSTNAME);
82
+ const { globalMetadataState: { loggedInUsersAccount }, } = useContext(GlobalMetadataStateContext);
83
+ const { request: fetchHostnameDefault } = useFetch(accounts.getIsSharingHostname);
84
+ const accountNumber = loggedInUsersAccount.data.accountNumber;
85
+ const { request: updateShareHostnames } = useFetch(accounts.updateIsSharingHostname);
86
+ useEffect(() => {
87
+ function userOriginalHostnameValue() {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ try {
90
+ const fetchedHostnameStatus = yield fetchHostnameDefault(accountNumber);
91
+ setIsSharingHostNames(fetchedHostnameStatus.shareHostnameWithRHT);
92
+ }
93
+ catch (error) {
94
+ console.log(error);
95
+ }
96
+ });
97
+ }
98
+ userOriginalHostnameValue();
99
+ // eslint-disable-next-line react-hooks/exhaustive-deps
100
+ }, []);
101
+ const onShareHostNamesSwitch = () => __awaiter(this, void 0, void 0, function* () {
102
+ try {
103
+ yield updateShareHostnames(!isSharingHostNames, accountNumber);
104
+ setIsSharingHostNames(!isSharingHostNames);
105
+ }
106
+ catch (error) {
107
+ console.log(error);
108
+ }
109
+ });
95
110
  return (React.createElement(Card, { className: "preference-card" },
96
111
  React.createElement(CardHeader, null,
97
112
  React.createElement("h3", null,
@@ -107,8 +122,8 @@ export function PreferencesCaseView(props) {
107
122
  // @ts-ignore
108
123
  validated: commentValidated }),
109
124
  isCommentSignatureLoading && React.createElement(Spinner, { size: "md" })),
110
- React.createElement("div", { className: "form-group" },
125
+ canUseHostName && (React.createElement("div", { className: "form-group" },
111
126
  React.createElement("label", { htmlFor: "share-hostnames-switch" },
112
127
  React.createElement(Trans, null, "Case information")),
113
- React.createElement(PreferenceSwitch, { className: "switches", id: "share-hostnames-switch", label: "Share hostnames with Red Hat", isChecked: isSharingHostNames, onSwitchChange: onShareHostNamesSwitch }))))));
128
+ React.createElement(PreferenceSwitch, { className: "switches", id: "share-hostnames-switch", label: "Share hostnames with Red Hat", isChecked: isSharingHostNames, onSwitchChange: onShareHostNamesSwitch })))))));
114
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rh-support/manage",
3
- "version": "0.2.90",
3
+ "version": "0.2.93",
4
4
  "description": "Customer Support Manage App",
5
5
  "author": "Jordan Eudy <jeudy100@gmail.com>",
6
6
  "homepage": "",
@@ -56,7 +56,7 @@
56
56
  "@patternfly/pfe-accordion": "1.12.3",
57
57
  "@patternfly/pfe-collapse": "1.12.3",
58
58
  "@patternfly/pfe-tabs": "1.12.3",
59
- "@patternfly/react-core": "4.202.16",
59
+ "@patternfly/react-core": "4.224.1",
60
60
  "@patternfly/react-table": "4.71.16",
61
61
  "@rh-support/api": "0.3.9",
62
62
  "@rh-support/components": "^0.1.3",
@@ -94,14 +94,14 @@
94
94
  "@patternfly/pfe-accordion": "1.12.3",
95
95
  "@patternfly/pfe-collapse": "1.12.3",
96
96
  "@patternfly/pfe-tabs": "1.12.3",
97
- "@patternfly/react-core": "4.202.16",
97
+ "@patternfly/react-core": "4.224.1",
98
98
  "@patternfly/react-table": "4.71.16",
99
99
  "@rh-support/api": "0.3.24",
100
- "@rh-support/components": "1.1.72",
100
+ "@rh-support/components": "1.1.74",
101
101
  "@rh-support/configs": "0.2.5",
102
- "@rh-support/react-context": "0.2.77",
102
+ "@rh-support/react-context": "0.2.80",
103
103
  "@rh-support/types": "0.2.0",
104
- "@rh-support/user-permissions": "0.2.61",
104
+ "@rh-support/user-permissions": "0.2.62",
105
105
  "@rh-support/utils": "0.2.46",
106
106
  "@types/react-beautiful-dnd": "^13.0.0",
107
107
  "i18next": ">=17.0.1",
@@ -113,5 +113,5 @@
113
113
  "react-i18next": ">=10.11.0",
114
114
  "react-router-dom": ">=5.1.2"
115
115
  },
116
- "gitHead": "1d8c25adcf1bc30eb2560bf210f96994b63237e3"
116
+ "gitHead": "92d0e7c14067d191a4b8d1a12df459c61deca4c0"
117
117
  }