@opengeoweb/taf 11.1.0 → 12.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
@@ -6,19 +6,21 @@ import { useFormContext, useFieldArray, Controller } from 'react-hook-form';
6
6
  import { useDispatch } from 'react-redux';
7
7
  import { ReactSortable } from 'react-sortablejs';
8
8
  import Sortable from 'sortablejs';
9
- import { getConfig, useAuthenticationContext } from '@opengeoweb/authentication';
9
+ import { getConfig, useAuthenticationContext as useAuthenticationContext$1 } from '@opengeoweb/authentication';
10
10
  import { HIDDEN_INPUT_HELPER_IS_DRAFT, getDeepProperty, useDraftFormHelpers, ReactHookFormHiddenInput, ReactHookFormProvider } from '@opengeoweb/form-fields';
11
- import { SHARED_NAMESPACE, dateUtils, useIsMounted, CustomIconButton, CustomTooltip, ToolContainerDraggable, Avatar, getInitials, ToggleMenu, useConfirmationDialog, usePreventBrowserClose, SwitchButton, ToolHeader, AlertBanner, getErrorMessage as getErrorMessage$1, getWarningMessage, LastUpdateTime, ErrorBoundary } from '@opengeoweb/shared';
11
+ import { SHARED_NAMESPACE, dateUtils, getErrorMessage as getErrorMessage$1, getWarningMessage, CustomIconButton, CustomTooltip, ToolContainerDraggable, Avatar, getInitials, ToggleMenu, useConfirmationDialog, usePreventBrowserClose, SwitchButton, ToolHeader, AlertBanner, LastUpdateTime, ErrorBoundary } from '@opengeoweb/shared';
12
12
  import { snackbarActions, snackbarTypes } from '@opengeoweb/snackbar';
13
13
  import 'i18next';
14
14
  import { useTranslation } from 'react-i18next';
15
15
  import { isEqual } from 'lodash';
16
+ import { useQueryClient, useMutation } from '@tanstack/react-query';
17
+ import { getHeaders, handleResponse, useAuthQuery, useAuthenticationContext } from '@opengeoweb/api';
16
18
  import { DragHandle as DragHandle$1, ThumbsUp, Add, Delete, Close, Clock, Cancel, Success, Edit, Export, ListItem } from '@opengeoweb/theme';
17
19
  import ReactDOM from 'react-dom';
18
20
  import { useTheme } from '@emotion/react';
19
- import { getHeaders, handleResponse, useAuthQuery, useApiContext, createApiInstance, createFakeApiInstance, ApiProvider } from '@opengeoweb/api';
20
21
  import LinearProgress from '@mui/material/LinearProgress';
21
22
  import Box$1 from '@mui/material/Box';
23
+ import { http, HttpResponse, delay } from 'msw';
22
24
 
