@opengeoweb/taf 3.0.0 → 4.1.0

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/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@mui/material'), require('react-hook-form'), require('react-sortablejs'), require('lodash'), require('@opengeoweb/authentication'), require('@opengeoweb/form-fields'), require('@opengeoweb/shared'), require('moment'), require('@opengeoweb/theme'), require('@mui/styles/makeStyles'), require('react-dom'), require('@opengeoweb/api'), require('@mui/material/LinearProgress'), require('@mui/material/Box')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react', '@mui/material', 'react-hook-form', 'react-sortablejs', 'lodash', '@opengeoweb/authentication', '@opengeoweb/form-fields', '@opengeoweb/shared', 'moment', '@opengeoweb/theme', '@mui/styles/makeStyles', 'react-dom', '@opengeoweb/api', '@mui/material/LinearProgress', '@mui/material/Box'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Taf = {}, global.React, global.material, global.reactHookForm, global.reactSortablejs, global.lodash, global.authentication, global.formFields, global.shared, global.moment, global.theme, global.makeStyles, global.ReactDOM, global.api, global.LinearProgress, global.Box));
5
- })(this, (function (exports, React, material, reactHookForm, reactSortablejs, lodash, authentication, formFields, shared, moment, theme, makeStyles, ReactDOM, api, LinearProgress, Box) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@mui/material'), require('react-hook-form'), require('react-redux'), require('react-sortablejs'), require('lodash'), require('@opengeoweb/authentication'), require('@opengeoweb/form-fields'), require('@opengeoweb/shared'), require('@opengeoweb/core'), require('moment'), require('@opengeoweb/theme'), require('react-dom'), require('@opengeoweb/api'), require('@mui/material/LinearProgress'), require('@mui/material/Box')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'react', '@mui/material', 'react-hook-form', 'react-redux', 'react-sortablejs', 'lodash', '@opengeoweb/authentication', '@opengeoweb/form-fields', '@opengeoweb/shared', '@opengeoweb/core', 'moment', '@opengeoweb/theme', 'react-dom', '@opengeoweb/api', '@mui/material/LinearProgress', '@mui/material/Box'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Taf = {}, global.React, global.material, global.reactHookForm, global.reactRedux, global.reactSortablejs, global.lodash, global.authentication, global.formFields, global.shared, global.core, global.moment, global.theme, global.ReactDOM, global.api, global.LinearProgress, global.Box));
5
+ })(this, (function (exports, React, material, reactHookForm, reactRedux, reactSortablejs, lodash, authentication, formFields, shared, core, moment, theme, ReactDOM, api, LinearProgress, Box) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -27,7 +27,6 @@
27
27
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
28
28
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
29
29
  var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
30
- var makeStyles__default = /*#__PURE__*/_interopDefaultLegacy(makeStyles);
31
30
  var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
32
31
  var LinearProgress__default = /*#__PURE__*/_interopDefaultLegacy(LinearProgress);
33
32
  var Box__default = /*#__PURE__*/_interopDefaultLegacy(Box);
@@ -2317,7 +2316,11 @@
2317
2316
  var tacHasError = function tacHasError(tac) {
2318
2317
  return tac === TAC_MISSING_DATA || tac === TAC_NOT_AVAILABLE || tac === TAC_RETRIEVING_DATA || tac === TAC_FAILED;
2319
2318
  };
2320
- var useTACGenerator = function useTACGenerator(taf, requestTAC) {
2319
+ var useTACGenerator = function useTACGenerator(taf, requestTAC, getJSON) {
2320
+ if (getJSON === void 0) {
2321
+ getJSON = false;
2322
+ }
2323
+
2321
2324
  var _a = __read(React__default["default"].useState(!taf || taf.status === 'NEW' ? TAC_NOT_AVAILABLE : TAC_RETRIEVING_DATA), 2),
2322
2325
  TAC = _a[0],
2323
2326
  setTAC = _a[1];
@@ -2341,7 +2344,7 @@
2341
2344
 
2342
2345
  controller.current = new AbortController();
2343
2346
  setTAC(TAC_RETRIEVING_DATA);
2344
- requestTAC(tafToPost, controller.current.signal).then(function (result) {
2347
+ requestTAC(tafToPost, getJSON, controller.current.signal).then(function (result) {
2345
2348
  if (isMounted.current) {
2346
2349
  setTAC(result.data);
2347
2350
  }
@@ -2353,7 +2356,7 @@
2353
2356
  } else {
2354
2357
  setTAC(TAC_MISSING_DATA);
2355
2358
  }
2356
- }, [isMounted, requestTAC]);
2359
+ }, [isMounted, requestTAC, getJSON]);
2357
2360
  React__default["default"].useEffect(function () {
2358
2361
  if (taf && taf.status !== 'NEW') {
2359
2362
  retrieveTAC(taf);
@@ -3515,19 +3518,6 @@
3515
3518
  * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3516
3519
  * Copyright 2021 - Finnish Meteorological Institute (FMI)
3517
3520
  * */
3518
- var useStyles = makeStyles__default["default"](function () {
3519
- return {
3520
- dragHandle: {
3521
- backgroundColor: 'transparent',
3522
- '&:hover': {
3523
- backgroundColor: 'transparent'
3524
- },
3525
- cursor: function cursor(isSorting) {
3526
- return isSorting ? 'grabbing' : 'grab';
3527
- }
3528
- }
3529
- };
3530
- });
3531
3521
 
3532
3522
  var DragHandle = function DragHandle(_a) {
3533
3523
  var _b = _a.isSorting,
@@ -3535,13 +3525,21 @@
3535
3525
  _c = _a.isDisabled,
3536
3526
  isDisabled = _c === void 0 ? false : _c,
3537
3527
  index = _a.index;
3538
- var classes = useStyles(isSorting);
3539
3528
  return /*#__PURE__*/React__default["default"].createElement(material.IconButton, {
3540
- className: classes.dragHandle + " handle",
3529
+ className: "handle",
3541
3530
  "data-testid": "dragHandle-" + index,
3542
3531
  disableRipple: true,
3543
3532
  disabled: isDisabled,
3544
- size: "large"
3533
+ size: "large",
3534
+ sx: {
3535
+ backgroundColor: 'transparent',
3536
+ '&:hover': {
3537
+ backgroundColor: 'transparent'
3538
+ },
3539
+ cursor: function cursor() {
3540
+ return isSorting ? 'grabbing' : 'grab';
3541
+ }
3542
+ }
3545
3543
  }, /*#__PURE__*/React__default["default"].createElement(theme.DragHandle, null));
3546
3544
  };
3547
3545
 
@@ -3966,6 +3964,9 @@
3966
3964
 
3967
3965
  var noop = function noop() {};
3968
3966
 
3967
+ var getSnackbarMessage$2 = function getSnackbarMessage(isChecked, location) {
3968
+ return "You are now " + (isChecked ? '' : 'no longer ') + "the editor for TAF " + location;
3969
+ };
3969
3970
  var TafForm = /*#__PURE__*/React__default["default"].memo(function (_a) {
3970
3971
  var tafFromBackend = _a.tafFromBackend,
3971
3972
  _b = _a.onFormAction,
@@ -3991,6 +3992,7 @@
3991
3992
  var originalTaf = tafFromBackend.taf,
3992
3993
  editor = tafFromBackend.editor;
3993
3994
  var auth = authentication.useAuthenticationContext().auth;
3995
+ var dispatch = reactRedux.useDispatch();
3994
3996
  var isEditor = editor === (auth === null || auth === void 0 ? void 0 : auth.username) || false;
3995
3997
  var isDefaultDisabled = getIsFormDefaultDisabled(originalTaf.status);
3996
3998
  var confirmDialog = shared.useConfirmationDialog();
@@ -4098,6 +4100,12 @@
4098
4100
  setTafAction(action);
4099
4101
  };
4100
4102
 
4103
+ var showSnackbar = React__default["default"].useCallback(function (message) {
4104
+ dispatch(core.snackbarActions.openSnackbar({
4105
+ message: message
4106
+ }));
4107
+ }, [dispatch]);
4108
+
4101
4109
  var setIsEditor = function setIsEditor(checked) {
4102
4110
  return __awaiter(void 0, void 0, void 0, function () {
4103
4111
  var editor, didSucceed;
@@ -4138,6 +4146,11 @@
4138
4146
 
4139
4147
  case 3:
4140
4148
  didSucceed = _a.sent();
4149
+
4150
+ if (didSucceed) {
4151
+ showSnackbar(getSnackbarMessage$2(checked, originalTaf.location));
4152
+ }
4153
+
4141
4154
  return [2
4142
4155
  /*return*/
4143
4156
  , didSucceed];
@@ -4441,8 +4454,8 @@
4441
4454
  alignItems: 'center',
4442
4455
  position: 'absolute',
4443
4456
  top: {
4444
- xs: '20px',
4445
- sm: '0px'
4457
+ xs: '34px',
4458
+ sm: '-3px'
4446
4459
  },
4447
4460
  right: {
4448
4461
  xs: 'calc(50% - 70px)',
@@ -4467,11 +4480,15 @@
4467
4480
  sx: {
4468
4481
  fontSize: '20px',
4469
4482
  fontWeight: 500,
4470
- height: '24px'
4483
+ height: '24px',
4484
+ display: 'flex',
4485
+ alignItems: 'center'
4471
4486
  }
4472
4487
  }, "TAC"), /*#__PURE__*/React__default["default"].createElement(material.Typography, {
4473
4488
  sx: {
4474
- fontSize: '14px',
4489
+ fontSize: '12px',
4490
+ lineHeight: 1.67,
4491
+ letterSpacing: '0.21px',
4475
4492
  margin: '8px 0px'
4476
4493
  },
4477
4494
  "data-testid": "form-tac-message"
@@ -4597,7 +4614,7 @@
4597
4614
  sx: __assign({
4598
4615
  textAlign: 'center',
4599
4616
  fontWeight: 500,
4600
- paddingTop: '6px',
4617
+ paddingTop: '4px',
4601
4618
  textTransform: 'capitalize'
4602
4619
  }, sx)
4603
4620
  }, title);
@@ -4663,17 +4680,32 @@
4663
4680
  return locationSettings[location];
4664
4681
  };
4665
4682
  var sortTafsOnLocation = function sortTafsOnLocation(tafList, locationOrder) {
4683
+ if (tafList === void 0) {
4684
+ tafList = [];
4685
+ }
4686
+
4666
4687
  if (locationOrder === void 0) {
4667
4688
  locationOrder = tafSettings.locationOrder;
4668
4689
  }
4669
4690
 
4670
- if (!tafList) return [];
4671
4691
  return __spreadArray([], __read(tafList)).sort(function (_a, _b) {
4672
4692
  var tafA = _a.taf;
4673
4693
  var tafB = _b.taf;
4674
4694
  return locationOrder.indexOf(tafA.location) < locationOrder.indexOf(tafB.location) ? -1 : 1;
4675
4695
  });
4676
4696
  };
4697
+ var sortTafsOnIssueDate = function sortTafsOnIssueDate(tafList) {
4698
+ if (tafList === void 0) {
4699
+ tafList = [];
4700
+ }
4701
+
4702
+ return __spreadArray([], __read(tafList)).sort(function (_a, _b) {
4703
+ var tafA = _a.taf;
4704
+ var tafB = _b.taf;
4705
+ if (tafA.issueDate < tafB.issueDate || tafA.issueDate && !tafB.issueDate) return -1;
4706
+ return 1;
4707
+ });
4708
+ };
4677
4709
  var getBaseTime = function getBaseTime(baseTime, location) {
4678
4710
  var currentBaseTime = moment__default["default"].utc(baseTime);
4679
4711
  var activityPeriod = getLocationSetting(location).activity_period;
@@ -4701,7 +4733,8 @@
4701
4733
  return 'UPCOMING';
4702
4734
  };
4703
4735
  var sortTafTimeSlots = function sortTafTimeSlots(tafList) {
4704
- var sortedListOnLocation = sortTafsOnLocation(tafList);
4736
+ var sortedListOnIssueDate = sortTafsOnIssueDate(tafList);
4737
+ var sortedListOnLocation = sortTafsOnLocation(sortedListOnIssueDate);
4705
4738
  return sortedListOnLocation.reduce(function (sortedTafList, tafFromBackend) {
4706
4739
  var taf = tafFromBackend.taf;
4707
4740
  var timeSlot = getTafTimeSlot(taf.baseTime, taf.location, taf.status);
@@ -4741,6 +4774,29 @@
4741
4774
  changeGroups: changeGroups
4742
4775
  });
4743
4776
  };
4777
+ var getNewTafLocationIndex = function getNewTafLocationIndex(tafLocations, previousTafLocationUUID) {
4778
+ var newActiveIndexForDraft = tafLocations.findIndex(function (location) {
4779
+ var _a;
4780
+
4781
+ return ((_a = location === null || location === void 0 ? void 0 : location.taf) === null || _a === void 0 ? void 0 : _a.previousId) === previousTafLocationUUID;
4782
+ });
4783
+
4784
+ if (newActiveIndexForDraft !== -1) {
4785
+ return newActiveIndexForDraft;
4786
+ }
4787
+
4788
+ var newActiveIndexForPublished = tafLocations.findIndex(function (location) {
4789
+ var _a;
4790
+
4791
+ return ((_a = location === null || location === void 0 ? void 0 : location.taf) === null || _a === void 0 ? void 0 : _a.uuid) === previousTafLocationUUID;
4792
+ });
4793
+
4794
+ if (newActiveIndexForPublished !== -1) {
4795
+ return newActiveIndexForPublished;
4796
+ }
4797
+
4798
+ return 0;
4799
+ };
4744
4800
 
4745
4801
  /* *
4746
4802
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -4845,17 +4901,70 @@
4845
4901
  * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
4846
4902
  * Copyright 2022 - Finnish Meteorological Institute (FMI)
4847
4903
  * */
4904
+ var TOOLTIP_TITLE = 'Import TAC';
4848
4905
 
4849
4906
  var ExportButton = function ExportButton(_a) {
4850
4907
  var onClick = _a.onClick,
4851
4908
  isHidden = _a.isHidden;
4852
4909
  return isHidden ? null : /*#__PURE__*/React__default["default"].createElement(material.Tooltip, {
4853
- title: "Import TAC",
4910
+ title: TOOLTIP_TITLE,
4854
4911
  placement: "left"
4855
- }, /*#__PURE__*/React__default["default"].createElement("span", null, /*#__PURE__*/React__default["default"].createElement(shared.ToolButton, {
4912
+ }, /*#__PURE__*/React__default["default"].createElement(shared.ToolButton, {
4856
4913
  onClick: onClick,
4857
4914
  "data-testid": "export-tac-button"
4858
- }, /*#__PURE__*/React__default["default"].createElement(theme.Export, null))));
4915
+ }, /*#__PURE__*/React__default["default"].createElement(theme.Export, null)));
4916
+ };
4917
+
4918
+ /* *
4919
+ * Licensed under the Apache License, Version 2.0 (the "License");
4920
+ * you may not use this file except in compliance with the License.
4921
+ * You may obtain a copy of the License at
4922
+ *
4923
+ * http://www.apache.org/licenses/LICENSE-2.0
4924
+ *
4925
+ * Unless required by applicable law or agreed to in writing, software
4926
+ * distributed under the License is distributed on an "AS IS" BASIS,
4927
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4928
+ * See the License for the specific language governing permissions and
4929
+ * limitations under the License.
4930
+ *
4931
+ * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
4932
+ * Copyright 2022 - Finnish Meteorological Institute (FMI)
4933
+ * */
4934
+ var AdverseWeatherTACMessage = function AdverseWeatherTACMessage(_a) {
4935
+ var TAC = _a.TAC,
4936
+ isActive = _a.isActive;
4937
+ return /*#__PURE__*/React__default["default"].createElement(Box__default["default"], {
4938
+ "data-testid": "adverse-weather-tac",
4939
+ sx: {
4940
+ fontSize: '12px',
4941
+ lineHeight: '16px',
4942
+ letterSpacing: '0.4px',
4943
+ color: 'geowebColors.captions.captionStatus.rgba'
4944
+ }
4945
+ }, TAC.tac.map(function (line, index) {
4946
+ return /*#__PURE__*/React__default["default"].createElement(Box__default["default"], {
4947
+ key: line.toString() + index.toString(),
4948
+ component: "span",
4949
+ sx: {
4950
+ display: 'inline-block'
4951
+ }
4952
+ }, line.map(function (word, index) {
4953
+ return /*#__PURE__*/React__default["default"].createElement(Box__default["default"], {
4954
+ key: word.text + index.toString(),
4955
+ component: "span",
4956
+ sx: __assign(__assign({
4957
+ display: 'inline',
4958
+ boxDecorationBreak: 'clone',
4959
+ WebkitBoxDecorationBreak: 'clone'
4960
+ }, isActive && {
4961
+ backgroundColor: 'geowebColors.functional.warningHighlight.rgba'
4962
+ }), word.type === 'adverse' && {
4963
+ color: 'geowebColors.captions.captionError.rgba'
4964
+ })
4965
+ }, word.text === '=' ? "" + word.text : " " + word.text);
4966
+ }));
4967
+ }));
4859
4968
  };
4860
4969
 
4861
4970
  /* *
@@ -4874,6 +4983,9 @@
4874
4983
  * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
4875
4984
  * Copyright 2022 - Finnish Meteorological Institute (FMI)
4876
4985
  * */
4986
+ var getSnackbarMessage$1 = function getSnackbarMessage(location, locationLabel) {
4987
+ return "TAF " + location + " " + locationLabel + " was imported successfully";
4988
+ };
4877
4989
 
4878
4990
  var TacContainer = function TacContainer(_a) {
4879
4991
  var taf = _a.taf,
@@ -4882,8 +4994,9 @@
4882
4994
  _c = _a.isFormDisabled,
4883
4995
  isFormDisabled = _c === void 0 ? false : _c;
4884
4996
  var api$1 = api.useApiContext().api;
4997
+ var dispatch = reactRedux.useDispatch();
4885
4998
 
4886
- var _d = __read(useTACGenerator(taf, api$1.getTAC), 2),
4999
+ var _d = __read(useTACGenerator(taf, api$1.getTAC, true), 2),
4887
5000
  TAC = _d[0],
4888
5001
  retrieveTAC = _d[1];
4889
5002
 
@@ -4899,6 +5012,11 @@
4899
5012
  setValue = _e.setValue;
4900
5013
 
4901
5014
  var updateTAC = useTafModuleContext().updateTAC;
5015
+ var showSnackbar = React__default["default"].useCallback(function (message) {
5016
+ dispatch(core.snackbarActions.openSnackbar({
5017
+ message: message
5018
+ }));
5019
+ }, [dispatch]);
4902
5020
 
4903
5021
  var handleExport = function handleExport() {
4904
5022
  var currentTaf = getValues();
@@ -4913,6 +5031,7 @@
4913
5031
  trigger(); // trigger all fields validation
4914
5032
  }, 0);
4915
5033
  updateTAC(convertTafValuesToObject(newTaf));
5034
+ showSnackbar(getSnackbarMessage$1(location, locationLabel));
4916
5035
  };
4917
5036
 
4918
5037
  React__default["default"].useEffect(function () {
@@ -4982,23 +5101,18 @@
4982
5101
  letterSpacing: '0.4px',
4983
5102
  color: 'geowebColors.captions.captionStatus.rgba'
4984
5103
  }
4985
- }, TAC.split('\n').map(function (line) {
4986
- return /*#__PURE__*/React__default["default"].createElement(material.Box, {
4987
- component: "span",
4988
- key: line,
4989
- sx: {
4990
- display: 'inline-block'
4991
- }
4992
- }, /*#__PURE__*/React__default["default"].createElement(material.Box, {
4993
- component: "span",
4994
- sx: __assign({
4995
- display: 'inline',
4996
- boxDecorationBreak: 'clone',
4997
- WebkitBoxDecorationBreak: 'clone'
4998
- }, isActive && {
4999
- backgroundColor: 'geowebColors.functional.warningHighlight.rgba'
5000
- })
5001
- }, line));
5104
+ }, typeof TAC === 'string' ? /*#__PURE__*/React__default["default"].createElement(material.Box, {
5105
+ component: "span",
5106
+ sx: __assign({
5107
+ display: 'inline',
5108
+ boxDecorationBreak: 'clone',
5109
+ WebkitBoxDecorationBreak: 'clone'
5110
+ }, isActive && {
5111
+ backgroundColor: 'geowebColors.functional.warningHighlight.rgba'
5112
+ })
5113
+ }, TAC) : /*#__PURE__*/React__default["default"].createElement(AdverseWeatherTACMessage, {
5114
+ TAC: TAC,
5115
+ isActive: isActive
5002
5116
  })));
5003
5117
  };
5004
5118
 
@@ -5145,8 +5259,8 @@
5145
5259
  sm: 'none'
5146
5260
  },
5147
5261
  position: 'absolute',
5148
- right: '8px',
5149
- top: '48px'
5262
+ right: '4px',
5263
+ top: '82px'
5150
5264
  }
5151
5265
  }, /*#__PURE__*/React__namespace.createElement(theme.ListItem, null)), /*#__PURE__*/React__namespace.createElement(material.Dialog, {
5152
5266
  open: isOpen,
@@ -5597,7 +5711,10 @@
5597
5711
  shouldClose: true
5598
5712
  }), /*#__PURE__*/React__default["default"].createElement(material.Box, {
5599
5713
  sx: {
5600
- marginTop: '10px',
5714
+ marginTop: {
5715
+ xs: '44px',
5716
+ sm: '10px'
5717
+ },
5601
5718
  padding: 1
5602
5719
  }
5603
5720
  }, /*#__PURE__*/React__default["default"].createElement(TafForm, {
@@ -5664,7 +5781,10 @@
5664
5781
  "data-testid": "updateTafBtn",
5665
5782
  onClick: onUpdateTaf,
5666
5783
  sx: {
5667
- marginRight: 1,
5784
+ marginRight: {
5785
+ xs: 2,
5786
+ sm: 1
5787
+ },
5668
5788
  marginLeft: 1
5669
5789
  }
5670
5790
  }, /*#__PURE__*/React__default["default"].createElement(theme.Cached, null))));
