@opengeoweb/taf 2.14.0 → 4.0.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
@@ -1,16 +1,16 @@
1
1
  import * as React from 'react';
2
2
  import React__default from 'react';
3
- import { TextField, Grid, Box, Button, IconButton, Tooltip, Chip, Typography, Card, Tabs, Tab, Dialog, MenuList, MenuItem, Backdrop, CircularProgress } from '@mui/material';
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
5
  import { ReactSortable, Sortable } from 'react-sortablejs';
6
- import { getDeepProperty, ReactHookFormHiddenInput, ReactHookFormProvider } from '@opengeoweb/form-fields';
7
- import { useIsMounted, ToggleMenu, useDraftFormHelpers, ToolContainerDraggable, useConfirmationDialog, usePreventBrowserClose, ToolButton, ToolHeader, isAxiosError, getAxiosErrorMessage, AlertBanner, ConfirmationServiceProvider, usePoller, ErrorBoundary } from '@opengeoweb/shared';
8
6
  import { isEqual } from 'lodash';
7
+ import { useAuthenticationContext } from '@opengeoweb/authentication';
8
+ import { getDeepProperty, ReactHookFormHiddenInput, ReactHookFormProvider } from '@opengeoweb/form-fields';
9
+ import { useIsMounted, ToggleMenu, useDraftFormHelpers, ToolContainerDraggable, Avatar, getInitials, useConfirmationDialog, usePreventBrowserClose, ToolButton, ToolHeader, AlertBanner, getErrorMessage as getErrorMessage$1, getWarningMessage, ConfirmationServiceProvider, usePoller, ErrorBoundary } from '@opengeoweb/shared';
9
10
  import moment from 'moment';
10
- import { Add, Delete, Close, DragHandle as DragHandle$1, ThumbsUp, Clock, Cancel, Edit, Success, Export, ListItem } from '@opengeoweb/theme';
11
- import makeStyles from '@mui/styles/makeStyles';
11
+ import { Add, Delete, Close, DragHandle as DragHandle$1, ThumbsUp, Clock, Cancel, Edit, Success, Export, ListItem, Cached } from '@opengeoweb/theme';
12
12
  import ReactDOM from 'react-dom';
13
- import { useApiContext, useApi, createApiInstance, ApiProvider } from '@opengeoweb/api';
13
+ import { useApiContext, createApiInstance, createFakeApiInstance, ApiProvider } from '@opengeoweb/api';
14
14
  import LinearProgress from '@mui/material/LinearProgress';
15
15
  import Box$1 from '@mui/material/Box';
16
16
 
@@ -3517,19 +3517,6 @@ var TafFormButtons = function TafFormButtons(_ref2) {
3517
3517
  * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3518
3518
  * Copyright 2021 - Finnish Meteorological Institute (FMI)
3519
3519
  * */
3520
- var useStyles = makeStyles(function () {
3521
- return {
3522
- dragHandle: {
3523
- backgroundColor: 'transparent',
3524
- '&:hover': {
3525
- backgroundColor: 'transparent'
3526
- },
3527
- cursor: function cursor(isSorting) {
3528
- return isSorting ? 'grabbing' : 'grab';
3529
- }
3530
- }
3531
- };
3532
- });
3533
3520
 
3534
3521
  var DragHandle = function DragHandle(_ref) {
3535
3522
  var _ref$isSorting = _ref.isSorting,
@@ -3537,13 +3524,21 @@ var DragHandle = function DragHandle(_ref) {
3537
3524
  _ref$isDisabled = _ref.isDisabled,
3538
3525
  isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
3539
3526
  index = _ref.index;
3540
- var classes = useStyles(isSorting);
3541
3527
  return /*#__PURE__*/React__default.createElement(IconButton, {
3542
- className: "".concat(classes.dragHandle, " handle"),
3528
+ className: "handle",
3543
3529
  "data-testid": "dragHandle-".concat(index),
3544
3530
  disableRipple: true,
3545
3531
  disabled: isDisabled,
3546
- size: "large"
3532
+ size: "large",
3533
+ sx: {
3534
+ backgroundColor: 'transparent',
3535
+ '&:hover': {
3536
+ backgroundColor: 'transparent'
3537
+ },
3538
+ cursor: function cursor() {
3539
+ return isSorting ? 'grabbing' : 'grab';
3540
+ }
3541
+ }
3547
3542
  }, /*#__PURE__*/React__default.createElement(DragHandle$1, null));
3548
3543
  };
3549
3544
 
@@ -3832,7 +3827,12 @@ var IssuesPane = function IssuesPane(_ref3) {
3832
3827
  fontSize: '4rem'
3833
3828
  },
3834
3829
  "data-testid": "zeroIssuesImage"
3835
- }, /*#__PURE__*/React.createElement(ThumbsUp, null)), errorList.length > 0 && errorList.map(function (error, index) {
3830
+ }, /*#__PURE__*/React.createElement(ThumbsUp, {
3831
+ sx: {
3832
+ height: '69px',
3833
+ width: '58px'
3834
+ }
3835
+ })), errorList.length > 0 && errorList.map(function (error, index) {
3836
3836
  return /*#__PURE__*/React.createElement(Typography // eslint-disable-next-line react/no-array-index-key
3837
3837
  , {
3838
3838
  // eslint-disable-next-line react/no-array-index-key
@@ -3922,9 +3922,75 @@ var TafModuleProvider = function TafModuleProvider(_ref2) {
3922
3922
  }, children);
3923
3923
  };
3924
3924
 
3925
+ /* *
3926
+ * Licensed under the Apache License, Version 2.0 (the "License");
3927
+ * you may not use this file except in compliance with the License.
3928
+ * You may obtain a copy of the License at
3929
+ *
3930
+ * http://www.apache.org/licenses/LICENSE-2.0
3931
+ *
3932
+ * Unless required by applicable law or agreed to in writing, software
3933
+ * distributed under the License is distributed on an "AS IS" BASIS,
3934
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3935
+ * See the License for the specific language governing permissions and
3936
+ * limitations under the License.
3937
+ *
3938
+ * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3939
+ * Copyright 2022 - Finnish Meteorological Institute (FMI)
3940
+ * */
3941
+ var styles = {
3942
+ label: {
3943
+ color: 'geowebColors.buttons.tertiary.default.color',
3944
+ opacity: 1,
3945
+ fontSize: '12px',
3946
+ fontWeight: 500
3947
+ }
3948
+ };
3949
+
3950
+ var SwitchButton = function SwitchButton(props) {
3951
+ return /*#__PURE__*/React.createElement(Tooltip, {
3952
+ title: "Switch mode"
3953
+ }, /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(FormLabel, {
3954
+ sx: styles.label
3955
+ }, "Viewer"), /*#__PURE__*/React.createElement(Switch, Object.assign({
3956
+ "data-testid": "switchMode"
3957
+ }, props)), /*#__PURE__*/React.createElement(FormLabel, {
3958
+ sx: styles.label
3959
+ }, "Editor")));
3960
+ };
3961
+
3962
+ /* *
3963
+ * Licensed under the Apache License, Version 2.0 (the "License");
3964
+ * you may not use this file except in compliance with the License.
3965
+ * You may obtain a copy of the License at
3966
+ *
3967
+ * http://www.apache.org/licenses/LICENSE-2.0
3968
+ *
3969
+ * Unless required by applicable law or agreed to in writing, software
3970
+ * distributed under the License is distributed on an "AS IS" BASIS,
3971
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3972
+ * See the License for the specific language governing permissions and
3973
+ * limitations under the License.
3974
+ *
3975
+ * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3976
+ * Copyright 2022 - Finnish Meteorological Institute (FMI)
3977
+ * */
3978
+
3979
+ var TafAvatar = function TafAvatar(_ref) {
3980
+ var editor = _ref.editor,
3981
+ _ref$tooltipPlacement = _ref.tooltipPlacement,
3982
+ tooltipPlacement = _ref$tooltipPlacement === void 0 ? 'bottom' : _ref$tooltipPlacement;
3983
+ return /*#__PURE__*/React.createElement(Tooltip, {
3984
+ title: "Editor: ".concat(editor),
3985
+ placement: tooltipPlacement
3986
+ }, /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(Avatar, {
3987
+ size: "small"
3988
+ }, getInitials(editor))));
3989
+ };
3990
+
3925
3991
  var noop = function noop() {};
