@copart/ops-tool-kit 1.12.4-alpha.2 → 1.12.4

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.
@@ -47,7 +47,7 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
47
47
  var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
48
48
 
49
49
  const name$r = "@copart/ops-tool-kit";
50
- const version$8 = "1.12.4-alpha.2";
50
+ const version$8 = "1.12.4";
51
51
  const main$1 = "dist/ops-tool-kit.js";
52
52
  const style = "dist/ops-tool-kit.css";
53
53
  const files = [
@@ -57669,6 +57669,8 @@ var MiHelpAgent = function MiHelpAgent(_ref) {
57669
57669
  };
57670
57670
  }, []);
57671
57671
  var chatBodyRef = React.useRef(null);
57672
+ var previousConversationLengthRef = React.useRef(conversations.length);
57673
+ var previousShowChatWindowRef = React.useRef(showChatWindow);
57672
57674
  var scroll = function scroll() {
57673
57675
  chatBodyRef.current && chatBodyRef.current.scrollTo({
57674
57676
  top: chatBodyRef.current.scrollHeight,
@@ -57829,10 +57831,19 @@ var MiHelpAgent = function MiHelpAgent(_ref) {
57829
57831
  }
57830
57832
  };
57831
57833
  React.useEffect(function () {
57832
- if (showChatWindow && conversations.length) {
57834
+ var conversationLengthChanged = previousConversationLengthRef.current !== conversations.length;
57835
+ var chatWindowJustOpened = !previousShowChatWindowRef.current && showChatWindow && conversations.length;
57836
+ if (showChatWindow && conversations.length && (conversationLengthChanged || chatWindowJustOpened)) {
57833
57837
  scroll();
57834
57838
  }
57839
+ previousConversationLengthRef.current = conversations.length;
57840
+ previousShowChatWindowRef.current = showChatWindow;
57835
57841
  }, [conversations, showChatWindow]);
57842
+ React.useEffect(function () {
57843
+ if (messageError) {
57844
+ scroll();
57845
+ }
57846
+ }, [messageError]);
57836
57847
  // useEffect(
57837
57848
  // () => {
57838
57849
  // if (!collection || typeof collection !== 'string') {
@@ -57949,36 +57960,55 @@ var MiHelpAgent = function MiHelpAgent(_ref) {
57949
57960
  var updateFeedback = /*#__PURE__*/function () {
57950
57961
  var _ref4 = _asyncToGenerator$1(/*#__PURE__*/_regenerator().m(function _callee3(feedback, Currentconversation, conversations) {
57951
57962
  var _storage$getLocalItem3, _storage$getLocalItem4;
57952
- var payload, endpoint, newConversations;
57963
+ var payload, feedbackEndpoint, endpoint, newConversations, _t3;
57953
57964
  return _regenerator().w(function (_context3) {
57954
- while (1) switch (_context3.n) {
57965
+ while (1) switch (_context3.p = _context3.n) {
57955
57966
  case 0:
57967
+ setMessageError(false);
57956
57968
  payload = {
57957
57969
  feedback: feedback
57958
57970
  };
57971
+ feedbackEndpoint = (_storage$getLocalItem3 = storage$1.getLocalItem('opsportal-core:config')) === null || _storage$getLocalItem3 === void 0 ? void 0 : (_storage$getLocalItem4 = _storage$getLocalItem3.endpoints) === null || _storage$getLocalItem4 === void 0 ? void 0 : _storage$getLocalItem4.mihelpChatFeedback;
57972
+ if (feedbackEndpoint) {
57973
+ _context3.n = 1;
57974
+ break;
57975
+ }
57976
+ console.log('MiHelpAgent: feedback endpoint missing from config');
57977
+ setMessageError(true);
57978
+ return _context3.a(2);
57979
+ case 1:
57980
+ endpoint = "".concat(feedbackEndpoint, "/").concat(Currentconversation === null || Currentconversation === void 0 ? void 0 : Currentconversation.feedbackId);
57959
57981
  setIsFeedbackLoading(true);
57960
- endpoint = "".concat((_storage$getLocalItem3 = storage$1.getLocalItem('opsportal-core:config')) === null || _storage$getLocalItem3 === void 0 ? void 0 : (_storage$getLocalItem4 = _storage$getLocalItem3.endpoints) === null || _storage$getLocalItem4 === void 0 ? void 0 : _storage$getLocalItem4.mihelpChatFeedback, "/").concat(Currentconversation === null || Currentconversation === void 0 ? void 0 : Currentconversation.feedbackId);
57961
- _context3.n = 1;
57982
+ _context3.p = 2;
57983
+ _context3.n = 3;
57962
57984
  return fetcher.put(endpoint, payload, {
57963
57985
  headers: {
57964
57986
  'Content-Type': 'application/json'
57965
57987
  }
57966
57988
  });
57967
- case 1:
57968
- _context3.v;
57969
- newConversations = clone$1(conversations).map(function (conversation) {
57970
- if ((conversation === null || conversation === void 0 ? void 0 : conversation.id) === (Currentconversation === null || Currentconversation === void 0 ? void 0 : Currentconversation.id)) {
57971
- conversation.feedback = feedback;
57972
- }
57973
- return conversation;
57989
+ case 3:
57990
+ newConversations = conversations.map(function (conversation) {
57991
+ return (conversation === null || conversation === void 0 ? void 0 : conversation.id) === (Currentconversation === null || Currentconversation === void 0 ? void 0 : Currentconversation.id) ? _objectSpread2(_objectSpread2({}, conversation), {}, {
57992
+ feedback: feedback
57993
+ }) : conversation;
57974
57994
  });
57975
57995
  setConversations(newConversations);
57976
- setIsFeedbackLoading(false);
57977
57996
  storage$1.setLocalItem('mihelpAgentConversations', newConversations);
57978
- case 2:
57997
+ _context3.n = 5;
57998
+ break;
57999
+ case 4:
58000
+ _context3.p = 4;
58001
+ _t3 = _context3.v;
58002
+ console.log('MiHelpAgent: failed to update feedback', _t3);
58003
+ setMessageError(true);
58004
+ case 5:
58005
+ _context3.p = 5;
58006
+ setIsFeedbackLoading(false);
58007
+ return _context3.f(5);
58008
+ case 6:
57979
58009
  return _context3.a(2);
57980
58010
  }
57981
- }, _callee3);
58011
+ }, _callee3, null, [[2, 4, 5, 6]]);
57982
58012
  }));
57983
58013
  return function updateFeedback(_x2, _x3, _x4) {
57984
58014
  return _ref4.apply(this, arguments);
@@ -57987,9 +58017,9 @@ var MiHelpAgent = function MiHelpAgent(_ref) {
57987
58017
  var handleFeedback = /*#__PURE__*/function () {
57988
58018
  var _ref5 = _asyncToGenerator$1(/*#__PURE__*/_regenerator().m(function _callee4(feedback, Currentconversation, conversations) {
57989
58019
  var _storage$getLocalItem5, _storage$getLocalItem6;
57990
- var conversationsUntilCurrentMessage, lastFeedbackIndex, chatHistoryAfterLastFeedback, chatHistoryWithoutSystemPrompts, payload, endpoint, response, newConversations, newFeedbacks;
58020
+ var conversationsUntilCurrentMessage, lastFeedbackIndex, chatHistoryAfterLastFeedback, chatHistoryWithoutSystemPrompts, payload, endpoint, response, newConversations, newFeedbacks, _t4;
57991
58021
  return _regenerator().w(function (_context4) {
57992
- while (1) switch (_context4.n) {
58022
+ while (1) switch (_context4.p = _context4.n) {
57993
58023
  case 0:
57994
58024
  if (!((Currentconversation === null || Currentconversation === void 0 ? void 0 : Currentconversation.feedback) === feedback)) {
57995
58025
  _context4.n = 1;
@@ -58003,6 +58033,7 @@ var MiHelpAgent = function MiHelpAgent(_ref) {
58003
58033
  }
58004
58034
  return _context4.a(2, updateFeedback(feedback, Currentconversation, conversations));
58005
58035
  case 2:
58036
+ setMessageError(false);
58006
58037
  conversationsUntilCurrentMessage = _toConsumableArray(conversations).slice(0, conversations.findIndex(function (c) {
58007
58038
  return (c === null || c === void 0 ? void 0 : c.id) === (Currentconversation === null || Currentconversation === void 0 ? void 0 : Currentconversation.id);
58008
58039
  }) + 1);
@@ -58024,34 +58055,51 @@ var MiHelpAgent = function MiHelpAgent(_ref) {
58024
58055
  user_email: storage$1.userEmail
58025
58056
  };
58026
58057
  endpoint = (_storage$getLocalItem5 = storage$1.getLocalItem('opsportal-core:config')) === null || _storage$getLocalItem5 === void 0 ? void 0 : (_storage$getLocalItem6 = _storage$getLocalItem5.endpoints) === null || _storage$getLocalItem6 === void 0 ? void 0 : _storage$getLocalItem6.mihelpChatFeedback;
58058
+ if (endpoint) {
58059
+ _context4.n = 3;
58060
+ break;
58061
+ }
58062
+ console.log('MiHelpAgent: feedback endpoint missing from config');
58063
+ setMessageError(true);
58064
+ return _context4.a(2);
58065
+ case 3:
58027
58066
  setIsFeedbackLoading(true);
58028
- _context4.n = 3;
58067
+ _context4.p = 4;
58068
+ _context4.n = 5;
58029
58069
  return fetcher.post(endpoint, payload, {
58030
58070
  headers: {
58031
58071
  'Content-Type': 'application/json'
58032
58072
  }
58033
58073
  });
58034
- case 3:
58074
+ case 5:
58035
58075
  response = _context4.v;
58036
- newConversations = clone$1(conversations).map(function (conversation) {
58037
- if ((conversation === null || conversation === void 0 ? void 0 : conversation.id) === (Currentconversation === null || Currentconversation === void 0 ? void 0 : Currentconversation.id)) {
58038
- var _response$data3;
58039
- conversation.feedback = feedback;
58040
- conversation.feedbackId = response === null || response === void 0 ? void 0 : (_response$data3 = response.data) === null || _response$data3 === void 0 ? void 0 : _response$data3.feedback_id;
58041
- }
58042
- return conversation;
58076
+ newConversations = conversations.map(function (conversation) {
58077
+ var _response$data3;
58078
+ return (conversation === null || conversation === void 0 ? void 0 : conversation.id) === (Currentconversation === null || Currentconversation === void 0 ? void 0 : Currentconversation.id) ? _objectSpread2(_objectSpread2({}, conversation), {}, {
58079
+ feedback: feedback,
58080
+ feedbackId: response === null || response === void 0 ? void 0 : (_response$data3 = response.data) === null || _response$data3 === void 0 ? void 0 : _response$data3.feedback_id
58081
+ }) : conversation;
58043
58082
  });
58044
- newFeedbacks = _objectSpread2({}, feedbacks);
58045
- newFeedbacks[Currentconversation === null || Currentconversation === void 0 ? void 0 : Currentconversation.id] = chatHistoryWithoutSystemPrompts;
58083
+ newFeedbacks = _objectSpread2(_objectSpread2({}, feedbacks), {}, _defineProperty$2({}, Currentconversation === null || Currentconversation === void 0 ? void 0 : Currentconversation.id, chatHistoryWithoutSystemPrompts));
58046
58084
  setFeedbacks(newFeedbacks);
58047
58085
  setConversations(newConversations);
58048
- setIsFeedbackLoading(false);
58049
58086
  storage$1.setLocalItem('mihelpAgentConversations', newConversations);
58050
58087
  storage$1.setLocalItem('mihelpAgentFeedbacks', newFeedbacks);
58051
- case 4:
58088
+ _context4.n = 7;
58089
+ break;
58090
+ case 6:
58091
+ _context4.p = 6;
58092
+ _t4 = _context4.v;
58093
+ console.log('MiHelpAgent: failed to submit feedback', _t4);
58094
+ setMessageError(true);
58095
+ case 7:
58096
+ _context4.p = 7;
58097
+ setIsFeedbackLoading(false);
58098
+ return _context4.f(7);
58099
+ case 8:
58052
58100
  return _context4.a(2);
58053
58101
  }
58054
- }, _callee4);
58102
+ }, _callee4, null, [[4, 6, 7, 8]]);
58055
58103
  }));
58056
58104
  return function handleFeedback(_x5, _x6, _x7) {
58057
58105
  return _ref5.apply(this, arguments);