@opengeoweb/taf 4.0.0 → 4.2.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.esm.js CHANGED
@@ -2,11 +2,13 @@ import * as React from 'react';
2
2
  import React__default from 'react';
3
3
  import { TextField, Grid, Box, Button, IconButton, Tooltip, Chip, Typography, FormLabel, Switch, Card, Tabs, Tab, Dialog, MenuList, MenuItem, Backdrop, CircularProgress } from '@mui/material';
4
4
  import { useFormContext, Controller, useFieldArray } from 'react-hook-form';
5
+ import { useDispatch } from 'react-redux';
5
6
  import { ReactSortable, Sortable } from 'react-sortablejs';
6
7
  import { isEqual } from 'lodash';
7
8
  import { useAuthenticationContext } from '@opengeoweb/authentication';
8
9
  import { getDeepProperty, ReactHookFormHiddenInput, ReactHookFormProvider } from '@opengeoweb/form-fields';
9
10
  import { useIsMounted, ToggleMenu, useDraftFormHelpers, ToolContainerDraggable, Avatar, getInitials, useConfirmationDialog, usePreventBrowserClose, ToolButton, ToolHeader, AlertBanner, getErrorMessage as getErrorMessage$1, getWarningMessage, ConfirmationServiceProvider, usePoller, ErrorBoundary } from '@opengeoweb/shared';
11
+ import { snackbarActions } from '@opengeoweb/core';
10
12
  import moment from 'moment';
11
13
  import { Add, Delete, Close, DragHandle as DragHandle$1, ThumbsUp, Clock, Cancel, Edit, Success, Export, ListItem, Cached } from '@opengeoweb/theme';
12
14
  import ReactDOM from 'react-dom';
@@ -2314,6 +2316,8 @@ var tacHasError = function tacHasError(tac) {
2314
2316
  return tac === TAC_MISSING_DATA || tac === TAC_NOT_AVAILABLE || tac === TAC_RETRIEVING_DATA || tac === TAC_FAILED;
2315
2317
  };
