@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.esm.js CHANGED
@@ -2,16 +2,17 @@ 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
- import makeStyles from '@mui/styles/makeStyles';
13
14
  import ReactDOM from 'react-dom';
14
- import { useApiContext, createApiInstance, ApiProvider } from '@opengeoweb/api';
15
+ import { useApiContext, createApiInstance, createFakeApiInstance, ApiProvider } from '@opengeoweb/api';
15
16
  import LinearProgress from '@mui/material/LinearProgress';
16
17
  import Box$1 from '@mui/material/Box';
17
18
 
@@ -2315,6 +2316,8 @@ var tacHasError = function tacHasError(tac) {
2315
2316
  return tac === TAC_MISSING_DATA || tac === TAC_NOT_AVAILABLE || tac === TAC_RETRIEVING_DATA || tac === TAC_FAILED;
2316
2317
  };
2317
2318
  var useTACGenerator = function useTACGenerator(taf, requestTAC) {
2319
+ var getJSON = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
2320
+
2318
2321
  var _React$useState = React__default.useState(!taf || taf.status === 'NEW' ? TAC_NOT_AVAILABLE : TAC_RETRIEVING_DATA),
2319
2322
  _React$useState2 = _slicedToArray(_React$useState, 2),
2320
2323
  TAC = _React$useState2[0],
@@ -2341,7 +2344,7 @@ var useTACGenerator = function useTACGenerator(taf, requestTAC) {
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 @@ var useTACGenerator = function useTACGenerator(taf, requestTAC) {
2353
2356
  } else {
2354
2357
  setTAC(TAC_MISSING_DATA);
2355
2358
  }
2356
- }, [isMounted, requestTAC]);
2359
+ }, [isMounted, requestTAC, getJSON]);
2357
2360
  React__default.useEffect(function () {
2358
2361
  if (taf && taf.status !== 'NEW') {
2359
2362
  retrieveTAC(taf);
@@ -3518,19 +3521,6 @@ var TafFormButtons = function TafFormButtons(_ref2) {
3518
3521
  * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3519
3522
  * Copyright 2021 - Finnish Meteorological Institute (FMI)
3520
3523
  * */
3521
- var useStyles = makeStyles(function () {
3522
- return {
3523
- dragHandle: {
3524
- backgroundColor: 'transparent',
3525
- '&:hover': {
3526
- backgroundColor: 'transparent'
3527
- },
3528
- cursor: function cursor(isSorting) {
3529
- return isSorting ? 'grabbing' : 'grab';
3530
- }
3531
- }
3532
- };
3533
- });
3534
3524
 
3535
3525
  var DragHandle = function DragHandle(_ref) {
3536
3526
  var _ref$isSorting = _ref.isSorting,
@@ -3538,13 +3528,21 @@ var DragHandle = function DragHandle(_ref) {
3538
3528
  _ref$isDisabled = _ref.isDisabled,
3539
3529
  isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
3540
3530
  index = _ref.index;
3541
- var classes = useStyles(isSorting);
3542
3531
  return /*#__PURE__*/React__default.createElement(IconButton, {
3543
- className: "".concat(classes.dragHandle, " handle"),
3532
+ className: "handle",
3544
3533
  "data-testid": "dragHandle-".concat(index),
3545
3534
  disableRipple: true,
3546
3535
  disabled: isDisabled,
3547
- size: "large"
3536
+ size: "large",
3537
+ sx: {
3538
+ backgroundColor: 'transparent',
3539
+ '&:hover': {
3540
+ backgroundColor: 'transparent'
3541
+ },
3542
+ cursor: function cursor() {
3543
+ return isSorting ? 'grabbing' : 'grab';
3544
+ }
3545
+ }
3548
3546
  }, /*#__PURE__*/React__default.createElement(DragHandle$1, null));
3549
3547
  };
3550
3548
 
@@ -3996,6 +3994,9 @@ var TafAvatar = function TafAvatar(_ref) {
3996
3994
 
3997
3995
  var noop = function noop() {};
3998
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
+ };
3999
4000
  var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4000
4001
  var tafFromBackend = _ref.tafFromBackend,
4001
4002
  _ref$onFormAction = _ref.onFormAction,
@@ -4024,6 +4025,7 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4024
4025
  var _useAuthenticationCon = useAuthenticationContext(),
4025
4026
  auth = _useAuthenticationCon.auth;
4026
4027
 
4028
+ var dispatch = useDispatch();
4027
4029
  var isEditor = editor === (auth === null || auth === void 0 ? void 0 : auth.username) || false;
4028
4030
  var isDefaultDisabled = getIsFormDefaultDisabled(originalTaf.status);
4029
4031
  var confirmDialog = useConfirmationDialog();
@@ -4129,6 +4131,12 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4129
4131
  setTafAction(action);
4130
4132
  };
4131
4133
 
4134
+ var showSnackbar = React__default.useCallback(function (message) {
4135
+ dispatch(snackbarActions.openSnackbar({
4136
+ message: message
4137
+ }));
4138
+ }, [dispatch]);
4139
+
4132
4140
  var setIsEditor = function setIsEditor(checked) {
4133
4141
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
4134
4142
  var editor, didSucceed;
@@ -4166,9 +4174,14 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4166
4174
 
4167
4175
  case 8:
4168
4176
  didSucceed = _context.sent;
4177
+
4178
+ if (didSucceed) {
4179
+ showSnackbar(getSnackbarMessage$2(checked, originalTaf.location));
4180
+ }
4181
+
4169
4182
  return _context.abrupt("return", didSucceed);
4170
4183
 
4171
- case 10:
4184
+ case 11:
4172
4185
  case "end":
4173
4186
  return _context.stop();
4174
4187
  }
@@ -4458,8 +4471,8 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4458
4471
  alignItems: 'center',
4459
4472
  position: 'absolute',
4460
4473
  top: {
4461
- xs: '20px',
4462
- sm: '0px'
4474
+ xs: '34px',
4475
+ sm: '-3px'
4463
4476
  },
4464
4477
  right: {
4465
4478
  xs: 'calc(50% - 70px)',
@@ -4484,11 +4497,15 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4484
4497
  sx: {
4485
4498
  fontSize: '20px',
4486
4499
  fontWeight: 500,
4487
- height: '24px'
4500
+ height: '24px',
4501
+ display: 'flex',
4502
+ alignItems: 'center'
4488
4503
  }
4489
4504
  }, "TAC"), /*#__PURE__*/React__default.createElement(Typography, {
4490
4505
  sx: {
4491
- fontSize: '14px',
4506
+ fontSize: '12px',
4507
+ lineHeight: 1.67,
4508
+ letterSpacing: '0.21px',
4492
4509
  margin: '8px 0px'
4493
4510
  },
4494
4511
  "data-testid": "form-tac-message"
@@ -4631,7 +4648,7 @@ var TafHeader = function TafHeader(_ref) {
4631
4648
  sx: Object.assign({
4632
4649
  textAlign: 'center',
4633
4650
  fontWeight: 500,
4634
- paddingTop: '6px',
4651
+ paddingTop: '4px',
4635
4652
  textTransform: 'capitalize'
4636
4653
  }, sx)
4637
4654
  }, title);
@@ -4693,15 +4710,24 @@ var getLocationSetting = function getLocationSetting(location) {
4693
4710
  var locationSettings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : tafSettings.locations;
4694
4711
  return locationSettings[location];
4695
4712
  };
4696
- var sortTafsOnLocation = function sortTafsOnLocation(tafList) {
4713
+ var sortTafsOnLocation = function sortTafsOnLocation() {
4714
+ var tafList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
4697
4715
  var locationOrder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : tafSettings.locationOrder;
4698
- if (!tafList) return [];
4699
4716
  return _toConsumableArray(tafList).sort(function (_ref, _ref2) {
4700
4717
  var tafA = _ref.taf;
4701
4718
  var tafB = _ref2.taf;
4702
4719
  return locationOrder.indexOf(tafA.location) < locationOrder.indexOf(tafB.location) ? -1 : 1;
4703
4720
  });
4704
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
+ };
4705
4731
  var getBaseTime = function getBaseTime(baseTime, location) {
4706
4732
  var currentBaseTime = moment.utc(baseTime);
4707
4733
  var activityPeriod = getLocationSetting(location).activity_period;
@@ -4729,7 +4755,8 @@ var getTafTimeSlot = function getTafTimeSlot(baseTime, location, status) {
4729
4755
  return 'UPCOMING';
4730
4756
  };
4731
4757
  var sortTafTimeSlots = function sortTafTimeSlots(tafList) {
4732
- var sortedListOnLocation = sortTafsOnLocation(tafList);
4758
+ var sortedListOnIssueDate = sortTafsOnIssueDate(tafList);
4759
+ var sortedListOnLocation = sortTafsOnLocation(sortedListOnIssueDate);
4733
4760
  return sortedListOnLocation.reduce(function (sortedTafList, tafFromBackend) {
4734
4761
  var taf = tafFromBackend.taf;
4735
4762
  var timeSlot = getTafTimeSlot(taf.baseTime, taf.location, taf.status);
@@ -4769,6 +4796,29 @@ var prepareTafExportValues = function prepareTafExportValues(tafToCopy, currentT
4769
4796
  changeGroups: changeGroups
4770
4797
  });
4771
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
+ };
4772
4822
 
4773
4823
  /* *
4774
4824
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -4873,17 +4923,74 @@ var StatusIcon = function StatusIcon(_ref2) {
4873
4923
  * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
4874
4924
  * Copyright 2022 - Finnish Meteorological Institute (FMI)
4875
4925
  * */
4926
+ var TOOLTIP_TITLE = 'Import TAC';
4876
4927
 
4877
4928
  var ExportButton = function ExportButton(_ref) {
4878
4929
  var onClick = _ref.onClick,
4879
4930
  isHidden = _ref.isHidden;
4880
4931
  return isHidden ? null : /*#__PURE__*/React__default.createElement(Tooltip, {
4881
- title: "Import TAC",
4932
+ title: TOOLTIP_TITLE,
4882
4933
  placement: "left"
4883
- }, /*#__PURE__*/React__default.createElement("span", null, /*#__PURE__*/React__default.createElement(ToolButton, {
4934
+ }, /*#__PURE__*/React__default.createElement(ToolButton, {
4884
4935
  onClick: onClick,
4885
4936
  "data-testid": "export-tac-button"
4886
- }, /*#__PURE__*/React__default.createElement(Export, null))));
4937
+ }, /*#__PURE__*/React__default.createElement(Export, null)));
4938
+ };
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");
4887
4994
  };
4888
4995
 
4889
4996
  var TacContainer = function TacContainer(_ref) {
@@ -4896,7 +5003,9 @@ var TacContainer = function TacContainer(_ref) {
4896
5003
  var _useApiContext = useApiContext(),
4897
5004
  api = _useApiContext.api;
4898
5005
 
4899
- var _useTACGenerator = useTACGenerator(taf, api.getTAC),
5006
+ var dispatch = useDispatch();
5007
+
5008
+ var _useTACGenerator = useTACGenerator(taf, api.getTAC, true),
4900
5009
  _useTACGenerator2 = _slicedToArray(_useTACGenerator, 2),
4901
5010
  TAC = _useTACGenerator2[0],
4902
5011
  retrieveTAC = _useTACGenerator2[1];
@@ -4915,6 +5024,12 @@ var TacContainer = function TacContainer(_ref) {
4915
5024
  var _useTafModuleContext = useTafModuleContext(),
4916
5025
  updateTAC = _useTafModuleContext.updateTAC;
4917
5026
 
5027
+ var showSnackbar = React__default.useCallback(function (message) {
5028
+ dispatch(snackbarActions.openSnackbar({
5029
+ message: message
5030
+ }));
5031
+ }, [dispatch]);
5032
+
4918
5033
  var handleExport = function handleExport() {
4919
5034
  var currentTaf = getValues();
4920
5035
  var newTaf = prepareTafExportValues(taf, currentTaf);
@@ -4928,6 +5043,7 @@ var TacContainer = function TacContainer(_ref) {
4928
5043
  trigger(); // trigger all fields validation
4929
5044
  }, 0);
4930
5045
  updateTAC(convertTafValuesToObject(newTaf));
5046
+ showSnackbar(getSnackbarMessage$1(location, locationLabel));
4931
5047
  };
4932
5048
 
4933
5049
  React__default.useEffect(function () {
@@ -4997,23 +5113,18 @@ var TacContainer = function TacContainer(_ref) {
4997
5113
  letterSpacing: '0.4px',
4998
5114
  color: 'geowebColors.captions.captionStatus.rgba'
4999
5115
  }
5000
- }, TAC.split('\n').map(function (line) {
5001
- return /*#__PURE__*/React__default.createElement(Box, {
5002
- component: "span",
5003
- key: line,
5004
- sx: {
5005
- display: 'inline-block'
5006
- }
5007
- }, /*#__PURE__*/React__default.createElement(Box, {
5008
- component: "span",
5009
- sx: Object.assign({
5010
- display: 'inline',
5011
- boxDecorationBreak: 'clone',
5012
- WebkitBoxDecorationBreak: 'clone'
5013
- }, isActive && {
5014
- backgroundColor: 'geowebColors.functional.warningHighlight.rgba'
5015
- })
5016
- }, 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
5017
5128
  })));
5018
5129
  };
5019
5130
 
@@ -5162,8 +5273,8 @@ var TacOverviewMobile = function TacOverviewMobile(_ref) {
5162
5273
  sm: 'none'
5163
5274
  },
5164
5275
  position: 'absolute',
5165
- right: '8px',
5166
- top: '48px'
5276
+ right: '4px',
5277
+ top: '82px'
5167
5278
  }
5168
5279
  }, /*#__PURE__*/React.createElement(ListItem, null)), /*#__PURE__*/React.createElement(Dialog, {
5169
5280
  open: isOpen,
@@ -5206,7 +5317,6 @@ var TacOverviewMobile = function TacOverviewMobile(_ref) {
5206
5317
  * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
5207
5318
  * Copyright 2022 - Finnish Meteorological Institute (FMI)
5208
5319
  * */
5209
-
5210
5320
  var formatBaseTime = function formatBaseTime(time) {
5211
5321
  return time.format('HH:mm DD MMM');
5212
5322
  };
@@ -5602,7 +5712,10 @@ var TafPanel = function TafPanel(_ref) {
5602
5712
  shouldClose: true
5603
5713
  }), /*#__PURE__*/React__default.createElement(Box, {
5604
5714
  sx: {
5605
- marginTop: '10px',
5715
+ marginTop: {
5716
+ xs: '44px',
5717
+ sm: '10px'
5718
+ },
5606
5719
  padding: 1
5607
5720
  }
5608
5721
  }, /*#__PURE__*/React__default.createElement(TafForm, {
@@ -5688,7 +5801,10 @@ var LastUpdateTime = function LastUpdateTime(_ref) {
5688
5801
  "data-testid": "updateTafBtn",
5689
5802
  onClick: onUpdateTaf,
5690
5803
  sx: {
5691
- marginRight: 1,
5804
+ marginRight: {
5805
+ xs: 2,
5806
+ sm: 1
5807
+ },
5692
5808
  marginLeft: 1
5693
5809
  }
5694
5810
  }, /*#__PURE__*/React__default.createElement(Cached, null))));
@@ -5699,17 +5815,60 @@ var CONFIRM_DIALOG_OPTIONS = {
5699
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.",
5700
5816
  confirmLabel: 'Exit without saving'
5701
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;
5702
5829
 
5703
- var TafLayout = function TafLayout(_ref) {
5704
- var _ref$tafList = _ref.tafList,
5705
- tafList = _ref$tafList === void 0 ? [] : _ref$tafList,
5706
- _ref$onUpdateTaf = _ref.onUpdateTaf,
5707
- onUpdateTaf = _ref$onUpdateTaf === void 0 ? function () {} : _ref$onUpdateTaf,
5708
- 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;
5709
5867
 
5710
5868
  var _useApiContext = useApiContext(),
5711
5869
  api = _useApiContext.api;
5712
5870
 
5871
+ var dispatch = useDispatch();
5713
5872
  var confirmDialog = useConfirmationDialog();
5714
5873
 
5715
5874
  var _useIssuesPane = useIssuesPane(),
@@ -5769,7 +5928,14 @@ var TafLayout = function TafLayout(_ref) {
5769
5928
  error = _React$useState12[0],
5770
5929
  setError = _React$useState12[1];
5771
5930
 
5931
+ var showSnackbar = React__default.useCallback(function (message) {
5932
+ dispatch(snackbarActions.openSnackbar({
5933
+ message: message
5934
+ }));
5935
+ }, [dispatch]);
5936
+
5772
5937
  var postTaf = function postTaf(data) {
5938
+ var isAutoSaved = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
5773
5939
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
5774
5940
  return regeneratorRuntime.wrap(function _callee$(_context) {
5775
5941
  while (1) {
@@ -5781,13 +5947,14 @@ var TafLayout = function TafLayout(_ref) {
5781
5947
  return postTafRequest(data);
5782
5948
 
5783
5949
  case 4:
5784
- // callback
5950
+ showSnackbar(getSnackbarMessage(data, isAutoSaved)); // callback
5951
+
5785
5952
  onUpdateTaf();
5786
- _context.next = 11;
5953
+ _context.next = 12;
5787
5954
  break;
5788
5955
 
5789
- case 7:
5790
- _context.prev = 7;
5956
+ case 8:
5957
+ _context.prev = 8;
5791
5958
  _context.t0 = _context["catch"](0);
5792
5959
 
5793
5960
  if (isWarning(_context.t0)) {
@@ -5796,12 +5963,12 @@ var TafLayout = function TafLayout(_ref) {
5796
5963
 
5797
5964
  throw _context.t0;
5798
5965
 
5799
- case 11:
5966
+ case 12:
5800
5967
  case "end":
5801
5968
  return _context.stop();
5802
5969
  }
5803
5970
  }
5804
- }, _callee, null, [[0, 7]]);
5971
+ }, _callee, null, [[0, 8]]);
5805
5972
  }));
5806
5973
  };
5807
5974
 
@@ -5857,7 +6024,7 @@ var TafLayout = function TafLayout(_ref) {
5857
6024
  return postTaf({
5858
6025
  taf: taf,
5859
6026
  changeStatusTo: fromActionToStatus(tafActionToDraftAction(tafAction))
5860
- });
6027
+ }, true);
5861
6028
 
5862
6029
  case 7:
5863
6030
  action(value);
@@ -5904,18 +6071,16 @@ var TafLayout = function TafLayout(_ref) {
5904
6071
  };
5905
6072
 
5906
6073
  React__default.useEffect(function () {
6074
+ var _a, _b;
6075
+
5907
6076
  var newSortedTafs = sortTafTimeSlots(tafList);
5908
6077
  var updatedLocations = timeSlot === 'ACTIVE' ? newSortedTafs.current : newSortedTafs.upcoming;
5909
6078
  updateSortedTafs(sortTafTimeSlots(tafList));
5910
6079
  setLocations(updatedLocations); // update active index
5911
6080
 
5912
- var newActiveIndex = updatedLocations.findIndex(function (location) {
5913
- var _a, _b, _c;
5914
-
5915
- 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);
5916
- });
5917
- var newIndex = newActiveIndex !== -1 ? newActiveIndex : activeTafIndex;
5918
- 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
5919
6084
  }, [tafList, setLocations]);
5920
6085
  React__default.useEffect(function () {
5921
6086
  setError(postError);
@@ -5932,7 +6097,7 @@ var TafLayout = function TafLayout(_ref) {
5932
6097
  setError(patchError);
5933
6098
  }, [patchError]);
5934
6099
 
5935
- if (!tafList) {
6100
+ if (!tafList || !tafList.length) {
5936
6101
  return null;
5937
6102
  }
5938
6103
 
@@ -6179,27 +6344,6 @@ var Wrapper = function Wrapper(props) {
6179
6344
  return /*#__PURE__*/React.createElement(TafWrapper, Object.assign({}, props), /*#__PURE__*/React.createElement(TafModule, null));
6180
6345
  };
6181
6346
 
6182
- var createApi$1 = function createApi(url, appUrl, auth, setAuth, authTokenUrl, authClientId) {
6183
- var axiosInstance = createApiInstance(url, appUrl, auth, setAuth, authTokenUrl, authClientId);
6184
- return {
6185
- // api data
6186
- getTafList: function getTafList() {
6187
- return axiosInstance.get('/taflist');
6188
- },
6189
- postTaf: function postTaf(formData) {
6190
- return axiosInstance.post('/taf', Object.assign({}, formData));
6191
- },
6192
- getTAC: function getTAC(tafData, signal) {
6193
- return axiosInstance.post.apply(axiosInstance, ['/taf2tac'].concat([Object.assign({}, tafData)].concat(_toConsumableArray(signal ? [{
6194
- signal: signal
6195
- }] : []))));
6196
- },
6197
- patchTaf: function patchTaf(formData) {
6198
- return axiosInstance.patch('/taf', Object.assign({}, formData));
6199
- }
6200
- };
6201
- };
6202
-
6203
6347
  /* *
6204
6348
  * Licensed under the Apache License, Version 2.0 (the "License");
6205
6349
  * you may not use this file except in compliance with the License.
@@ -6217,8 +6361,35 @@ var createApi$1 = function createApi(url, appUrl, auth, setAuth, authTokenUrl, a
6217
6361
  * Copyright 2022 - Finnish Meteorological Institute (FMI)
6218
6362
  * */
6219
6363
 
6220
- var MOCK_USERNAME = 'user.name';
6364
+ var getApiRoutes$1 = function getApiRoutes(axiosInstance) {
6365
+ return {
6366
+ getTafList: function getTafList() {
6367
+ return axiosInstance.get('/taflist');
6368
+ },
6369
+ postTaf: function postTaf(formData) {
6370
+ return axiosInstance.post('/taf', Object.assign({}, formData));
6371
+ },
6372
+ getTAC: function getTAC(tafData, getJSON, signal) {
6373
+ return axiosInstance.post('/taf2tac', tafData, Object.assign(Object.assign({}, signal ? {
6374
+ signal: signal
6375
+ } : {}), {
6376
+ headers: {
6377
+ Accept: getJSON ? 'application/json' : 'text/plain'
6378
+ }
6379
+ }));
6380
+ },
6381
+ patchTaf: function patchTaf(formData) {
6382
+ return axiosInstance.patch('/taf', Object.assign({}, formData));
6383
+ }
6384
+ };
6385
+ };
6386
+
6387
+ var createApi$1 = function createApi(props) {
6388
+ var axiosInstance = createApiInstance(props);
6389
+ return getApiRoutes$1(axiosInstance);
6390
+ };
6221
6391
 
6392
+ var MOCK_USERNAME = 'user.name';
6222
6393
  var currentDate = moment.utc().format('YYYY-MM-DD');
6223
6394
  var tomorrowDate = moment.utc().add(1, 'day').format('YYYY-MM-DD');
6224
6395
  var airportPeriod = 6;
@@ -7020,7 +7191,6 @@ var fakeDraftAmendmentTaf = {
7020
7191
  taf: {
7021
7192
  uuid: '954905487',
7022
7193
  previousId: '5f9583fjdf45ff4330f337925',
7023
- issueDate: "".concat(currentDate, "T14:00:00Z"),
7024
7194
  baseTime: "".concat(currentDate, "T12:00:00Z"),
7025
7195
  validDateStart: "".concat(currentDate, "T14:00:00Z"),
7026
7196
  validDateEnd: "".concat(tomorrowDate, "T18:00:00Z"),
@@ -7080,7 +7250,6 @@ var fakeDraftAmendmentTaf = {
7080
7250
  editor: null,
7081
7251
  taf: Object.assign(Object.assign({}, fakeDraftAmendmentTaf.taf), {
7082
7252
  location: 'EHRD',
7083
- issueDate: "2022-01-06T14:00:00Z",
7084
7253
  baseTime: "2022-01-06T12:00:00Z",
7085
7254
  validDateStart: "2022-01-06T14:00:00Z",
7086
7255
  validDateEnd: "2022-01-07T18:00:00Z",
@@ -7161,20 +7330,37 @@ var fakeAmendmentTaf = {
7161
7330
  });
7162
7331
 
7163
7332
  var fakeTafTac = 'TAF EHAM 0812/0918 20020G35KT 0500 SN BKN040\nBECMG 0814/0816 0700 BKN001=';
7164
-
7165
- var fakePromise = function fakePromise(withRandomError) {
7166
- var signal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
7167
- return new Promise(function (resolve, reject) {
7168
- var timer = setTimeout(function () {
7169
- if (!withRandomError) return resolve();
7170
- var randomError = Math.floor(Math.random() * 4) + 1;
7171
- return randomError === 4 ? reject(new Error('something went wrong')) : resolve();
7172
- }, 300);
7173
- signal === null || signal === void 0 ? void 0 : signal.signal.addEventListener('abort', function () {
7174
- clearTimeout(timer);
7175
- reject(new Error('canceled'));
7176
- });
7177
- });
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
+ }]]
7178
7364
  };
7179
7365
 
7180
7366
  var fakeUpdatedTafList = _toConsumableArray(fakeTafList);
@@ -7182,29 +7368,17 @@ var fakeUpdatedTafList = _toConsumableArray(fakeTafList);
7182
7368
  var setFakeUpdatedList = function setFakeUpdatedList(newList) {
7183
7369
  fakeUpdatedTafList = newList;
7184
7370
  };
7371
+
7185
7372
  var getFakeUpdatedList = function getFakeUpdatedList() {
7186
7373
  return fakeUpdatedTafList;
7187
7374
  };
7188
- var fakeAxiosInstance = {
7189
- // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars, @typescript-eslint/explicit-module-boundary-types
7190
- get: function get(_url, _params) {
7191
- return fakePromise(false);
7192
- },
7193
- // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars, @typescript-eslint/explicit-module-boundary-types
7194
- post: function post(_url, _params, _signal) {
7195
- return fakePromise(false, _signal);
7196
- },
7197
- // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars, @typescript-eslint/explicit-module-boundary-types
7198
- patch: function patch(_url, _params, _signal) {
7199
- return fakePromise(false, _signal);
7200
- }
7201
- };
7202
- var createApi = function createApi() {
7375
+
7376
+ var getApiRoutes = function getApiRoutes(axiosInstance) {
7203
7377
  return {
7204
7378
  getTafList: function getTafList() {
7205
7379
  // eslint-disable-next-line no-console
7206
7380
  console.log('Retrieving new TAF list');
7207
- return fakeAxiosInstance.get('/taflist').then(function () {
7381
+ return axiosInstance.get('/taflist').then(function () {
7208
7382
  return {
7209
7383
  data: getFakeUpdatedList()
7210
7384
  };
@@ -7215,14 +7389,18 @@ var createApi = function createApi() {
7215
7389
  console.log("The new status of the taf will be ".concat(_postTaf.changeStatusTo)); // eslint-disable-next-line no-console
7216
7390
 
7217
7391
  console.log('form has been posted with following values:', _postTaf.taf);
7218
- return fakeAxiosInstance.post('/taf', _postTaf);
7392
+ return axiosInstance.post('/taf', _postTaf);
7219
7393
  },
7220
- getTAC: function getTAC(tafData, signal) {
7221
- return fakeAxiosInstance.post.apply(fakeAxiosInstance, ['/taf2tac'].concat([Object.assign({}, tafData)].concat(_toConsumableArray(signal ? [{
7394
+ getTAC: function getTAC(taf, getJSON, signal) {
7395
+ return axiosInstance.post('/taf2tac', taf, Object.assign(Object.assign({}, signal ? {
7222
7396
  signal: signal
7223
- }] : [])))).then(function () {
7397
+ } : {}), {
7398
+ headers: {
7399
+ Accept: getJSON ? 'application/json' : 'text/plain'
7400
+ }
7401
+ })).then(function () {
7224
7402
  return {
7225
- data: fakeTafTac
7403
+ data: getJSON ? fakeTafTacJson : fakeTafTac
7226
7404
  };
7227
7405
  });
7228
7406
  },
@@ -7239,11 +7417,16 @@ var createApi = function createApi() {
7239
7417
  setFakeUpdatedList(updatedList); // eslint-disable-next-line no-console
7240
7418
 
7241
7419
  console.log("The new editor of the taf will be ".concat(_patchTaf.editor || 'empty'));
7242
- return fakeAxiosInstance.patch('/taf', _patchTaf);
7420
+ return axiosInstance.patch('/taf', _patchTaf);
7243
7421
  }
7244
7422
  };
7245
7423
  };
7246
7424
 
7425
+ var createApi = function createApi() {
7426
+ var instance = createFakeApiInstance();
7427
+ return getApiRoutes(instance);
7428
+ };
7429
+
7247
7430
  /* *
7248
7431
  * Licensed under the Apache License, Version 2.0 (the "License");
7249
7432
  * you may not use this file except in compliance with the License.
@@ -7282,13 +7465,15 @@ var TafApiWrapper = function TafApiWrapper(_ref) {
7282
7465
  onSetAuth = _ref.onSetAuth,
7283
7466
  onPreventCloseView = _ref.onPreventCloseView;
7284
7467
  return config ? /*#__PURE__*/React.createElement(ApiProvider, {
7285
- baseURL: config.baseUrl,
7286
- appURL: config.appUrl,
7468
+ config: {
7469
+ baseURL: config.baseURL,
7470
+ appURL: config.baseURL,
7471
+ authTokenURL: config.authTokenURL,
7472
+ authClientId: config.authClientId
7473
+ },
7287
7474
  auth: auth,
7288
7475
  onSetAuth: onSetAuth,
7289
- createApi: createApi$1,
7290
- authTokenUrl: config.authTokenUrl,
7291
- authClientId: config.authClientId
7476
+ createApi: createApi$1
7292
7477
  }, /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(Wrapper, {
7293
7478
  onPreventCloseView: onPreventCloseView
7294
7479
  }))) : null;