3926
3992
 
3927
- var TafForm = function TafForm(_ref) {
3993
+ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
3928
3994
  var tafFromBackend = _ref.tafFromBackend,
3929
3995
  _ref$onFormAction = _ref.onFormAction,
3930
3996
  onFormAction = _ref$onFormAction === void 0 ? function () {
@@ -3941,9 +4007,19 @@ var TafForm = function TafForm(_ref) {
3941
4007
  _ref$setIsDisabled = _ref.setIsDisabled,
3942
4008
  setIsDisabled = _ref$setIsDisabled === void 0 ? function () {
3943
4009
  return null;
3944
- } : _ref$setIsDisabled;
3945
- var originalTaf = tafFromBackend.taf;
3946
- var isDefaultDisabled = getIsFormDefaultDisabled(tafFromBackend.taf.status);
4010
+ } : _ref$setIsDisabled,
4011
+ _ref$onSwitchEditor = _ref.onSwitchEditor,
4012
+ onSwitchEditor = _ref$onSwitchEditor === void 0 ? function () {
4013
+ return null;
4014
+ } : _ref$onSwitchEditor;
4015
+ var originalTaf = tafFromBackend.taf,
4016
+ editor = tafFromBackend.editor;
4017
+
4018
+ var _useAuthenticationCon = useAuthenticationContext(),
4019
+ auth = _useAuthenticationCon.auth;
4020
+
4021
+ var isEditor = editor === (auth === null || auth === void 0 ? void 0 : auth.username) || false;
4022
+ var isDefaultDisabled = getIsFormDefaultDisabled(originalTaf.status);
3947
4023
  var confirmDialog = useConfirmationDialog();
3948
4024
 
3949
4025
  var _useDraftFormHelpers = useDraftFormHelpers(true),
@@ -4034,19 +4110,106 @@ var TafForm = function TafForm(_ref) {
4034
4110
  var resetFormValues = function resetFormValues() {
4035
4111
  var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
4036
4112
  var shouldAddEmptyChangGroup = arguments.length > 1 ? arguments[1] : undefined;
4037
- var newTaf = prepareTafValues(tafFromBackend.taf, action, shouldAddEmptyChangGroup);
4113
+ var newTaf = prepareTafValues(originalTaf, action, shouldAddEmptyChangGroup);
4038
4114
  reset(newTaf);
4039
4115
  };
4040
4116
 
4041
4117
  var resetForm = function resetForm() {
4042
4118
  var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
4043
4119
  var resetDisabled = arguments.length > 1 ? arguments[1] : undefined;
4044
- var shouldAddEmptyChangGroup = !(tafFromBackend.taf && tafFromBackend.taf.changeGroups) && !resetDisabled;
4120
+ var shouldAddEmptyChangGroup = !(originalTaf && originalTaf.changeGroups) && !resetDisabled;
4045
4121
  resetFormValues(action, shouldAddEmptyChangGroup);
4046
4122
  setIsDisabled(resetDisabled);
4047
4123
  setTafAction(action);
4048
4124
  };
4049
4125
 
4126
+ var setIsEditor = function setIsEditor(checked) {
4127
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
4128
+ var editor, didSucceed;
4129
+ return regeneratorRuntime.wrap(function _callee$(_context) {
4130
+ while (1) {
4131
+ switch (_context.prev = _context.next) {
4132
+ case 0:
4133
+ editor = checked ? auth === null || auth === void 0 ? void 0 : auth.username : '';
4134
+
4135
+ if (!(editor === tafFromBackend.editor)) {
4136
+ _context.next = 3;
4137
+ break;
4138
+ }
4139
+
4140
+ return _context.abrupt("return", true);
4141
+
4142
+ case 3:
4143
+ if (!(tafFromBackend.editor !== '' && tafFromBackend.editor !== null && tafFromBackend.editor !== (auth === null || auth === void 0 ? void 0 : auth.username))) {
4144
+ _context.next = 6;
4145
+ break;
4146
+ }
4147
+
4148
+ _context.next = 6;
4149
+ return confirmDialog({
4150
+ title: 'Switch to editor mode',
4151
+ description: 'This TAF is already in edit mode and important information could get lost in the switching process.',
4152
+ confirmLabel: 'Edit mode'
4153
+ });
4154
+
4155
+ case 6:
4156
+ _context.next = 8;
4157
+ return onSwitchEditor(Object.assign(Object.assign({}, tafFromBackend), {
4158
+ editor: editor
4159
+ }));
4160
+
4161
+ case 8:
4162
+ didSucceed = _context.sent;
4163
+ return _context.abrupt("return", didSucceed);
4164
+
4165
+ case 10:
4166
+ case "end":
4167
+ return _context.stop();
4168
+ }
4169
+ }
4170
+ }, _callee);
4171
+ }));
4172
+ };
4173
+
4174
+ var onSwitchMode = function onSwitchMode(event) {
4175
+ var checked = event.target.checked;
4176
+
4177
+ if (!checked && isFormDirty) {
4178
+ confirmDialog({
4179
+ title: 'Whoops',
4180
+ description: 'Are you sure you want to switch to viewer mode? Your unsaved changes will be lost.',
4181
+ confirmLabel: 'Switch mode'
4182
+ }).then(function () {
4183
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
4184
+ var didSucceed;
4185
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
4186
+ while (1) {
4187
+ switch (_context2.prev = _context2.next) {
4188
+ case 0:
4189
+ _context2.next = 2;
4190
+ return setIsEditor(checked);
4191
+
4192
+ case 2:
4193
+ didSucceed = _context2.sent;
4194
+
4195
+ if (didSucceed) {
4196
+ resetForm(undefined, isDefaultDisabled);
4197
+ resetTAC();
4198
+ }
4199
+
4200
+ case 4:
4201
+ case "end":
4202
+ return _context2.stop();
4203
+ }
4204
+ }
4205
+ }, _callee2);
4206
+ }));
4207
+ });
4208
+ } else {
4209
+ setIsEditor(checked);
4210
+ }
4211
+ };
4212
+
4050
4213
  var onTafEditModeButtonPress = function onTafEditModeButtonPress(action) {
4051
4214
  switch (action) {
4052
4215
  case 'DRAFT':
@@ -4076,21 +4239,21 @@ var TafForm = function TafForm(_ref) {
4076
4239
  case 'PUBLISH':
4077
4240
  toggleIsDraft(false);
4078
4241
  handleSubmit(function (data) {
4079
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
4242
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
4080
4243
  var didSucceed;
4081
- return regeneratorRuntime.wrap(function _callee$(_context) {
4244
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
4082
4245
  while (1) {
4083
- switch (_context.prev = _context.next) {
4246
+ switch (_context3.prev = _context3.next) {
4084
4247
  case 0:
4085
- _context.next = 2;
4248
+ _context3.next = 2;
4086
4249
  return showConfirmDialog(action);
4087
4250
 
4088
4251
  case 2:
4089
- _context.next = 4;
4252
+ _context3.next = 4;
4090
4253
  return onFormAction(action, convertTafValuesToObject(data));
4091
4254
 
4092
4255
  case 4:
4093
- didSucceed = _context.sent;
4256
+ didSucceed = _context3.sent;
4094
4257
 
4095
4258
  if (didSucceed) {
4096
4259
  setIsDisabled(true);
@@ -4100,10 +4263,10 @@ var TafForm = function TafForm(_ref) {
4100
4263
 
4101
4264
  case 6:
4102
4265
  case "end":
4103
- return _context.stop();
4266
+ return _context3.stop();
4104
4267
  }
4105
4268
  }
4106
- }, _callee);
4269
+ }, _callee3);
4107
4270
  }));
4108
4271
  })();
4109
4272
  break;
@@ -4118,7 +4281,21 @@ var TafForm = function TafForm(_ref) {
4118
4281
  switch (action) {
4119
4282
  case 'CANCEL':
4120
4283
  showConfirmDialog(action).then(function () {
4121
- onFormAction(action, convertTafValuesToObject(prepareTafValues(tafFromBackend.taf, action)));
4284
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
4285
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
4286
+ while (1) {
4287
+ switch (_context4.prev = _context4.next) {
4288
+ case 0:
4289
+ _context4.next = 2;
4290
+ return onFormAction(action, convertTafValuesToObject(prepareTafValues(originalTaf, action)));
4291
+
4292
+ case 2:
4293
+ case "end":
4294
+ return _context4.stop();
4295
+ }
4296
+ }
4297
+ }, _callee4);
4298
+ }));
4122
4299
  });