23
25
  var en = {
24
26
  "issues-button-title": "View details",
@@ -2607,438 +2609,468 @@ var validateFourthCloud = function validateFourthCloud(firstCloudValue, secondCl
2607
2609
  var DATE_FORMAT_ISSUE_TIME = "ddHHmm'Z";
2608
2610
  var DATE_FORMAT_BASE_TIME = 'HH:mm dd MMM';
2609
2611
 
2610
- var _excluded$5 = ["cavOK"],
2611
- _excluded2 = ["visibility"],
2612
- _excluded3 = ["cloud"],
2613
- _excluded4 = ["weather"],
2614
- _excluded5 = ["wind"],
2615
- _excluded6 = ["visibility"],
2616
- _excluded7 = ["IS_DRAFT"],
2617
- _excluded8 = ["changeGroups"],
2618
- _excluded9 = ["valid"],
2619
- _excluded10 = ["valid"];
2620
- var emptyBaseForecast = {
2621
- wind: '',
2622
- visibility: '',
2623
- weather: {
2624
- weather1: '',
2625
- weather2: '',
2626
- weather3: ''
2627
- },
2628
- cloud: {
2629
- cloud1: '',
2630
- cloud2: '',
2631
- cloud3: '',
2632
- cloud4: ''
2612
+ /* *
2613
+ * Licensed under the Apache License, Version 2.0 (the "License");
2614
+ * you may not use this file except in compliance with the License.
2615
+ * You may obtain a copy of the License at
2616
+ *
2617
+ * http://www.apache.org/licenses/LICENSE-2.0
2618
+ *
2619
+ * Unless required by applicable law or agreed to in writing, software
2620
+ * distributed under the License is distributed on an "AS IS" BASIS,
2621
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2622
+ * See the License for the specific language governing permissions and
2623
+ * limitations under the License.
2624
+ *
2625
+ * Copyright 2025 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2626
+ * Copyright 2025 - Finnish Meteorological Institute (FMI)
2627
+ * Copyright 2025 - The Norwegian Meteorological Institute (MET Norway)
2628
+ * */
2629
+ var config = getConfig();
2630
+ var tafBaseUrl = config.GW_TAF_BASE_URL || '';
2631
+ var getTafList = function getTafList(auth) {
2632
+ return fetch(tafBaseUrl + "/taflist", {
2633
+ headers: getHeaders(auth)
2634
+ }).then(handleResponse);
2635
+ };
2636
+ var postTaf = function postTaf(auth, data) {
2637
+ return fetch(tafBaseUrl + "/taf", {
2638
+ method: 'POST',
2639
+ headers: getHeaders(auth),
2640
+ body: JSON.stringify(data)
2641
+ }).then(handleResponse);
2642
+ };
2643
+ var patchTaf = function patchTaf(auth, data) {
2644
+ return fetch(tafBaseUrl + "/taf?force=true", {
2645
+ method: 'PATCH',
2646
+ headers: getHeaders(auth),
2647
+ body: JSON.stringify(data)
2648
+ }).then(handleResponse);
2649
+ };
2650
+ var getTAC = function getTAC(auth, data) {
2651
+ return fetch(tafBaseUrl + "/taf2tac", {
2652
+ method: 'POST',
2653
+ headers: getHeaders(auth),
2654
+ body: JSON.stringify(data)
2655
+ }).then(handleResponse);
2656
+ };
2657
+
2658
+ var location_indicator_mwo = "EHDB";
2659
+ var locations = {
2660
+ EHAM: {
2661
+ validity_duration: 30,
2662
+ activity_period: 6,
2663
+ label: "Schiphol"
2664
+ },
2665
+ EHRD: {
2666
+ validity_duration: 30,
2667
+ activity_period: 6,
2668
+ label: "Rotterdam"
2669
+ },
2670
+ EHGG: {
2671
+ validity_duration: 30,
2672
+ activity_period: 6,
2673
+ label: "Eelde"
2674
+ },
2675
+ EHBK: {
2676
+ validity_duration: 30,
2677
+ activity_period: 6,
2678
+ label: "Maastricht"
2679
+ },
2680
+ EHLE: {
2681
+ validity_duration: 30,
2682
+ activity_period: 6,
2683
+ label: "Lelystad"
2684
+ },
2685
+ TNCB: {
2686
+ validity_duration: 30,
2687
+ activity_period: 6,
2688
+ label: "Bonaire"
2689
+ }
2690
+ };
2691
+ var locationOrder = [
2692
+ "EHAM",
2693
+ "EHRD",
2694
+ "EHLE",
2695
+ "EHGG",
2696
+ "EHBK",
2697
+ "TNCB"
2698
+ ];
2699
+ var autoTAFlocations = [
2700
+ "EHAM",
2701
+ "EHRD",
2702
+ "EHLE",
2703
+ "EHGG",
2704
+ "EHBK"
2705
+ ];
2706
+ var tafConfig = {
2707
+ location_indicator_mwo: location_indicator_mwo,
2708
+ locations: locations,
2709
+ locationOrder: locationOrder,
2710
+ autoTAFlocations: autoTAFlocations
2711
+ };
2712
+
2713
+ /* *
2714
+ * Licensed under the Apache License, Version 2.0 (the "License");
2715
+ * you may not use this file except in compliance with the License.
2716
+ * You may obtain a copy of the License at
2717
+ *
2718
+ * http://www.apache.org/licenses/LICENSE-2.0
2719
+ *
2720
+ * Unless required by applicable law or agreed to in writing, software
2721
+ * distributed under the License is distributed on an "AS IS" BASIS,
2722
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2723
+ * See the License for the specific language governing permissions and
2724
+ * limitations under the License.
2725
+ *
2726
+ * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2727
+ * Copyright 2022 - Finnish Meteorological Institute (FMI)
2728
+ * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2729
+ * */
2730
+ // TODO: should be validated
2731
+ var getTafSettings = function getTafSettings() {
2732
+ return tafConfig;
2733
+ };
2734
+ var tafSettings = getTafSettings();
2735
+ var getLocationSetting = function getLocationSetting(location, locationSettings) {
2736
+ if (locationSettings === void 0) {
2737
+ locationSettings = tafSettings.locations;
2633
2738
  }
2739
+ return locationSettings[location];
2634
2740
  };
2635
- var MIN_NUMBER_CHANGE_GROUP = 5;
2636
- // formatters
2637
- var formatIssueTime = function formatIssueTime(issueDate) {
2638
- var issueDateAsString = dateUtils.dateToString(new Date(issueDate), DATE_FORMAT_ISSUE_TIME);
2639
- return issueDateAsString || 'Not issued';
2741
+ var sortTafsOnLocation = function sortTafsOnLocation(tafList, locationOrder) {
2742
+ if (tafList === void 0) {
2743
+ tafList = [];
2744
+ }
2745
+ if (locationOrder === void 0) {
2746
+ locationOrder = tafSettings.locationOrder;
2747
+ }
2748
+ return [].concat(tafList).sort(function (_ref, _ref2) {
2749
+ var tafA = _ref.taf;
2750
+ var tafB = _ref2.taf;
2751
+ return locationOrder.indexOf(tafA.location) < locationOrder.indexOf(tafB.location) ? -1 : 1;
2752
+ });
2640
2753
  };
2641
- function formatFormValues(row) {
2642
- return Object.keys(row).reduce(function (list, key) {
2643
- switch (key) {
2644
- case 'valid':
2645
- {
2646
- return Object.assign({}, list, {
2647
- valid: formatValidToString(list[key])
2648
- });
2649
- }
2650
- case 'wind':
2651
- {
2652
- return Object.assign({}, list, {
2653
- wind: formatWindToString(list[key])
2654
- });
2655
- }
2656
- case 'visibility':
2657
- {
2658
- // Assume if visibility field set - no cavOK
2659
- return Object.assign({}, list, {
2660
- visibility: formatVisibilityToString(list[key])
2661
- });
2662
- }
2663
- case 'cavOK':
2664
- {
2665
- // Assume if cavOK field set to true - no visibility field, otherwise return the original list containing the visibility and remove cavOK
2666
- list.cavOK;
2667
- var formData = _objectWithoutPropertiesLoose(list, _excluded$5);
2668
- if (list[key]) {
2669
- return Object.assign({}, formData, {
2670
- visibility: formatVisibilityToString(list[key])
2671
- });
2672
- }
2673
- return formData;
2674
- }
2675
- case 'cloud':
2676
- {
2677
- return Object.assign({}, list, {
2678
- cloud: formatCloudsToString(list[key])
2679
- });
2680
- }
2681
- default:
2682
- {
2683
- return list;
2684
- }
2685
- }
2686
- }, row);
2687
- }
2688
- // parsers
2689
- function reduceRowValues(row, tafStart, tafEnd) {
2690
- return Object.keys(row).reduce(function (list, key) {
2691
- switch (key) {
2692
- case 'valid':
2693
- {
2694
- return Object.assign({}, list, {
2695
- valid: parseValidToObject(list[key], tafStart, tafEnd)
2696
- });
2697
- }
2698
- case 'wind':
2699
- {
2700
- return Object.assign({}, list, {
2701
- wind: parseWindToObject(list[key])
2702
- });
2703
- }
2704
- case 'visibility':
2705
- {
2706
- return Object.assign({}, list, parseVisibilityToObject(list[key]));
2707
- }
2708
- case 'weather':
2709
- {
2710
- return Object.assign({}, list, {
2711
- weather: parseWeatherToObject(list[key])
2712
- });
2713
- }
2714
- case 'cloud':
2715
- {
2716
- return Object.assign({}, list, {
2717
- cloud: parseCloudsToObject(list[key])
2718
- });
2719
- }
2720
- // Trim string field
2721
- case 'change':
2722
- case 'probability':
2723
- {
2724
- var _Object$assign;
2725
- return Object.assign({}, list, (_Object$assign = {}, _Object$assign[key] = String(list[key]).trim(), _Object$assign));
2726
- }
2727
- default:
2728
- {
2729
- return list;
2730
- }
2754
+ var sortTafsOnIssueDate = function sortTafsOnIssueDate(tafList) {
2755
+ if (tafList === void 0) {
2756
+ tafList = [];
2757
+ }
2758
+ return [].concat(tafList).sort(function (_ref3, _ref4) {
2759
+ var tafA = _ref3.taf;
2760
+ var tafB = _ref4.taf;
2761
+ if (tafA.issueDate < tafB.issueDate || tafA.issueDate && !tafB.issueDate) {
2762
+ return 1;
2731
2763
  }
2732
- }, row);
2733
- }
2734
- function parseFormValues(row, tafStart, tafEnd) {
2735
- var reducedRow = reduceRowValues(row, tafStart, tafEnd);
2736
- return Object.keys(reducedRow).reduce(function (list, key) {
2737
- switch (key) {
2738
- case 'cavOK':
2739
- {
2740
- // if cavOK is set - remove visibility from the list
2741
- if (reducedRow.cavOK) {
2742
- list.visibility;
2743
- var rest = _objectWithoutPropertiesLoose(list, _excluded2);
2744
- return rest;
2745
- }
2746
- return list;
2747
- }
2748
- case 'cloud':
2749
- {
2750
- // If cloud is undefined or empty, remove it from the list
2751
- if (!reducedRow.cloud || Object.keys(reducedRow.cloud).length === 0) {
2752
- list.cloud;
2753
- var _rest = _objectWithoutPropertiesLoose(list, _excluded3);
2754
- return _rest;
2755
- }
2756
- return list;
2757
- }
2758
- case 'weather':
2759
- {
2760
- // If empty, remove it from the list
2761
- if (!reducedRow.weather.weather1) {
2762
- list.weather;
2763
- var _rest2 = _objectWithoutPropertiesLoose(list, _excluded4);
2764
- return _rest2;
2765
- }
2766
- return list;
2767
- }
2768
- case 'wind':
2769
- {
2770
- // If empty, remove it from the list
2771
- if (!reducedRow.wind.direction && isNaN(Number(reducedRow.wind.direction))) {
2772
- list.wind;
2773
- var _rest3 = _objectWithoutPropertiesLoose(list, _excluded5);
2774
- return _rest3;
2775
- }
2776
- return list;
2777
- }
2778
- case 'visibility':
2779
- {
2780
- // If empty, remove it from the list
2781
- if (!reducedRow.visibility.range && isNaN(reducedRow.visibility.range)) {
2782
- list.visibility;
2783
- var _rest4 = _objectWithoutPropertiesLoose(list, _excluded6);
2784
- return _rest4;
2785
- }
2786
- return list;
2787
- }
2788
- case 'change':
2789
- case 'probability':
2790
- // If empty, remove it from the list
2791
- if (!reducedRow[key]) {
2792
- list[key];
2793
- var _rest5 = _objectWithoutPropertiesLoose(list, [key].map(_toPropertyKey));
2794
- return _rest5;
2795
- }
2796
- return list;
2797
- case 'valid':
2798
- {
2799
- // If empty, remove it from the list
2800
- if (!reducedRow[key]) {
2801
- list[key];
2802
- var _rest6 = _objectWithoutPropertiesLoose(list, [key].map(_toPropertyKey));
2803
- return _rest6;
2804
- }
2805
- return list;
2806
- }
2807
- default:
2808
- {
2809
- return list;
2810
- }
2811
- }
2812
- }, reducedRow);
2813
- }
2814
- var convertTafValuesToObject = function convertTafValuesToObject(formData) {
2815
- formData.IS_DRAFT;
2816
- var productToPost = _objectWithoutPropertiesLoose(formData, _excluded7);
2817
- var tafStart = productToPost.validDateStart;
2818
- var tafEnd = productToPost.validDateEnd;
2819
- var parsedChangeGroups = productToPost.changeGroups && productToPost.changeGroups
2820
- // parse data for each changegroup row
2821
- .map(function (row) {
2822
- return parseFormValues(row, tafStart, tafEnd);
2823
- })
2824
- // filter out empty changegroup rows
2825
- .filter(function (value) {
2826
- return Object.keys(value).length;
2827
- });
2828
- var parsedBaseForecast = productToPost.baseForecast && parseFormValues(productToPost.baseForecast, tafStart, tafEnd);
2829
- var parsedFormValues = Object.assign({}, productToPost, {
2830
- baseForecast: parsedBaseForecast,
2831
- changeGroups: parsedChangeGroups
2764
+ return -1;
2832
2765
  });
2833
- return Object.keys(parsedFormValues).reduce(function (list, key) {
2834
- switch (key) {
2835
- case 'changeGroups':
2836
- {
2837
- // remove changeGroups when empty
2838
- if (!parsedFormValues.changeGroups || !parsedFormValues.changeGroups.length) {
2839
- list.changeGroups;
2840
- var rest = _objectWithoutPropertiesLoose(list, _excluded8);
2841
- return rest;
2842
- }
2843
- return list;
2844
- }
2845
- case 'previousId':
2846
- case 'previousValidDateStart':
2847
- case 'previousValidDateEnd':
2848
- case 'issueDate':
2849
- {
2850
- // remove when empty
2851
- if (!parsedFormValues[key]) {
2852
- list[key];
2853
- var _rest7 = _objectWithoutPropertiesLoose(list, [key].map(_toPropertyKey));
2854
- return _rest7;
2855
- }
2856
- return list;
2857
- }
2858
- default:
2859
- {
2860
- return list;
2861
- }
2862
- }
2863
- }, parsedFormValues);
2864
- };
2865
- // Ensure we have enough data to retrieve a TAC - we only need to check for wind and visibility/ cavok as those are the only ones required in all cases
2866
- var shouldRetrieveTAC = function shouldRetrieveTAC(product) {
2867
- if (product && product.baseForecast && product.baseForecast.wind && 'speed' in product.baseForecast.wind && product.baseForecast.wind.speed !== '' && (product.baseForecast.visibility && 'range' in product.baseForecast.visibility && product.baseForecast.visibility.range !== '' || product.baseForecast.cavOK)) {
2868
- return true;
2869
- }
2870
- return false;
2871
2766
  };
2872
- var getFieldNames = function getFieldNames(isChangeGroup, index) {
2873
- var namePrefix = !isChangeGroup ? 'baseForecast' : "changeGroups[" + index + "]";
2874
- return Object.assign({}, !isChangeGroup && {
2875
- messageType: 'messageType',
2876
- location: 'location',
2877
- issueDate: 'issueDate'
2878
- }, isChangeGroup && {
2879
- probability: namePrefix + ".probability",
2880
- change: namePrefix + ".change"
2881
- }, {
2882
- valid: namePrefix + ".valid",
2883
- wind: namePrefix + ".wind",
2884
- visibility: namePrefix + ".visibility",
2885
- weather1: namePrefix + ".weather.weather1",
2886
- weather2: namePrefix + ".weather.weather2",
2887
- weather3: namePrefix + ".weather.weather3",
2888
- cloud1: namePrefix + ".cloud.cloud1",
2889
- cloud2: namePrefix + ".cloud.cloud2",
2890
- cloud3: namePrefix + ".cloud.cloud3",
2891
- cloud4: namePrefix + ".cloud.cloud4"
2767
+ var getBaseTime = function getBaseTime(baseTime, location) {
2768
+ var currentBaseTime = dateUtils.utc(baseTime);
2769
+ var activityPeriod = getLocationSetting(location).activity_period;
2770
+ var nextBaseTime = dateUtils.add(dateUtils.utc(baseTime), {
2771
+ hours: activityPeriod
2892
2772
  });
2773
+ return {
2774
+ currentBaseTime: currentBaseTime,
2775
+ nextBaseTime: nextBaseTime
2776
+ };
2893
2777
  };
2894
- var tacHasError = function tacHasError(tac, t) {
2895
- return tac === t('TAC-missing-data') || tac === t('TAC-not-available') || tac === t('TAC-retrieving-data') || tac === t('TAC-failed');
2778
+ var getTafTimeSlot = function getTafTimeSlot(baseTime, location, status) {
2779
+ var now = dateUtils.utc();
2780
+ var _getBaseTime = getBaseTime(baseTime, location),
2781
+ currentBaseTime = _getBaseTime.currentBaseTime,
2782
+ nextBaseTime = _getBaseTime.nextBaseTime;
2783
+ if (status === 'EXPIRED') {
2784
+ return 'EXPIRED';
2785
+ }
2786
+ if (currentBaseTime.getTime() < now.getTime() && nextBaseTime.getTime() > now.getTime()) {
2787
+ return 'ACTIVE';
2788
+ }
2789
+ return 'UPCOMING';
2896
2790
  };
2897
- var useTACGenerator = function useTACGenerator(taf, requestTAC, getJSON) {
2898
- var _useTafTranslation = useTafTranslation(),
2899
- t = _useTafTranslation.t;
2900
- var _React$useState = React__default.useState(!taf || taf.status === 'NEW' ? t('TAC-not-available') : t('TAC-retrieving-data')),
2901
- TAC = _React$useState[0],
2902
- setTAC = _React$useState[1];
2903
- var _useIsMounted = useIsMounted(),
2904
- isMounted = _useIsMounted.isMounted;
2905
- var controller = React__default.useRef();
2906
- var onSetTac = function onSetTac(newTAC) {
2907
- if (controller.current) {
2908
- controller.current.abort();
2909
- }
2910
- setTAC(newTAC);
2911
- };
2912
- var retrieveTAC = React__default.useCallback(function (tafToPost) {
2913
- if (shouldRetrieveTAC(tafToPost)) {
2914
- if (controller.current) {
2915
- controller.current.abort();
2916
- }
2917
- controller.current = new AbortController();
2918
- setTAC(t('TAC-retrieving-data'));
2919
- requestTAC(tafToPost, getJSON, controller.current.signal).then(function (result) {
2920
- if (isMounted.current) {
2921
- setTAC(result.data);
2922
- }
2923
- })["catch"](function (error) {
2924
- if (isMounted && error.message !== 'canceled') {
2925
- setTAC(t('TAC-failed'));
2926
- }
2927
- });
2791
+ var sortTafTimeSlots = function sortTafTimeSlots(tafList) {
2792
+ var sortedListOnIssueDate = sortTafsOnIssueDate(tafList);
2793
+ var sortedListOnLocation = sortTafsOnLocation(sortedListOnIssueDate);
2794
+ return sortedListOnLocation.reduce(function (sortedTafList, tafFromBackend) {
2795
+ var taf = tafFromBackend.taf;
2796
+ var timeSlot = getTafTimeSlot(taf.baseTime, taf.location, taf.status);
2797
+ if (timeSlot === 'EXPIRED') {
2798
+ sortedTafList.expired.push(tafFromBackend);
2799
+ } else if (timeSlot === 'ACTIVE') {
2800
+ sortedTafList.current.push(tafFromBackend);
2928
2801
  } else {
2929
- setTAC(t('TAC-missing-data'));
2930
- }
2931
- },
2932
- // eslint-disable-next-line react-hooks/exhaustive-deps
2933
- [isMounted, requestTAC, getJSON]);
2934
- React__default.useEffect(function () {
2935
- if (taf && taf.status !== 'NEW') {
2936
- retrieveTAC(taf);
2802
+ sortedTafList.upcoming.push(tafFromBackend);
2937
2803
  }
2938
- }, [retrieveTAC, taf]);
2939
- return [TAC, retrieveTAC, onSetTac];
2804
+ return sortedTafList;
2805
+ }, {
2806
+ current: [],
2807
+ upcoming: [],
2808
+ expired: []
2809
+ });
2940
2810
  };
2941
- var useDragOrder = function useDragOrder(trigger, move) {
2942
- var _React$useState2 = React__default.useState(null),
2943
- activeDraggingIndex = _React$useState2[0],
2944
- setActiveDraggingIndex = _React$useState2[1];
2945
- var _React$useState3 = React__default.useState([null, null]),
2946
- lastDragOrder = _React$useState3[0],
2947
- onUpdatelastDragOrder = _React$useState3[1];
2948
- var onChangeOrder = function onChangeOrder(_ref) {
2949
- var oldIndex = _ref.oldIndex,
2950
- newIndex = _ref.newIndex;
2951
- if (oldIndex === undefined || newIndex === undefined) {
2952
- return;
2953
- }
2954
- move(oldIndex, newIndex);
2955
- onUpdatelastDragOrder([oldIndex, newIndex]);
2956
- setActiveDraggingIndex(false);
2957
- };
2958
- var onStartDrag = function onStartDrag(_ref2) {
2959
- var oldIndex = _ref2.oldIndex;
2960
- return setActiveDraggingIndex(oldIndex);
2961
- };
2962
- // triggers validation AFTER render of new sorted elements
2963
- React__default.useEffect(function () {
2964
- var oldIndex = lastDragOrder[0],
2965
- newIndex = lastDragOrder[1];
2966
- if (oldIndex !== null && newIndex !== null) {
2967
- // trigger validation of all fields
2968
- void trigger();
2969
- }
2970
- }, [lastDragOrder, trigger]);
2811
+ var muiTabA11yProps = function muiTabA11yProps(index) {
2971
2812
  return {
2972
- onChangeOrder: onChangeOrder,
2973
- activeDraggingIndex: activeDraggingIndex,
2974
- onStartDrag: onStartDrag
2813
+ id: "simple-tab-" + index,
2814
+ 'aria-controls': "simple-tabpanel-" + index
2975
2815
  };
2976
2816
  };
2977
- // dialog utils
2978
- var getConfirmationDialogTitle = function getConfirmationDialogTitle(action, t) {
2979
- if (action === 'CLEAR') {
2980
- return t('confirm-clear-title');
2981
- }
2982
- if (action === 'PUBLISH') {
2983
- return t('button-publish');
2817
+ var getNewTafLocationIndex = function getNewTafLocationIndex(tafLocations, previousTafLocationUUID) {
2818
+ var newActiveIndexForDraft = tafLocations.findIndex(function (location) {
2819
+ var _location$taf;
2820
+ return (location == null || (_location$taf = location.taf) == null ? void 0 : _location$taf.previousId) === previousTafLocationUUID;
2821
+ });
2822
+ if (newActiveIndexForDraft !== -1) {
2823
+ return newActiveIndexForDraft;
2984
2824
  }
2985
- if (action === 'AMEND') {
2986
- return t('confirm-amend-title');
2825
+ var newActiveIndexForPublished = tafLocations.findIndex(function (location) {
2826
+ var _location$taf2;
2827
+ return (location == null || (_location$taf2 = location.taf) == null ? void 0 : _location$taf2.uuid) === previousTafLocationUUID;
2828
+ });
2829
+ if (newActiveIndexForPublished !== -1) {
2830
+ return newActiveIndexForPublished;
2987
2831
  }
2988
- if (action === 'CORRECT') {
2989
- return t('confirm-correct-title');
2832
+ return 0;
2833
+ };
2834
+ var getPreviousTaf = function getPreviousTaf(tafList, currentTaf) {
2835
+ var previousId = currentTaf.taf.previousId;
2836
+ if (!previousId) {
2837
+ return null;
2990
2838
  }
2991
- if (action === 'CANCEL') {
2992
- return t('confirm-cancel-title');
2839
+ var previousTaf = tafList.find(function (taf) {
2840
+ return taf.taf.uuid === previousId;
2841
+ });
2842
+ return previousTaf ? previousTaf.taf : null;
2843
+ };
2844
+ var getAutoTafLocations = function getAutoTafLocations(autoTAFlocations) {
2845
+ if (autoTAFlocations === void 0) {
2846
+ autoTAFlocations = tafSettings.autoTAFlocations;
2993
2847
  }
2994
- return t('confirm-cancel-title');
2848
+ return autoTAFlocations || null;
2995
2849
  };
2996
- // Check if the amended/corrected TAF has been changed. Only compare the fields users are able to fill in
2997
- // (i.e. exclude baseforecast valid time as that gets updated when doing an amendment automatically outside of the users influence)
2998
- var isTafAmendedCorrectedChanged = function isTafAmendedCorrectedChanged(originalTaf, currentTaf) {
2999
- if (originalTaf === null || currentTaf === null) {
3000
- return false;
2850
+ var scrollToPosition = function scrollToPosition(scrollRef, activeLocation) {
2851
+ if (!scrollRef.current) {
2852
+ return;
3001
2853
  }
3002
- var originalBaseF = originalTaf.baseForecast,
3003
- originalChG = originalTaf.changeGroups;
3004
- var currentBaseF = currentTaf.baseForecast,
3005
- currentChG = currentTaf.changeGroups;
3006
- originalBaseF.valid;
3007
- var originalNoValid = _objectWithoutPropertiesLoose(originalBaseF, _excluded9);
3008
- currentBaseF.valid;
3009
- var currentNoValid = _objectWithoutPropertiesLoose(currentBaseF, _excluded10);
3010
- return !isEqual(originalNoValid, currentNoValid) || !isEqual(originalChG, currentChG);
2854
+ var containerTop = scrollRef.current.getBoundingClientRect().top;
2855
+ var firstLocation = scrollRef.current.querySelector("[data-location=\"" + activeLocation + "\"]");
2856
+ var paddingTop = parseInt(getComputedStyle(scrollRef.current).paddingTop, 10);
2857
+ var firstLocationTop = firstLocation == null ? void 0 : firstLocation.getBoundingClientRect().top;
2858
+ var newScrollPosition = firstLocationTop - containerTop + scrollRef.current.scrollTop - paddingTop;
2859
+ scrollRef.current.scrollTo(newScrollPosition, newScrollPosition);
3011
2860
  };
3012
- var getConfirmationDialogContent = function getConfirmationDialogContent(action, isFormDirty, t) {
3013
- switch (action) {
3014
- case 'CLEAR':
3015
- return t('confirm-clear-content');
3016
- case 'PUBLISH':
3017
- return t('confirm-publish-content');
3018
- case 'AMEND':
3019
- case 'CORRECT':
3020
- return isFormDirty() ? t('confirm-correct-amend-content') : t('confirm-correct-amend-content-no-changes');
3021
- case 'CANCEL':
2861
+ var formatBaseTime = function formatBaseTime(time) {
2862
+ return dateUtils.dateToString(time, DATE_FORMAT_BASE_TIME);
2863
+ };
2864
+ var getTafMessageContent = function getTafMessageContent(_ref5) {
2865
+ var location = _ref5.location,
2866
+ validDateStart = _ref5.validDateStart,
2867
+ messageType = _ref5.messageType;
2868
+ var formattedDate = formatBaseTime(dateUtils.utc(validDateStart));
2869
+ return {
2870
+ location: location,
2871
+ formattedDate: formattedDate,
2872
+ messageType: messageType
2873
+ };
2874
+ };
2875
+ var getSnackbarMessage = function getSnackbarMessage(tafFromFrontEnd, isAutoSaved, t) {
2876
+ var changeStatusTo = tafFromFrontEnd.changeStatusTo,
2877
+ taf = tafFromFrontEnd.taf;
2878
+ if (isAutoSaved) {
2879
+ return t('snackbar-auto-save');
2880
+ }
2881
+ var content = getTafMessageContent(taf);
2882
+ switch (changeStatusTo) {
2883
+ case 'DRAFT':
2884
+ return t('snackbar-draft');
2885
+ case 'DRAFT_AMENDED':
2886
+ return t('snackbar-draft-amend');
2887
+ case 'DRAFT_CORRECTED':
2888
+ return t('snackbar-draft-correct');
2889
+ case 'PUBLISHED':
2890
+ return t('snackbar-publish', content);
2891
+ case 'CANCELLED':
2892
+ return t('snackbar-cancel', content);
2893
+ case 'CORRECTED':
2894
+ return t('snackbar-correct', content);
2895
+ case 'AMENDED':
2896
+ return t('snackbar-amend', content);
3022
2897
  default:
3023
- return t('confirm-cancel-content');
2898
+ return t('snackbar-save', content);
3024
2899
  }
3025
2900
  };
3026
- var getConfirmationDialogButtonLabel = function getConfirmationDialogButtonLabel(action, t) {
3027
- switch (action) {
3028
- case 'CLEAR':
3029
- {
3030
- return t('button-clear');
2901
+ var isWarning = function isWarning(error) {
2902
+ return (error == null ? void 0 : error.type) === 'WARNING';
2903
+ };
2904
+ var parseErrorMessage = function parseErrorMessage(error, params, t) {
2905
+ var message = getErrorMessage$1(error);
2906
+ var warningMessage = getWarningMessage(error);
2907
+ if (warningMessage) {
2908
+ return {
2909
+ type: 'WARNING',
2910
+ title: warningMessage
2911
+ };
2912
+ }
2913
+ return params.changeStatusTo === 'CANCELLED' ? {
2914
+ type: 'CANCELLED',
2915
+ title: t('error-cancel'),
2916
+ message: message
2917
+ } : {
2918
+ type: 'SERVER',
2919
+ title: t('error-save'),
2920
+ message: message
2921
+ };
2922
+ };
2923
+
2924
+ var useTafList = function useTafList(disabled) {
2925
+ if (disabled === void 0) {
2926
+ disabled = false;
2927
+ }
2928
+ return useAuthQuery(['taf-list'], getTafList, disabled, 1000 * 60 * 5);
2929
+ };
2930
+ var usePostTaf = function usePostTaf() {
2931
+ var queryClient = useQueryClient();
2932
+ var _useAuthenticationCon = useAuthenticationContext(),
2933
+ auth = _useAuthenticationCon.auth;
2934
+ var _useTafTranslation = useTafTranslation(),
2935
+ t = _useTafTranslation.t;
2936
+ var dispatch = useDispatch();
2937
+ return useMutation({
2938
+ mutationFn: function mutationFn(_ref) {
2939
+ var tafData = _ref.tafData,
2940
+ setError = _ref.setError;
2941
+ if (!auth) {
2942
+ throw new Error('Authentication context not found');
3031
2943
  }
3032
- case 'CANCEL':
3033
- return t('button-cancel');
3034
- default:
3035
- {
3036
- return t('button-publish');
2944
+ setError(null);
2945
+ return postTaf(auth, tafData);
2946
+ },
2947
+ onSuccess: function () {
2948
+ var _onSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_data, _ref2) {
2949
+ var tafData, isAutoSaved, message;
2950
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2951
+ while (1) switch (_context.prev = _context.next) {
2952
+ case 0:
2953
+ tafData = _ref2.tafData, isAutoSaved = _ref2.isAutoSaved;
2954
+ message = getSnackbarMessage(tafData, isAutoSaved, t);
2955
+ dispatch(snackbarActions.openSnackbar({
2956
+ type: snackbarTypes.SnackbarMessageType.VERBATIM_MESSAGE,
2957
+ message: message
2958
+ }));
2959
+ // trigger refetch for the list
2960
+ _context.next = 5;
2961
+ return queryClient.invalidateQueries({
2962
+ queryKey: ['taf-list']
2963
+ });
2964
+ case 5:
2965
+ case "end":
2966
+ return _context.stop();
2967
+ }
2968
+ }, _callee);
2969
+ }));
2970
+ function onSuccess(_x, _x2) {
2971
+ return _onSuccess.apply(this, arguments);
3037
2972
  }
3038
- }
2973
+ return onSuccess;
2974
+ }(),
2975
+ onError: function () {
2976
+ var _onError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(error, _ref3) {
2977
+ var tafData, setError, tafError;
2978
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
2979
+ while (1) switch (_context2.prev = _context2.next) {
2980
+ case 0:
2981
+ tafData = _ref3.tafData, setError = _ref3.setError;
2982
+ tafError = parseErrorMessage(error, tafData, t);
2983
+ setError(tafError);
2984
+ if (!isWarning(tafError)) {
2985
+ _context2.next = 6;
2986
+ break;
2987
+ }
2988
+ _context2.next = 6;
2989
+ return queryClient.invalidateQueries({
2990
+ queryKey: ['taf-list']
2991
+ });
2992
+ case 6:
2993
+ case "end":
2994
+ return _context2.stop();
2995
+ }
2996
+ }, _callee2);
2997
+ }));
2998
+ function onError(_x3, _x4) {
2999
+ return _onError.apply(this, arguments);
3000
+ }
3001
+ return onError;
3002
+ }()
3003
+ });
3039
3004
  };
3040
- var emptyChangegroup = {
3041
- valid: '',
3005
+ var usePatchTaf = function usePatchTaf() {
3006
+ var queryClient = useQueryClient();
3007
+ var _useAuthenticationCon2 = useAuthenticationContext(),
3008
+ auth = _useAuthenticationCon2.auth;
3009
+ var _useTafTranslation2 = useTafTranslation(),
3010
+ t = _useTafTranslation2.t;
3011
+ return useMutation({
3012
+ mutationFn: function mutationFn(_ref4) {
3013
+ var tafData = _ref4.tafData,
3014
+ setError = _ref4.setError;
3015
+ if (!auth) {
3016
+ throw new Error('Authentication context not found');
3017
+ }
3018
+ setError(null);
3019
+ return patchTaf(auth, tafData);
3020
+ },
3021
+ onSuccess: function () {
3022
+ var _onSuccess2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
3023
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
3024
+ while (1) switch (_context3.prev = _context3.next) {
3025
+ case 0:
3026
+ _context3.next = 2;
3027
+ return queryClient.invalidateQueries({
3028
+ queryKey: ['taf-list']
3029
+ });
3030
+ case 2:
3031
+ case "end":
3032
+ return _context3.stop();
3033
+ }
3034
+ }, _callee3);
3035
+ }));
3036
+ function onSuccess() {
3037
+ return _onSuccess2.apply(this, arguments);
3038
+ }
3039
+ return onSuccess;
3040
+ }(),
3041
+ onError: function onError(error, _ref5) {
3042
+ var tafData = _ref5.tafData,
3043
+ setError = _ref5.setError;
3044
+ var newError = parseErrorMessage(error, tafData, t);
3045
+ setError(newError);
3046
+ }
3047
+ });
3048
+ };
3049
+ var useGetTAC = function useGetTAC() {
3050
+ var _useAuthenticationCon3 = useAuthenticationContext(),
3051
+ auth = _useAuthenticationCon3.auth;
3052
+ return useMutation({
3053
+ mutationFn: function mutationFn(_ref6) {
3054
+ var tafData = _ref6.tafData;
3055
+ if (!auth) {
3056
+ throw new Error('Authentication context not found');
3057
+ }
3058
+ return getTAC(auth, tafData);
3059
+ }
3060
+ });
3061
+ };
3062
+
3063
+ var _excluded$5 = ["cavOK"],
3064
+ _excluded2 = ["visibility"],
3065
+ _excluded3 = ["cloud"],
3066
+ _excluded4 = ["weather"],
3067
+ _excluded5 = ["wind"],
3068
+ _excluded6 = ["visibility"],
3069
+ _excluded7 = ["IS_DRAFT"],
3070
+ _excluded8 = ["changeGroups"],
3071
+ _excluded9 = ["valid"],
3072
+ _excluded10 = ["valid"];
3073
+ var emptyBaseForecast = {
3042
3074
  wind: '',
3043
3075
  visibility: '',
3044
3076
  weather: {
@@ -3051,93 +3083,502 @@ var emptyChangegroup = {
3051
3083
  cloud2: '',
3052
3084
  cloud3: '',
3053
3085
  cloud4: ''
3054
- },
3055
- change: '',
3056
- probability: ''
3057
- };
3058
- var getTafStatusLabel = function getTafStatusLabel(t, status, action, isFormDisabled) {
3059
- // See if we need to base status label on action if form is not disabled and action passed
3060
- var baseOnAction = isFormDisabled !== undefined && !isFormDisabled && action;
3061
- if (baseOnAction && action === 'AMEND' && (status === 'PUBLISHED' || status === 'AMENDED' || status === 'CORRECTED')) {
3062
- return t('status-new-amendment');
3063
- }
3064
- if (baseOnAction && action === 'CORRECT' && (status === 'PUBLISHED' || status === 'AMENDED' || status === 'CORRECTED')) {
3065
- return t('status-new-correction');
3066
- }
3067
- switch (status) {
3068
- case 'DRAFT_AMENDED':
3069
- return t('status-draft-amendment');
3070
- case 'DRAFT_CORRECTED':
3071
- return t('status-draft-correction');
3072
- case 'AMENDED':
3073
- return t('status-published-amendment');
3074
- case 'CORRECTED':
3075
- return t('status-published-correction');
3076
- default:
3077
- return t("status-" + status.toLocaleLowerCase());
3078
3086
  }
3079
3087
  };
3080
- var getMessageType = function getMessageType(taf, tafAction) {
3081
- if (tafAction === 'CORRECT') {
3082
- return 'COR';
3083
- }
3084
- if (tafAction === 'AMEND') {
3085
- return 'AMD';
3086
- }
3087
- if (tafAction === 'CANCEL') {
3088
- return 'CNL';
3089
- }
3090
- return taf.messageType;
3088
+ var MIN_NUMBER_CHANGE_GROUP = 5;
3089
+ // formatters
3090
+ var formatIssueTime = function formatIssueTime(issueDate) {
3091
+ var issueDateAsString = dateUtils.dateToString(new Date(issueDate), DATE_FORMAT_ISSUE_TIME);
3092
+ return issueDateAsString || 'Not issued';
3091
3093
  };
3092
- // For corrections and amendment we need to add the previousValidStart and End for the TAC converter
3093
- var getAmendedCorrectedTafTimes = function getAmendedCorrectedTafTimes(taf, tafAction) {
3094
- var previousValidDateStart = taf.previousValidDateStart && tafAction !== 'AMEND' ? taf.previousValidDateStart : taf.validDateStart;
3095
- var previousValidDateEnd = taf.previousValidDateEnd && tafAction !== 'AMEND' ? taf.previousValidDateEnd : taf.validDateEnd;
3096
- // For amendment change valid start time to current time
3097
- // only do this if we're already within the validity period
3098
- var now = dateUtils.utc();
3099
- var validDateStart = dateUtils.utc(taf.validDateStart);
3100
- if ((tafAction === 'AMEND' || tafAction === 'DRAFT_AMEND') && now.getTime() >= validDateStart.getTime()) {
3101
- var _now = dateUtils.dateToString(dateUtils.utc(), dateUtils.DATE_FORMAT_UTC);
3102
- var validObj = {
3103
- start: _now,
3104
- end: taf.baseForecast.valid.end
3105
- };
3106
- return Object.assign({}, taf, {
3107
- previousValidDateStart: previousValidDateStart,
3108
- previousValidDateEnd: previousValidDateEnd,
3109
- validDateStart: _now,
3110
- baseForecast: Object.assign({}, taf.baseForecast, {
3111
- valid: validObj
3112
- })
3113
- });
3114
- }
3115
- return Object.assign({}, taf, {
3116
- previousValidDateStart: previousValidDateStart,
3117
- previousValidDateEnd: previousValidDateEnd
3094
+ function formatFormValues(row) {
3095
+ return Object.keys(row).reduce(function (list, key) {
3096
+ switch (key) {
3097
+ case 'valid':
3098
+ {
3099
+ return Object.assign({}, list, {
3100
+ valid: formatValidToString(list[key])
3101
+ });
3102
+ }
3103
+ case 'wind':
3104
+ {
3105
+ return Object.assign({}, list, {
3106
+ wind: formatWindToString(list[key])
3107
+ });
3108
+ }
3109
+ case 'visibility':
3110
+ {
3111
+ // Assume if visibility field set - no cavOK
3112
+ return Object.assign({}, list, {
3113
+ visibility: formatVisibilityToString(list[key])
3114
+ });
3115
+ }
3116
+ case 'cavOK':
3117
+ {
3118
+ // Assume if cavOK field set to true - no visibility field, otherwise return the original list containing the visibility and remove cavOK
3119
+ list.cavOK;
3120
+ var formData = _objectWithoutPropertiesLoose(list, _excluded$5);
3121
+ if (list[key]) {
3122
+ return Object.assign({}, formData, {
3123
+ visibility: formatVisibilityToString(list[key])
3124
+ });
3125
+ }
3126
+ return formData;
3127
+ }
3128
+ case 'cloud':
3129
+ {
3130
+ return Object.assign({}, list, {
3131
+ cloud: formatCloudsToString(list[key])
3132
+ });
3133
+ }
3134
+ default:
3135
+ {
3136
+ return list;
3137
+ }
3138
+ }
3139
+ }, row);
3140
+ }
3141
+ // parsers
3142
+ function reduceRowValues(row, tafStart, tafEnd) {
3143
+ return Object.keys(row).reduce(function (list, key) {
3144
+ switch (key) {
3145
+ case 'valid':
3146
+ {
3147
+ return Object.assign({}, list, {
3148
+ valid: parseValidToObject(list[key], tafStart, tafEnd)
3149
+ });
3150
+ }
3151
+ case 'wind':
3152
+ {
3153
+ return Object.assign({}, list, {
3154
+ wind: parseWindToObject(list[key])
3155
+ });
3156
+ }
3157
+ case 'visibility':
3158
+ {
3159
+ return Object.assign({}, list, parseVisibilityToObject(list[key]));
3160
+ }
3161
+ case 'weather':
3162
+ {
3163
+ return Object.assign({}, list, {
3164
+ weather: parseWeatherToObject(list[key])
3165
+ });
3166
+ }
3167
+ case 'cloud':
3168
+ {
3169
+ return Object.assign({}, list, {
3170
+ cloud: parseCloudsToObject(list[key])
3171
+ });
3172
+ }
3173
+ // Trim string field
3174
+ case 'change':
3175
+ case 'probability':
3176
+ {
3177
+ var _Object$assign;
3178
+ return Object.assign({}, list, (_Object$assign = {}, _Object$assign[key] = String(list[key]).trim(), _Object$assign));
3179
+ }
3180
+ default:
3181
+ {
3182
+ return list;
3183
+ }
3184
+ }
3185
+ }, row);
3186
+ }
3187
+ function parseFormValues(row, tafStart, tafEnd) {
3188
+ var reducedRow = reduceRowValues(row, tafStart, tafEnd);
3189
+ return Object.keys(reducedRow).reduce(function (list, key) {
3190
+ switch (key) {
3191
+ case 'cavOK':
3192
+ {
3193
+ // if cavOK is set - remove visibility from the list
3194
+ if (reducedRow.cavOK) {
3195
+ list.visibility;
3196
+ var rest = _objectWithoutPropertiesLoose(list, _excluded2);
3197
+ return rest;
3198
+ }
3199
+ return list;
3200
+ }
3201
+ case 'cloud':
3202
+ {
3203
+ // If cloud is undefined or empty, remove it from the list
3204
+ if (!reducedRow.cloud || Object.keys(reducedRow.cloud).length === 0) {
3205
+ list.cloud;
3206
+ var _rest = _objectWithoutPropertiesLoose(list, _excluded3);
3207
+ return _rest;
3208
+ }
3209
+ return list;
3210
+ }
3211
+ case 'weather':
3212
+ {
3213
+ // If empty, remove it from the list
3214
+ if (!reducedRow.weather.weather1) {
3215
+ list.weather;
3216
+ var _rest2 = _objectWithoutPropertiesLoose(list, _excluded4);
3217
+ return _rest2;
3218
+ }
3219
+ return list;
3220
+ }
3221
+ case 'wind':
3222
+ {
3223
+ // If empty, remove it from the list
3224
+ if (!reducedRow.wind.direction && isNaN(Number(reducedRow.wind.direction))) {
3225
+ list.wind;
3226
+ var _rest3 = _objectWithoutPropertiesLoose(list, _excluded5);
3227
+ return _rest3;
3228
+ }
3229
+ return list;
3230
+ }
3231
+ case 'visibility':
3232
+ {
3233
+ // If empty, remove it from the list
3234
+ if (!reducedRow.visibility.range && isNaN(reducedRow.visibility.range)) {
3235
+ list.visibility;
3236
+ var _rest4 = _objectWithoutPropertiesLoose(list, _excluded6);
3237
+ return _rest4;
3238
+ }
3239
+ return list;
3240
+ }
3241
+ case 'change':
3242
+ case 'probability':
3243
+ // If empty, remove it from the list
3244
+ if (!reducedRow[key]) {
3245
+ list[key];
3246
+ var _rest5 = _objectWithoutPropertiesLoose(list, [key].map(_toPropertyKey));
3247
+ return _rest5;
3248
+ }
3249
+ return list;
3250
+ case 'valid':
3251
+ {
3252
+ // If empty, remove it from the list
3253
+ if (!reducedRow[key]) {
3254
+ list[key];
3255
+ var _rest6 = _objectWithoutPropertiesLoose(list, [key].map(_toPropertyKey));
3256
+ return _rest6;
3257
+ }
3258
+ return list;
3259
+ }
3260
+ default:
3261
+ {
3262
+ return list;
3263
+ }
3264
+ }
3265
+ }, reducedRow);
3266
+ }
3267
+ var convertTafValuesToObject = function convertTafValuesToObject(formData) {
3268
+ formData.IS_DRAFT;
3269
+ var productToPost = _objectWithoutPropertiesLoose(formData, _excluded7);
3270
+ var tafStart = productToPost.validDateStart;
3271
+ var tafEnd = productToPost.validDateEnd;
3272
+ var parsedChangeGroups = productToPost.changeGroups && productToPost.changeGroups
3273
+ // parse data for each changegroup row
3274
+ .map(function (row) {
3275
+ return parseFormValues(row, tafStart, tafEnd);
3276
+ })
3277
+ // filter out empty changegroup rows
3278
+ .filter(function (value) {
3279
+ return Object.keys(value).length;
3118
3280
  });
3119
- };
3120
- var createChangeGroup = function createChangeGroup(changeGroup) {
3121
- return Object.assign({}, emptyChangegroup, changeGroup, {
3122
- weather: Object.assign({}, emptyChangegroup.weather, changeGroup.weather),
3123
- cloud: Object.assign({}, emptyChangegroup.cloud, changeGroup.cloud)
3281
+ var parsedBaseForecast = productToPost.baseForecast && parseFormValues(productToPost.baseForecast, tafStart, tafEnd);
3282
+ var parsedFormValues = Object.assign({}, productToPost, {
3283
+ baseForecast: parsedBaseForecast,
3284
+ changeGroups: parsedChangeGroups
3124
3285
  });
3286
+ return Object.keys(parsedFormValues).reduce(function (list, key) {
3287
+ switch (key) {
3288
+ case 'changeGroups':
3289
+ {
3290
+ // remove changeGroups when empty
3291
+ if (!parsedFormValues.changeGroups || !parsedFormValues.changeGroups.length) {
3292
+ list.changeGroups;
3293
+ var rest = _objectWithoutPropertiesLoose(list, _excluded8);
3294
+ return rest;
3295
+ }
3296
+ return list;
3297
+ }
3298
+ case 'previousId':
3299
+ case 'previousValidDateStart':
3300
+ case 'previousValidDateEnd':
3301
+ case 'issueDate':
3302
+ {
3303
+ // remove when empty
3304
+ if (!parsedFormValues[key]) {
3305
+ list[key];
3306
+ var _rest7 = _objectWithoutPropertiesLoose(list, [key].map(_toPropertyKey));
3307
+ return _rest7;
3308
+ }
3309
+ return list;
3310
+ }
3311
+ default:
3312
+ {
3313
+ return list;
3314
+ }
3315
+ }
3316
+ }, parsedFormValues);
3125
3317
  };
3126
- var prepareTafValues = function prepareTafValues(_taf, tafAction, addEmptyChangeGroups) {
3127
- var _taf$changeGroups, _Object$assign2;
3128
- if (addEmptyChangeGroups === void 0) {
3129
- addEmptyChangeGroups = false;
3318
+ // Ensure we have enough data to retrieve a TAC - we only need to check for wind and visibility/ cavok as those are the only ones required in all cases
3319
+ var shouldRetrieveTAC = function shouldRetrieveTAC(product) {
3320
+ if (product && product.baseForecast && product.baseForecast.wind && 'speed' in product.baseForecast.wind && product.baseForecast.wind.speed !== '' && (product.baseForecast.visibility && 'range' in product.baseForecast.visibility && product.baseForecast.visibility.range !== '' || product.baseForecast.cavOK)) {
3321
+ return true;
3130
3322
  }
3131
- // If action is AMEND/CORRECT/DRAFT_AMEND/DRAFT_CORRECTION - add previous valid start and end
3132
- // If action is AMEND/DRAFT_AMEND - update validity start time to current time
3133
- var taf = tafAction === 'AMEND' || tafAction === 'DRAFT_AMEND' || tafAction === 'CORRECT' || tafAction === 'DRAFT_CORRECT' ? getAmendedCorrectedTafTimes(_taf, tafAction) : _taf;
3134
- var formattedBaseForecast = formatFormValues(taf.baseForecast);
3135
- var baseForecast = Object.assign({}, emptyBaseForecast, formattedBaseForecast, {
3136
- weather: Object.assign({}, emptyBaseForecast.weather, formattedBaseForecast.weather),
3137
- cloud: Object.assign({}, emptyBaseForecast.cloud, formattedBaseForecast.cloud)
3138
- });
3139
- var formattedChangeGroups = ((_taf$changeGroups = taf.changeGroups) == null ? void 0 : _taf$changeGroups.map(formatFormValues)) || [];
3140
- var changeGroups = formattedChangeGroups.map(createChangeGroup);
3323
+ return false;
3324
+ };
3325
+ var getFieldNames = function getFieldNames(isChangeGroup, index) {
3326
+ var namePrefix = !isChangeGroup ? 'baseForecast' : "changeGroups[" + index + "]";
3327
+ return Object.assign({}, !isChangeGroup && {
3328
+ messageType: 'messageType',
3329
+ location: 'location',
3330
+ issueDate: 'issueDate'
3331
+ }, isChangeGroup && {
3332
+ probability: namePrefix + ".probability",
3333
+ change: namePrefix + ".change"
3334
+ }, {
3335
+ valid: namePrefix + ".valid",
3336
+ wind: namePrefix + ".wind",
3337
+ visibility: namePrefix + ".visibility",
3338
+ weather1: namePrefix + ".weather.weather1",
3339
+ weather2: namePrefix + ".weather.weather2",
3340
+ weather3: namePrefix + ".weather.weather3",
3341
+ cloud1: namePrefix + ".cloud.cloud1",
3342
+ cloud2: namePrefix + ".cloud.cloud2",
3343
+ cloud3: namePrefix + ".cloud.cloud3",
3344
+ cloud4: namePrefix + ".cloud.cloud4"
3345
+ });
3346
+ };
3347
+ var tacHasError = function tacHasError(tac, t) {
3348
+ return tac === t('TAC-missing-data') || tac === t('TAC-not-available') || tac === t('TAC-retrieving-data') || tac === t('TAC-failed');
3349
+ };
3350
+ var useTACGenerator = function useTACGenerator(taf) {
3351
+ var _useTafTranslation = useTafTranslation(),
3352
+ t = _useTafTranslation.t;
3353
+ var _useGetTAC = useGetTAC(),
3354
+ requestTAC = _useGetTAC.mutateAsync;
3355
+ var _React$useState = React__default.useState(!taf || taf.status === 'NEW' ? t('TAC-not-available') : t('TAC-retrieving-data')),
3356
+ TAC = _React$useState[0],
3357
+ setTAC = _React$useState[1];
3358
+ var retrieveTAC = React__default.useCallback(function (tafToPost) {
3359
+ if (shouldRetrieveTAC(tafToPost)) {
3360
+ setTAC(t('TAC-retrieving-data'));
3361
+ requestTAC({
3362
+ tafData: tafToPost
3363
+ }).then(function (result) {
3364
+ setTAC(result);
3365
+ })["catch"](function () {
3366
+ setTAC(t('TAC-failed'));
3367
+ });
3368
+ } else {
3369
+ setTAC(t('TAC-missing-data'));
3370
+ }
3371
+ },
3372
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3373
+ [requestTAC]);
3374
+ React__default.useEffect(function () {
3375
+ if (taf && taf.status !== 'NEW') {
3376
+ retrieveTAC(taf);
3377
+ }
3378
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3379
+ }, [taf]);
3380
+ return [TAC, retrieveTAC];
3381
+ };
3382
+ var useDragOrder = function useDragOrder(trigger, move) {
3383
+ var _React$useState2 = React__default.useState(null),
3384
+ activeDraggingIndex = _React$useState2[0],
3385
+ setActiveDraggingIndex = _React$useState2[1];
3386
+ var _React$useState3 = React__default.useState([null, null]),
3387
+ lastDragOrder = _React$useState3[0],
3388
+ onUpdatelastDragOrder = _React$useState3[1];
3389
+ var onChangeOrder = function onChangeOrder(_ref) {
3390
+ var oldIndex = _ref.oldIndex,
3391
+ newIndex = _ref.newIndex;
3392
+ if (oldIndex === undefined || newIndex === undefined) {
3393
+ return;
3394
+ }
3395
+ move(oldIndex, newIndex);
3396
+ onUpdatelastDragOrder([oldIndex, newIndex]);
3397
+ setActiveDraggingIndex(false);
3398
+ };
3399
+ var onStartDrag = function onStartDrag(_ref2) {
3400
+ var oldIndex = _ref2.oldIndex;
3401
+ return setActiveDraggingIndex(oldIndex);
3402
+ };
3403
+ // triggers validation AFTER render of new sorted elements
3404
+ React__default.useEffect(function () {
3405
+ var oldIndex = lastDragOrder[0],
3406
+ newIndex = lastDragOrder[1];
3407
+ if (oldIndex !== null && newIndex !== null) {
3408
+ // trigger validation of all fields
3409
+ void trigger();
3410
+ }
3411
+ }, [lastDragOrder, trigger]);
3412
+ return {
3413
+ onChangeOrder: onChangeOrder,
3414
+ activeDraggingIndex: activeDraggingIndex,
3415
+ onStartDrag: onStartDrag
3416
+ };
3417
+ };
3418
+ // dialog utils
3419
+ var getConfirmationDialogTitle = function getConfirmationDialogTitle(action, t) {
3420
+ if (action === 'CLEAR') {
3421
+ return t('confirm-clear-title');
3422
+ }
3423
+ if (action === 'PUBLISH') {
3424
+ return t('button-publish');
3425
+ }
3426
+ if (action === 'AMEND') {
3427
+ return t('confirm-amend-title');
3428
+ }
3429
+ if (action === 'CORRECT') {
3430
+ return t('confirm-correct-title');
3431
+ }
3432
+ if (action === 'CANCEL') {
3433
+ return t('confirm-cancel-title');
3434
+ }
3435
+ return t('confirm-cancel-title');
3436
+ };
3437
+ // Check if the amended/corrected TAF has been changed. Only compare the fields users are able to fill in
3438
+ // (i.e. exclude baseforecast valid time as that gets updated when doing an amendment automatically outside of the users influence)
3439
+ var isTafAmendedCorrectedChanged = function isTafAmendedCorrectedChanged(originalTaf, currentTaf) {
3440
+ if (originalTaf === null || currentTaf === null) {
3441
+ return false;
3442
+ }
3443
+ var originalBaseF = originalTaf.baseForecast,
3444
+ originalChG = originalTaf.changeGroups;
3445
+ var currentBaseF = currentTaf.baseForecast,
3446
+ currentChG = currentTaf.changeGroups;
3447
+ originalBaseF.valid;
3448
+ var originalNoValid = _objectWithoutPropertiesLoose(originalBaseF, _excluded9);
3449
+ currentBaseF.valid;
3450
+ var currentNoValid = _objectWithoutPropertiesLoose(currentBaseF, _excluded10);
3451
+ return !isEqual(originalNoValid, currentNoValid) || !isEqual(originalChG, currentChG);
3452
+ };
3453
+ var getConfirmationDialogContent = function getConfirmationDialogContent(action, isFormDirty, t) {
3454
+ switch (action) {
3455
+ case 'CLEAR':
3456
+ return t('confirm-clear-content');
3457
+ case 'PUBLISH':
3458
+ return t('confirm-publish-content');
3459
+ case 'AMEND':
3460
+ case 'CORRECT':
3461
+ return isFormDirty() ? t('confirm-correct-amend-content') : t('confirm-correct-amend-content-no-changes');
3462
+ case 'CANCEL':
3463
+ default:
3464
+ return t('confirm-cancel-content');
3465
+ }
3466
+ };
3467
+ var getConfirmationDialogButtonLabel = function getConfirmationDialogButtonLabel(action, t) {
3468
+ switch (action) {
3469
+ case 'CLEAR':
3470
+ {
3471
+ return t('button-clear');
3472
+ }
3473
+ case 'CANCEL':
3474
+ return t('button-cancel');
3475
+ default:
3476
+ {
3477
+ return t('button-publish');
3478
+ }
3479
+ }
3480
+ };
3481
+ var emptyChangegroup = {
3482
+ valid: '',
3483
+ wind: '',
3484
+ visibility: '',
3485
+ weather: {
3486
+ weather1: '',
3487
+ weather2: '',
3488
+ weather3: ''
3489
+ },
3490
+ cloud: {
3491
+ cloud1: '',
3492
+ cloud2: '',
3493
+ cloud3: '',
3494
+ cloud4: ''
3495
+ },
3496
+ change: '',
3497
+ probability: ''
3498
+ };
3499
+ var getTafStatusLabel = function getTafStatusLabel(t, status, action, isFormDisabled) {
3500
+ // See if we need to base status label on action if form is not disabled and action passed
3501
+ var baseOnAction = isFormDisabled !== undefined && !isFormDisabled && action;
3502
+ if (baseOnAction && action === 'AMEND' && (status === 'PUBLISHED' || status === 'AMENDED' || status === 'CORRECTED')) {
3503
+ return t('status-new-amendment');
3504
+ }
3505
+ if (baseOnAction && action === 'CORRECT' && (status === 'PUBLISHED' || status === 'AMENDED' || status === 'CORRECTED')) {
3506
+ return t('status-new-correction');
3507
+ }
3508
+ switch (status) {
3509
+ case 'DRAFT_AMENDED':
3510
+ return t('status-draft-amendment');
3511
+ case 'DRAFT_CORRECTED':
3512
+ return t('status-draft-correction');
3513
+ case 'AMENDED':
3514
+ return t('status-published-amendment');
3515
+ case 'CORRECTED':
3516
+ return t('status-published-correction');
3517
+ default:
3518
+ return t("status-" + status.toLocaleLowerCase());
3519
+ }
3520
+ };
3521
+ var getMessageType = function getMessageType(taf, tafAction) {
3522
+ if (tafAction === 'CORRECT') {
3523
+ return 'COR';
3524
+ }
3525
+ if (tafAction === 'AMEND') {
3526
+ return 'AMD';
3527
+ }
3528
+ if (tafAction === 'CANCEL') {
3529
+ return 'CNL';
3530
+ }
3531
+ return taf.messageType;
3532
+ };
3533
+ // For corrections and amendment we need to add the previousValidStart and End for the TAC converter
3534
+ var getAmendedCorrectedTafTimes = function getAmendedCorrectedTafTimes(taf, tafAction) {
3535
+ var previousValidDateStart = taf.previousValidDateStart && tafAction !== 'AMEND' ? taf.previousValidDateStart : taf.validDateStart;
3536
+ var previousValidDateEnd = taf.previousValidDateEnd && tafAction !== 'AMEND' ? taf.previousValidDateEnd : taf.validDateEnd;
3537
+ // For amendment change valid start time to current time
3538
+ // only do this if we're already within the validity period
3539
+ var now = dateUtils.utc();
3540
+ var validDateStart = dateUtils.utc(taf.validDateStart);
3541
+ if ((tafAction === 'AMEND' || tafAction === 'DRAFT_AMEND') && now.getTime() >= validDateStart.getTime()) {
3542
+ var _now = dateUtils.dateToString(dateUtils.utc(), dateUtils.DATE_FORMAT_UTC);
3543
+ var validObj = {
3544
+ start: _now,
3545
+ end: taf.baseForecast.valid.end
3546
+ };
3547
+ return Object.assign({}, taf, {
3548
+ previousValidDateStart: previousValidDateStart,
3549
+ previousValidDateEnd: previousValidDateEnd,
3550
+ validDateStart: _now,
3551
+ baseForecast: Object.assign({}, taf.baseForecast, {
3552
+ valid: validObj
3553
+ })
3554
+ });
3555
+ }
3556
+ return Object.assign({}, taf, {
3557
+ previousValidDateStart: previousValidDateStart,
3558
+ previousValidDateEnd: previousValidDateEnd
3559
+ });
3560
+ };
3561
+ var createChangeGroup = function createChangeGroup(changeGroup) {
3562
+ return Object.assign({}, emptyChangegroup, changeGroup, {
3563
+ weather: Object.assign({}, emptyChangegroup.weather, changeGroup.weather),
3564
+ cloud: Object.assign({}, emptyChangegroup.cloud, changeGroup.cloud)
3565
+ });
3566
+ };
3567
+ var prepareTafValues = function prepareTafValues(_taf, tafAction, addEmptyChangeGroups) {
3568
+ var _taf$changeGroups, _Object$assign2;
3569
+ if (addEmptyChangeGroups === void 0) {
3570
+ addEmptyChangeGroups = false;
3571
+ }
3572
+ // If action is AMEND/CORRECT/DRAFT_AMEND/DRAFT_CORRECTION - add previous valid start and end
3573
+ // If action is AMEND/DRAFT_AMEND - update validity start time to current time
3574
+ var taf = tafAction === 'AMEND' || tafAction === 'DRAFT_AMEND' || tafAction === 'CORRECT' || tafAction === 'DRAFT_CORRECT' ? getAmendedCorrectedTafTimes(_taf, tafAction) : _taf;
3575
+ var formattedBaseForecast = formatFormValues(taf.baseForecast);
3576
+ var baseForecast = Object.assign({}, emptyBaseForecast, formattedBaseForecast, {
3577
+ weather: Object.assign({}, emptyBaseForecast.weather, formattedBaseForecast.weather),
3578
+ cloud: Object.assign({}, emptyBaseForecast.cloud, formattedBaseForecast.cloud)
3579
+ });
3580
+ var formattedChangeGroups = ((_taf$changeGroups = taf.changeGroups) == null ? void 0 : _taf$changeGroups.map(formatFormValues)) || [];
3581
+ var changeGroups = formattedChangeGroups.map(createChangeGroup);
3141
3582
  // If addEmptyChangeGroups is true - ensure there are at least MIN_NUMBER_CHANGE_GROUP changegroups
3142
3583
  if (addEmptyChangeGroups) {
3143
3584
  var changeGroupsToAdd = MIN_NUMBER_CHANGE_GROUP - changeGroups.length;
@@ -3158,15 +3599,28 @@ var prepareTafValues = function prepareTafValues(_taf, tafAction, addEmptyChange
3158
3599
  changeGroups: changeGroups
3159
3600
  }, _Object$assign2[HIDDEN_INPUT_HELPER_IS_DRAFT] = true, _Object$assign2));
3160
3601
  };
3161
- var clearTafFormData = function clearTafFormData(tafFormValues) {
3162
- // Remove all except for the validity times
3163
- var baseForecast = {
3164
- valid: tafFormValues.baseForecast.valid
3165
- };
3166
- var emptyChangeGroups = [];
3167
- Array.from(Array(MIN_NUMBER_CHANGE_GROUP)).map(function () {
3168
- return emptyChangeGroups.push(emptyChangegroup);
3169
- });
3602
+ var prepareTafExportValues = function prepareTafExportValues(tafToCopy, currentTaf) {
3603
+ var _currentTaf$baseForec;
3604
+ var convertedCopy = prepareTafValues(tafToCopy, undefined, false);
3605
+ var baseForecast = convertedCopy.baseForecast,
3606
+ _convertedCopy$change = convertedCopy.changeGroups,
3607
+ changeGroups = _convertedCopy$change === void 0 ? [] : _convertedCopy$change;
3608
+ return Object.assign({}, currentTaf, {
3609
+ baseForecast: Object.assign({}, baseForecast, {
3610
+ valid: currentTaf == null || (_currentTaf$baseForec = currentTaf.baseForecast) == null ? void 0 : _currentTaf$baseForec.valid
3611
+ }),
3612
+ changeGroups: changeGroups
3613
+ });
3614
+ };
3615
+ var clearTafFormData = function clearTafFormData(tafFormValues) {
3616
+ // Remove all except for the validity times
3617
+ var baseForecast = {
3618
+ valid: tafFormValues.baseForecast.valid
3619
+ };
3620
+ var emptyChangeGroups = [];
3621
+ Array.from(Array(MIN_NUMBER_CHANGE_GROUP)).map(function () {
3622
+ return emptyChangeGroups.push(emptyChangegroup);
3623
+ });
3170
3624
  return Object.assign({}, tafFormValues, {
3171
3625
  baseForecast: Object.assign({}, emptyBaseForecast, baseForecast),
3172
3626
  // Add empty change groups
@@ -4348,55 +4802,6 @@ var TafFormRow = /*#__PURE__*/React__default.forwardRef(function (_ref, ref) {
4348
4802
  }));
4349
4803
  });
4350
4804
 
4351
- /* *
4352
- * Licensed under the Apache License, Version 2.0 (the "License");
4353
- * you may not use this file except in compliance with the License.
4354
- * You may obtain a copy of the License at
4355
- *
4356
- * http://www.apache.org/licenses/LICENSE-2.0
4357
- *
4358
- * Unless required by applicable law or agreed to in writing, software
4359
- * distributed under the License is distributed on an "AS IS" BASIS,
4360
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4361
- * See the License for the specific language governing permissions and
4362
- * limitations under the License.
4363
- *
4364
- * Copyright 2025 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
4365
- * Copyright 2025 - Finnish Meteorological Institute (FMI)
4366
- * Copyright 2025 - The Norwegian Meteorological Institute (MET Norway)
4367
- * */
4368
- var config = getConfig();
4369
- var tafBaseUrl = config.GW_TAF_BASE_URL || '';
4370
- var getTafList = function getTafList(auth) {
4371
- return fetch(tafBaseUrl + "/taflist", {
4372
- headers: getHeaders(auth)
4373
- }).then(handleResponse);
4374
- };
4375
-
4376
- /* *
4377
- * Licensed under the Apache License, Version 2.0 (the "License");
4378
- * you may not use this file except in compliance with the License.
4379
- * You may obtain a copy of the License at
4380
- *
4381
- * http://www.apache.org/licenses/LICENSE-2.0
4382
- *
4383
- * Unless required by applicable law or agreed to in writing, software
4384
- * distributed under the License is distributed on an "AS IS" BASIS,
4385
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4386
- * See the License for the specific language governing permissions and
4387
- * limitations under the License.
4388
- *
4389
- * Copyright 2025 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
4390
- * Copyright 2025 - Finnish Meteorological Institute (FMI)
4391
- * Copyright 2025 - The Norwegian Meteorological Institute (MET Norway)
4392
- * */
4393
- var useTafList = function useTafList(disabled) {
4394
- if (disabled === void 0) {
4395
- disabled = false;
4396
- }
4397
- return useAuthQuery(['taf-list'], getTafList, disabled, 1000 * 60 * 5);
4398
- };
4399
-
4400
4805
  // prevents default functionality
4401
4806
  var noop = function noop() {};
4402
4807
  var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
@@ -4428,7 +4833,7 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4428
4833
  var formRef = React__default.useRef(null);
4429
4834
  var originalTaf = tafFromBackend.taf,
4430
4835
  editor = tafFromBackend.editor;
4431
- var _useAuthenticationCon = useAuthenticationContext(),
4836
+ var _useAuthenticationCon = useAuthenticationContext$1(),
4432
4837
  auth = _useAuthenticationCon.auth;
4433
4838
  var dispatch = useDispatch();
4434
4839
  var isEditor = editor === (auth == null ? void 0 : auth.username) || false;
@@ -4715,493 +5120,276 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4715
5120
  break;
4716
5121
  default:
4717
5122
  resetFormState(false, action);
4718
- break;
4719
- }
4720
- };
4721
- var onRemoverow = function onRemoverow(index) {
4722
- void confirmDialog({
4723
- title: t('options-delete'),
4724
- description: t('confirm-delete-description'),
4725
- confirmLabel: t('confirm-yes')
4726
- }).then(function () {
4727
- remove(index);
4728
- void trigger(); // trigger all fields validation
4729
- });
4730
- };
4731
- // TODO: https://gitlab.com/opengeoweb/opengeoweb/-/issues/726 insert (react-hook-form) does not work well with focus (only last row will get focus), so added this dirty solution. This can be fixed in a better way in react-hook-form v7
4732
- var focusFirstInput = function focusFirstInput(rowIndex) {
4733
- var selector = rowIndex === -1 ? "[name=\"baseForecast.wind\"]" : "[name=\"changeGroups[" + rowIndex + "].probability\"]";
4734
- var nextRowFirstInput = document.querySelector(selector);
4735
- if (nextRowFirstInput) {
4736
- nextRowFirstInput.focus();
4737
- }
4738
- };
4739
- // adding rows and validation don't work well combined, with always skipping validation of fields of rows above the one the inserted row. A setTimeout prevents this issue
4740
- var setFocusAndValidate = function setFocusAndValidate(rowIndex) {
4741
- return setTimeout(function () {
4742
- focusFirstInput(rowIndex);
4743
- void trigger(); // trigger all fields validation
4744
- }, 0);
4745
- };
4746
- var onAddRow = function onAddRow(rowIndex, above) {
4747
- if (rowIndex === void 0) {
4748
- rowIndex = -1;
4749
- }
4750
- if (above === void 0) {
4751
- above = false;
4752
- }
4753
- var newRowIndex = above ? rowIndex : rowIndex + 1;
4754
- insert(newRowIndex, emptyChangegroup, {
4755
- shouldFocus: false
4756
- });
4757
- setFocusAndValidate(newRowIndex);
4758
- };
4759
- var _onClearRow = function onClearRow(rowIndex, isChangeGroup) {
4760
- if (rowIndex === void 0) {
4761
- rowIndex = -1;
4762
- }
4763
- if (isChangeGroup === void 0) {
4764
- isChangeGroup = false;
4765
- }
4766
- void confirmDialog({
4767
- title: t('options-clear'),
4768
- description: t('confirm-clear-description'),
4769
- confirmLabel: t('confirm-yes')
4770
- }).then(function () {
4771
- if (isChangeGroup) {
4772
- remove(rowIndex);
4773
- insert(rowIndex, emptyChangegroup, {
4774
- shouldFocus: false
4775
- });
4776
- } else {
4777
- var baseForecastFields = getFieldNames(false, -1);
4778
- setValue(baseForecastFields.wind, '');
4779
- setValue(baseForecastFields.visibility, '');
4780
- setValue(baseForecastFields.weather1, '');
4781
- setValue(baseForecastFields.weather2, '');
4782
- setValue(baseForecastFields.weather3, '');
4783
- setValue(baseForecastFields.cloud1, '');
4784
- setValue(baseForecastFields.cloud2, '');
4785
- setValue(baseForecastFields.cloud3, '');
4786
- setValue(baseForecastFields.cloud4, '');
4787
- }
4788
- setFocusAndValidate(rowIndex);
4789
- });
4790
- };
4791
- var _React$useState = React__default.useState(false),
4792
- shouldValidate = _React$useState[0],
4793
- setShouldValidate = _React$useState[1];
4794
- React__default.useEffect(function () {
4795
- setIsDisabled(!isEditor || isDefaultDisabled);
4796
- // set validate flag to validate after the values have been set
4797
- setShouldValidate(true);
4798
- // register validate method to use in parent components
4799
- var onValidateFormPromise = function onValidateFormPromise() {
4800
- return new Promise(function (resolve, reject) {
4801
- toggleIsDraft(true);
4802
- void handleSubmit(function (formData) {
4803
- resolve(convertTafValuesToObject(formData));
4804
- })().then(function (formData) {
4805
- if (formData === undefined) {
4806
- reject();
4807
- }
4808
- resolve(formData);
4809
- });
4810
- });
4811
- };
4812
- if (registerValidateForm) {
4813
- registerValidateForm(onValidateFormPromise);
4814
- }
4815
- // set default taf action
4816
- if (setTafAction) {
4817
- setTafAction(fromStatusToAction(originalTaf.status));
4818
- }
4819
- return function () {
4820
- resetFormValues({});
4821
- };
4822
- // eslint-disable-next-line react-hooks/exhaustive-deps
4823
- }, []);
4824
- React__default.useEffect(function () {
4825
- var newValues = prepareTafValues(originalTaf, undefined, !isDefaultDisabled);
4826
- // set new form values when taf values changed
4827
- resetFormValues(newValues);
4828
- // eslint-disable-next-line react-hooks/exhaustive-deps
4829
- }, [originalTaf]);
4830
- React__default.useEffect(function () {
4831
- // update disabled state when editor changed
4832
- setIsDisabled(!isEditor || isDefaultDisabled);
4833
- // eslint-disable-next-line react-hooks/exhaustive-deps
4834
- }, [editor]);
4835
- React__default.useEffect(function () {
4836
- if (shouldValidate && !isDisabled) {
4837
- // trigger validation on all changegroup validity times after form is enabled since they could be outside the new validity period
4838
- var _originalTaf$changeGr = originalTaf.changeGroups,
4839
- changeGroups = _originalTaf$changeGr === void 0 ? [] : _originalTaf$changeGr;
4840
- var validFields = changeGroups.map(function (_field, index) {
4841
- return "changeGroups[" + index + "].valid";
4842
- });
4843
- void trigger(validFields);
4844
- }
4845
- // eslint-disable-next-line react-hooks/exhaustive-deps
4846
- }, [shouldValidate, isDisabled]);
4847
- return jsxs(Fragment, {
4848
- children: [jsxs(Box, {
4849
- sx: {
4850
- display: 'flex',
4851
- flexDirection: 'row',
4852
- alignItems: 'center',
4853
- position: 'absolute',
4854
- top: {
4855
- xs: '34px',
4856
- sm: '-3px'
4857
- },
4858
- right: {
4859
- xs: 'calc(50% - 70px)',
4860
- sm: '8px'
4861
- }
4862
- },
4863
- children: [jsx(SwitchButton, {
4864
- checked: isEditor,
4865
- onChange: onSwitchMode
4866
- }), jsx(Box, {
4867
- sx: {
4868
- width: '16px',
4869
- marginLeft: 1
4870
- },
4871
- children: editor && jsx(TafAvatar, {
4872
- editor: editor
4873
- })
4874
- })]
4875
- }), jsxs("form", {
4876
- "data-testid": "taf-form",
4877
- onSubmit: handleSubmit(onSubmit),
4878
- ref: formRef,
4879
- children: [jsx(TafFormRow, {
4880
- disabled: isDisabled,
4881
- onAddChangeGroupBelow: onAddRow,
4882
- onClearRow: _onClearRow,
4883
- isNotRequiredForAction: isNotRequiredForAction
4884
- }), jsx(ReactSortable, {
4885
- tag: "div",
4886
- list: fields,
4887
- setList: noop,
4888
- animation: 200,
4889
- onSort: onChangeOrder,
4890
- handle: ".handle",
4891
- direction: "vertical",
4892
- // hover props
4893
- forceFallback: false,
4894
- onStart: function onStart(event) {
4895
- onStartDrag(event);
4896
- if (Sortable.ghost) {
4897
- Sortable.ghost.style.opacity = '1';
4898
- }
4899
- },
4900
- children: fields.map(function (item, index) {
4901
- return jsx(TafFormRow, {
4902
- field: item,
4903
- index: index,
4904
- disabled: isDisabled,
4905
- onRemoveChangeGroup: onRemoverow,
4906
- onAddChangeGroupBelow: onAddRow,
4907
- onAddChangeGroupAbove: function onAddChangeGroupAbove() {
4908
- return onAddRow(index, true);
4909
- },
4910
- onClearRow: function onClearRow() {
4911
- return _onClearRow(index, true);
4912
- },
4913
- isChangeGroup: true,
4914
- dragHandle: jsx(DragHandle, {
4915
- isDisabled: fields.length === 1 || isDisabled,
4916
- isSorting: activeDraggingIndex === index,
4917
- index: index
4918
- }),
4919
- isNotRequiredForAction: isNotRequiredForAction
4920
- }, item.id);
4921
- })
4922
- }), !isDisabled && isEditor && jsx(Grid2, {
4923
- container: true,
4924
- sx: {
4925
- justifyContent: 'space-between',
4926
- alignItems: 'center',
4927
- marginLeft: 1.5,
4928
- marginTop: 1
4929
- },
4930
- children: jsx(Grid2, {
4931
- children: jsx(IssuesButton, {
4932
- errors: errors,
4933
- isIssuesPaneOpen: isIssuesPaneOpen,
4934
- setIsIssuesPaneOpen: setIsIssuesPaneOpen
4935
- })
4936
- })
4937
- }), isEditor && jsx(TafFormButtons, {
4938
- isFormDisabled: isDisabled,
4939
- tafAction: tafAction,
4940
- canBe: tafFromBackend.canbe,
4941
- onTafEditModeButtonPress: onTafEditModeButtonPress,
4942
- onTafViewModeButtonPress: onTafViewModeButtonPress
4943
- }), hiddenInputFields.map(function (field) {
4944
- return jsx(ReactHookFormHiddenInput, {
4945
- name: field,
4946
- "data-testid": field
4947
- }, field);
4948
- })]
4949
- })]
4950
- });
4951
- }, function (prevProps, nextProps) {
4952
- // prevent re-render
4953
- return !nextProps.isDisabled && prevProps.tafFromBackend !== nextProps.tafFromBackend &&
4954
- // if editor changed it should rerender
4955
- prevProps.tafFromBackend.editor === nextProps.tafFromBackend.editor;
4956
- });
4957
-
4958
- var _excluded$2 = ["children", "value", "index"];
4959
- var TabPanel = function TabPanel(_ref) {
4960
- var children = _ref.children,
4961
- value = _ref.value,
4962
- index = _ref.index,
4963
- other = _objectWithoutPropertiesLoose(_ref, _excluded$2);
4964
- return jsx(Box, Object.assign({
4965
- role: "tabpanel",
4966
- hidden: value !== index,
4967
- id: "simple-tabpanel-" + index,
4968
- "aria-labelledby": "simple-tab-" + index,
4969
- "data-testid": "tab-panel-" + index
4970
- }, other, {
4971
- children: value === index && children
4972
- }));
4973
- };
4974
-
4975
- var TafHeader = function TafHeader(_ref) {
4976
- var title = _ref.title,
4977
- _ref$sx = _ref.sx,
4978
- sx = _ref$sx === void 0 ? {} : _ref$sx;
4979
- return jsx(Typography, {
4980
- sx: Object.assign({
4981
- textAlign: 'center',
4982
- fontWeight: 500,
4983
- paddingTop: '4px',
4984
- textTransform: 'capitalize'
4985
- }, sx),
4986
- children: title
4987
- });
4988
- };
4989
-
4990
- var location_indicator_mwo = "EHDB";
4991
- var locations = {
4992
- EHAM: {
4993
- validity_duration: 30,
4994
- activity_period: 6,
4995
- label: "Schiphol"
4996
- },
4997
- EHRD: {
4998
- validity_duration: 30,
4999
- activity_period: 6,
5000
- label: "Rotterdam"
5001
- },
5002
- EHGG: {
5003
- validity_duration: 30,
5004
- activity_period: 6,
5005
- label: "Eelde"
5006
- },
5007
- EHBK: {
5008
- validity_duration: 30,
5009
- activity_period: 6,
5010
- label: "Maastricht"
5011
- },
5012
- EHLE: {
5013
- validity_duration: 30,
5014
- activity_period: 6,
5015
- label: "Lelystad"
5016
- },
5017
- TNCB: {
5018
- validity_duration: 30,
5019
- activity_period: 6,
5020
- label: "Bonaire"
5021
- }
5022
- };
5023
- var locationOrder = [
5024
- "EHAM",
5025
- "EHRD",
5026
- "EHLE",
5027
- "EHGG",
5028
- "EHBK",
5029
- "TNCB"
5030
- ];
5031
- var autoTAFlocations = [
5032
- "EHAM",
5033
- "EHRD",
5034
- "EHLE",
5035
- "EHGG",
5036
- "EHBK"
5037
- ];
5038
- var tafConfig = {
5039
- location_indicator_mwo: location_indicator_mwo,
5040
- locations: locations,
5041
- locationOrder: locationOrder,
5042
- autoTAFlocations: autoTAFlocations
5043
- };
5044
-
5045
- /* *
5046
- * Licensed under the Apache License, Version 2.0 (the "License");
5047
- * you may not use this file except in compliance with the License.
5048
- * You may obtain a copy of the License at
5049
- *
5050
- * http://www.apache.org/licenses/LICENSE-2.0
5051
- *
5052
- * Unless required by applicable law or agreed to in writing, software
5053
- * distributed under the License is distributed on an "AS IS" BASIS,
5054
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5055
- * See the License for the specific language governing permissions and
5056
- * limitations under the License.
5057
- *
5058
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
5059
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
5060
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
5061
- * */
5062
- // TODO: should be validated
5063
- var getTafSettings = function getTafSettings() {
5064
- return tafConfig;
5065
- };
5066
- var tafSettings = getTafSettings();
5067
- var getLocationSetting = function getLocationSetting(location, locationSettings) {
5068
- if (locationSettings === void 0) {
5069
- locationSettings = tafSettings.locations;
5070
- }
5071
- return locationSettings[location];
5072
- };
5073
- var sortTafsOnLocation = function sortTafsOnLocation(tafList, locationOrder) {
5074
- if (tafList === void 0) {
5075
- tafList = [];
5076
- }
5077
- if (locationOrder === void 0) {
5078
- locationOrder = tafSettings.locationOrder;
5079
- }
5080
- return [].concat(tafList).sort(function (_ref, _ref2) {
5081
- var tafA = _ref.taf;
5082
- var tafB = _ref2.taf;
5083
- return locationOrder.indexOf(tafA.location) < locationOrder.indexOf(tafB.location) ? -1 : 1;
5084
- });
5085
- };
5086
- var sortTafsOnIssueDate = function sortTafsOnIssueDate(tafList) {
5087
- if (tafList === void 0) {
5088
- tafList = [];
5089
- }
5090
- return [].concat(tafList).sort(function (_ref3, _ref4) {
5091
- var tafA = _ref3.taf;
5092
- var tafB = _ref4.taf;
5093
- if (tafA.issueDate < tafB.issueDate || tafA.issueDate && !tafB.issueDate) {
5094
- return 1;
5123
+ break;
5095
5124
  }
5096
- return -1;
5097
- });
5098
- };
5099
- var getBaseTime = function getBaseTime(baseTime, location) {
5100
- var currentBaseTime = dateUtils.utc(baseTime);
5101
- var activityPeriod = getLocationSetting(location).activity_period;
5102
- var nextBaseTime = dateUtils.add(dateUtils.utc(baseTime), {
5103
- hours: activityPeriod
5104
- });
5105
- return {
5106
- currentBaseTime: currentBaseTime,
5107
- nextBaseTime: nextBaseTime
5108
5125
  };
5109
- };
5110
- var getTafTimeSlot = function getTafTimeSlot(baseTime, location, status) {
5111
- var now = dateUtils.utc();
5112
- var _getBaseTime = getBaseTime(baseTime, location),
5113
- currentBaseTime = _getBaseTime.currentBaseTime,
5114
- nextBaseTime = _getBaseTime.nextBaseTime;
5115
- if (status === 'EXPIRED') {
5116
- return 'EXPIRED';
5117
- }
5118
- if (currentBaseTime.getTime() < now.getTime() && nextBaseTime.getTime() > now.getTime()) {
5119
- return 'ACTIVE';
5120
- }
5121
- return 'UPCOMING';
5122
- };
5123
- var sortTafTimeSlots = function sortTafTimeSlots(tafList) {
5124
- var sortedListOnIssueDate = sortTafsOnIssueDate(tafList);
5125
- var sortedListOnLocation = sortTafsOnLocation(sortedListOnIssueDate);
5126
- return sortedListOnLocation.reduce(function (sortedTafList, tafFromBackend) {
5127
- var taf = tafFromBackend.taf;
5128
- var timeSlot = getTafTimeSlot(taf.baseTime, taf.location, taf.status);
5129
- if (timeSlot === 'EXPIRED') {
5130
- sortedTafList.expired.push(tafFromBackend);
5131
- } else if (timeSlot === 'ACTIVE') {
5132
- sortedTafList.current.push(tafFromBackend);
5133
- } else {
5134
- sortedTafList.upcoming.push(tafFromBackend);
5126
+ var onRemoverow = function onRemoverow(index) {
5127
+ void confirmDialog({
5128
+ title: t('options-delete'),
5129
+ description: t('confirm-delete-description'),
5130
+ confirmLabel: t('confirm-yes')
5131
+ }).then(function () {
5132
+ remove(index);
5133
+ void trigger(); // trigger all fields validation
5134
+ });
5135
+ };
5136
+ // TODO: https://gitlab.com/opengeoweb/opengeoweb/-/issues/726 insert (react-hook-form) does not work well with focus (only last row will get focus), so added this dirty solution. This can be fixed in a better way in react-hook-form v7
5137
+ var focusFirstInput = function focusFirstInput(rowIndex) {
5138
+ var selector = rowIndex === -1 ? "[name=\"baseForecast.wind\"]" : "[name=\"changeGroups[" + rowIndex + "].probability\"]";
5139
+ var nextRowFirstInput = document.querySelector(selector);
5140
+ if (nextRowFirstInput) {
5141
+ nextRowFirstInput.focus();
5135
5142
  }
5136
- return sortedTafList;
5137
- }, {
5138
- current: [],
5139
- upcoming: [],
5140
- expired: []
5141
- });
5142
- };
5143
- var muiTabA11yProps = function muiTabA11yProps(index) {
5144
- return {
5145
- id: "simple-tab-" + index,
5146
- 'aria-controls': "simple-tabpanel-" + index
5147
5143
  };
5148
- };
5149
- var prepareTafExportValues = function prepareTafExportValues(tafToCopy, currentTaf) {
5150
- var _currentTaf$baseForec;
5151
- var convertedCopy = prepareTafValues(tafToCopy, undefined, false);
5152
- var baseForecast = convertedCopy.baseForecast,
5153
- _convertedCopy$change = convertedCopy.changeGroups,
5154
- changeGroups = _convertedCopy$change === void 0 ? [] : _convertedCopy$change;
5155
- return Object.assign({}, currentTaf, {
5156
- baseForecast: Object.assign({}, baseForecast, {
5157
- valid: currentTaf == null || (_currentTaf$baseForec = currentTaf.baseForecast) == null ? void 0 : _currentTaf$baseForec.valid
5158
- }),
5159
- changeGroups: changeGroups
5160
- });
5161
- };
5162
- var getNewTafLocationIndex = function getNewTafLocationIndex(tafLocations, previousTafLocationUUID) {
5163
- var newActiveIndexForDraft = tafLocations.findIndex(function (location) {
5164
- var _location$taf;
5165
- return (location == null || (_location$taf = location.taf) == null ? void 0 : _location$taf.previousId) === previousTafLocationUUID;
5166
- });
5167
- if (newActiveIndexForDraft !== -1) {
5168
- return newActiveIndexForDraft;
5169
- }
5170
- var newActiveIndexForPublished = tafLocations.findIndex(function (location) {
5171
- var _location$taf2;
5172
- return (location == null || (_location$taf2 = location.taf) == null ? void 0 : _location$taf2.uuid) === previousTafLocationUUID;
5144
+ // adding rows and validation don't work well combined, with always skipping validation of fields of rows above the one the inserted row. A setTimeout prevents this issue
5145
+ var setFocusAndValidate = function setFocusAndValidate(rowIndex) {
5146
+ return setTimeout(function () {
5147
+ focusFirstInput(rowIndex);
5148
+ void trigger(); // trigger all fields validation
5149
+ }, 0);
5150
+ };
5151
+ var onAddRow = function onAddRow(rowIndex, above) {
5152
+ if (rowIndex === void 0) {
5153
+ rowIndex = -1;
5154
+ }
5155
+ if (above === void 0) {
5156
+ above = false;
5157
+ }
5158
+ var newRowIndex = above ? rowIndex : rowIndex + 1;
5159
+ insert(newRowIndex, emptyChangegroup, {
5160
+ shouldFocus: false
5161
+ });
5162
+ setFocusAndValidate(newRowIndex);
5163
+ };
5164
+ var _onClearRow = function onClearRow(rowIndex, isChangeGroup) {
5165
+ if (rowIndex === void 0) {
5166
+ rowIndex = -1;
5167
+ }
5168
+ if (isChangeGroup === void 0) {
5169
+ isChangeGroup = false;
5170
+ }
5171
+ void confirmDialog({
5172
+ title: t('options-clear'),
5173
+ description: t('confirm-clear-description'),
5174
+ confirmLabel: t('confirm-yes')
5175
+ }).then(function () {
5176
+ if (isChangeGroup) {
5177
+ remove(rowIndex);
5178
+ insert(rowIndex, emptyChangegroup, {
5179
+ shouldFocus: false
5180
+ });
5181
+ } else {
5182
+ var baseForecastFields = getFieldNames(false, -1);
5183
+ setValue(baseForecastFields.wind, '');
5184
+ setValue(baseForecastFields.visibility, '');
5185
+ setValue(baseForecastFields.weather1, '');
5186
+ setValue(baseForecastFields.weather2, '');
5187
+ setValue(baseForecastFields.weather3, '');
5188
+ setValue(baseForecastFields.cloud1, '');
5189
+ setValue(baseForecastFields.cloud2, '');
5190
+ setValue(baseForecastFields.cloud3, '');
5191
+ setValue(baseForecastFields.cloud4, '');
5192
+ }
5193
+ setFocusAndValidate(rowIndex);
5194
+ });
5195
+ };
5196
+ var _React$useState = React__default.useState(false),
5197
+ shouldValidate = _React$useState[0],
5198
+ setShouldValidate = _React$useState[1];
5199
+ React__default.useEffect(function () {
5200
+ setIsDisabled(!isEditor || isDefaultDisabled);
5201
+ // set validate flag to validate after the values have been set
5202
+ setShouldValidate(true);
5203
+ // register validate method to use in parent components
5204
+ var onValidateFormPromise = function onValidateFormPromise() {
5205
+ return new Promise(function (resolve, reject) {
5206
+ toggleIsDraft(true);
5207
+ void handleSubmit(function (formData) {
5208
+ resolve(convertTafValuesToObject(formData));
5209
+ })().then(function (formData) {
5210
+ if (formData === undefined) {
5211
+ reject();
5212
+ }
5213
+ resolve(formData);
5214
+ });
5215
+ });
5216
+ };
5217
+ if (registerValidateForm) {
5218
+ registerValidateForm(onValidateFormPromise);
5219
+ }
5220
+ // set default taf action
5221
+ if (setTafAction) {
5222
+ setTafAction(fromStatusToAction(originalTaf.status));
5223
+ }
5224
+ return function () {
5225
+ resetFormValues({});
5226
+ };
5227
+ // eslint-disable-next-line react-hooks/exhaustive-deps
5228
+ }, []);
5229
+ React__default.useEffect(function () {
5230
+ var newValues = prepareTafValues(originalTaf, undefined, !isDefaultDisabled);
5231
+ // set new form values when taf values changed
5232
+ resetFormValues(newValues);
5233
+ // eslint-disable-next-line react-hooks/exhaustive-deps
5234
+ }, [originalTaf]);
5235
+ React__default.useEffect(function () {
5236
+ // update disabled state when editor changed
5237
+ setIsDisabled(!isEditor || isDefaultDisabled);
5238
+ // eslint-disable-next-line react-hooks/exhaustive-deps
5239
+ }, [editor]);
5240
+ React__default.useEffect(function () {
5241
+ if (shouldValidate && !isDisabled) {
5242
+ // trigger validation on all changegroup validity times after form is enabled since they could be outside the new validity period
5243
+ var _originalTaf$changeGr = originalTaf.changeGroups,
5244
+ changeGroups = _originalTaf$changeGr === void 0 ? [] : _originalTaf$changeGr;
5245
+ var validFields = changeGroups.map(function (_field, index) {
5246
+ return "changeGroups[" + index + "].valid";
5247
+ });
5248
+ void trigger(validFields);
5249
+ }
5250
+ // eslint-disable-next-line react-hooks/exhaustive-deps
5251
+ }, [shouldValidate, isDisabled]);
5252
+ return jsxs(Fragment, {
5253
+ children: [jsxs(Box, {
5254
+ sx: {
5255
+ display: 'flex',
5256
+ flexDirection: 'row',
5257
+ alignItems: 'center',
5258
+ position: 'absolute',
5259
+ top: {
5260
+ xs: '34px',
5261
+ sm: '-3px'
5262
+ },
5263
+ right: {
5264
+ xs: 'calc(50% - 70px)',
5265
+ sm: '8px'
5266
+ }
5267
+ },
5268
+ children: [jsx(SwitchButton, {
5269
+ checked: isEditor,
5270
+ onChange: onSwitchMode
5271
+ }), jsx(Box, {
5272
+ sx: {
5273
+ width: '16px',
5274
+ marginLeft: 1
5275
+ },
5276
+ children: editor && jsx(TafAvatar, {
5277
+ editor: editor
5278
+ })
5279
+ })]
5280
+ }), jsxs("form", {
5281
+ "data-testid": "taf-form",
5282
+ onSubmit: handleSubmit(onSubmit),
5283
+ ref: formRef,
5284
+ children: [jsx(TafFormRow, {
5285
+ disabled: isDisabled,
5286
+ onAddChangeGroupBelow: onAddRow,
5287
+ onClearRow: _onClearRow,
5288
+ isNotRequiredForAction: isNotRequiredForAction
5289
+ }), jsx(ReactSortable, {
5290
+ tag: "div",
5291
+ list: fields,
5292
+ setList: noop,
5293
+ animation: 200,
5294
+ onSort: onChangeOrder,
5295
+ handle: ".handle",
5296
+ direction: "vertical",
5297
+ // hover props
5298
+ forceFallback: false,
5299
+ onStart: function onStart(event) {
5300
+ onStartDrag(event);
5301
+ if (Sortable.ghost) {
5302
+ Sortable.ghost.style.opacity = '1';
5303
+ }
5304
+ },
5305
+ children: fields.map(function (item, index) {
5306
+ return jsx(TafFormRow, {
5307
+ field: item,
5308
+ index: index,
5309
+ disabled: isDisabled,
5310
+ onRemoveChangeGroup: onRemoverow,
5311
+ onAddChangeGroupBelow: onAddRow,
5312
+ onAddChangeGroupAbove: function onAddChangeGroupAbove() {
5313
+ return onAddRow(index, true);
5314
+ },
5315
+ onClearRow: function onClearRow() {
5316
+ return _onClearRow(index, true);
5317
+ },
5318
+ isChangeGroup: true,
5319
+ dragHandle: jsx(DragHandle, {
5320
+ isDisabled: fields.length === 1 || isDisabled,
5321
+ isSorting: activeDraggingIndex === index,
5322
+ index: index
5323
+ }),
5324
+ isNotRequiredForAction: isNotRequiredForAction
5325
+ }, item.id);
5326
+ })
5327
+ }), !isDisabled && isEditor && jsx(Grid2, {
5328
+ container: true,
5329
+ sx: {
5330
+ justifyContent: 'space-between',
5331
+ alignItems: 'center',
5332
+ marginLeft: 1.5,
5333
+ marginTop: 1
5334
+ },
5335
+ children: jsx(Grid2, {
5336
+ children: jsx(IssuesButton, {
5337
+ errors: errors,
5338
+ isIssuesPaneOpen: isIssuesPaneOpen,
5339
+ setIsIssuesPaneOpen: setIsIssuesPaneOpen
5340
+ })
5341
+ })
5342
+ }), isEditor && jsx(TafFormButtons, {
5343
+ isFormDisabled: isDisabled,
5344
+ tafAction: tafAction,
5345
+ canBe: tafFromBackend.canbe,
5346
+ onTafEditModeButtonPress: onTafEditModeButtonPress,
5347
+ onTafViewModeButtonPress: onTafViewModeButtonPress
5348
+ }), hiddenInputFields.map(function (field) {
5349
+ return jsx(ReactHookFormHiddenInput, {
5350
+ name: field,
5351
+ "data-testid": field
5352
+ }, field);
5353
+ })]
5354
+ })]
5173
5355
  });
5174
- if (newActiveIndexForPublished !== -1) {
5175
- return newActiveIndexForPublished;
5176
- }
5177
- return 0;
5356
+ }, function (prevProps, nextProps) {
5357
+ // prevent re-render
5358
+ return !nextProps.isDisabled && prevProps.tafFromBackend !== nextProps.tafFromBackend &&
5359
+ // if editor changed it should rerender
5360
+ prevProps.tafFromBackend.editor === nextProps.tafFromBackend.editor;
5361
+ });
5362
+
5363
+ var _excluded$2 = ["children", "value", "index"];
5364
+ var TabPanel = function TabPanel(_ref) {
5365
+ var children = _ref.children,
5366
+ value = _ref.value,
5367
+ index = _ref.index,
5368
+ other = _objectWithoutPropertiesLoose(_ref, _excluded$2);
5369
+ return jsx(Box, Object.assign({
5370
+ role: "tabpanel",
5371
+ hidden: value !== index,
5372
+ id: "simple-tabpanel-" + index,
5373
+ "aria-labelledby": "simple-tab-" + index,
5374
+ "data-testid": "tab-panel-" + index
5375
+ }, other, {
5376
+ children: value === index && children
5377
+ }));
5178
5378
  };
5179
- var getPreviousTaf = function getPreviousTaf(tafList, currentTaf) {
5180
- var previousId = currentTaf.taf.previousId;
5181
- if (!previousId) {
5182
- return null;
5183
- }
5184
- var previousTaf = tafList.find(function (taf) {
5185
- return taf.taf.uuid === previousId;
5379
+
5380
+ var TafHeader = function TafHeader(_ref) {
5381
+ var title = _ref.title,
5382
+ _ref$sx = _ref.sx,
5383
+ sx = _ref$sx === void 0 ? {} : _ref$sx;
5384
+ return jsx(Typography, {
5385
+ sx: Object.assign({
5386
+ textAlign: 'center',
5387
+ fontWeight: 500,
5388
+ paddingTop: '4px',
5389
+ textTransform: 'capitalize'
5390
+ }, sx),
5391
+ children: title
5186
5392
  });
5187
- return previousTaf ? previousTaf.taf : null;
5188
- };
5189
- var getAutoTafLocations = function getAutoTafLocations(autoTAFlocations) {
5190
- if (autoTAFlocations === void 0) {
5191
- autoTAFlocations = tafSettings.autoTAFlocations;
5192
- }
5193
- return autoTAFlocations || null;
5194
- };
5195
- var scrollToPosition = function scrollToPosition(scrollRef, activeLocation) {
5196
- if (!scrollRef.current) {
5197
- return;
5198
- }
5199
- var containerTop = scrollRef.current.getBoundingClientRect().top;
5200
- var firstLocation = scrollRef.current.querySelector("[data-location=\"" + activeLocation + "\"]");
5201
- var paddingTop = parseInt(getComputedStyle(scrollRef.current).paddingTop, 10);
5202
- var firstLocationTop = firstLocation == null ? void 0 : firstLocation.getBoundingClientRect().top;
5203
- var newScrollPosition = firstLocationTop - containerTop + scrollRef.current.scrollTop - paddingTop;
5204
- scrollRef.current.scrollTo(newScrollPosition, newScrollPosition);
5205
5393
  };
5206
5394
 
5207
5395
  var IconWithTooltip = function IconWithTooltip(_ref) {
@@ -5357,10 +5545,8 @@ var TacContainer = function TacContainer(_ref2) {
5357
5545
  isFormDisabled = _ref2$isFormDisabled === void 0 ? false : _ref2$isFormDisabled;
5358
5546
  var _useTafTranslation = useTafTranslation(),
5359
5547
  t = _useTafTranslation.t;
5360
- var _useApiContext = useApiContext(),
5361
- api = _useApiContext.api;
5362
5548
  var dispatch = useDispatch();
5363
- var _useTACGenerator = useTACGenerator(taf, api.getTAC, true),
5549
+ var _useTACGenerator = useTACGenerator(taf),
5364
5550
  TAC = _useTACGenerator[0],
5365
5551
  retrieveTAC = _useTACGenerator[1];
5366
5552
  var status = taf.status,
@@ -5411,7 +5597,8 @@ var TacContainer = function TacContainer(_ref2) {
5411
5597
  if (isActive) {
5412
5598
  retrieveTAC(taf);
5413
5599
  }
5414
- }, [taf, isActive, retrieveTAC]);
5600
+ // eslint-disable-next-line react-hooks/exhaustive-deps
5601
+ }, [isActive]);
5415
5602
  return jsxs(Box, {
5416
5603
  sx: {
5417
5604
  marginBottom: '20px'
@@ -5837,9 +6024,6 @@ var TacOverviewMobile = function TacOverviewMobile(_ref) {
5837
6024
  });
5838
6025
  };
5839
6026
 
5840
- var formatBaseTime = function formatBaseTime(time) {
5841
- return dateUtils.dateToString(time, DATE_FORMAT_BASE_TIME);
5842
- };
5843
6027
  var TopTabs = function TopTabs(_ref) {
5844
6028
  var timeSlot = _ref.timeSlot,
5845
6029
  _ref$onChangeTimeSlot = _ref.onChangeTimeSlot,
@@ -5998,159 +6182,73 @@ var fromActionToStatus = function fromActionToStatus(tafAction) {
5998
6182
  return 'NEW';
5999
6183
  }
6000
6184
  };
6001
- var isWarning = function isWarning(error) {
6002
- return (error == null ? void 0 : error.type) === 'WARNING';
6003
- };
6004
- var parseErrorMessage = function parseErrorMessage(error, params, t) {
6005
- var message = getErrorMessage$1(error);
6006
- var warningMessage = getWarningMessage(error);
6007
- if (warningMessage) {
6008
- return {
6009
- type: 'WARNING',
6010
- title: warningMessage
6011
- };
6012
- }
6013
- return params.changeStatusTo === 'CANCELLED' ? {
6014
- type: 'CANCELLED',
6015
- title: t('error-cancel'),
6016
- message: message
6017
- } : {
6018
- type: 'SERVER',
6019
- title: t('error-save'),
6020
- message: message
6021
- };
6022
- };
6023
- var usePostTafRequest = function usePostTafRequest(request) {
6024
- var _useTafTranslation = useTafTranslation(),
6025
- t = _useTafTranslation.t;
6026
- var _useIsMounted = useIsMounted(),
6027
- isMounted = _useIsMounted.isMounted;
6028
- var _React$useState = React__default.useState(false),
6029
- isLoading = _React$useState[0],
6030
- setLoading = _React$useState[1];
6031
- var _React$useState2 = React__default.useState(),
6032
- error = _React$useState2[0],
6033
- setError = _React$useState2[1];
6034
- var doRequest = /*#__PURE__*/function () {
6035
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
6036
- var newError;
6037
- return _regeneratorRuntime().wrap(function _callee$(_context) {
6038
- while (1) switch (_context.prev = _context.next) {
6039
- case 0:
6040
- setLoading(true);
6041
- setError(null);
6042
- _context.prev = 2;
6043
- _context.next = 5;
6044
- return request(params);
6045
- case 5:
6046
- if (isMounted.current) {
6047
- _context.next = 7;
6048
- break;
6049
- }
6050
- return _context.abrupt("return");
6051
- case 7:
6052
- setLoading(false);
6053
- setError(null);
6054
- _context.next = 19;
6055
- break;
6056
- case 11:
6057
- _context.prev = 11;
6058
- _context.t0 = _context["catch"](2);
6059
- if (isMounted.current) {
6060
- _context.next = 15;
6061
- break;
6062
- }
6063
- return _context.abrupt("return");
6064
- case 15:
6065
- newError = parseErrorMessage(_context.t0, params, t);
6066
- setLoading(false);
6067
- setError(newError);
6068
- // eslint-disable-next-line @typescript-eslint/no-throw-literal
6069
- throw newError;
6070
- case 19:
6071
- case "end":
6072
- return _context.stop();
6073
- }
6074
- }, _callee, null, [[2, 11]]);
6075
- }));
6076
- return function doRequest(_x) {
6077
- return _ref.apply(this, arguments);
6078
- };
6079
- }();
6080
- return {
6081
- isLoading: isLoading,
6082
- error: error,
6083
- setError: setError,
6084
- doRequest: doRequest
6085
- };
6086
- };
6087
- var TafPanel = function TafPanel(_ref2) {
6088
- var tafFromBackend = _ref2.tafFromBackend,
6089
- activeTafIndex = _ref2.activeTafIndex,
6090
- index = _ref2.index,
6091
- _ref2$isLoading = _ref2.isLoading,
6092
- isLoading = _ref2$isLoading === void 0 ? false : _ref2$isLoading,
6093
- _ref2$postTaf = _ref2.postTaf,
6094
- postTaf = _ref2$postTaf === void 0 ? function () {
6185
+ var TafPanel = function TafPanel(_ref) {
6186
+ var tafFromBackend = _ref.tafFromBackend,
6187
+ activeTafIndex = _ref.activeTafIndex,
6188
+ index = _ref.index,
6189
+ _ref$isLoading = _ref.isLoading,
6190
+ isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
6191
+ _ref$postTaf = _ref.postTaf,
6192
+ postTaf = _ref$postTaf === void 0 ? function () {
6095
6193
  return null;
6096
- } : _ref2$postTaf,
6097
- _ref2$patchTaf = _ref2.patchTaf,
6098
- patchTaf = _ref2$patchTaf === void 0 ? function () {
6194
+ } : _ref$postTaf,
6195
+ _ref$patchTaf = _ref.patchTaf,
6196
+ patchTaf = _ref$patchTaf === void 0 ? function () {
6099
6197
  return null;
6100
- } : _ref2$patchTaf,
6101
- _ref2$isIssuesPaneOpe = _ref2.isIssuesPaneOpen,
6102
- isIssuesPaneOpen = _ref2$isIssuesPaneOpe === void 0 ? false : _ref2$isIssuesPaneOpe,
6103
- _ref2$setIsIssuesPane = _ref2.setIsIssuesPaneOpen,
6104
- setIsIssuesPaneOpen = _ref2$setIsIssuesPane === void 0 ? function () {
6198
+ } : _ref$patchTaf,
6199
+ _ref$isIssuesPaneOpen = _ref.isIssuesPaneOpen,
6200
+ isIssuesPaneOpen = _ref$isIssuesPaneOpen === void 0 ? false : _ref$isIssuesPaneOpen,
6201
+ _ref$setIsIssuesPaneO = _ref.setIsIssuesPaneOpen,
6202
+ setIsIssuesPaneOpen = _ref$setIsIssuesPaneO === void 0 ? function () {
6105
6203
  return null;
6106
- } : _ref2$setIsIssuesPane,
6107
- _ref2$isFormDisabled = _ref2.isFormDisabled,
6108
- isFormDisabled = _ref2$isFormDisabled === void 0 ? false : _ref2$isFormDisabled,
6109
- _ref2$setIsFormDisabl = _ref2.setIsFormDisabled,
6110
- setIsFormDisabled = _ref2$setIsFormDisabl === void 0 ? function () {
6204
+ } : _ref$setIsIssuesPaneO,
6205
+ _ref$isFormDisabled = _ref.isFormDisabled,
6206
+ isFormDisabled = _ref$isFormDisabled === void 0 ? false : _ref$isFormDisabled,
6207
+ _ref$setIsFormDisable = _ref.setIsFormDisabled,
6208
+ setIsFormDisabled = _ref$setIsFormDisable === void 0 ? function () {
6111
6209
  return null;
6112
- } : _ref2$setIsFormDisabl,
6113
- error = _ref2.error,
6114
- _ref2$previousTaf = _ref2.previousTaf,
6115
- previousTaf = _ref2$previousTaf === void 0 ? null : _ref2$previousTaf,
6116
- tafAction = _ref2.tafAction;
6117
- var _useTafTranslation2 = useTafTranslation(),
6118
- t = _useTafTranslation2.t;
6210
+ } : _ref$setIsFormDisable,
6211
+ error = _ref.error,
6212
+ _ref$previousTaf = _ref.previousTaf,
6213
+ previousTaf = _ref$previousTaf === void 0 ? null : _ref$previousTaf,
6214
+ tafAction = _ref.tafAction;
6215
+ var _useTafTranslation = useTafTranslation(),
6216
+ t = _useTafTranslation.t;
6119
6217
  var severity = isWarning(error) ? 'warning' : 'error';
6120
6218
  var onTafAction = /*#__PURE__*/function () {
6121
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(action, taf) {
6122
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
6123
- while (1) switch (_context2.prev = _context2.next) {
6219
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(action, taf) {
6220
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
6221
+ while (1) switch (_context.prev = _context.next) {
6124
6222
  case 0:
6125
- _context2.prev = 0;
6126
- _context2.t0 = action;
6127
- _context2.next = _context2.t0 === 'DRAFT' ? 4 : _context2.t0 === 'DRAFT_AMEND' ? 4 : _context2.t0 === 'DRAFT_CORRECT' ? 4 : _context2.t0 === 'PUBLISH' ? 4 : _context2.t0 === 'AMEND' ? 4 : _context2.t0 === 'CANCEL' ? 4 : _context2.t0 === 'CORRECT' ? 4 : 7;
6223
+ _context.prev = 0;
6224
+ _context.t0 = action;
6225
+ _context.next = _context.t0 === 'DRAFT' ? 4 : _context.t0 === 'DRAFT_AMEND' ? 4 : _context.t0 === 'DRAFT_CORRECT' ? 4 : _context.t0 === 'PUBLISH' ? 4 : _context.t0 === 'AMEND' ? 4 : _context.t0 === 'CANCEL' ? 4 : _context.t0 === 'CORRECT' ? 4 : 7;
6128
6226
  break;
6129
6227
  case 4:
6130
- _context2.next = 6;
6228
+ _context.next = 6;
6131
6229
  return postTaf({
6132
6230
  taf: taf,
6133
6231
  changeStatusTo: fromActionToStatus(action)
6134
6232
  });
6135
6233
  case 6:
6136
- return _context2.abrupt("return", true);
6234
+ return _context.abrupt("return", true);
6137
6235
  case 7:
6138
- return _context2.abrupt("return", false);
6236
+ return _context.abrupt("return", false);
6139
6237
  case 8:
6140
- _context2.next = 13;
6238
+ _context.next = 13;
6141
6239
  break;
6142
6240
  case 10:
6143
- _context2.prev = 10;
6144
- _context2.t1 = _context2["catch"](0);
6145
- return _context2.abrupt("return", false);
6241
+ _context.prev = 10;
6242
+ _context.t1 = _context["catch"](0);
6243
+ return _context.abrupt("return", false);
6146
6244
  case 13:
6147
6245
  case "end":
6148
- return _context2.stop();
6246
+ return _context.stop();
6149
6247
  }
6150
- }, _callee2, null, [[0, 10]]);
6248
+ }, _callee, null, [[0, 10]]);
6151
6249
  }));
6152
- return function onTafAction(_x2, _x3) {
6153
- return _ref3.apply(this, arguments);
6250
+ return function onTafAction(_x, _x2) {
6251
+ return _ref2.apply(this, arguments);
6154
6252
  };
6155
6253
  }();
6156
6254
  return jsxs(TabPanel, {
@@ -6176,73 +6274,36 @@ var TafPanel = function TafPanel(_ref2) {
6176
6274
  dataTestId: "taf-error",
6177
6275
  shouldClose: true
6178
6276
  }), jsx(Box, {
6179
- sx: {
6180
- marginTop: {
6181
- xs: '44px',
6182
- sm: '10px'
6183
- },
6184
- padding: 1
6185
- },
6186
- children: jsx(TafForm, {
6187
- tafFromBackend: tafFromBackend,
6188
- onFormAction: onTafAction,
6189
- isIssuesPaneOpen: isIssuesPaneOpen,
6190
- setIsIssuesPaneOpen: setIsIssuesPaneOpen,
6191
- isDisabled: isFormDisabled,
6192
- setIsDisabled: setIsFormDisabled,
6193
- onSwitchEditor: patchTaf,
6194
- previousTaf: previousTaf
6195
- })
6196
- })]
6197
- });
6198
- };
6199
-
6200
- var IssuesPaneWrapper = function IssuesPaneWrapper(props) {
6201
- var _useFormContext = useFormContext(),
6202
- errors = _useFormContext.formState.errors;
6203
- var errorList = filterDuplicateErrors(getErrors(errors));
6204
- return jsx(IssuesPane, Object.assign({
6205
- errorList: errorList
6206
- }, props));
6207
- };
6208
-
6209
- var getTafMessageContent = function getTafMessageContent(_ref) {
6210
- var location = _ref.location,
6211
- validDateStart = _ref.validDateStart,
6212
- messageType = _ref.messageType;
6213
- var formattedDate = formatBaseTime(dateUtils.utc(validDateStart));
6214
- return {
6215
- location: location,
6216
- formattedDate: formattedDate,
6217
- messageType: messageType
6218
- };
6219
- };
6220
- var getSnackbarMessage = function getSnackbarMessage(tafFromFrontEnd, isAutoSaved, t) {
6221
- var changeStatusTo = tafFromFrontEnd.changeStatusTo,
6222
- taf = tafFromFrontEnd.taf;
6223
- if (isAutoSaved) {
6224
- return t('snackbar-auto-save');
6225
- }
6226
- var content = getTafMessageContent(taf);
6227
- switch (changeStatusTo) {
6228
- case 'DRAFT':
6229
- return t('snackbar-draft');
6230
- case 'DRAFT_AMENDED':
6231
- return t('snackbar-draft-amend');
6232
- case 'DRAFT_CORRECTED':
6233
- return t('snackbar-draft-correct');
6234
- case 'PUBLISHED':
6235
- return t('snackbar-publish', content);
6236
- case 'CANCELLED':
6237
- return t('snackbar-cancel', content);
6238
- case 'CORRECTED':
6239
- return t('snackbar-correct', content);
6240
- case 'AMENDED':
6241
- return t('snackbar-amend', content);
6242
- default:
6243
- return t('snackbar-save', content);
6244
- }
6277
+ sx: {
6278
+ marginTop: {
6279
+ xs: '44px',
6280
+ sm: '10px'
6281
+ },
6282
+ padding: 1
6283
+ },
6284
+ children: jsx(TafForm, {
6285
+ tafFromBackend: tafFromBackend,
6286
+ onFormAction: onTafAction,
6287
+ isIssuesPaneOpen: isIssuesPaneOpen,
6288
+ setIsIssuesPaneOpen: setIsIssuesPaneOpen,
6289
+ isDisabled: isFormDisabled,
6290
+ setIsDisabled: setIsFormDisabled,
6291
+ onSwitchEditor: patchTaf,
6292
+ previousTaf: previousTaf
6293
+ })
6294
+ })]
6295
+ });
6296
+ };
6297
+
6298
+ var IssuesPaneWrapper = function IssuesPaneWrapper(props) {
6299
+ var _useFormContext = useFormContext(),
6300
+ errors = _useFormContext.formState.errors;
6301
+ var errorList = filterDuplicateErrors(getErrors(errors));
6302
+ return jsx(IssuesPane, Object.assign({
6303
+ errorList: errorList
6304
+ }, props));
6245
6305
  };
6306
+
6246
6307
  var filterAutoTafs = function filterAutoTafs(tafList) {
6247
6308
  return tafList.reduce(function (tList, tafFromBackend) {
6248
6309
  var _Object$assign;
@@ -6254,25 +6315,22 @@ var filterAutoTafs = function filterAutoTafs(tafList) {
6254
6315
  autoTafList: []
6255
6316
  });
6256
6317
  };
6257
- var TafLayout = function TafLayout(_ref2) {
6258
- var completTafList = _ref2.tafList,
6259
- _ref2$onUpdateTaf = _ref2.onUpdateTaf,
6260
- onUpdateTaf = _ref2$onUpdateTaf === void 0 ? function () {
6318
+ var TafLayout = function TafLayout(_ref) {
6319
+ var completeTafList = _ref.tafList,
6320
+ _ref$onUpdateTaf = _ref.onUpdateTaf,
6321
+ onUpdateTaf = _ref$onUpdateTaf === void 0 ? function () {
6261
6322
  return null;
6262
- } : _ref2$onUpdateTaf,
6263
- lastUpdateTime = _ref2.lastUpdateTime,
6264
- _ref2$isAutoTafEnable = _ref2.isAutoTafEnabled,
6265
- isAutoTafEnabled = _ref2$isAutoTafEnable === void 0 ? false : _ref2$isAutoTafEnable;
6323
+ } : _ref$onUpdateTaf,
6324
+ lastUpdateTime = _ref.lastUpdateTime,
6325
+ _ref$isAutoTafEnabled = _ref.isAutoTafEnabled,
6326
+ isAutoTafEnabled = _ref$isAutoTafEnabled === void 0 ? false : _ref$isAutoTafEnabled;
6266
6327
  var _React$useMemo = React__default.useMemo(function () {
6267
- return filterAutoTafs(completTafList);
6268
- }, [completTafList]),
6328
+ return filterAutoTafs(completeTafList);
6329
+ }, [completeTafList]),
6269
6330
  tafList = _React$useMemo.tafList,
6270
6331
  autoTafList = _React$useMemo.autoTafList;
6271
6332
  var _useTafTranslation = useTafTranslation(),
6272
6333
  t = _useTafTranslation.t;
6273
- var _useApiContext = useApiContext(),
6274
- api = _useApiContext.api;
6275
- var dispatch = useDispatch();
6276
6334
  var confirmDialog = useConfirmationDialog();
6277
6335
  var _useIssuesPane = useIssuesPane(),
6278
6336
  isIssuesPaneOpen = _useIssuesPane.isIssuesPaneOpen,
@@ -6280,13 +6338,11 @@ var TafLayout = function TafLayout(_ref2) {
6280
6338
  onCloseIssuesPane = _useIssuesPane.onCloseIssuesPane,
6281
6339
  startPosition = _useIssuesPane.startPosition,
6282
6340
  onUserHasDragged = _useIssuesPane.onUserHasDragged;
6283
- var _usePostTafRequest = usePostTafRequest(api.postTaf),
6284
- isLoading = _usePostTafRequest.isLoading,
6285
- postTafRequest = _usePostTafRequest.doRequest,
6286
- postError = _usePostTafRequest.error;
6287
- var _usePostTafRequest2 = usePostTafRequest(api.patchTaf),
6288
- patchTafRequest = _usePostTafRequest2.doRequest,
6289
- patchError = _usePostTafRequest2.error;
6341
+ var _usePostTaf = usePostTaf(),
6342
+ isPostTafPending = _usePostTaf.isPending,
6343
+ postTafRequest = _usePostTaf.mutateAsync;
6344
+ var _usePatchTaf = usePatchTaf(),
6345
+ patchTafRequest = _usePatchTaf.mutateAsync;
6290
6346
  var _useTafModuleContext = useTafModuleContext(),
6291
6347
  onValidateForm = _useTafModuleContext.onValidateForm,
6292
6348
  tafAction = _useTafModuleContext.tafAction;
@@ -6310,75 +6366,58 @@ var TafLayout = function TafLayout(_ref2) {
6310
6366
  var _React$useState5 = React__default.useState(false),
6311
6367
  isFormDisabled = _React$useState5[0],
6312
6368
  setIsFormDisabled = _React$useState5[1];
6313
- var _React$useState6 = React__default.useState(),
6369
+ var _React$useState6 = React__default.useState(null),
6314
6370
  error = _React$useState6[0],
6315
6371
  setError = _React$useState6[1];
6316
- var showSnackbar = React__default.useCallback(function (message) {
6317
- dispatch(snackbarActions.openSnackbar({
6318
- type: snackbarTypes.SnackbarMessageType.VERBATIM_MESSAGE,
6319
- message: message
6320
- }));
6321
- }, [dispatch]);
6322
6372
  var postTaf = /*#__PURE__*/function () {
6323
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data, isAutoSaved) {
6373
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data, isAutoSaved) {
6324
6374
  return _regeneratorRuntime().wrap(function _callee$(_context) {
6325
6375
  while (1) switch (_context.prev = _context.next) {
6326
6376
  case 0:
6327
6377
  if (isAutoSaved === void 0) {
6328
6378
  isAutoSaved = false;
6329
6379
  }
6330
- _context.prev = 1;
6331
- setError(null);
6332
- _context.next = 5;
6333
- return postTafRequest(data);
6334
- case 5:
6335
- showSnackbar(getSnackbarMessage(data, isAutoSaved, t));
6336
- // callback
6337
- void onUpdateTaf();
6338
- _context.next = 13;
6339
- break;
6340
- case 9:
6341
- _context.prev = 9;
6342
- _context.t0 = _context["catch"](1);
6343
- if (isWarning(_context.t0)) {
6344
- void onUpdateTaf();
6345
- }
6346
- throw _context.t0;
6347
- case 13:
6380
+ _context.next = 3;
6381
+ return postTafRequest({
6382
+ tafData: data,
6383
+ isAutoSaved: isAutoSaved,
6384
+ setError: setError
6385
+ });
6386
+ case 3:
6348
6387
  case "end":
6349
6388
  return _context.stop();
6350
6389
  }
6351
- }, _callee, null, [[1, 9]]);
6390
+ }, _callee);
6352
6391
  }));
6353
6392
  return function postTaf(_x, _x2) {
6354
- return _ref3.apply(this, arguments);
6393
+ return _ref2.apply(this, arguments);
6355
6394
  };
6356
6395
  }();
6357
6396
  var patchTaf = /*#__PURE__*/function () {
6358
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(data) {
6397
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(data) {
6359
6398
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
6360
6399
  while (1) switch (_context2.prev = _context2.next) {
6361
6400
  case 0:
6362
6401
  _context2.prev = 0;
6363
- setError(null);
6364
- _context2.next = 4;
6365
- return patchTafRequest(data);
6366
- case 4:
6367
- // callback
6368
- void onUpdateTaf();
6402
+ _context2.next = 3;
6403
+ return patchTafRequest({
6404
+ tafData: data,
6405
+ setError: setError
6406
+ });
6407
+ case 3:
6369
6408
  return _context2.abrupt("return", true);
6370
- case 8:
6371
- _context2.prev = 8;
6409
+ case 6:
6410
+ _context2.prev = 6;
6372
6411
  _context2.t0 = _context2["catch"](0);
6373
6412
  return _context2.abrupt("return", false);
6374
- case 11:
6413
+ case 9:
6375
6414
  case "end":
6376
6415
  return _context2.stop();
6377
6416
  }
6378
- }, _callee2, null, [[0, 8]]);
6417
+ }, _callee2, null, [[0, 6]]);
6379
6418
  }));
6380
6419
  return function patchTaf(_x3) {
6381
- return _ref4.apply(this, arguments);
6420
+ return _ref3.apply(this, arguments);
6382
6421
  };
6383
6422
  }();
6384
6423
  var CONFIRM_DIALOG_OPTIONS = {
@@ -6458,8 +6497,7 @@ var TafLayout = function TafLayout(_ref2) {
6458
6497
  // eslint-disable-next-line react-hooks/exhaustive-deps
6459
6498
  }, [tafList, setLocations]);
6460
6499
  React__default.useEffect(function () {
6461
- setError(postError);
6462
- var cancelErrorTimeout = postError && postError.type === 'CANCELLED' ? setTimeout(function () {
6500
+ var cancelErrorTimeout = error && error.type === 'CANCELLED' ? setTimeout(function () {
6463
6501
  setError(null);
6464
6502
  }, 10000) : null;
6465
6503
  return function () {
@@ -6467,10 +6505,7 @@ var TafLayout = function TafLayout(_ref2) {
6467
6505
  clearTimeout(cancelErrorTimeout);
6468
6506
  }
6469
6507
  };
6470
- }, [postError]);
6471
- React__default.useEffect(function () {
6472
- setError(patchError);
6473
- }, [patchError]);
6508
+ }, [error]);
6474
6509
  if (!tafList || !tafList.length) {
6475
6510
  return null;
6476
6511
  }
@@ -6581,7 +6616,7 @@ var TafLayout = function TafLayout(_ref2) {
6581
6616
  setIsFormDisabled: setIsFormDisabled,
6582
6617
  postTaf: postTaf,
6583
6618
  patchTaf: patchTaf,
6584
- isLoading: isLoading,
6619
+ isLoading: isPostTafPending,
6585
6620
  error: error,
6586
6621
  previousTaf: getPreviousTaf(tafList, tafFromBackend),
6587
6622
  tafAction: tafAction
@@ -6666,7 +6701,7 @@ var TafModule = function TafModule(_ref) {
6666
6701
  var _React$useState = React.useState(null),
6667
6702
  errorMessage = _React$useState[0],
6668
6703
  setErrorMessage = _React$useState[1];
6669
- var _useAuthenticationCon = useAuthenticationContext(),
6704
+ var _useAuthenticationCon = useAuthenticationContext$1(),
6670
6705
  isLoggedIn = _useAuthenticationCon.isLoggedIn;
6671
6706
  var ERROR_AUTH = t('error-auth');
6672
6707
  var ERROR_AUTH_MESSAGE = t('error-auth-message');
@@ -6752,45 +6787,72 @@ var Wrapper = function Wrapper(_ref3) {
6752
6787
  }));
6753
6788
  };
6754
6789
 
6755
- /* *
6756
- * Licensed under the Apache License, Version 2.0 (the "License");
6757
- * you may not use this file except in compliance with the License.
6758
- * You may obtain a copy of the License at
6759
- *
6760
- * http://www.apache.org/licenses/LICENSE-2.0
6761
- *
6762
- * Unless required by applicable law or agreed to in writing, software
6763
- * distributed under the License is distributed on an "AS IS" BASIS,
6764
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6765
- * See the License for the specific language governing permissions and
6766
- * limitations under the License.
6767
- *
6768
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
6769
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
6770
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
6771
- * */
6772
- var getApiRoutes$1 = function getApiRoutes(axiosInstance) {
6773
- return {
6774
- postTaf: function postTaf(formData) {
6775
- return axiosInstance.post('/taf', Object.assign({}, formData));
6776
- },
6777
- getTAC: function getTAC(tafData, getJSON, signal) {
6778
- return axiosInstance.post('/taf2tac', tafData, Object.assign({}, signal ? {
6779
- signal: signal
6780
- } : {}, {
6781
- headers: {
6782
- Accept: getJSON ? 'application/json' : 'text/plain'
6783
- }
6784
- }));
6790
+ var tafScreenPreset = {
6791
+ id: 'screenConfigTaf',
6792
+ title: 'TAF',
6793
+ views: {
6794
+ byId: {
6795
+ taf: {
6796
+ title: 'TAF',
6797
+ componentType: 'TafModule',
6798
+ initialProps: {}
6799
+ }
6785
6800
  },
6786
- patchTaf: function patchTaf(formData) {
6787
- return axiosInstance.patch('/taf?force=true', Object.assign({}, formData));
6788
- }
6789
- };
6801
+ allIds: ['taf']
6802
+ },
6803
+ syncGroups: [],
6804
+ mosaicNode: 'taf'
6805
+ };
6806
+ var TafApiWrapper = function TafApiWrapper(_ref) {
6807
+ var config = _ref.config,
6808
+ onPreventCloseView = _ref.onPreventCloseView,
6809
+ initialProps = _ref.initialProps;
6810
+ return config ? jsx(ErrorBoundary, {
6811
+ children: jsx(Wrapper, {
6812
+ onPreventCloseView: onPreventCloseView,
6813
+ isAutoTafEnabled: initialProps == null ? void 0 : initialProps.isAutoTafEnabled
6814
+ })
6815
+ }) : null;
6790
6816
  };
6791
- var createApi$1 = function createApi(props) {
6792
- var axiosInstance = createApiInstance(props);
6793
- return getApiRoutes$1(axiosInstance);
6817
+ var componentsLookUp = function componentsLookUp(payload, _ref2,
6818
+ // TODO: find a good way to type this module without the apps complaining
6819
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
6820
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6821
+ ConnectedModuleWrapper) {
6822
+ var config = _ref2.config,
6823
+ auth = _ref2.auth,
6824
+ onSetAuth = _ref2.onSetAuth;
6825
+ if (ConnectedModuleWrapper === void 0) {
6826
+ ConnectedModuleWrapper = null;
6827
+ }
6828
+ var componentType = payload.componentType,
6829
+ initialProps = payload.initialProps;
6830
+ switch (componentType) {
6831
+ case 'TafModule':
6832
+ if (ConnectedModuleWrapper) {
6833
+ return jsx(ConnectedModuleWrapper, {
6834
+ component: function component(props) {
6835
+ return jsx(TafApiWrapper, Object.assign({}, props, {
6836
+ initialProps: initialProps
6837
+ }));
6838
+ },
6839
+ payload: payload,
6840
+ "data-testid": "tafmodule",
6841
+ config: config,
6842
+ auth: auth,
6843
+ onSetAuth: onSetAuth
6844
+ });
6845
+ }
6846
+ return jsx(TafApiWrapper, {
6847
+ "data-testid": "tafmodule",
6848
+ config: config,
6849
+ auth: auth,
6850
+ onSetAuth: onSetAuth,
6851
+ initialProps: initialProps
6852
+ });
6853
+ default:
6854
+ return null;
6855
+ }
6794
6856
  };
6795
6857
 
6796
6858
  // Used to mimic an authenticated user
@@ -7970,24 +8032,13 @@ var fakeAmendmentTaf = {
7970
8032
  })
7971
8033
  });
7972
8034
 
7973
- /* *
7974
- * Licensed under the Apache License, Version 2.0 (the "License");
7975
- * you may not use this file except in compliance with the License.
7976
- * You may obtain a copy of the License at
7977
- *
7978
- * http://www.apache.org/licenses/LICENSE-2.0
7979
- *
7980
- * Unless required by applicable law or agreed to in writing, software
7981
- * distributed under the License is distributed on an "AS IS" BASIS,
7982
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7983
- * See the License for the specific language governing permissions and
7984
- * limitations under the License.
7985
- *
7986
- * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
7987
- * Copyright 2021 - Finnish Meteorological Institute (FMI)
7988
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
7989
- * */
7990
- var fakeTafTac = 'TAF EHAM 0812/0918 20020G35KT 0500 SN BKN040\nBECMG 0814/0816 0700 BKN001=';
8035
+ var fakeUpdatedTafList = [].concat(fakeTafList);
8036
+ var setFakeUpdatedList = function setFakeUpdatedList(newList) {
8037
+ fakeUpdatedTafList = newList;
8038
+ };
8039
+ var getFakeUpdatedList = function getFakeUpdatedList() {
8040
+ return fakeUpdatedTafList;
8041
+ };
7991
8042
  var fakeTafTacJson = {
7992
8043
  tac: [[{
7993
8044
  text: 'TAF'
@@ -8020,135 +8071,67 @@ var fakeTafTacJson = {
8020
8071
  text: '='
8021
8072
  }]]
8022
8073
  };
8023
- var fakeUpdatedTafList = [].concat(fakeTafList);
8024
- var setFakeUpdatedList = function setFakeUpdatedList(newList) {
8025
- fakeUpdatedTafList = newList;
8026
- };
8027
- var getFakeUpdatedList = function getFakeUpdatedList() {
8028
- return fakeUpdatedTafList;
8029
- };
8030
- var getApiRoutes = function getApiRoutes(axiosInstance) {
8031
- return {
8032
- postTaf: function postTaf(_postTaf) {
8033
- // eslint-disable-next-line no-console
8034
- console.log("The new status of the taf will be " + _postTaf.changeStatusTo);
8035
- // eslint-disable-next-line no-console
8036
- console.log('form has been posted with following values:', _postTaf.taf);
8037
- return axiosInstance.post('/taf', _postTaf);
8038
- },
8039
- getTAC: function getTAC(taf, getJSON, signal) {
8040
- return axiosInstance.post('/taf2tac', taf, Object.assign({}, signal ? {
8041
- signal: signal
8042
- } : {}, {
8043
- headers: {
8044
- Accept: getJSON ? 'application/json' : 'text/plain'
8045
- }
8046
- })).then(function () {
8047
- return {
8048
- data: getJSON ? fakeTafTacJson : fakeTafTac
8049
- };
8050
- });
8051
- },
8052
- patchTaf: function patchTaf(_patchTaf) {
8053
- var updatedList = getFakeUpdatedList().map(function (tafFromBackend) {
8054
- if (tafFromBackend.taf.uuid === _patchTaf.taf.uuid) {
8055
- return Object.assign({}, tafFromBackend, {
8056
- editor: _patchTaf.editor
8057
- });
8058
- }
8059
- return tafFromBackend;
8060
- });
8061
- setFakeUpdatedList(updatedList);
8062
- // eslint-disable-next-line no-console
8063
- console.log("The new editor of the taf will be " + (_patchTaf.editor || 'empty'));
8064
- return axiosInstance.patch('/taf', _patchTaf);
8074
+ var tafEndPoints = [http.get(/^.*\/taflist$/, function () {
8075
+ return HttpResponse.json(getFakeUpdatedList());
8076
+ }), http.post(/^.*\/taf$/, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
8077
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
8078
+ while (1) switch (_context.prev = _context.next) {
8079
+ case 0:
8080
+ _context.next = 2;
8081
+ return delay();
8082
+ case 2:
8083
+ return _context.abrupt("return", HttpResponse.json(null));
8084
+ case 3:
8085
+ case "end":
8086
+ return _context.stop();
8065
8087
  }
8066
- };
8067
- };
8068
- var createApi = function createApi() {
8069
- var instance = createFakeApiInstance();
8070
- return getApiRoutes(instance);
8071
- };
8072
-
8073
- var tafScreenPreset = {
8074
- id: 'screenConfigTaf',
8075
- title: 'TAF',
8076
- views: {
8077
- byId: {
8078
- taf: {
8079
- title: 'TAF',
8080
- componentType: 'TafModule',
8081
- initialProps: {}
8082
- }
8083
- },
8084
- allIds: ['taf']
8085
- },
8086
- syncGroups: [],
8087
- mosaicNode: 'taf'
8088
- };
8089
- var TafApiWrapper = function TafApiWrapper(_ref) {
8090
- var config = _ref.config,
8091
- auth = _ref.auth,
8092
- onSetAuth = _ref.onSetAuth,
8093
- onPreventCloseView = _ref.onPreventCloseView,
8094
- initialProps = _ref.initialProps;
8095
- return config ? jsx(ApiProvider, {
8096
- config: {
8097
- baseURL: config.baseURL,
8098
- appURL: config.baseURL,
8099
- authTokenURL: config.authTokenURL,
8100
- authClientId: config.authClientId
8101
- },
8102
- auth: auth,
8103
- onSetAuth: onSetAuth,
8104
- createApi: createApi$1,
8105
- children: jsx(ErrorBoundary, {
8106
- children: jsx(Wrapper, {
8107
- onPreventCloseView: onPreventCloseView,
8108
- isAutoTafEnabled: initialProps == null ? void 0 : initialProps.isAutoTafEnabled
8109
- })
8110
- })
8111
- }) : null;
8112
- };
8113
- var componentsLookUp = function componentsLookUp(payload, _ref2,
8114
- // TODO: find a good way to type this module without the apps complaining
8115
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
8116
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8117
- ConnectedModuleWrapper) {
8118
- var config = _ref2.config,
8119
- auth = _ref2.auth,
8120
- onSetAuth = _ref2.onSetAuth;
8121
- if (ConnectedModuleWrapper === void 0) {
8122
- ConnectedModuleWrapper = null;
8123
- }
8124
- var componentType = payload.componentType,
8125
- initialProps = payload.initialProps;
8126
- switch (componentType) {
8127
- case 'TafModule':
8128
- if (ConnectedModuleWrapper) {
8129
- return jsx(ConnectedModuleWrapper, {
8130
- component: function component(props) {
8131
- return jsx(TafApiWrapper, Object.assign({}, props, {
8132
- initialProps: initialProps
8133
- }));
8134
- },
8135
- payload: payload,
8136
- "data-testid": "tafmodule",
8137
- config: config,
8138
- auth: auth,
8139
- onSetAuth: onSetAuth
8140
- });
8088
+ }, _callee);
8089
+ }))), http.patch(/^.*\/taf$/, /*#__PURE__*/function () {
8090
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
8091
+ var request, patchTaf, updatedList;
8092
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
8093
+ while (1) switch (_context2.prev = _context2.next) {
8094
+ case 0:
8095
+ request = _ref2.request;
8096
+ _context2.next = 3;
8097
+ return request.json();
8098
+ case 3:
8099
+ patchTaf = _context2.sent;
8100
+ updatedList = getFakeUpdatedList().map(function (tafFromBackend) {
8101
+ if (tafFromBackend.taf.uuid === patchTaf.taf.uuid) {
8102
+ return Object.assign({}, tafFromBackend, {
8103
+ editor: patchTaf.editor
8104
+ });
8105
+ }
8106
+ return tafFromBackend;
8107
+ });
8108
+ setFakeUpdatedList(updatedList);
8109
+ _context2.next = 8;
8110
+ return delay();
8111
+ case 8:
8112
+ return _context2.abrupt("return", HttpResponse.json(null));
8113
+ case 9:
8114
+ case "end":
8115
+ return _context2.stop();
8141
8116
  }
8142
- return jsx(TafApiWrapper, {
8143
- "data-testid": "tafmodule",
8144
- config: config,
8145
- auth: auth,
8146
- onSetAuth: onSetAuth,
8147
- initialProps: initialProps
8148
- });
8149
- default:
8150
- return null;
8151
- }
8152
- };
8117
+ }, _callee2);
8118
+ }));
8119
+ return function (_x) {
8120
+ return _ref3.apply(this, arguments);
8121
+ };
8122
+ }()), http.post(/^.*\/taf2tac$/, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
8123
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
8124
+ while (1) switch (_context3.prev = _context3.next) {
8125
+ case 0:
8126
+ _context3.next = 2;
8127
+ return delay();
8128
+ case 2:
8129
+ return _context3.abrupt("return", HttpResponse.json(fakeTafTacJson));
8130
+ case 3:
8131
+ case "end":
8132
+ return _context3.stop();
8133
+ }
8134
+ }, _callee3);
8135
+ })))];
8153
8136
 
8154
- export { TAF_NAMESPACE, TafApiWrapper, TafForm, Wrapper as TafModule, componentsLookUp, createApi$1 as createApi, createApi as createFakeApi, tafScreenPreset, tafTranslations };
8137
+ export { TAF_NAMESPACE, TafApiWrapper, TafForm, Wrapper as TafModule, componentsLookUp, tafEndPoints, tafScreenPreset, tafTranslations };