@@ -5675,6 +5795,51 @@
5675
5795
  description: "It's not possible to autosave this TAF due to the presence of issue(s). Are you sure you want to close this TAF? Any changes made will be lost.",
5676
5796
  confirmLabel: 'Exit without saving'
5677
5797
  };
5798
+ var getTafMessagePrefix = function getTafMessagePrefix(_a, newStatus) {
5799
+ var location = _a.location,
5800
+ validDateStart = _a.validDateStart,
5801
+ messageType = _a.messageType;
5802
+ var formattedDate = formatBaseTime(moment__default["default"].utc(validDateStart));
5803
+ return "TAF " + location + " " + formattedDate + " " + messageType + " was " + newStatus + " successfully";
5804
+ };
5805
+ var getSnackbarMessage = function getSnackbarMessage(tafFromFrontEnd, isAutoSaved) {
5806
+ if (isAutoSaved === void 0) {
5807
+ isAutoSaved = false;
5808
+ }
5809
+
5810
+ var changeStatusTo = tafFromFrontEnd.changeStatusTo,
5811
+ taf = tafFromFrontEnd.taf;
5812
+
5813
+ if (isAutoSaved) {
5814
+ return 'All changes have been saved automatically';
5815
+ }
5816
+
5817
+ switch (changeStatusTo) {
5818
+ case 'DRAFT':
5819
+ return 'Saved as draft';
5820
+
5821
+ case 'DRAFT_AMENDED':
5822
+ return 'Saved as draft amended';
5823
+
5824
+ case 'DRAFT_CORRECTED':
5825
+ return 'Saved as draft correction';
5826
+
5827
+ case 'PUBLISHED':
5828
+ return getTafMessagePrefix(taf, 'published');
5829
+
5830
+ case 'CANCELLED':
5831
+ return getTafMessagePrefix(taf, 'cancelled');
5832
+
5833
+ case 'CORRECTED':
5834
+ return getTafMessagePrefix(taf, 'corrected');
5835
+
5836
+ case 'AMENDED':
5837
+ return getTafMessagePrefix(taf, 'amended');
5838
+
5839
+ default:
5840
+ return getTafMessagePrefix(taf, 'saved');
5841
+ }
5842
+ };
5678
5843
 