4123
4300
  break;
4124
4301
 
@@ -4215,8 +4392,8 @@ var TafForm = function TafForm(_ref) {
4215
4392
  setShouldValidate = _React$useState4[1];
4216
4393
 
4217
4394
  React__default.useEffect(function () {
4218
- setIsDisabled(isDefaultDisabled);
4219
- var defaultValues = prepareTafValues(tafFromBackend.taf, undefined, !isDefaultDisabled && !tafFromBackend.taf.changeGroups); // set initial form values
4395
+ setIsDisabled(!isEditor || isDefaultDisabled);
4396
+ var defaultValues = prepareTafValues(originalTaf, undefined, !isDefaultDisabled && !originalTaf.changeGroups); // set initial form values
4220
4397
 
4221
4398
  reset(defaultValues); // set validate flag to validate after the values have been set
4222
4399
 
@@ -4246,23 +4423,54 @@ var TafForm = function TafForm(_ref) {
4246
4423
  }; // eslint-disable-next-line react-hooks/exhaustive-deps
4247
4424
  }, []);
4248
4425
  React__default.useEffect(function () {
4249
- var newValues = prepareTafValues(tafFromBackend.taf, undefined, !isDefaultDisabled && !tafFromBackend.taf.changeGroups); // set new form values when tafFromBackend changed
4426
+ var newValues = prepareTafValues(originalTaf, undefined, !isDefaultDisabled && !originalTaf.changeGroups); // set new form values when taf values changed
4427
+
4428
+ reset(newValues); // reset TAC when taf values changed
4250
4429
 
4251
- reset(newValues); // eslint-disable-next-line react-hooks/exhaustive-deps
4252
- }, [tafFromBackend]);
4430
+ resetTAC(); // eslint-disable-next-line react-hooks/exhaustive-deps
4431
+ }, [originalTaf]);
4432
+ React__default.useEffect(function () {
4433
+ // update disabled state when editor changed
4434
+ setIsDisabled(!isEditor || isDefaultDisabled); // eslint-disable-next-line react-hooks/exhaustive-deps
4435
+ }, [editor]);
4253
4436
  React__default.useEffect(function () {
4254
4437
  if (shouldValidate && !isDisabled) {
4255
- // trigger validation on all changegroup validity times after initial load since they could be outside the new validity period
4256
- var _tafFromBackend$taf$c = tafFromBackend.taf.changeGroups,
4257
- changeGroups = _tafFromBackend$taf$c === void 0 ? [] : _tafFromBackend$taf$c;
4438
+ // trigger validation on all changegroup validity times after form is enabled since they could be outside the new validity period
4439
+ var _originalTaf$changeGr = originalTaf.changeGroups,
4440
+ changeGroups = _originalTaf$changeGr === void 0 ? [] : _originalTaf$changeGr;
4258
4441
  var validFields = changeGroups.map(function (_field, index) {
4259
4442
  return "changeGroups[".concat(index, "].valid");
4260
4443
  });
4261
4444
  trigger(validFields);
4262
4445
  } // eslint-disable-next-line react-hooks/exhaustive-deps
4263
4446
 
4264
- }, [shouldValidate]);
4265
- return /*#__PURE__*/React__default.createElement("form", {
4447
+ }, [shouldValidate, isDisabled]);
4448
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Box, {
4449
+ sx: {
4450
+ display: 'flex',
4451
+ flexDirection: 'row',
4452
+ alignItems: 'center',
4453
+ position: 'absolute',
4454
+ top: {
4455
+ xs: '20px',
4456
+ sm: '0px'
4457
+ },
4458
+ right: {
4459
+ xs: 'calc(50% - 70px)',
4460
+ sm: '8px'
4461
+ }
4462
+ }
4463
+ }, /*#__PURE__*/React__default.createElement(SwitchButton, {
4464
+ checked: isEditor,
4465
+ onChange: onSwitchMode
4466
+ }), /*#__PURE__*/React__default.createElement(Box, {
4467
+ sx: {
4468
+ width: '16px',
4469
+ marginLeft: 1
4470
+ }
4471
+ }, editor && /*#__PURE__*/React__default.createElement(TafAvatar, {
4472
+ editor: editor
4473
+ }))), /*#__PURE__*/React__default.createElement("form", {
4266
4474
  "data-testid": "taf-form",
4267
4475
  onSubmit: handleSubmit(onSubmit),
4268
4476
  onBlur: onFormBlur
@@ -4328,7 +4536,7 @@ var TafForm = function TafForm(_ref) {
4328
4536
  index: index
4329
4537
  })
4330
4538
  });
4331
- })), !isDisabled && /*#__PURE__*/React__default.createElement(Grid, {
4539
+ })), !isDisabled && isEditor && /*#__PURE__*/React__default.createElement(Grid, {
4332
4540
  container: true,
4333
4541
  justifyContent: "space-between",
4334
4542
  alignItems: "center",
@@ -4342,7 +4550,7 @@ var TafForm = function TafForm(_ref) {
4342
4550
  errors: errors,
4343
4551
  isIssuesPaneOpen: isIssuesPaneOpen,
4344
4552
  setIsIssuesPaneOpen: setIsIssuesPaneOpen
4345
- }))), /*#__PURE__*/React__default.createElement(TafFormButtons, {
4553
+ }))), isEditor && /*#__PURE__*/React__default.createElement(TafFormButtons, {
4346
4554
  isFormDisabled: isDisabled,
4347
4555
  tafAction: tafAction,
4348
4556
  canBe: tafFromBackend.canbe,
@@ -4353,8 +4561,12 @@ var TafForm = function TafForm(_ref) {
4353
4561
  name: field,
4354
4562
  key: field
4355
4563
  });
4356
- }), /*#__PURE__*/React__default.createElement(DraftFieldHelper, null));
4357
- };
4564
+ }), /*#__PURE__*/React__default.createElement(DraftFieldHelper, null)));
4565
+ }, function (prevProps, nextProps) {
4566
+ // prevent re-render
4567
+ return !nextProps.isDisabled && prevProps.tafFromBackend !== nextProps.tafFromBackend && // if editor changed it should rerender
4568
+ prevProps.tafFromBackend.editor === nextProps.tafFromBackend.editor;
4569
+ });
4358
4570
 
4359
4571
  /* *
4360
4572
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -4406,14 +4618,16 @@ var TabPanel = function TabPanel(_a) {
4406
4618
  * */
4407
4619
 
4408
4620
  var TafHeader = function TafHeader(_ref) {
4409
- var title = _ref.title;
4621
+ var title = _ref.title,
4622
+ _ref$sx = _ref.sx,
4623
+ sx = _ref$sx === void 0 ? {} : _ref$sx;
4410
4624
  return /*#__PURE__*/React__default.createElement(Typography, {
4411
- sx: {
4625
+ sx: Object.assign({
4412
4626
  textAlign: 'center',
4413
4627
  fontWeight: 500,
4414
4628
  paddingTop: '6px',
4415
4629
  textTransform: 'capitalize'
4416
- }
4630
+ }, sx)
4417
4631
  }, title);
4418
4632
  };
4419
4633
 
@@ -4653,17 +4867,18 @@ var StatusIcon = function StatusIcon(_ref2) {
4653
4867
  * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
4654
4868
  * Copyright 2022 - Finnish Meteorological Institute (FMI)
4655
4869
  * */
4870
+ var TOOLTIP_TITLE = 'Import TAC';
4656
4871
 
4657
4872
  var ExportButton = function ExportButton(_ref) {
4658
4873
  var onClick = _ref.onClick,
4659
4874
  isHidden = _ref.isHidden;
4660
4875
  return isHidden ? null : /*#__PURE__*/React__default.createElement(Tooltip, {
4661
- title: "Import TAC",
4876
+ title: TOOLTIP_TITLE,
4662
4877
  placement: "left"
4663
- }, /*#__PURE__*/React__default.createElement("span", null, /*#__PURE__*/React__default.createElement(ToolButton, {
4878
+ }, /*#__PURE__*/React__default.createElement(ToolButton, {
4664
4879
  onClick: onClick,
4665
4880
  "data-testid": "export-tac-button"
4666
- }, /*#__PURE__*/React__default.createElement(Export, null))));
4881
+ }, /*#__PURE__*/React__default.createElement(Export, null)));
4667
4882
  };