2316
2318
  var useTACGenerator = function useTACGenerator(taf, requestTAC) {
2319
+ var getJSON = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
2320
+
2317
2321
  var _React$useState = React__default.useState(!taf || taf.status === 'NEW' ? TAC_NOT_AVAILABLE : TAC_RETRIEVING_DATA),
2318
2322
  _React$useState2 = _slicedToArray(_React$useState, 2),
2319
2323
  TAC = _React$useState2[0],
@@ -2340,7 +2344,7 @@ var useTACGenerator = function useTACGenerator(taf, requestTAC) {
2340
2344
 
2341
2345
  controller.current = new AbortController();
2342
2346
  setTAC(TAC_RETRIEVING_DATA);
2343
- requestTAC(tafToPost, controller.current.signal).then(function (result) {
2347
+ requestTAC(tafToPost, getJSON, controller.current.signal).then(function (result) {
2344
2348
  if (isMounted.current) {
2345
2349
  setTAC(result.data);
2346
2350
  }
@@ -2352,7 +2356,7 @@ var useTACGenerator = function useTACGenerator(taf, requestTAC) {
2352
2356
  } else {
2353
2357
  setTAC(TAC_MISSING_DATA);
2354
2358
  }
2355
- }, [isMounted, requestTAC]);
2359
+ }, [isMounted, requestTAC, getJSON]);
2356
2360
  React__default.useEffect(function () {
2357
2361
  if (taf && taf.status !== 'NEW') {
2358
2362
  retrieveTAC(taf);
@@ -3990,6 +3994,9 @@ var TafAvatar = function TafAvatar(_ref) {
3990
3994
 
3991
3995
  var noop = function noop() {};
3992
3996
 
3997
+ var getSnackbarMessage$2 = function getSnackbarMessage(isChecked, location) {
3998
+ return "You are now ".concat(isChecked ? '' : 'no longer ', "the editor for TAF ").concat(location);
3999
+ };
3993
4000
  var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
3994
4001
  var tafFromBackend = _ref.tafFromBackend,
3995
4002
  _ref$onFormAction = _ref.onFormAction,
@@ -4018,6 +4025,7 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4018
4025
  var _useAuthenticationCon = useAuthenticationContext(),
4019
4026
  auth = _useAuthenticationCon.auth;
4020
4027
 
4028
+ var dispatch = useDispatch();
4021
4029
  var isEditor = editor === (auth === null || auth === void 0 ? void 0 : auth.username) || false;
4022
4030
  var isDefaultDisabled = getIsFormDefaultDisabled(originalTaf.status);
4023
4031
  var confirmDialog = useConfirmationDialog();
@@ -4123,6 +4131,12 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4123
4131
  setTafAction(action);
4124
4132
  };
4125
4133
 
4134
+ var showSnackbar = React__default.useCallback(function (message) {
4135
+ dispatch(snackbarActions.openSnackbar({
4136
+ message: message
4137
+ }));
4138
+ }, [dispatch]);
4139
+
4126
4140
  var setIsEditor = function setIsEditor(checked) {
4127
4141
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
4128
4142
  var editor, didSucceed;
@@ -4160,9 +4174,14 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4160
4174
 
4161
4175
  case 8:
4162
4176
  didSucceed = _context.sent;
4177
+
4178
+ if (didSucceed) {
4179
+ showSnackbar(getSnackbarMessage$2(checked, originalTaf.location));
4180
+ }
4181
+
4163
4182
  return _context.abrupt("return", didSucceed);
4164
4183
 
4165
- case 10:
4184
+ case 11:
4166
4185
  case "end":
4167
4186
  return _context.stop();
4168
4187
  }
@@ -4452,8 +4471,8 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4452
4471
  alignItems: 'center',
4453
4472
  position: 'absolute',
4454
4473
  top: {
4455
- xs: '20px',
4456
- sm: '0px'
4474
+ xs: '34px',
4475
+ sm: '-3px'
4457
4476
  },
4458
4477
  right: {
4459
4478
  xs: 'calc(50% - 70px)',
@@ -4478,11 +4497,15 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4478
4497
  sx: {
4479
4498
  fontSize: '20px',
4480
4499
  fontWeight: 500,
4481
- height: '24px'
4500
+ height: '24px',
4501
+ display: 'flex',
4502
+ alignItems: 'center'
4482
4503
  }
4483
4504
  }, "TAC"), /*#__PURE__*/React__default.createElement(Typography, {
4484
4505
  sx: {
4485
- fontSize: '14px',
4506
+ fontSize: '12px',
4507
+ lineHeight: 1.67,
4508
+ letterSpacing: '0.21px',
4486
4509
  margin: '8px 0px'
4487
4510
  },
4488
4511
  "data-testid": "form-tac-message"
@@ -4625,7 +4648,7 @@ var TafHeader = function TafHeader(_ref) {
4625
4648
  sx: Object.assign({
4626
4649
  textAlign: 'center',
4627
4650
  fontWeight: 500,
4628
- paddingTop: '6px',
4651
+ paddingTop: '4px',
4629
4652
  textTransform: 'capitalize'
4630
4653
  }, sx)
4631
4654
  }, title);
@@ -4687,15 +4710,24 @@ var getLocationSetting = function getLocationSetting(location) {
4687
4710
  var locationSettings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : tafSettings.locations;
4688
4711
  return locationSettings[location];
4689
4712
  };
4690
- var sortTafsOnLocation = function sortTafsOnLocation(tafList) {
4713
+ var sortTafsOnLocation = function sortTafsOnLocation() {
4714
+ var tafList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
4691
4715
  var locationOrder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : tafSettings.locationOrder;
4692
- if (!tafList) return [];
4693
4716
  return _toConsumableArray(tafList).sort(function (_ref, _ref2) {
4694
4717
  var tafA = _ref.taf;
4695
4718
  var tafB = _ref2.taf;
4696
4719
  return locationOrder.indexOf(tafA.location) < locationOrder.indexOf(tafB.location) ? -1 : 1;
4697
4720
  });
4698
4721
  };
4722
+ var sortTafsOnIssueDate = function sortTafsOnIssueDate() {
4723
+ var tafList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
4724
+ return _toConsumableArray(tafList).sort(function (_ref3, _ref4) {
4725
+ var tafA = _ref3.taf;
4726
+ var tafB = _ref4.taf;
4727
+ if (tafA.issueDate < tafB.issueDate || tafA.issueDate && !tafB.issueDate) return -1;
4728
+ return 1;
4729
+ });
4730
+ };
4699
4731
  var getBaseTime = function getBaseTime(baseTime, location) {
4700
4732
  var currentBaseTime = moment.utc(baseTime);
4701
4733
  var activityPeriod = getLocationSetting(location).activity_period;
@@ -4723,7 +4755,8 @@ var getTafTimeSlot = function getTafTimeSlot(baseTime, location, status) {
4723
4755
  return 'UPCOMING';
4724
4756
  };
4725
4757
  var sortTafTimeSlots = function sortTafTimeSlots(tafList) {
4726
- var sortedListOnLocation = sortTafsOnLocation(tafList);
4758
+ var sortedListOnIssueDate = sortTafsOnIssueDate(tafList);
4759
+ var sortedListOnLocation = sortTafsOnLocation(sortedListOnIssueDate);
4727
4760
  return sortedListOnLocation.reduce(function (sortedTafList, tafFromBackend) {
4728
4761
  var taf = tafFromBackend.taf;
4729
4762
  var timeSlot = getTafTimeSlot(taf.baseTime, taf.location, taf.status);
@@ -4763,6 +4796,29 @@ var prepareTafExportValues = function prepareTafExportValues(tafToCopy, currentT
4763
4796
  changeGroups: changeGroups
4764
4797
  });
4765
4798
  };
4799
+ var getNewTafLocationIndex = function getNewTafLocationIndex(tafLocations, previousTafLocationUUID) {
4800
+ var newActiveIndexForDraft = tafLocations.findIndex(function (location) {
4801
+ var _a;
4802
+
4803
+ return ((_a = location === null || location === void 0 ? void 0 : location.taf) === null || _a === void 0 ? void 0 : _a.previousId) === previousTafLocationUUID;
4804
+ });
4805
+
4806
+ if (newActiveIndexForDraft !== -1) {
4807
+ return newActiveIndexForDraft;
4808
+ }
4809
+
4810
+ var newActiveIndexForPublished = tafLocations.findIndex(function (location) {
4811
+ var _a;
4812
+
4813
+ return ((_a = location === null || location === void 0 ? void 0 : location.taf) === null || _a === void 0 ? void 0 : _a.uuid) === previousTafLocationUUID;
4814
+ });
4815
+
4816
+ if (newActiveIndexForPublished !== -1) {
4817
+ return newActiveIndexForPublished;
4818
+ }
4819
+
4820
+ return 0;
4821
+ };
4766
4822
 
4767
4823
  /* *
4768
4824
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -4881,6 +4937,62 @@ var ExportButton = function ExportButton(_ref) {
4881
4937
  }, /*#__PURE__*/React__default.createElement(Export, null)));
4882
4938
  };
4883
4939
 
4940
+ /* *
4941
+ * Licensed under the Apache License, Version 2.0 (the "License");
4942
+ * you may not use this file except in compliance with the License.
4943
+ * You may obtain a copy of the License at
4944
+ *
4945
+ * http://www.apache.org/licenses/LICENSE-2.0
4946
+ *
4947
+ * Unless required by applicable law or agreed to in writing, software
4948
+ * distributed under the License is distributed on an "AS IS" BASIS,
4949
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4950
+ * See the License for the specific language governing permissions and
4951
+ * limitations under the License.
4952
+ *
4953
+ * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
4954
+ * Copyright 2022 - Finnish Meteorological Institute (FMI)
4955
+ * */
4956
+ var AdverseWeatherTACMessage = function AdverseWeatherTACMessage(_ref) {
4957
+ var TAC = _ref.TAC,
4958
+ isActive = _ref.isActive;
4959
+ return /*#__PURE__*/React__default.createElement(Box$1, {
4960
+ "data-testid": "adverse-weather-tac",
4961
+ sx: {
4962
+ fontSize: '12px',
4963
+ lineHeight: '16px',
4964
+ letterSpacing: '0.4px',
4965
+ color: 'geowebColors.captions.captionStatus.rgba'
4966
+ }
4967
+ }, TAC.tac.map(function (line, index) {
4968
+ return /*#__PURE__*/React__default.createElement(Box$1, {
4969
+ key: line.toString() + index.toString(),
4970
+ component: "span",
4971
+ sx: {
4972
+ display: 'inline-block'
4973
+ }
4974
+ }, line.map(function (word, index) {
4975
+ return /*#__PURE__*/React__default.createElement(Box$1, {
4976
+ key: word.text + index.toString(),
4977
+ component: "span",
4978
+ sx: Object.assign(Object.assign({
4979
+ display: 'inline',
4980
+ boxDecorationBreak: 'clone',
4981
+ WebkitBoxDecorationBreak: 'clone'
4982
+ }, isActive && {
4983
+ backgroundColor: 'geowebColors.functional.warningHighlight.rgba'
4984
+ }), word.type === 'adverse' && {
4985
+ color: 'geowebColors.captions.captionError.rgba'
4986
+ })
4987
+ }, word.text === '=' ? "".concat(word.text) : " ".concat(word.text));
4988
+ }));
4989
+ }));
4990
+ };
4991
+
4992
+ var getSnackbarMessage$1 = function getSnackbarMessage(location, locationLabel) {
4993
+ return "TAF ".concat(location, " ").concat(locationLabel, " was imported successfully");
4994
+ };
4995
+
4884
4996
  var TacContainer = function TacContainer(_ref) {
4885
4997
  var taf = _ref.taf,
4886
4998
  _ref$isActive = _ref.isActive,
@@ -4891,7 +5003,9 @@ var TacContainer = function TacContainer(_ref) {
4891
5003
  var _useApiContext = useApiContext(),
4892
5004
  api = _useApiContext.api;
4893
5005
 
4894
- var _useTACGenerator = useTACGenerator(taf, api.getTAC),
5006
+ var dispatch = useDispatch();
5007
+
5008
+ var _useTACGenerator = useTACGenerator(taf, api.getTAC, true),
4895
5009
  _useTACGenerator2 = _slicedToArray(_useTACGenerator, 2),
4896
5010
  TAC = _useTACGenerator2[0],
4897
5011
  retrieveTAC = _useTACGenerator2[1];
@@ -4910,6 +5024,12 @@ var TacContainer = function TacContainer(_ref) {
4910
5024
  var _useTafModuleContext = useTafModuleContext(),
4911
5025
  updateTAC = _useTafModuleContext.updateTAC;
4912
5026
 
5027
+ var showSnackbar = React__default.useCallback(function (message) {
5028
+ dispatch(snackbarActions.openSnackbar({
5029
+ message: message
5030
+ }));
5031
+ }, [dispatch]);
5032
+
4913
5033
  var handleExport = function handleExport() {
4914
5034
  var currentTaf = getValues();
4915
5035
  var newTaf = prepareTafExportValues(taf, currentTaf);
@@ -4923,6 +5043,7 @@ var TacContainer = function TacContainer(_ref) {
4923
5043
  trigger(); // trigger all fields validation
4924
5044
  }, 0);
4925
5045
  updateTAC(convertTafValuesToObject(newTaf));
5046
+ showSnackbar(getSnackbarMessage$1(location, locationLabel));
4926
5047
  };
4927
5048
 
4928
5049
  React__default.useEffect(function () {
@@ -4992,23 +5113,18 @@ var TacContainer = function TacContainer(_ref) {
4992
5113
  letterSpacing: '0.4px',
4993
5114
  color: 'geowebColors.captions.captionStatus.rgba'
4994
5115
  }
4995
- }, TAC.split('\n').map(function (line) {
4996
- return /*#__PURE__*/React__default.createElement(Box, {
4997
- component: "span",
4998
- key: line,
4999
- sx: {
5000
- display: 'inline-block'
5001
- }
5002
- }, /*#__PURE__*/React__default.createElement(Box, {
5003
- component: "span",
5004
- sx: Object.assign({
5005
- display: 'inline',
5006
- boxDecorationBreak: 'clone',
5007
- WebkitBoxDecorationBreak: 'clone'
5008
- }, isActive && {
5009
- backgroundColor: 'geowebColors.functional.warningHighlight.rgba'
5010
- })
5011
- }, line));
5116
+ }, typeof TAC === 'string' ? /*#__PURE__*/React__default.createElement(Box, {
5117
+ component: "span",
5118
+ sx: Object.assign({
5119
+ display: 'inline',
5120
+ boxDecorationBreak: 'clone',
5121
+ WebkitBoxDecorationBreak: 'clone'
5122
+ }, isActive && {
5123
+ backgroundColor: 'geowebColors.functional.warningHighlight.rgba'
5124
+ })
5125
+ }, TAC) : /*#__PURE__*/React__default.createElement(AdverseWeatherTACMessage, {
5126
+ TAC: TAC,
5127
+ isActive: isActive
5012
5128
  })));
5013
5129
  };
5014
5130
 
@@ -5157,8 +5273,8 @@ var TacOverviewMobile = function TacOverviewMobile(_ref) {
5157
5273
  sm: 'none'
5158
5274
  },
5159
5275
  position: 'absolute',
5160
- right: '8px',
5161
- top: '48px'
5276
+ right: '4px',
5277
+ top: '82px'
5162
5278
  }
5163
5279
  }, /*#__PURE__*/React.createElement(ListItem, null)), /*#__PURE__*/React.createElement(Dialog, {
5164
5280
  open: isOpen,
@@ -5201,7 +5317,6 @@ var TacOverviewMobile = function TacOverviewMobile(_ref) {
5201
5317
  * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
5202
5318
  * Copyright 2022 - Finnish Meteorological Institute (FMI)
5203
5319
  * */
5204
-
5205
5320
  var formatBaseTime = function formatBaseTime(time) {
5206
5321
  return time.format('HH:mm DD MMM');
5207
5322
  };
@@ -5597,7 +5712,10 @@ var TafPanel = function TafPanel(_ref) {
5597
5712
  shouldClose: true
5598
5713
  }), /*#__PURE__*/React__default.createElement(Box, {
5599
5714
  sx: {
5600
- marginTop: '10px',
5715
+ marginTop: {
5716
+ xs: '44px',
5717
+ sm: '10px'
5718
+ },
5601
5719
  padding: 1
5602
5720
  }
5603
5721
  }, /*#__PURE__*/React__default.createElement(TafForm, {
@@ -5683,7 +5801,10 @@ var LastUpdateTime = function LastUpdateTime(_ref) {
5683
5801
  "data-testid": "updateTafBtn",
5684
5802
  onClick: onUpdateTaf,
5685
5803
  sx: {
5686
- marginRight: 1,
5804
+ marginRight: {
5805
+ xs: 2,
5806
+ sm: 1
5807
+ },
5687
5808
  marginLeft: 1
5688
5809
  }
5689
5810
  }, /*#__PURE__*/React__default.createElement(Cached, null))));
@@ -5694,17 +5815,60 @@ var CONFIRM_DIALOG_OPTIONS = {
5694
5815
  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.",
5695
5816
  confirmLabel: 'Exit without saving'
5696
5817
  };
5818
+ var getTafMessagePrefix = function getTafMessagePrefix(_ref, newStatus) {
5819
+ var location = _ref.location,
5820
+ validDateStart = _ref.validDateStart,
5821
+ messageType = _ref.messageType;
5822
+ var formattedDate = formatBaseTime(moment.utc(validDateStart));
5823
+ return "TAF ".concat(location, " ").concat(formattedDate, " ").concat(messageType, " was ").concat(newStatus, " successfully");
5824
+ };
5825
+ var getSnackbarMessage = function getSnackbarMessage(tafFromFrontEnd) {
5826
+ var isAutoSaved = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
5827
+ var changeStatusTo = tafFromFrontEnd.changeStatusTo,
5828
+ taf = tafFromFrontEnd.taf;
5697
5829
 
5698
- var TafLayout = function TafLayout(_ref) {
5699
- var _ref$tafList = _ref.tafList,
5700
- tafList = _ref$tafList === void 0 ? [] : _ref$tafList,
5701
- _ref$onUpdateTaf = _ref.onUpdateTaf,
5702
- onUpdateTaf = _ref$onUpdateTaf === void 0 ? function () {} : _ref$onUpdateTaf,
5703
- lastUpdateTime = _ref.lastUpdateTime;
5830
+ if (isAutoSaved) {
5831
+ return 'All changes have been saved automatically';
5832
+ }
5833
+
5834
+ switch (changeStatusTo) {
5835
+ case 'DRAFT':
5836
+ return 'Saved as draft';
5837
+
5838
+ case 'DRAFT_AMENDED':
5839
+ return 'Saved as draft amended';
5840
+
5841
+ case 'DRAFT_CORRECTED':
5842
+ return 'Saved as draft correction';
5843
+
5844
+ case 'PUBLISHED':
5845
+ return getTafMessagePrefix(taf, 'published');
5846
+
5847
+ case 'CANCELLED':
5848
+ return getTafMessagePrefix(taf, 'cancelled');
5849
+
5850
+ case 'CORRECTED':
5851
+ return getTafMessagePrefix(taf, 'corrected');
5852
+
5853
+ case 'AMENDED':
5854
+ return getTafMessagePrefix(taf, 'amended');
5855
+
5856
+ default:
5857
+ return getTafMessagePrefix(taf, 'saved');
5858
+ }
5859
+ };
5860
+
5861
+ var TafLayout = function TafLayout(_ref2) {
5862
+ var _ref2$tafList = _ref2.tafList,
5863
+ tafList = _ref2$tafList === void 0 ? [] : _ref2$tafList,
5864
+ _ref2$onUpdateTaf = _ref2.onUpdateTaf,
5865
+ onUpdateTaf = _ref2$onUpdateTaf === void 0 ? function () {} : _ref2$onUpdateTaf,
5866
+ lastUpdateTime = _ref2.lastUpdateTime;
5704
5867
 
5705
5868
  var _useApiContext = useApiContext(),
5706
5869
  api = _useApiContext.api;
5707
5870
 
5871
+ var dispatch = useDispatch();
5708
5872
  var confirmDialog = useConfirmationDialog();
5709
5873
 
5710
5874
  var _useIssuesPane = useIssuesPane(),
@@ -5764,7 +5928,14 @@ var TafLayout = function TafLayout(_ref) {
5764
5928
  error = _React$useState12[0],
5765
5929
  setError = _React$useState12[1];
5766
5930
 
5931
+ var showSnackbar = React__default.useCallback(function (message) {
5932
+ dispatch(snackbarActions.openSnackbar({
5933
+ message: message
5934
+ }));
5935
+ }, [dispatch]);
5936
+
5767
5937
  var postTaf = function postTaf(data) {
5938
+ var isAutoSaved = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
5768
5939
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
5769
5940
  return regeneratorRuntime.wrap(function _callee$(_context) {
5770
5941
  while (1) {
@@ -5776,13 +5947,14 @@ var TafLayout = function TafLayout(_ref) {
5776
5947
  return postTafRequest(data);
5777
5948
 
5778
5949
  case 4:
5779
- // callback
5950
+ showSnackbar(getSnackbarMessage(data, isAutoSaved)); // callback
5951
+
5780
5952
  onUpdateTaf();
5781
- _context.next = 11;
5953
+ _context.next = 12;
5782
5954
  break;
5783
5955
 
5784
- case 7:
5785
- _context.prev = 7;
5956
+ case 8:
5957
+ _context.prev = 8;
5786
5958
  _context.t0 = _context["catch"](0);
5787
5959
 
5788
5960
  if (isWarning(_context.t0)) {
@@ -5791,12 +5963,12 @@ var TafLayout = function TafLayout(_ref) {
5791
5963
 
5792
5964
  throw _context.t0;
5793
5965
 
5794
- case 11:
5966
+ case 12:
5795
5967
  case "end":
5796
5968
  return _context.stop();
5797
5969
  }
5798
5970
  }
5799
- }, _callee, null, [[0, 7]]);
5971
+ }, _callee, null, [[0, 8]]);
5800
5972
  }));
5801
5973
  };
5802
5974
 
@@ -5852,7 +6024,7 @@ var TafLayout = function TafLayout(_ref) {
5852
6024
  return postTaf({
5853
6025
  taf: taf,
5854
6026
  changeStatusTo: fromActionToStatus(tafActionToDraftAction(tafAction))
5855
- });
6027
+ }, true);
5856
6028
 
5857
6029
  case 7:
5858
6030
  action(value);
@@ -5899,18 +6071,16 @@ var TafLayout = function TafLayout(_ref) {
5899
6071
  };
5900
6072
 
5901
6073
  React__default.useEffect(function () {
6074
+ var _a, _b;
6075
+
5902
6076
  var newSortedTafs = sortTafTimeSlots(tafList);
5903
6077
  var updatedLocations = timeSlot === 'ACTIVE' ? newSortedTafs.current : newSortedTafs.upcoming;
5904
6078
  updateSortedTafs(sortTafTimeSlots(tafList));
5905
6079
  setLocations(updatedLocations); // update active index
5906
6080
 
5907
- var newActiveIndex = updatedLocations.findIndex(function (location) {
5908
- var _a, _b, _c;
5909
-
5910
- 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);
5911
- });
5912
- var newIndex = newActiveIndex !== -1 ? newActiveIndex : activeTafIndex;
5913
- setActiveTafIndex(newIndex); // eslint-disable-next-line react-hooks/exhaustive-deps
6081
+ var previousActiveLocationUUID = (_b = (_a = locations[activeTafIndex]) === null || _a === void 0 ? void 0 : _a.taf) === null || _b === void 0 ? void 0 : _b.uuid;
6082
+ var newTafLocationIndex = getNewTafLocationIndex(updatedLocations, previousActiveLocationUUID);
6083
+ setActiveTafIndex(newTafLocationIndex); // eslint-disable-next-line react-hooks/exhaustive-deps
5914
6084
  }, [tafList, setLocations]);
5915
6085
  React__default.useEffect(function () {
5916
6086
  setError(postError);
@@ -5927,7 +6097,7 @@ var TafLayout = function TafLayout(_ref) {
5927
6097
  setError(patchError);
5928
6098
  }, [patchError]);
5929
6099
 
5930
- if (!tafList) {
6100
+ if (!tafList || !tafList.length) {
5931
6101
  return null;
5932
6102
  }
5933
6103
 
@@ -6174,6 +6344,23 @@ var Wrapper = function Wrapper(props) {
6174
6344
  return /*#__PURE__*/React.createElement(TafWrapper, Object.assign({}, props), /*#__PURE__*/React.createElement(TafModule, null));
6175
6345
  };
6176
6346
 
6347
+ /* *
6348
+ * Licensed under the Apache License, Version 2.0 (the "License");
6349
+ * you may not use this file except in compliance with the License.
6350
+ * You may obtain a copy of the License at
6351
+ *
6352
+ * http://www.apache.org/licenses/LICENSE-2.0
6353
+ *
6354
+ * Unless required by applicable law or agreed to in writing, software
6355
+ * distributed under the License is distributed on an "AS IS" BASIS,
6356
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6357
+ * See the License for the specific language governing permissions and
6358
+ * limitations under the License.
6359
+ *
6360
+ * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
6361
+ * Copyright 2022 - Finnish Meteorological Institute (FMI)
6362
+ * */
6363
+
6177
6364
  var getApiRoutes$1 = function getApiRoutes(axiosInstance) {
6178
6365
  return {
6179
6366
  getTafList: function getTafList() {
@@ -6182,10 +6369,14 @@ var getApiRoutes$1 = function getApiRoutes(axiosInstance) {
6182
6369
  postTaf: function postTaf(formData) {
6183
6370
  return axiosInstance.post('/taf', Object.assign({}, formData));
6184
6371
  },
6185
- getTAC: function getTAC(tafData, signal) {
6186
- return axiosInstance.post.apply(axiosInstance, ['/taf2tac'].concat([Object.assign({}, tafData)].concat(_toConsumableArray(signal ? [{
6372
+ getTAC: function getTAC(tafData, getJSON, signal) {
6373
+ return axiosInstance.post('/taf2tac', tafData, Object.assign(Object.assign({}, signal ? {
6187
6374
  signal: signal
6188
- }] : []))));
6375
+ } : {}), {
6376
+ headers: {
6377
+ Accept: getJSON ? 'application/json' : 'text/plain'
6378
+ }
6379
+ }));
6189
6380
  },
6190
6381
  patchTaf: function patchTaf(formData) {
6191
6382
  return axiosInstance.patch('/taf', Object.assign({}, formData));
@@ -6193,30 +6384,12 @@ var getApiRoutes$1 = function getApiRoutes(axiosInstance) {
6193
6384
  };
6194
6385
  };
6195
6386
 
6196
- var createApi$1 = function createApi(url, appUrl, auth, setAuth, authTokenUrl, authClientId) {
6197
- var axiosInstance = createApiInstance(url, appUrl, auth, setAuth, authTokenUrl, authClientId);
6387
+ var createApi$1 = function createApi(props) {
6388
+ var axiosInstance = createApiInstance(props);
6198
6389
  return getApiRoutes$1(axiosInstance);
6199
6390
  };
6200
6391
 
6201
- /* *
6202
- * Licensed under the Apache License, Version 2.0 (the "License");
6203
- * you may not use this file except in compliance with the License.
6204
- * You may obtain a copy of the License at
6205
- *
6206
- * http://www.apache.org/licenses/LICENSE-2.0
6207
- *
6208
- * Unless required by applicable law or agreed to in writing, software
6209
- * distributed under the License is distributed on an "AS IS" BASIS,
6210
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6211
- * See the License for the specific language governing permissions and
6212
- * limitations under the License.
6213
- *
6214
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
6215
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
6216
- * */
6217
-
6218
6392
  var MOCK_USERNAME = 'user.name';
6219
-
6220
6393
  var currentDate = moment.utc().format('YYYY-MM-DD');
6221
6394
  var tomorrowDate = moment.utc().add(1, 'day').format('YYYY-MM-DD');
6222
6395
  var airportPeriod = 6;
@@ -7018,7 +7191,6 @@ var fakeDraftAmendmentTaf = {
7018
7191
  taf: {
7019
7192
  uuid: '954905487',
7020
7193
  previousId: '5f9583fjdf45ff4330f337925',
7021
- issueDate: "".concat(currentDate, "T14:00:00Z"),
7022
7194
  baseTime: "".concat(currentDate, "T12:00:00Z"),
7023
7195
  validDateStart: "".concat(currentDate, "T14:00:00Z"),
7024
7196
  validDateEnd: "".concat(tomorrowDate, "T18:00:00Z"),
@@ -7078,7 +7250,6 @@ var fakeDraftAmendmentTaf = {
7078
7250
  editor: null,
7079
7251
  taf: Object.assign(Object.assign({}, fakeDraftAmendmentTaf.taf), {
7080
7252
  location: 'EHRD',
7081
- issueDate: "2022-01-06T14:00:00Z",
7082
7253
  baseTime: "2022-01-06T12:00:00Z",
7083
7254
  validDateStart: "2022-01-06T14:00:00Z",
7084
7255
  validDateEnd: "2022-01-07T18:00:00Z",
@@ -7159,12 +7330,45 @@ var fakeAmendmentTaf = {
7159
7330
  });
7160
7331
 
7161
7332
  var fakeTafTac = 'TAF EHAM 0812/0918 20020G35KT 0500 SN BKN040\nBECMG 0814/0816 0700 BKN001=';
7333
+ var fakeTafTacJson = {
7334
+ tac: [[{
7335
+ text: 'TAF'
7336
+ }, {
7337
+ text: 'EHAM'
7338
+ }, {
7339
+ text: '0812/0918'
7340
+ }, {
7341
+ text: '20020G35KT',
7342
+ type: 'adverse'
7343
+ }, {
7344
+ text: '0500',
7345
+ type: 'adverse'
7346
+ }, {
7347
+ text: 'SN',
7348
+ type: 'adverse'
7349
+ }, {
7350
+ text: 'BKN040'
7351
+ }], [{
7352
+ text: 'BECMG'
7353
+ }, {
7354
+ text: '0814/0816'
7355
+ }, {
7356
+ text: '0700',
7357
+ type: 'adverse'
7358
+ }, {
7359
+ text: 'BKN001',
7360
+ type: 'adverse'
7361
+ }, {
7362
+ text: '='
7363
+ }]]
7364
+ };
7162
7365
 
7163
7366
  var fakeUpdatedTafList = _toConsumableArray(fakeTafList);
7164
7367
 
7165
7368
  var setFakeUpdatedList = function setFakeUpdatedList(newList) {
7166
7369
  fakeUpdatedTafList = newList;
7167
7370
  };
7371
+
7168
7372
  var getFakeUpdatedList = function getFakeUpdatedList() {
7169
7373
  return fakeUpdatedTafList;
7170
7374
  };
@@ -7187,12 +7391,16 @@ var getApiRoutes = function getApiRoutes(axiosInstance) {
7187
7391
  console.log('form has been posted with following values:', _postTaf.taf);
7188
7392
  return axiosInstance.post('/taf', _postTaf);
7189
7393
  },
7190
- getTAC: function getTAC(taf, signal) {
7191
- return axiosInstance.post.apply(axiosInstance, ['/taf2tac'].concat([Object.assign({}, taf)].concat(_toConsumableArray(signal ? [{
7394
+ getTAC: function getTAC(taf, getJSON, signal) {
7395
+ return axiosInstance.post('/taf2tac', taf, Object.assign(Object.assign({}, signal ? {
7192
7396
  signal: signal
7193
- }] : [])))).then(function () {
7397
+ } : {}), {
7398
+ headers: {
7399
+ Accept: getJSON ? 'application/json' : 'text/plain'
7400
+ }
7401
+ })).then(function () {
7194
7402
  return {
7195
- data: fakeTafTac
7403
+ data: getJSON ? fakeTafTacJson : fakeTafTac
7196
7404
  };
7197
7405
  });
7198
7406
  },
@@ -7257,13 +7465,15 @@ var TafApiWrapper = function TafApiWrapper(_ref) {
7257
7465
  onSetAuth = _ref.onSetAuth,
7258
7466
  onPreventCloseView = _ref.onPreventCloseView;
7259
7467
  return config ? /*#__PURE__*/React.createElement(ApiProvider, {
7260
- baseURL: config.baseUrl,
7261
- appURL: config.appUrl,
7468
+ config: {
7469
+ baseURL: config.baseURL,
7470
+ appURL: config.baseURL,
7471
+ authTokenURL: config.authTokenURL,
7472
+ authClientId: config.authClientId
7473
+ },
7262
7474
  auth: auth,
7263
7475
  onSetAuth: onSetAuth,
7264
- createApi: createApi$1,
7265
- authTokenUrl: config.authTokenUrl,
7266
- authClientId: config.authClientId
7476
+ createApi: createApi$1
7267
7477
  }, /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(Wrapper, {
7268
7478
  onPreventCloseView: onPreventCloseView
7269
7479
  }))) : null;