5679
5844
  var TafLayout = function TafLayout(_a) {
5680
5845
  var _b = _a.tafList,
@@ -5683,6 +5848,7 @@
5683
5848
  onUpdateTaf = _c === void 0 ? function () {} : _c,
5684
5849
  lastUpdateTime = _a.lastUpdateTime;
5685
5850
  var api$1 = api.useApiContext().api;
5851
+ var dispatch = reactRedux.useDispatch();
5686
5852
  var confirmDialog = shared.useConfirmationDialog();
5687
5853
 
5688
5854
  var _d = useIssuesPane(),
@@ -5735,7 +5901,17 @@
5735
5901
  error = _q[0],
5736
5902
  setError = _q[1];
5737
5903
 
5738
- var postTaf = function postTaf(data) {
5904
+ var showSnackbar = React__default["default"].useCallback(function (message) {
5905
+ dispatch(core.snackbarActions.openSnackbar({
5906
+ message: message
5907
+ }));
5908
+ }, [dispatch]);
5909
+
5910
+ var postTaf = function postTaf(data, isAutoSaved) {
5911
+ if (isAutoSaved === void 0) {
5912
+ isAutoSaved = false;
5913
+ }
5914
+
5739
5915
  return __awaiter(void 0, void 0, void 0, function () {
5740
5916
  var error_1;
5741
5917
  return __generator(this, function (_a) {
@@ -5749,8 +5925,9 @@
5749
5925
  , postTafRequest(data)];
5750
5926
 
5751
5927
  case 1:
5752
- _a.sent(); // callback
5928
+ _a.sent();
5753
5929
 
5930
+ showSnackbar(getSnackbarMessage(data, isAutoSaved)); // callback
5754
5931
 
5755
5932
  onUpdateTaf();
5756
5933
  return [3
@@ -5836,7 +6013,7 @@
5836
6013
  , postTaf({
5837
6014
  taf: taf,
5838
6015
  changeStatusTo: fromActionToStatus(tafActionToDraftAction(tafAction))
5839
- })];
6016
+ }, true)];
5840
6017
 
5841
6018
  case 3:
5842
6019
  _a.sent();
@@ -5890,18 +6067,16 @@
5890
6067
  };
5891
6068
 
5892
6069
  React__default["default"].useEffect(function () {
6070
+ var _a, _b;
6071
+
5893
6072
  var newSortedTafs = sortTafTimeSlots(tafList);
5894
6073
  var updatedLocations = timeSlot === 'ACTIVE' ? newSortedTafs.current : newSortedTafs.upcoming;
5895
6074
  updateSortedTafs(sortTafTimeSlots(tafList));
5896
6075
  setLocations(updatedLocations); // update active index
5897
6076
 
5898
- var newActiveIndex = updatedLocations.findIndex(function (location) {
5899
- var _a, _b, _c;
5900
-
5901
- return ((_a = location === null || location === void 0 ? void 0 : location.taf) === null || _a === void 0 ? void 0 : _a.previousId) === ((_c = (_b = locations[activeTafIndex]) === null || _b === void 0 ? void 0 : _b.taf) === null || _c === void 0 ? void 0 : _c.uuid);
5902
- });
5903
- var newIndex = newActiveIndex !== -1 ? newActiveIndex : activeTafIndex;
5904
- setActiveTafIndex(newIndex); // eslint-disable-next-line react-hooks/exhaustive-deps
6077
+ var previousActiveLocationUUID = (_b = (_a = locations[activeTafIndex]) === null || _a === void 0 ? void 0 : _a.taf) === null || _b === void 0 ? void 0 : _b.uuid;
6078
+ var newTafLocationIndex = getNewTafLocationIndex(updatedLocations, previousActiveLocationUUID);
6079
+ setActiveTafIndex(newTafLocationIndex); // eslint-disable-next-line react-hooks/exhaustive-deps
5905
6080
  }, [tafList, setLocations]);
5906
6081
  React__default["default"].useEffect(function () {
5907
6082
  setError(postError);
@@ -5918,7 +6093,7 @@
5918
6093
  setError(patchError);
5919
6094
  }, [patchError]);
5920
6095
 
5921
- if (!tafList) {
6096
+ if (!tafList || !tafList.length) {
5922
6097
  return null;
5923
6098
  }
5924
6099
 
@@ -6167,20 +6342,22 @@
6167
6342
  return /*#__PURE__*/React__namespace.createElement(TafWrapper, __assign({}, props), /*#__PURE__*/React__namespace.createElement(TafModule, null));
6168
6343
  };
6169
6344
 
6170
- var createApi$1 = function createApi(url, appUrl, auth, setAuth, authTokenUrl, authClientId) {
6171
- var axiosInstance = api.createApiInstance(url, appUrl, auth, setAuth, authTokenUrl, authClientId);
6345
+ var getApiRoutes$1 = function getApiRoutes(axiosInstance) {
6172
6346
  return {
6173
- // api data
6174
6347
  getTafList: function getTafList() {
6175
6348
  return axiosInstance.get('/taflist');
6176
6349
  },
6177
6350
  postTaf: function postTaf(formData) {
6178
6351
  return axiosInstance.post('/taf', __assign({}, formData));
6179
6352
  },
6180
- getTAC: function getTAC(tafData, signal) {
6181
- return axiosInstance.post.apply(axiosInstance, __spreadArray(['/taf2tac'], __read(__spreadArray([__assign({}, tafData)], __read(signal ? [{
6353
+ getTAC: function getTAC(tafData, getJSON, signal) {
6354
+ return axiosInstance.post('/taf2tac', tafData, __assign(__assign({}, signal ? {
6182
6355
  signal: signal
6183
- }] : [])))));
6356
+ } : {}), {
6357
+ headers: {
6358
+ Accept: getJSON ? 'application/json' : 'text/plain'
6359
+ }
6360
+ }));
6184
6361
  },
6185
6362
  patchTaf: function patchTaf(formData) {
6186
6363
  return axiosInstance.patch('/taf', __assign({}, formData));
@@ -6188,25 +6365,12 @@
6188
6365
  };
6189
6366
  };
6190
6367
 
6191
- /* *
6192
- * Licensed under the Apache License, Version 2.0 (the "License");
6193
- * you may not use this file except in compliance with the License.
6194
- * You may obtain a copy of the License at
6195
- *
6196
- * http://www.apache.org/licenses/LICENSE-2.0
6197
- *
6198
- * Unless required by applicable law or agreed to in writing, software
6199
- * distributed under the License is distributed on an "AS IS" BASIS,
6200
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6201
- * See the License for the specific language governing permissions and
6202
- * limitations under the License.
6203
- *
6204
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
6205
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
6206
- * */
6368
+ var createApi$1 = function createApi(props) {
6369
+ var axiosInstance = api.createApiInstance(props);
6370
+ return getApiRoutes$1(axiosInstance);
6371
+ };
6207
6372
 
6208
6373
  var MOCK_USERNAME = 'user.name';
6209
-
6210
6374
  var currentDate = moment__default["default"].utc().format('YYYY-MM-DD');
6211
6375
  var tomorrowDate = moment__default["default"].utc().add(1, 'day').format('YYYY-MM-DD');
6212
6376
  var airportPeriod = 6;
@@ -7005,7 +7169,6 @@
7005
7169
  taf: {
7006
7170
  uuid: '954905487',
7007
7171
  previousId: '5f9583fjdf45ff4330f337925',
7008
- issueDate: currentDate + "T14:00:00Z",
7009
7172
  baseTime: currentDate + "T12:00:00Z",
7010
7173
  validDateStart: currentDate + "T14:00:00Z",
7011
7174
  validDateEnd: tomorrowDate + "T18:00:00Z",
@@ -7065,7 +7228,6 @@
7065
7228
  editor: null,
7066
7229
  taf: __assign(__assign({}, fakeDraftAmendmentTaf.taf), {
7067
7230
  location: 'EHRD',
7068
- issueDate: "2022-01-06T14:00:00Z",
7069
7231
  baseTime: "2022-01-06T12:00:00Z",
7070
7232
  validDateStart: "2022-01-06T14:00:00Z",
7071
7233
  validDateEnd: "2022-01-07T18:00:00Z",
@@ -7146,23 +7308,37 @@
7146
7308
  });
7147
7309
 
7148
7310
  var fakeTafTac = 'TAF EHAM 0812/0918 20020G35KT 0500 SN BKN040\nBECMG 0814/0816 0700 BKN001=';
7149
-
7150
- var fakePromise = function fakePromise(withRandomError, signal) {
7151
- if (signal === void 0) {
7152
- signal = null;
7153
- }
7154
-
7155
- return new Promise(function (resolve, reject) {
7156
- var timer = setTimeout(function () {
7157
- if (!withRandomError) return resolve();
7158
- var randomError = Math.floor(Math.random() * 4) + 1;
7159
- return randomError === 4 ? reject(new Error('something went wrong')) : resolve();
7160
- }, 300);
7161
- signal === null || signal === void 0 ? void 0 : signal.signal.addEventListener('abort', function () {
7162
- clearTimeout(timer);
7163
- reject(new Error('canceled'));
7164
- });
7165
- });
7311
+ var fakeTafTacJson = {
7312
+ tac: [[{
7313
+ text: 'TAF'
7314
+ }, {
7315
+ text: 'EHAM'
7316
+ }, {
7317
+ text: '0812/0918'
7318
+ }, {
7319
+ text: '20020G35KT',
7320
+ type: 'adverse'
7321
+ }, {
7322
+ text: '0500',
7323
+ type: 'adverse'
7324
+ }, {
7325
+ text: 'SN',
7326
+ type: 'adverse'
7327
+ }, {
7328
+ text: 'BKN040'
7329
+ }], [{
7330
+ text: 'BECMG'
7331
+ }, {
7332
+ text: '0814/0816'
7333
+ }, {
7334
+ text: '0700',
7335
+ type: 'adverse'
7336
+ }, {
7337
+ text: 'BKN001',
7338
+ type: 'adverse'
7339
+ }, {
7340
+ text: '='
7341
+ }]]
7166
7342
  };
7167
7343
 
7168
7344
  var fakeUpdatedTafList = __spreadArray([], __read(fakeTafList));
@@ -7170,29 +7346,17 @@
7170
7346
  var setFakeUpdatedList = function setFakeUpdatedList(newList) {
7171
7347
  fakeUpdatedTafList = newList;
7172
7348
  };
7349
+
7173
7350
  var getFakeUpdatedList = function getFakeUpdatedList() {
7174
7351
  return fakeUpdatedTafList;
7175
7352
  };
7176
- var fakeAxiosInstance = {
7177
- // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars, @typescript-eslint/explicit-module-boundary-types
7178
- get: function get(_url, _params) {
7179
- return fakePromise(false);
7180
- },
7181
- // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars, @typescript-eslint/explicit-module-boundary-types
7182
- post: function post(_url, _params, _signal) {
7183
- return fakePromise(false, _signal);
7184
- },
7185
- // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars, @typescript-eslint/explicit-module-boundary-types
7186
- patch: function patch(_url, _params, _signal) {
7187
- return fakePromise(false, _signal);
7188
- }
7189
- };
7190
- var createApi = function createApi() {
7353
+
7354
+ var getApiRoutes = function getApiRoutes(axiosInstance) {
7191
7355
  return {
7192
7356
  getTafList: function getTafList() {
7193
7357
  // eslint-disable-next-line no-console
7194
7358
  console.log('Retrieving new TAF list');
7195
- return fakeAxiosInstance.get('/taflist').then(function () {
7359
+ return axiosInstance.get('/taflist').then(function () {
7196
7360
  return {
7197
7361
  data: getFakeUpdatedList()
7198
7362
  };
@@ -7203,14 +7367,18 @@
7203
7367
  console.log("The new status of the taf will be " + _postTaf.changeStatusTo); // eslint-disable-next-line no-console
7204
7368
 
7205
7369
  console.log('form has been posted with following values:', _postTaf.taf);
7206
- return fakeAxiosInstance.post('/taf', _postTaf);
7370
+ return axiosInstance.post('/taf', _postTaf);
7207
7371
  },
7208
- getTAC: function getTAC(tafData, signal) {
7209
- return fakeAxiosInstance.post.apply(fakeAxiosInstance, __spreadArray(['/taf2tac'], __read(__spreadArray([__assign({}, tafData)], __read(signal ? [{
7372
+ getTAC: function getTAC(taf, getJSON, signal) {
7373
+ return axiosInstance.post('/taf2tac', taf, __assign(__assign({}, signal ? {
7210
7374
  signal: signal
7211
- }] : []))))).then(function () {
7375
+ } : {}), {
7376
+ headers: {
7377
+ Accept: getJSON ? 'application/json' : 'text/plain'
7378
+ }
7379
+ })).then(function () {
7212
7380
  return {
7213
- data: fakeTafTac
7381
+ data: getJSON ? fakeTafTacJson : fakeTafTac
7214
7382
  };
7215
7383
  });
7216
7384
  },
@@ -7227,11 +7395,16 @@
7227
7395
  setFakeUpdatedList(updatedList); // eslint-disable-next-line no-console
7228
7396
 
7229
7397
  console.log("The new editor of the taf will be " + (_patchTaf.editor || 'empty'));
7230
- return fakeAxiosInstance.patch('/taf', _patchTaf);
7398
+ return axiosInstance.patch('/taf', _patchTaf);
7231
7399
  }
7232
7400
  };
7233
7401
  };
7234
7402
 
7403
+ var createApi = function createApi() {
7404
+ var instance = api.createFakeApiInstance();
7405
+ return getApiRoutes(instance);
7406
+ };
7407
+
7235
7408
  /* *
7236
7409
  * Licensed under the Apache License, Version 2.0 (the "License");
7237
7410
  * you may not use this file except in compliance with the License.
@@ -7270,13 +7443,15 @@
7270
7443
  onSetAuth = _a.onSetAuth,
7271
7444
  onPreventCloseView = _a.onPreventCloseView;
7272
7445
  return config ? /*#__PURE__*/React__namespace.createElement(api.ApiProvider, {
7273
- baseURL: config.baseUrl,
7274
- appURL: config.appUrl,
7446
+ config: {
7447
+ baseURL: config.baseURL,
7448
+ appURL: config.baseURL,
7449
+ authTokenURL: config.authTokenURL,
7450
+ authClientId: config.authClientId
7451
+ },
7275
7452
  auth: auth,
7276
7453
  onSetAuth: onSetAuth,
7277
- createApi: createApi$1,
7278
- authTokenUrl: config.authTokenUrl,
7279
- authClientId: config.authClientId
7454
+ createApi: createApi$1
7280
7455
  }, /*#__PURE__*/React__namespace.createElement(shared.ErrorBoundary, null, /*#__PURE__*/React__namespace.createElement(Wrapper, {
7281
7456
  onPreventCloseView: onPreventCloseView
7282
7457
  }))) : null;