4668
4883
 
4669
4884
  var TacContainer = function TacContainer(_ref) {
@@ -4943,7 +5158,7 @@ var TacOverviewMobile = function TacOverviewMobile(_ref) {
4943
5158
  },
4944
5159
  position: 'absolute',
4945
5160
  right: '8px',
4946
- top: '30px'
5161
+ top: '48px'
4947
5162
  }
4948
5163
  }, /*#__PURE__*/React.createElement(ListItem, null)), /*#__PURE__*/React.createElement(Dialog, {
4949
5164
  open: isOpen,
@@ -5073,7 +5288,8 @@ var LocationTabs = function LocationTabs(_ref) {
5073
5288
  paddingTop: '32px'
5074
5289
  }
5075
5290
  }, tafList.map(function (_ref2, index) {
5076
- var taf = _ref2.taf;
5291
+ var taf = _ref2.taf,
5292
+ editor = _ref2.editor;
5077
5293
  return /*#__PURE__*/React.createElement(MenuItem, {
5078
5294
  key: taf.uuid,
5079
5295
  selected: index === activeIndex,
@@ -5098,8 +5314,18 @@ var LocationTabs = function LocationTabs(_ref) {
5098
5314
  onClick: function onClick() {
5099
5315
  return onChangeTab(index);
5100
5316
  }
5101
- }, /*#__PURE__*/React.createElement(Box$1, {
5317
+ }, editor && /*#__PURE__*/React.createElement(Box$1, {
5318
+ sx: {
5319
+ position: 'absolute',
5320
+ top: '4px',
5321
+ left: '8px'
5322
+ }
5323
+ }, /*#__PURE__*/React.createElement(TafAvatar, {
5324
+ editor: editor,
5325
+ tooltipPlacement: "right"
5326
+ })), /*#__PURE__*/React.createElement(Box$1, {
5102
5327
  component: "span",
5328
+ "data-testid": "taf-location",
5103
5329
  sx: {
5104
5330
  fontSize: '12px',
5105
5331
  fontWeight: '500',
@@ -5173,15 +5399,29 @@ var fromActionToStatus = function fromActionToStatus(tafAction) {
5173
5399
  return 'NEW';
5174
5400
  }
5175
5401
  };
5402
+ var isWarning = function isWarning(error) {
5403
+ return (error === null || error === void 0 ? void 0 : error.type) === 'WARNING';
5404
+ };
5176
5405
 
5177
5406
  var parseErrorMessage = function parseErrorMessage(error, params) {
5407
+ var message = getErrorMessage$1(error);
5408
+ var warningMessage = getWarningMessage(error);
5409
+
5410
+ if (warningMessage) {
5411
+ return {
5412
+ type: 'WARNING',
5413
+ title: warningMessage
5414
+ };
5415
+ }
5416
+
5178
5417
  return params.changeStatusTo === 'CANCELLED' ? {
5179
5418
  type: 'CANCELLED',
5180
- title: 'Cancelling this TAF failed, please try again'
5419
+ title: 'Cancelling this TAF failed, please try again',
5420
+ message: message
5181
5421
  } : {
5182
5422
  type: 'SERVER',
5183
5423
  title: 'An error has occurred while saving, please try again',
5184
- message: isAxiosError(error) ? getAxiosErrorMessage(error) : error.message
5424
+ message: message
5185
5425
  };
5186
5426
  };
5187
5427
 
@@ -5272,6 +5512,10 @@ var TafPanel = function TafPanel(_ref) {
5272
5512
  postTaf = _ref$postTaf === void 0 ? function () {
5273
5513
  return null;
5274
5514
  } : _ref$postTaf,
5515
+ _ref$patchTaf = _ref.patchTaf,
5516
+ patchTaf = _ref$patchTaf === void 0 ? function () {
5517
+ return null;
5518
+ } : _ref$patchTaf,
5275
5519
  _ref$isIssuesPaneOpen = _ref.isIssuesPaneOpen,
5276
5520
  isIssuesPaneOpen = _ref$isIssuesPaneOpen === void 0 ? false : _ref$isIssuesPaneOpen,
5277
5521
  _ref$setIsIssuesPaneO = _ref.setIsIssuesPaneOpen,
@@ -5285,6 +5529,7 @@ var TafPanel = function TafPanel(_ref) {
5285
5529
  return null;
5286
5530
  } : _ref$setIsFormDisable,
5287
5531
  error = _ref.error;
5532
+ var severity = isWarning(error) ? 'warning' : 'error';
5288
5533
 
5289
5534
  var onTafAction = function onTafAction(action, taf) {
5290
5535
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
@@ -5333,7 +5578,10 @@ var TafPanel = function TafPanel(_ref) {
5333
5578
  index: index,
5334
5579
  "data-testid": "taf-panel".concat(activeTafIndex === index ? '-active' : '')
5335
5580
  }, /*#__PURE__*/React__default.createElement(TafHeader, {
5336
- title: getTafStatusLabel(tafFromBackend.taf.status)
5581
+ title: getTafStatusLabel(tafFromBackend.taf.status),
5582
+ sx: {
5583
+ marginBottom: '4px'
5584
+ }
5337
5585
  }), isLoading && /*#__PURE__*/React__default.createElement(Spinner, {
5338
5586
  "data-testid": "taf-loading",
5339
5587
  sx: {
@@ -5342,7 +5590,7 @@ var TafPanel = function TafPanel(_ref) {
5342
5590
  color: 'geowebColors.backdrops.white.fill'
5343
5591
  }
5344
5592
  }), error && /*#__PURE__*/React__default.createElement(AlertBanner, {
5345
- severity: "error",
5593
+ severity: severity,
5346
5594
  title: error.title,
5347
5595
  info: error.message,
5348
5596
  dataTestId: "taf-error",
@@ -5358,7 +5606,8 @@ var TafPanel = function TafPanel(_ref) {
5358
5606
  isIssuesPaneOpen: isIssuesPaneOpen,
5359
5607
  setIsIssuesPaneOpen: setIsIssuesPaneOpen,
5360
5608
  isDisabled: isFormDisabled,
5361
- setIsDisabled: setIsFormDisabled
5609
+ setIsDisabled: setIsFormDisabled,
5610
+ onSwitchEditor: patchTaf
5362
5611
  })));
5363
5612
  };
5364
5613
 
@@ -5389,6 +5638,57 @@ var IssuesPaneWrapper = function IssuesPaneWrapper(props) {
5389
5638
  }, props));
5390
5639
  };
5391
5640
 
5641
+ /* *
5642
+ * Licensed under the Apache License, Version 2.0 (the "License");
5643
+ * you may not use this file except in compliance with the License.
5644
+ * You may obtain a copy of the License at
5645
+ *
5646
+ * http://www.apache.org/licenses/LICENSE-2.0
5647
+ *
5648
+ * Unless required by applicable law or agreed to in writing, software
5649
+ * distributed under the License is distributed on an "AS IS" BASIS,
5650
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5651
+ * See the License for the specific language governing permissions and
5652
+ * limitations under the License.
5653
+ *
5654
+ * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
5655
+ * Copyright 2022 - Finnish Meteorological Institute (FMI)
5656
+ * */
5657
+ var getLastUpdateTitle = function getLastUpdateTitle(time) {
5658
+ return "Last updated ".concat(time);
5659
+ };
5660
+
5661
+ var LastUpdateTime = function LastUpdateTime(_ref) {
5662
+ var _ref$onUpdateTaf = _ref.onUpdateTaf,
5663
+ onUpdateTaf = _ref$onUpdateTaf === void 0 ? function () {} : _ref$onUpdateTaf,
5664
+ lastUpdateTime = _ref.lastUpdateTime;
5665
+ return /*#__PURE__*/React__default.createElement(Box, {
5666
+ sx: {
5667
+ display: 'flex',
5668
+ alignItems: 'center',
5669
+ height: '100%',
5670
+ justifyContent: 'flex-end'
5671
+ }
5672
+ }, /*#__PURE__*/React__default.createElement(Typography, {
5673
+ sx: {
5674
+ color: 'geowebColors.captions.captionStatus.rgba',
5675
+ fontSize: '10px',
5676
+ lineHeight: '1.6',
5677
+ letterSpacing: '0.33px'
5678
+ },
5679
+ "data-testid": "lastupdated-time"
5680
+ }, getLastUpdateTitle(lastUpdateTime)), /*#__PURE__*/React__default.createElement(Tooltip, {
5681
+ title: "Click to refresh"
5682
+ }, /*#__PURE__*/React__default.createElement(ToolButton, {
5683
+ "data-testid": "updateTafBtn",
5684
+ onClick: onUpdateTaf,
5685
+ sx: {
5686
+ marginRight: 1,
5687
+ marginLeft: 1
5688
+ }
5689
+ }, /*#__PURE__*/React__default.createElement(Cached, null))));
5690
+ };
5691
+
5392
5692
  var CONFIRM_DIALOG_OPTIONS = {
5393
5693
  title: 'Whoops',
5394
5694
  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.",
@@ -5398,8 +5698,9 @@ var CONFIRM_DIALOG_OPTIONS = {
5398
5698
  var TafLayout = function TafLayout(_ref) {
5399
5699
  var _ref$tafList = _ref.tafList,
5400
5700
  tafList = _ref$tafList === void 0 ? [] : _ref$tafList,
5401
- _ref$onPostTaf = _ref.onPostTaf,
5402
- onPostTaf = _ref$onPostTaf === void 0 ? function () {} : _ref$onPostTaf;
5701
+ _ref$onUpdateTaf = _ref.onUpdateTaf,
5702
+ onUpdateTaf = _ref$onUpdateTaf === void 0 ? function () {} : _ref$onUpdateTaf,
5703
+ lastUpdateTime = _ref.lastUpdateTime;
5403
5704
 
5404
5705
  var _useApiContext = useApiContext(),
5405
5706
  api = _useApiContext.api;
@@ -5415,8 +5716,11 @@ var TafLayout = function TafLayout(_ref) {
5415
5716
  var _usePostTafRequest = usePostTafRequest(api.postTaf),
5416
5717
  isLoading = _usePostTafRequest.isLoading,
5417
5718
  postTafRequest = _usePostTafRequest.doRequest,
5418
- error = _usePostTafRequest.error,
5419
- setError = _usePostTafRequest.setError;
5719
+ postError = _usePostTafRequest.error;
5720
+
5721
+ var _usePostTafRequest2 = usePostTafRequest(api.patchTaf),
5722
+ patchTafRequest = _usePostTafRequest2.doRequest,
5723
+ patchError = _usePostTafRequest2.error;
5420
5724
 
5421
5725
  var _useTafModuleContext = useTafModuleContext(),
5422
5726
  onValidateForm = _useTafModuleContext.onValidateForm,
@@ -5455,47 +5759,96 @@ var TafLayout = function TafLayout(_ref) {
5455
5759
  isFormDisabled = _React$useState10[0],
5456
5760
  setIsFormDisabled = _React$useState10[1];
5457
5761
 
5762
+ var _React$useState11 = React__default.useState(),
5763
+ _React$useState12 = _slicedToArray(_React$useState11, 2),
5764
+ error = _React$useState12[0],
5765
+ setError = _React$useState12[1];
5766
+
5458
5767
  var postTaf = function postTaf(data) {
5459
5768
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
5460
5769
  return regeneratorRuntime.wrap(function _callee$(_context) {
5461
5770
  while (1) {
5462
5771
  switch (_context.prev = _context.next) {
5463
5772
  case 0:
5464
- _context.next = 2;
5773
+ _context.prev = 0;
5774
+ setError(null);
5775
+ _context.next = 4;
5465
5776
  return postTafRequest(data);
5466
5777
 
5467
- case 2:
5778
+ case 4:
5468
5779
  // callback
5469
- onPostTaf();
5780
+ onUpdateTaf();
5781
+ _context.next = 11;
5782
+ break;
5470
5783
 
5471
- case 3:
5784
+ case 7:
5785
+ _context.prev = 7;
5786
+ _context.t0 = _context["catch"](0);
5787
+
5788
+ if (isWarning(_context.t0)) {
5789
+ onUpdateTaf();
5790
+ }
5791
+
5792
+ throw _context.t0;
5793
+
5794
+ case 11:
5472
5795
  case "end":
5473
5796
  return _context.stop();
5474
5797
  }
5475
5798
  }
5476
- }, _callee);
5799
+ }, _callee, null, [[0, 7]]);
5477
5800
  }));
5478
5801
  };
5479
5802
 
5480
- function onChangeTab(action, value) {
5481
- return __awaiter(this, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
5482
- var taf;
5803
+ var patchTaf = function patchTaf(data) {
5804
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
5483
5805
  return regeneratorRuntime.wrap(function _callee2$(_context2) {
5484
5806
  while (1) {
5485
5807
  switch (_context2.prev = _context2.next) {
5808
+ case 0:
5809
+ _context2.prev = 0;
5810
+ setError(null);
5811
+ _context2.next = 4;
5812
+ return patchTafRequest(data);
5813
+
5814
+ case 4:
5815
+ // callback
5816
+ onUpdateTaf();
5817
+ return _context2.abrupt("return", true);
5818
+
5819
+ case 8:
5820
+ _context2.prev = 8;
5821
+ _context2.t0 = _context2["catch"](0);
5822
+ return _context2.abrupt("return", false);
5823
+
5824
+ case 11:
5825
+ case "end":
5826
+ return _context2.stop();
5827
+ }
5828
+ }
5829
+ }, _callee2, null, [[0, 8]]);
5830
+ }));
5831
+ };
5832
+
5833
+ function onChangeTab(action, value) {
5834
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
5835
+ var taf;
5836
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
5837
+ while (1) {
5838
+ switch (_context3.prev = _context3.next) {
5486
5839
  case 0:
5487
5840
  if (!isFormDirty) {
5488
- _context2.next = 15;
5841
+ _context3.next = 15;
5489
5842
  break;
5490
5843
  }
5491
5844
 
5492
- _context2.prev = 1;
5493
- _context2.next = 4;
5845
+ _context3.prev = 1;
5846
+ _context3.next = 4;
5494
5847
  return onValidateForm();
5495
5848
 
5496
5849
  case 4:
5497
- taf = _context2.sent;
5498
- _context2.next = 7;
5850
+ taf = _context3.sent;
5851
+ _context3.next = 7;
5499
5852
  return postTaf({
5500
5853
  taf: taf,
5501
5854
  changeStatusTo: fromActionToStatus(tafActionToDraftAction(tafAction))
@@ -5503,19 +5856,19 @@ var TafLayout = function TafLayout(_ref) {
5503
5856
 
5504
5857
  case 7:
5505
5858
  action(value);
5506
- _context2.next = 13;
5859
+ _context3.next = 13;
5507
5860
  break;
5508
5861
 
5509
5862
  case 10:
5510
- _context2.prev = 10;
5511
- _context2.t0 = _context2["catch"](1);
5863
+ _context3.prev = 10;
5864
+ _context3.t0 = _context3["catch"](1);
5512
5865
  confirmDialog(CONFIRM_DIALOG_OPTIONS).then(function () {
5513
5866
  action(value);
5514
5867
  setError(null);
5515
5868
  });
5516
5869
 
5517
5870
  case 13:
5518
- _context2.next = 17;
5871
+ _context3.next = 17;
5519
5872
  break;
5520
5873
 
5521
5874
  case 15:
@@ -5524,10 +5877,10 @@ var TafLayout = function TafLayout(_ref) {
5524
5877
 
5525
5878
  case 17:
5526
5879
  case "end":
5527
- return _context2.stop();
5880
+ return _context3.stop();
5528
5881
  }
5529
5882
  }
5530
- }, _callee2, null, [[1, 10]]);
5883
+ }, _callee3, null, [[1, 10]]);
5531
5884
  }));
5532
5885
  }
5533
5886
 
@@ -5560,7 +5913,8 @@ var TafLayout = function TafLayout(_ref) {
5560
5913
  setActiveTafIndex(newIndex); // eslint-disable-next-line react-hooks/exhaustive-deps
5561
5914
  }, [tafList, setLocations]);
5562
5915
  React__default.useEffect(function () {
5563
- var cancelErrorTimeout = error && error.type === 'CANCELLED' ? setTimeout(function () {
5916
+ setError(postError);
5917
+ var cancelErrorTimeout = postError && postError.type === 'CANCELLED' ? setTimeout(function () {
5564
5918
  setError(null);
5565
5919
  }, 10000) : null;
5566
5920
  return function () {
@@ -5568,7 +5922,10 @@ var TafLayout = function TafLayout(_ref) {
5568
5922
  clearTimeout(cancelErrorTimeout);
5569
5923
  }
5570
5924
  };
5571
- }, [error, setError]);
5925
+ }, [postError]);
5926
+ React__default.useEffect(function () {
5927
+ setError(patchError);
5928
+ }, [patchError]);
5572
5929
 
5573
5930
  if (!tafList) {
5574
5931
  return null;
@@ -5614,6 +5971,13 @@ var TafLayout = function TafLayout(_ref) {
5614
5971
  tafFromBackend: lastCurrentTaf,
5615
5972
  timeSlot: timeSlot,
5616
5973
  onChangeTimeSlot: onChangeTimeSlot
5974
+ })), /*#__PURE__*/React__default.createElement(Grid, {
5975
+ item: true,
5976
+ xs: 12,
5977
+ sm: 3
5978
+ }, lastUpdateTime && /*#__PURE__*/React__default.createElement(LastUpdateTime, {
5979
+ lastUpdateTime: lastUpdateTime,
5980
+ onUpdateTaf: onUpdateTaf
5617
5981
  }))), /*#__PURE__*/React__default.createElement(Grid, {
5618
5982
  container: true,
5619
5983
  flexGrow: 1,
@@ -5663,6 +6027,7 @@ var TafLayout = function TafLayout(_ref) {
5663
6027
  isFormDisabled: isFormDisabled,
5664
6028
  setIsFormDisabled: setIsFormDisabled,
5665
6029
  postTaf: postTaf,
6030
+ patchTaf: patchTaf,
5666
6031
  isLoading: isLoading,
5667
6032
  error: error
5668
6033
  });
@@ -5704,41 +6069,78 @@ var TafWrapper = function TafWrapper(_a) {
5704
6069
  }, children)));
5705
6070
  };
5706
6071
 
5707
- /* *
5708
- * Licensed under the Apache License, Version 2.0 (the "License");
5709
- * you may not use this file except in compliance with the License.
5710
- * You may obtain a copy of the License at
5711
- *
5712
- * http://www.apache.org/licenses/LICENSE-2.0
5713
- *
5714
- * Unless required by applicable law or agreed to in writing, software
5715
- * distributed under the License is distributed on an "AS IS" BASIS,
5716
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5717
- * See the License for the specific language governing permissions and
5718
- * limitations under the License.
5719
- *
5720
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
5721
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
5722
- * */
6072
+ var getCurrentDate = function getCurrentDate() {
6073
+ return moment.utc().format('HH:mm');
6074
+ };
5723
6075
 
5724
6076
  var TafModule = function TafModule() {
5725
6077
  var _useApiContext = useApiContext(),
5726
6078
  api = _useApiContext.api;
5727
6079
 
5728
- var _useApi = useApi(api.getTafList),
5729
- getTafListError = _useApi.error,
5730
- isLoading = _useApi.isLoading,
5731
- tafList = _useApi.result,
5732
- fetchNewTafList = _useApi.fetchApiData;
6080
+ var _React$useState = React.useState([]),
6081
+ _React$useState2 = _slicedToArray(_React$useState, 2),
6082
+ tafList = _React$useState2[0],
6083
+ setTafList = _React$useState2[1];
5733
6084
 
5734
- usePoller([tafList, getTafListError], function () {
5735
- return fetchNewTafList({});
5736
- });
6085
+ var _React$useState3 = React.useState(true),
6086
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
6087
+ isLoading = _React$useState4[0],
6088
+ setIsLoading = _React$useState4[1];
6089
+
6090
+ var _React$useState5 = React.useState(null),
6091
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
6092
+ getTafListError = _React$useState6[0],
6093
+ setError = _React$useState6[1];
6094
+
6095
+ var _React$useState7 = React.useState(),
6096
+ _React$useState8 = _slicedToArray(_React$useState7, 2),
6097
+ lastUpdateTime = _React$useState8[0],
6098
+ setLastUpdateTime = _React$useState8[1];
6099
+
6100
+ var fetchNewTafList = function fetchNewTafList() {
6101
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
6102
+ var result;
6103
+ return regeneratorRuntime.wrap(function _callee$(_context) {
6104
+ while (1) {
6105
+ switch (_context.prev = _context.next) {
6106
+ case 0:
6107
+ setIsLoading(true);
6108
+ setError(null);
6109
+ _context.prev = 2;
6110
+ _context.next = 5;
6111
+ return api.getTafList();
6112
+
6113
+ case 5:
6114
+ result = _context.sent;
6115
+ setTafList(result.data);
6116
+ setIsLoading(false);
6117
+ setLastUpdateTime(getCurrentDate());
6118
+ _context.next = 15;
6119
+ break;
5737
6120
 
5738
- var onPostTaf = function onPostTaf() {
5739
- fetchNewTafList({});
6121
+ case 11:
6122
+ _context.prev = 11;
6123
+ _context.t0 = _context["catch"](2);
6124
+ setError(_context.t0);
6125
+ setIsLoading(false);
6126
+
6127
+ case 15:
6128
+ case "end":
6129
+ return _context.stop();
6130
+ }
6131
+ }
6132
+ }, _callee, null, [[2, 11]]);
6133
+ }));
6134
+ };
6135
+
6136
+ var onUpdateTaf = function onUpdateTaf() {
6137
+ fetchNewTafList();
5740
6138
  };
5741
6139
 
6140
+ React.useEffect(function () {
6141
+ fetchNewTafList(); // eslint-disable-next-line react-hooks/exhaustive-deps
6142
+ }, []);
6143
+ usePoller([tafList, getTafListError], fetchNewTafList);
5742
6144
  var hasTafListError = getTafListError !== null;
5743
6145
  return /*#__PURE__*/React.createElement(Box, {
5744
6146
  component: "div",
@@ -5763,7 +6165,8 @@ var TafModule = function TafModule() {
5763
6165
  }
5764
6166
  }), /*#__PURE__*/React.createElement(TafLayout, {
5765
6167
  tafList: tafList,
5766
- onPostTaf: onPostTaf
6168
+ onUpdateTaf: onUpdateTaf,
6169
+ lastUpdateTime: lastUpdateTime
5767
6170
  }));
5768
6171
  };
5769
6172
 
@@ -5771,10 +6174,8 @@ var Wrapper = function Wrapper(props) {
5771
6174
  return /*#__PURE__*/React.createElement(TafWrapper, Object.assign({}, props), /*#__PURE__*/React.createElement(TafModule, null));
5772
6175
  };
5773
6176
 
5774
- var createApi$1 = function createApi(url, appUrl, auth, setAuth, authTokenUrl, authClientId) {
5775
- var axiosInstance = createApiInstance(url, appUrl, auth, setAuth, authTokenUrl, authClientId);
6177
+ var getApiRoutes$1 = function getApiRoutes(axiosInstance) {
5776
6178
  return {
5777
- // api data
5778
6179
  getTafList: function getTafList() {
5779
6180
  return axiosInstance.get('/taflist');
5780
6181
  },
@@ -5785,10 +6186,37 @@ var createApi$1 = function createApi(url, appUrl, auth, setAuth, authTokenUrl, a
5785
6186
  return axiosInstance.post.apply(axiosInstance, ['/taf2tac'].concat([Object.assign({}, tafData)].concat(_toConsumableArray(signal ? [{
5786
6187
  signal: signal
5787
6188
  }] : []))));
6189
+ },
6190
+ patchTaf: function patchTaf(formData) {
6191
+ return axiosInstance.patch('/taf', Object.assign({}, formData));
5788
6192
  }
5789
6193
  };
5790
6194
  };
5791
6195
 
6196
+ var createApi$1 = function createApi(url, appUrl, auth, setAuth, authTokenUrl, authClientId) {
6197
+ var axiosInstance = createApiInstance(url, appUrl, auth, setAuth, authTokenUrl, authClientId);
6198
+ return getApiRoutes$1(axiosInstance);
6199
+ };
6200
+
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
+ var MOCK_USERNAME = 'user.name';
6219
+
5792
6220
  var currentDate = moment.utc().format('YYYY-MM-DD');
5793
6221
  var tomorrowDate = moment.utc().add(1, 'day').format('YYYY-MM-DD');
5794
6222
  var airportPeriod = 6;
@@ -5827,6 +6255,7 @@ var _validDateRange5 = validDateRange(moment.utc().add(-6, 'hours'), airportPeri
5827
6255
  var fakeTafList = [{
5828
6256
  creationDate: upcomingValidDateStart,
5829
6257
  canbe: ['DRAFTED', 'DISCARDED', 'PUBLISHED'],
6258
+ editor: MOCK_USERNAME,
5830
6259
  taf: {
5831
6260
  uuid: '5f9583fjdf0f337925',
5832
6261
  baseTime: upcomingValidDateStart,
@@ -5846,6 +6275,7 @@ var fakeTafList = [{
5846
6275
  }, {
5847
6276
  creationDate: upcomingValidDateStart,
5848
6277
  canbe: ['DRAFTED', 'DISCARDED', 'PUBLISHED'],
6278
+ editor: null,
5849
6279
  taf: {
5850
6280
  uuid: '5f9583fjd111137925',
5851
6281
  baseTime: upcomingValidDateStart,
@@ -5871,6 +6301,7 @@ var fakeTafList = [{
5871
6301
  }, {
5872
6302
  creationDate: upcomingValidDateStart,
5873
6303
  canbe: ['CANCELLED', 'AMENDED', 'DISCARDED'],
6304
+ editor: null,
5874
6305
  taf: {
5875
6306
  uuid: '754905485',
5876
6307
  baseTime: upcomingValidDateStart,
@@ -5928,6 +6359,7 @@ var fakeTafList = [{
5928
6359
  }, {
5929
6360
  creationDate: upcomingValidDateStart,
5930
6361
  canbe: ['CANCELLED', 'AMENDED', 'CORRECTED'],
6362
+ editor: MOCK_USERNAME,
5931
6363
  taf: {
5932
6364
  uuid: '43545345345',
5933
6365
  issueDate: upcomingValidDateStart,
@@ -5998,6 +6430,7 @@ var fakeTafList = [{
5998
6430
  }, {
5999
6431
  creationDate: upcomingValidDateStart,
6000
6432
  canbe: ['CANCELLED', 'AMENDED', 'CORRECTED'],
6433
+ editor: null,
6001
6434
  taf: {
6002
6435
  uuid: '5f9583fjdf45ff4330f337925',
6003
6436
  issueDate: upcomingValidDateStart,
@@ -6053,6 +6486,7 @@ var fakeTafList = [{
6053
6486
  }, {
6054
6487
  creationDate: upcomingValidDateStart,
6055
6488
  canbe: ['AMENDED'],
6489
+ editor: null,
6056
6490
  taf: {
6057
6491
  uuid: '5464565464',
6058
6492
  previousId: '5445fghrfg3546456',
@@ -6094,6 +6528,7 @@ var fakeTafList = [{
6094
6528
  }, {
6095
6529
  creationDate: upcomingValidDateStart,
6096
6530
  canbe: ['CANCELLED', 'AMENDED', 'CORRECTED'],
6531
+ editor: 'max.jansen',
6097
6532
  taf: {
6098
6533
  uuid: 'gh56734fghfgh',
6099
6534
  previousId: '8574jnf93475',
@@ -6135,6 +6570,7 @@ var fakeTafList = [{
6135
6570
  }, {
6136
6571
  creationDate: currentValidDateStart,
6137
6572
  canbe: ['CANCELLED', 'AMENDED', 'CORRECTED'],
6573
+ editor: null,
6138
6574
  taf: {
6139
6575
  uuid: 'giskdj09845872039',
6140
6576
  issueDate: currentValidDateStart,
@@ -6174,6 +6610,7 @@ var fakeTafList = [{
6174
6610
  }, {
6175
6611
  creationDate: currentValidDateStart,
6176
6612
  canbe: ['DRAFTED', 'DISCARDED', 'PUBLISHED'],
6613
+ editor: null,
6177
6614
  taf: {
6178
6615
  uuid: 'ghskdj09845872039',
6179
6616
  baseTime: currentValidDateStart,
@@ -6193,6 +6630,7 @@ var fakeTafList = [{
6193
6630
  }, {
6194
6631
  creationDate: currentValidDateStart,
6195
6632
  canbe: ['DRAFTED', 'DISCARDED', 'PUBLISHED'],
6633
+ editor: null,
6196
6634
  taf: {
6197
6635
  uuid: 'ghskdj09845872040',
6198
6636
  issueDate: currentValidDateStart,
@@ -6213,6 +6651,7 @@ var fakeTafList = [{
6213
6651
  }, {
6214
6652
  creationDate: "".concat(currentDate, "T06:00:00Z"),
6215
6653
  canbe: ['DRAFTED', 'DISCARDED', 'PUBLISHED'],
6654
+ editor: null,
6216
6655
  taf: {
6217
6656
  uuid: 'ghskdj09845872041',
6218
6657
  issueDate: currentValidDateStart,
@@ -6233,6 +6672,7 @@ var fakeTafList = [{
6233
6672
  }, {
6234
6673
  creationDate: "".concat(currentDate, "T06:00:00Z"),
6235
6674
  canbe: ['DRAFTED', 'DISCARDED', 'PUBLISHED'],
6675
+ editor: null,
6236
6676
  taf: {
6237
6677
  uuid: 'ghskdj09845872042',
6238
6678
  issueDate: currentValidDateStart,
@@ -6253,6 +6693,7 @@ var fakeTafList = [{
6253
6693
  }, {
6254
6694
  creationDate: "".concat(currentDate, "T06:00:00Z"),
6255
6695
  canbe: ['DRAFTED', 'DISCARDED', 'PUBLISHED'],
6696
+ editor: null,
6256
6697
  taf: {
6257
6698
  uuid: 'ghskdj09845872043',
6258
6699
  issueDate: currentValidDateStart,
@@ -6273,6 +6714,7 @@ var fakeTafList = [{
6273
6714
  }, {
6274
6715
  creationDate: expiredValidDateStart,
6275
6716
  canbe: [],
6717
+ editor: null,
6276
6718
  taf: {
6277
6719
  uuid: 'sdkjhsdf90845890',
6278
6720
  issueDate: expiredValidDateStart,
@@ -6337,6 +6779,7 @@ var fakeTafList = [{
6337
6779
  var fakeNewTaf = {
6338
6780
  creationDate: "".concat(currentDate, "T12:00:00Z"),
6339
6781
  canbe: ['DRAFTED', 'DISCARDED', 'PUBLISHED'],
6782
+ editor: null,
6340
6783
  taf: {
6341
6784
  type: 'NORMAL',
6342
6785
  messageType: 'ORG',
@@ -6357,6 +6800,7 @@ var fakeNewTaf = {
6357
6800
  ({
6358
6801
  creationDate: "2022-01-06T12:00:00Z",
6359
6802
  canbe: ['DRAFTED', 'DISCARDED', 'PUBLISHED'],
6803
+ editor: MOCK_USERNAME,
6360
6804
  taf: Object.assign(Object.assign({}, fakeNewTaf.taf), {
6361
6805
  baseTime: "2022-01-06T12:00:00Z",
6362
6806
  validDateStart: "2022-01-06T12:00:00Z",
@@ -6372,6 +6816,7 @@ var fakeNewTaf = {
6372
6816
  var fakePublishedTaf = {
6373
6817
  creationDate: "".concat(currentDate, "T12:00:00Z"),
6374
6818
  canbe: ['CANCELLED', 'AMENDED', 'CORRECTED'],
6819
+ editor: null,
6375
6820
  taf: {
6376
6821
  uuid: 'slsdkjg-023895',
6377
6822
  issueDate: "".concat(currentDate, "T12:00:00Z"),
@@ -6447,7 +6892,9 @@ var fakePublishedTaf = {
6447
6892
  ({
6448
6893
  creationDate: "2022-01-06T12:00:00Z",
6449
6894
  canbe: ['CANCELLED', 'AMENDED', 'CORRECTED'],
6895
+ editor: MOCK_USERNAME,
6450
6896
  taf: Object.assign(Object.assign({}, fakePublishedTaf.taf), {
6897
+ uuid: 'sowi3u4o-lsdjflsk',
6451
6898
  location: 'EHGG',
6452
6899
  baseTime: "2022-01-06T12:00:00Z",
6453
6900
  issueDate: "2022-01-06T12:00:00Z",
@@ -6512,6 +6959,7 @@ var fakePublishedTaf = {
6512
6959
  var fakeDraftTaf = {
6513
6960
  creationDate: "".concat(currentDate, "T18:00:00Z"),
6514
6961
  canbe: ['DRAFTED', 'DISCARDED', 'PUBLISHED'],
6962
+ editor: null,
6515
6963
  taf: {
6516
6964
  uuid: '5f9583fjdf0f337925',
6517
6965
  baseTime: "".concat(currentDate, "T18:00:00Z"),
@@ -6550,6 +6998,7 @@ var fakeDraftTaf = {
6550
6998
  ({
6551
6999
  creationDate: "2022-01-06T18:00:00Z",
6552
7000
  canbe: ['DRAFTED', 'DISCARDED', 'PUBLISHED'],
7001
+ editor: MOCK_USERNAME,
6553
7002
  taf: Object.assign(Object.assign({}, fakeDraftTaf.taf), {
6554
7003
  baseTime: "2022-01-06T18:00:00Z",
6555
7004
  validDateStart: "2022-01-06T18:00:00Z",
@@ -6565,6 +7014,7 @@ var fakeDraftTaf = {
6565
7014
  var fakeDraftAmendmentTaf = {
6566
7015
  creationDate: "".concat(currentDate, "T14:00:00Z"),
6567
7016
  canbe: ['DRAFTED', 'DISCARDED', 'PUBLISHED'],
7017
+ editor: null,
6568
7018
  taf: {
6569
7019
  uuid: '954905487',
6570
7020
  previousId: '5f9583fjdf45ff4330f337925',
@@ -6625,6 +7075,7 @@ var fakeDraftAmendmentTaf = {
6625
7075
  ({
6626
7076
  creationDate: "2022-01-06T14:00:00Z",
6627
7077
  canbe: ['DRAFTED', 'DISCARDED', 'PUBLISHED'],
7078
+ editor: null,
6628
7079
  taf: Object.assign(Object.assign({}, fakeDraftAmendmentTaf.taf), {
6629
7080
  location: 'EHRD',
6630
7081
  issueDate: "2022-01-06T14:00:00Z",
@@ -6645,6 +7096,7 @@ var fakeDraftAmendmentTaf = {
6645
7096
  var fakeAmendmentTaf = {
6646
7097
  creationDate: "".concat(currentDate, "T14:00:00Z"),
6647
7098
  canbe: ['CANCELLED', 'CORRECTED', 'AMENDED'],
7099
+ editor: null,
6648
7100
  taf: {
6649
7101
  uuid: '754905486',
6650
7102
  previousId: '5f9583fjdf45ff4330f337925',
@@ -6688,6 +7140,7 @@ var fakeAmendmentTaf = {
6688
7140
  ({
6689
7141
  creationDate: "2022-01-06T14:00:00Z",
6690
7142
  canbe: ['CANCELLED', 'CORRECTED', 'AMENDED'],
7143
+ editor: MOCK_USERNAME,
6691
7144
  taf: Object.assign(Object.assign({}, fakeAmendmentTaf.taf), {
6692
7145
  uuid: '7549058980',
6693
7146
  issueDate: "2022-01-06T14:00:00Z",
@@ -6707,39 +7160,23 @@ var fakeAmendmentTaf = {
6707
7160
 
6708
7161
  var fakeTafTac = 'TAF EHAM 0812/0918 20020G35KT 0500 SN BKN040\nBECMG 0814/0816 0700 BKN001=';
6709
7162
 
6710
- var fakePromise = function fakePromise(withRandomError) {
6711
- var signal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
6712
- return new Promise(function (resolve, reject) {
6713
- var timer = setTimeout(function () {
6714
- if (!withRandomError) return resolve();
6715
- var randomError = Math.floor(Math.random() * 4) + 1;
6716
- return randomError === 4 ? reject(new Error('something went wrong')) : resolve();
6717
- }, 300);
6718
- signal === null || signal === void 0 ? void 0 : signal.signal.addEventListener('abort', function () {
6719
- clearTimeout(timer);
6720
- reject(new Error('canceled'));
6721
- });
6722
- });
6723
- };
7163
+ var fakeUpdatedTafList = _toConsumableArray(fakeTafList);
6724
7164
 
6725
- var fakeAxiosInstance = {
6726
- // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars, @typescript-eslint/explicit-module-boundary-types
6727
- get: function get(_url, _params) {
6728
- return fakePromise(false);
6729
- },
6730
- // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars, @typescript-eslint/explicit-module-boundary-types
6731
- post: function post(_url, _params, _signal) {
6732
- return fakePromise(false, _signal);
6733
- }
7165
+ var setFakeUpdatedList = function setFakeUpdatedList(newList) {
7166
+ fakeUpdatedTafList = newList;
6734
7167
  };
6735
- var createApi = function createApi() {
7168
+ var getFakeUpdatedList = function getFakeUpdatedList() {
7169
+ return fakeUpdatedTafList;
7170
+ };
7171
+
7172
+ var getApiRoutes = function getApiRoutes(axiosInstance) {
6736
7173
  return {
6737
7174
  getTafList: function getTafList() {
6738
7175
  // eslint-disable-next-line no-console
6739
7176
  console.log('Retrieving new TAF list');
6740
- return fakeAxiosInstance.get('/taflist').then(function () {
7177
+ return axiosInstance.get('/taflist').then(function () {
6741
7178
  return {
6742
- data: _toConsumableArray(fakeTafList)
7179
+ data: getFakeUpdatedList()
6743
7180
  };
6744
7181
  });
6745
7182
  },
@@ -6748,20 +7185,40 @@ var createApi = function createApi() {
6748
7185
  console.log("The new status of the taf will be ".concat(_postTaf.changeStatusTo)); // eslint-disable-next-line no-console
6749
7186
 
6750
7187
  console.log('form has been posted with following values:', _postTaf.taf);
6751
- return fakeAxiosInstance.post('/taf', _postTaf);
7188
+ return axiosInstance.post('/taf', _postTaf);
6752
7189
  },
6753
- getTAC: function getTAC(tafData, signal) {
6754
- return fakeAxiosInstance.post.apply(fakeAxiosInstance, ['/taf2tac'].concat([Object.assign({}, tafData)].concat(_toConsumableArray(signal ? [{
7190
+ getTAC: function getTAC(taf, signal) {
7191
+ return axiosInstance.post.apply(axiosInstance, ['/taf2tac'].concat([Object.assign({}, taf)].concat(_toConsumableArray(signal ? [{
6755
7192
  signal: signal
6756
7193
  }] : [])))).then(function () {
6757
7194
  return {
6758
7195
  data: fakeTafTac
6759
7196
  };
6760
7197
  });
7198
+ },
7199
+ patchTaf: function patchTaf(_patchTaf) {
7200
+ var updatedList = getFakeUpdatedList().map(function (tafFromBackend) {
7201
+ if (tafFromBackend.taf.uuid === _patchTaf.taf.uuid) {
7202
+ return Object.assign(Object.assign({}, tafFromBackend), {
7203
+ editor: _patchTaf.editor
7204
+ });
7205
+ }
7206
+
7207
+ return tafFromBackend;
7208
+ });
7209
+ setFakeUpdatedList(updatedList); // eslint-disable-next-line no-console
7210
+
7211
+ console.log("The new editor of the taf will be ".concat(_patchTaf.editor || 'empty'));
7212
+ return axiosInstance.patch('/taf', _patchTaf);
6761
7213
  }
6762
7214
  };
6763
7215
  };
6764
7216
 
7217
+ var createApi = function createApi() {
7218
+ var instance = createFakeApiInstance();
7219
+ return getApiRoutes(instance);
7220
+ };
7221
+
6765
7222
  /* *
6766
7223
  * Licensed under the Apache License, Version 2.0 (the "License");
6767
7224
  * you may not use this file except in compliance with the License.