@opengeoweb/taf 4.11.0 → 4.13.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.
Files changed (123) hide show
  1. package/README.md +0 -0
  2. package/index.d.ts +0 -0
  3. package/index.esm.js +1390 -1240
  4. package/index.umd.js +1416 -1270
  5. package/lib/TafDemo.stories.d.ts +0 -0
  6. package/lib/components/ComponentsLookUp/ComponentsLookUp.d.ts +0 -0
  7. package/lib/components/ComponentsLookUp/ComponentsLookUp.spec.d.ts +0 -0
  8. package/lib/components/ComponentsLookUp/index.d.ts +0 -0
  9. package/lib/components/IssuesPane/IssuesButton.d.ts +0 -0
  10. package/lib/components/IssuesPane/IssuesButton.spec.d.ts +0 -0
  11. package/lib/components/IssuesPane/IssuesPane.d.ts +1 -0
  12. package/lib/components/IssuesPane/IssuesPane.spec.d.ts +0 -0
  13. package/lib/components/IssuesPane/IssuesPane.stories.d.ts +0 -0
  14. package/lib/components/IssuesPane/IssuesPaneWrapper.d.ts +0 -0
  15. package/lib/components/IssuesPane/IssuesPaneWrapper.spec.d.ts +0 -0
  16. package/lib/components/IssuesPane/index.d.ts +0 -0
  17. package/lib/components/IssuesPane/types.d.ts +1 -0
  18. package/lib/components/IssuesPane/utils.d.ts +0 -0
  19. package/lib/components/IssuesPane/utils.spec.d.ts +0 -0
  20. package/lib/components/Providers/Providers.d.ts +0 -0
  21. package/lib/components/Providers/index.d.ts +0 -0
  22. package/lib/components/Spinner/Spinner.d.ts +0 -0
  23. package/lib/components/Spinner/Spinner.spec.d.ts +0 -0
  24. package/lib/components/Spinner/Spinner.stories.d.ts +0 -0
  25. package/lib/components/StatusIcon/StatusIcon.d.ts +0 -0
  26. package/lib/components/StatusIcon/StatusIcon.spec.d.ts +0 -0
  27. package/lib/components/SwitchButton/SwitchButton.d.ts +0 -0
  28. package/lib/components/SwitchButton/SwitchButton.spec.d.ts +0 -0
  29. package/lib/components/SwitchButton/index.d.ts +0 -0
  30. package/lib/components/TabPanel/TabPanel.d.ts +0 -0
  31. package/lib/components/TabPanel/TabPanel.spec.d.ts +0 -0
  32. package/lib/components/TabPanel/index.d.ts +0 -0
  33. package/lib/components/TafAvatar/TafAvatar.d.ts +0 -0
  34. package/lib/components/TafAvatar/index.d.ts +0 -0
  35. package/lib/components/TafForm/TafForm.d.ts +2 -1
  36. package/lib/components/TafForm/TafForm.spec.d.ts +0 -0
  37. package/lib/components/TafForm/TafForm.statusChanges.spec.d.ts +0 -0
  38. package/lib/components/TafForm/TafForm.stories.d.ts +0 -0
  39. package/lib/components/TafForm/TafFormButtons/TafFormButtons.d.ts +0 -0
  40. package/lib/components/TafForm/TafFormButtons/TafFormButtons.spec.d.ts +0 -0
  41. package/lib/components/TafForm/TafFormButtons/TafFormOptionsButton.d.ts +0 -0
  42. package/lib/components/TafForm/TafFormButtons/TafFormOptionsButton.spec.d.ts +0 -0
  43. package/lib/components/TafForm/TafFormRow/DragHandle.d.ts +0 -0
  44. package/lib/components/TafForm/TafFormRow/DragHandle.spec.d.ts +0 -0
  45. package/lib/components/TafForm/TafFormRow/TafFormRow.d.ts +0 -0
  46. package/lib/components/TafForm/TafFormRow/TafFormRow.spec.d.ts +0 -0
  47. package/lib/components/TafForm/TafFormRow/TafFormTextField.d.ts +5 -1
  48. package/lib/components/TafForm/TafFormRow/TafFormTextField.spec.d.ts +0 -0
  49. package/lib/components/TafForm/TafFormRow/types.d.ts +0 -0
  50. package/lib/components/TafForm/TafFormRow/validations/change.d.ts +0 -0
  51. package/lib/components/TafForm/TafFormRow/validations/change.spec.d.ts +0 -0
  52. package/lib/components/TafForm/TafFormRow/validations/clouds.d.ts +3 -3
  53. package/lib/components/TafForm/TafFormRow/validations/clouds.spec.d.ts +0 -0
  54. package/lib/components/TafForm/TafFormRow/validations/probability.d.ts +0 -0
  55. package/lib/components/TafForm/TafFormRow/validations/probability.spec.d.ts +0 -0
  56. package/lib/components/TafForm/TafFormRow/validations/utils.d.ts +1 -0
  57. package/lib/components/TafForm/TafFormRow/validations/utils.spec.d.ts +0 -0
  58. package/lib/components/TafForm/TafFormRow/validations/validField.d.ts +0 -0
  59. package/lib/components/TafForm/TafFormRow/validations/validField.spec.d.ts +0 -0
  60. package/lib/components/TafForm/TafFormRow/validations/visibility.d.ts +0 -0
  61. package/lib/components/TafForm/TafFormRow/validations/visibility.spec.d.ts +0 -0
  62. package/lib/components/TafForm/TafFormRow/validations/weather.d.ts +3 -3
  63. package/lib/components/TafForm/TafFormRow/validations/weather.spec.d.ts +0 -0
  64. package/lib/components/TafForm/TafFormRow/validations/wind.d.ts +0 -0
  65. package/lib/components/TafForm/TafFormRow/validations/wind.spec.d.ts +0 -0
  66. package/lib/components/TafForm/index.d.ts +0 -0
  67. package/lib/components/TafForm/utils.d.ts +4 -2
  68. package/lib/components/TafForm/utils.spec.d.ts +0 -0
  69. package/lib/components/TafHeader/TafHeader.d.ts +0 -0
  70. package/lib/components/TafHeader/TafHeader.spec.d.ts +0 -0
  71. package/lib/components/TafLayout/LastUpdateTime/LastUpdateTime.d.ts +0 -0
  72. package/lib/components/TafLayout/LastUpdateTime/LastUpdateTime.spec.d.ts +0 -0
  73. package/lib/components/TafLayout/LastUpdateTime/LastUpdateTime.stories.d.ts +0 -0
  74. package/lib/components/TafLayout/LastUpdateTime/index.d.ts +0 -0
  75. package/lib/components/TafLayout/LocationTabs/LocationTabs.d.ts +0 -0
  76. package/lib/components/TafLayout/LocationTabs/LocationTabs.spec.d.ts +0 -0
  77. package/lib/components/TafLayout/LocationTabs/LocationTabs.stories.d.ts +0 -0
  78. package/lib/components/TafLayout/LocationTabs/index.d.ts +0 -0
  79. package/lib/components/TafLayout/TacOverview/AdverseWeatherTacMessage.d.ts +0 -0
  80. package/lib/components/TafLayout/TacOverview/AdverseWeatherTacMessage.spec.d.ts +0 -0
  81. package/lib/components/TafLayout/TacOverview/AdverseWeatherTacMessage.stories.d.ts +0 -0
  82. package/lib/components/TafLayout/TacOverview/ExportButton.d.ts +0 -0
  83. package/lib/components/TafLayout/TacOverview/ExportButton.spec.d.ts +0 -0
  84. package/lib/components/TafLayout/TacOverview/TacContainer.d.ts +0 -0
  85. package/lib/components/TafLayout/TacOverview/TacContainer.spec.d.ts +0 -0
  86. package/lib/components/TafLayout/TacOverview/TacOverview.d.ts +0 -0
  87. package/lib/components/TafLayout/TacOverview/TacOverview.spec.d.ts +0 -0
  88. package/lib/components/TafLayout/TacOverview/TacOverview.stories.d.ts +0 -0
  89. package/lib/components/TafLayout/TacOverview/TacOverviewMobile.d.ts +0 -0
  90. package/lib/components/TafLayout/TacOverview/TacOverviewMobile.spec.d.ts +0 -0
  91. package/lib/components/TafLayout/TacOverview/TacOverviewMobile.stories.d.ts +0 -0
  92. package/lib/components/TafLayout/TacOverview/index.d.ts +0 -0
  93. package/lib/components/TafLayout/TafLayout.d.ts +0 -0
  94. package/lib/components/TafLayout/TafLayout.spec.d.ts +0 -0
  95. package/lib/components/TafLayout/TafLayout.stories.d.ts +0 -0
  96. package/lib/components/TafLayout/TafPanel/TafPanel.d.ts +3 -1
  97. package/lib/components/TafLayout/TafPanel/TafPanel.spec.d.ts +0 -0
  98. package/lib/components/TafLayout/TafPanel/TafPanel.stories.d.ts +0 -0
  99. package/lib/components/TafLayout/TafPanel/index.d.ts +0 -0
  100. package/lib/components/TafLayout/TopTabs/TopTabs.d.ts +0 -0
  101. package/lib/components/TafLayout/TopTabs/TopTabs.spec.d.ts +0 -0
  102. package/lib/components/TafLayout/TopTabs/TopTabs.stories.d.ts +0 -0
  103. package/lib/components/TafLayout/TopTabs/index.d.ts +0 -0
  104. package/lib/components/TafLayout/utils.d.ts +1 -0
  105. package/lib/components/TafLayout/utils.spec.d.ts +0 -0
  106. package/lib/components/TafModule/TafModule.d.ts +0 -0
  107. package/lib/components/TafModule/TafModule.spec.d.ts +0 -0
  108. package/lib/components/TafModule/TafModule.stories.d.ts +0 -0
  109. package/lib/components/TafModule/TafModuleProvider.d.ts +0 -0
  110. package/lib/components/TafModule/index.d.ts +0 -0
  111. package/lib/components/TafWrapper/TafWrapper.d.ts +0 -0
  112. package/lib/components/TafWrapper/TafWrapper.spec.d.ts +0 -0
  113. package/lib/components/TafWrapper/index.d.ts +0 -0
  114. package/lib/storyshots/Storyshots.spec.d.ts +0 -0
  115. package/lib/types.d.ts +0 -0
  116. package/lib/utils/__mocks__/api.d.ts +0 -0
  117. package/lib/utils/api.d.ts +0 -0
  118. package/lib/utils/api.spec.d.ts +0 -0
  119. package/lib/utils/fakeApi.d.ts +0 -0
  120. package/lib/utils/fakeApi.spec.d.ts +0 -0
  121. package/lib/utils/mockdata/fakeTafList.d.ts +1 -0
  122. package/lib/utils/weatherPhenomena.d.ts +0 -0
  123. package/package.json +12 -11
package/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@mui/material'), require('react-hook-form'), require('react-redux'), require('react-sortablejs'), require('sortablejs'), require('@opengeoweb/authentication'), require('@opengeoweb/form-fields'), require('@opengeoweb/shared'), require('@opengeoweb/core'), require('moment'), require('lodash'), require('@opengeoweb/theme'), require('react-dom'), require('@opengeoweb/api'), require('@mui/material/LinearProgress'), require('@mui/material/Box')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react', '@mui/material', 'react-hook-form', 'react-redux', 'react-sortablejs', 'sortablejs', '@opengeoweb/authentication', '@opengeoweb/form-fields', '@opengeoweb/shared', '@opengeoweb/core', 'moment', 'lodash', '@opengeoweb/theme', 'react-dom', '@opengeoweb/api', '@mui/material/LinearProgress', '@mui/material/Box'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Taf = {}, global.React, global.material, global.reactHookForm, global.reactRedux, global.reactSortablejs, global.Sortable, global.authentication, global.formFields, global.shared, global.core, global.moment, global.lodash, global.theme, global.ReactDOM, global.api, global.LinearProgress, global.Box));
5
- })(this, (function (exports, React, material, reactHookForm, reactRedux, reactSortablejs, Sortable, authentication, formFields, shared, core, moment, lodash, theme, ReactDOM, api, LinearProgress, Box) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@mui/material'), require('react-hook-form'), require('react-redux'), require('react-sortablejs'), require('sortablejs'), require('@opengeoweb/authentication'), require('@opengeoweb/form-fields'), require('@opengeoweb/shared'), require('@opengeoweb/core'), require('moment'), require('lodash'), require('@opengeoweb/theme'), require('react-dom'), require('@emotion/react'), require('@opengeoweb/api'), require('@mui/material/LinearProgress'), require('@mui/material/Box')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'react', '@mui/material', 'react-hook-form', 'react-redux', 'react-sortablejs', 'sortablejs', '@opengeoweb/authentication', '@opengeoweb/form-fields', '@opengeoweb/shared', '@opengeoweb/core', 'moment', 'lodash', '@opengeoweb/theme', 'react-dom', '@emotion/react', '@opengeoweb/api', '@mui/material/LinearProgress', '@mui/material/Box'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Taf = {}, global.React, global.material, global.reactHookForm, global.reactRedux, global.reactSortablejs, global.Sortable, global.authentication, global.formFields, global.shared, global.core, global.moment, global.lodash, global.theme, global.ReactDOM, global.emotionReact, global.api, global.LinearProgress, global.Box));
5
+ })(this, (function (exports, React, material, reactHookForm, reactRedux, reactSortablejs, Sortable, authentication, formFields, shared, core, moment, lodash, theme, ReactDOM, react, api, LinearProgress, Box) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -135,6 +135,158 @@
135
135
  return to.concat(ar || Array.prototype.slice.call(from));
136
136
  }
137
137
 
138
+ /* *
139
+ * Licensed under the Apache License, Version 2.0 (the "License");
140
+ * you may not use this file except in compliance with the License.
141
+ * You may obtain a copy of the License at
142
+ *
143
+ * http://www.apache.org/licenses/LICENSE-2.0
144
+ *
145
+ * Unless required by applicable law or agreed to in writing, software
146
+ * distributed under the License is distributed on an "AS IS" BASIS,
147
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
148
+ * See the License for the specific language governing permissions and
149
+ * limitations under the License.
150
+ *
151
+ * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
152
+ * Copyright 2021 - Finnish Meteorological Institute (FMI)
153
+ * */
154
+ var tafActionToDraftAction = function tafActionToDraftAction(tafAction) {
155
+ switch (tafAction) {
156
+ case 'AMEND':
157
+ case 'DRAFT_AMEND':
158
+ return 'DRAFT_AMEND';
159
+
160
+ case 'CORRECT':
161
+ case 'DRAFT_CORRECT':
162
+ return 'DRAFT_CORRECT';
163
+
164
+ default:
165
+ return 'DRAFT';
166
+ }
167
+ };
168
+
169
+ var tafActionToPublishAction = function tafActionToPublishAction(tafAction) {
170
+ switch (tafAction) {
171
+ case 'AMEND':
172
+ case 'DRAFT_AMEND':
173
+ return 'AMEND';
174
+
175
+ case 'CORRECT':
176
+ case 'DRAFT_CORRECT':
177
+ return 'CORRECT';
178
+
179
+ default:
180
+ return 'PUBLISH';
181
+ }
182
+ };
183
+
184
+ var buttonsStyle = {
185
+ button: {
186
+ minWidth: {
187
+ xs: '56px',
188
+ sm: '64px'
189
+ },
190
+ width: {
191
+ xs: '56px',
192
+ sm: '64px'
193
+ },
194
+ marginLeft: {
195
+ xs: 0.5,
196
+ sm: 1
197
+ },
198
+ marginTop: 3,
199
+ marginBottom: 3
200
+ }
201
+ };
202
+
203
+ var ViewModeButtons = function ViewModeButtons(_a) {
204
+ var canBe = _a.canBe,
205
+ onTafViewModeButtonPress = _a.onTafViewModeButtonPress;
206
+ return !canBe.includes('CANCELLED') && !canBe.includes('CORRECTED') && !canBe.includes('AMENDED') ? null : /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, canBe.includes('CANCELLED') && /*#__PURE__*/React__default["default"].createElement(material.Button, {
207
+ "data-testid": "canceltaf",
208
+ variant: "tertiary",
209
+ onClick: function onClick() {
210
+ return onTafViewModeButtonPress('CANCEL');
211
+ }
212
+ }, "Cancel"), canBe.includes('CORRECTED') && /*#__PURE__*/React__default["default"].createElement(material.Button, {
213
+ "data-testid": "correcttaf",
214
+ variant: "tertiary",
215
+ onClick: function onClick() {
216
+ return onTafViewModeButtonPress('CORRECT');
217
+ }
218
+ }, "Correct"), canBe.includes('AMENDED') && /*#__PURE__*/React__default["default"].createElement(material.Button, {
219
+ "data-testid": "amendtaf",
220
+ variant: "tertiary",
221
+ onClick: function onClick() {
222
+ return onTafViewModeButtonPress('AMEND');
223
+ }
224
+ }, "Amend"));
225
+ };
226
+
227
+ var TafFormButtons = function TafFormButtons(_a) {
228
+ var _b = _a.isFormDisabled,
229
+ isFormDisabled = _b === void 0 ? false : _b,
230
+ tafAction = _a.tafAction,
231
+ _c = _a.canBe,
232
+ canBe = _c === void 0 ? [] : _c,
233
+ onTafEditModeButtonPress = _a.onTafEditModeButtonPress,
234
+ onTafViewModeButtonPress = _a.onTafViewModeButtonPress;
235
+ return /*#__PURE__*/React__default["default"].createElement(material.Grid, {
236
+ container: true,
237
+ justifyContent: "flex-end",
238
+ sx: buttonsStyle,
239
+ columns: 24
240
+ }, /*#__PURE__*/React__default["default"].createElement(material.Grid, {
241
+ item: true,
242
+ container: true,
243
+ justifyContent: "flex-end",
244
+ columns: 24,
245
+ xs: 24,
246
+ sm: 23
247
+ }, isFormDisabled ? /*#__PURE__*/React__default["default"].createElement(ViewModeButtons, {
248
+ canBe: canBe,
249
+ onTafViewModeButtonPress: onTafViewModeButtonPress
250
+ }) : /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(material.Button, {
251
+ "data-testid": "cleartaf",
252
+ variant: "tertiary",
253
+ onClick: function onClick() {
254
+ // Simply discard the changes and close the dialog.
255
+ onTafEditModeButtonPress('CLEAR');
256
+ }
257
+ }, "Clear"), /*#__PURE__*/React__default["default"].createElement(material.Button, {
258
+ "data-testid": "savedrafttaf",
259
+ variant: "tertiary",
260
+ onClick: function onClick() {
261
+ /* Save the TAF as draft:
262
+ if action NEW or DRAFT - new status will be DRAFT -- default
263
+ if action AMEND - new status will be DRAFT_AMENDED
264
+ if action CORRECT - new status will be DRAFT_CORRECTED
265
+ if action DRAFT_AMEND - new status will be DRAFT_AMENDED
266
+ if action DRAFT_CORRECT - new status will be DRAFT_CORRECTED
267
+ */
268
+ onTafEditModeButtonPress(tafActionToDraftAction(tafAction));
269
+ }
270
+ }, "Save"), /*#__PURE__*/React__default["default"].createElement(material.Button, {
271
+ "data-testid": "publishtaf",
272
+ variant: "tertiary",
273
+ onClick: function onClick() {
274
+ /* Publish the TAF:
275
+ if action NEW or DRAFT - new status will be PUBLISHED -- default
276
+ if action AMEND - new status will be AMENDED
277
+ if action CORRECT - new status will be CORRECTED
278
+ if action DRAFT_AMEND - new status will be AMENDED
279
+ if action DRAFT_CORRECT - new status will be CORRECTED
280
+ */
281
+ onTafEditModeButtonPress(tafActionToPublishAction(tafAction));
282
+ }
283
+ }, "Publish"))), /*#__PURE__*/React__default["default"].createElement(material.Grid, {
284
+ item: true,
285
+ columns: 24,
286
+ sm: 1
287
+ }));
288
+ };
289
+
138
290
  function _typeof(obj) {
139
291
  "@babel/helpers - typeof";
140
292
 
@@ -164,8 +316,35 @@
164
316
  * See the License for the specific language governing permissions and
165
317
  * limitations under the License.
166
318
  *
167
- * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
168
- * Copyright 2021 - Finnish Meteorological Institute (FMI)
319
+ * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
320
+ * Copyright 2023 - Finnish Meteorological Institute (FMI)
321
+ * */
322
+
323
+ var prependZeroes = function prependZeroes(value, totalDigits) {
324
+ var valueAsString = value.toString();
325
+ return __spreadArray([], __read(Array(totalDigits - valueAsString.length))).reduce(function (newVal) {
326
+ return "0" + newVal;
327
+ }, valueAsString);
328
+ };
329
+ var getFieldValue = function getFieldValue(fieldValue) {
330
+ return fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.trim().toUpperCase();
331
+ };
332
+
333
+ /* *
334
+ * Licensed under the Apache License, Version 2.0 (the "License");
335
+ * you may not use this file except in compliance with the License.
336
+ * You may obtain a copy of the License at
337
+ *
338
+ * http://www.apache.org/licenses/LICENSE-2.0
339
+ *
340
+ * Unless required by applicable law or agreed to in writing, software
341
+ * distributed under the License is distributed on an "AS IS" BASIS,
342
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
343
+ * See the License for the specific language governing permissions and
344
+ * limitations under the License.
345
+ *
346
+ * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
347
+ * Copyright 2023 - Finnish Meteorological Institute (FMI)
169
348
  * */
170
349
  var FORMAT_DAYS_HOURS = 'DDHH';
171
350
  var FORMAT_DAYS_HOURS_MINUTES = 'DDHHmm'; // formatters
@@ -299,7 +478,7 @@
299
478
 
300
479
 
301
480
  var validateValidField = function validateValidField(value, tafStart, tafEnd) {
302
- var trimmedValue = value.trim();
481
+ var trimmedValue = getFieldValue(value);
303
482
 
304
483
  if (!trimmedValue.length) {
305
484
  return true;
@@ -322,9 +501,9 @@
322
501
  return true;
323
502
  };
324
503
  var validateValidChangeGroupInterField = function validateValidChangeGroupInterField(value, valueChange, valueProb, tafStart, tafEnd) {
325
- var trimmedValue = value.trim();
326
- var trimmedValueChange = valueChange.trim();
327
- var trimmedValueProb = valueProb.trim();
504
+ var trimmedValue = getFieldValue(value);
505
+ var trimmedValueChange = getFieldValue(valueChange);
506
+ var trimmedValueProb = getFieldValue(valueProb);
328
507
 
329
508
  if (!trimmedValue.length) {
330
509
  return true;
@@ -374,16 +553,12 @@
374
553
  var invalidPreviousChangeGroupHasSameValue = "When valid times are equal, probability/change can't have the same value as previous row value";
375
554
  var validatePreviousChangeGroup = function validatePreviousChangeGroup(currentChangeGroup, previousChangeGroup, tafStart, tafEnd) {
376
555
  // extract the needed values from changeGroups
377
- var valid = currentChangeGroup.valid,
378
- _a = currentChangeGroup.change,
379
- change = _a === void 0 ? '' : _a,
380
- _b = currentChangeGroup.probability,
381
- probability = _b === void 0 ? '' : _b;
382
- var previousValid = previousChangeGroup.valid,
383
- _c = previousChangeGroup.change,
384
- previousChange = _c === void 0 ? '' : _c,
385
- _d = previousChangeGroup.probability,
386
- previousProbability = _d === void 0 ? '' : _d; // get the parsed values
556
+ var valid = getFieldValue(currentChangeGroup.valid);
557
+ var change = getFieldValue(currentChangeGroup.change || '');
558
+ var probability = getFieldValue(currentChangeGroup.probability || '');
559
+ var previousValid = getFieldValue(previousChangeGroup.valid);
560
+ var previousChange = getFieldValue(previousChangeGroup.change || '');
561
+ var previousProbability = getFieldValue(previousChangeGroup.probability || ''); // get the parsed values
387
562
 
388
563
  var validValue = parseValidToObject(valid, tafStart, tafEnd);
389
564
  var previousValidValue = parseValidToObject(previousValid, tafStart, tafEnd);
@@ -420,12 +595,12 @@
420
595
  }; // validate overlapping validity when one of the following changegroups is FM
421
596
 
422
597
  var validateOverlapWithFM = function validateOverlapWithFM(currentChangeGroup, nextChangeGroups, tafStart, tafEnd) {
423
- var valid = currentChangeGroup.valid;
598
+ var valid = getFieldValue(currentChangeGroup.valid);
424
599
  if (!valid || !nextChangeGroups.length) return true;
425
600
  var validValue = parseValidToObject(valid, tafStart, tafEnd);
426
601
  var currentRowEndTime = moment__default["default"](validValue.end);
427
602
  var firstFMChangeGroup = nextChangeGroups.find(function (nextChangeGroup) {
428
- return nextChangeGroup.change.trim() === 'FM';
603
+ return getFieldValue(nextChangeGroup.change) === 'FM';
429
604
  });
430
605
 
431
606
  if (firstFMChangeGroup && firstFMChangeGroup.valid) {
@@ -440,30 +615,6 @@
440
615
  return true;
441
616
  };
442
617
 
443
- /* *
444
- * Licensed under the Apache License, Version 2.0 (the "License");
445
- * you may not use this file except in compliance with the License.
446
- * You may obtain a copy of the License at
447
- *
448
- * http://www.apache.org/licenses/LICENSE-2.0
449
- *
450
- * Unless required by applicable law or agreed to in writing, software
451
- * distributed under the License is distributed on an "AS IS" BASIS,
452
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
453
- * See the License for the specific language governing permissions and
454
- * limitations under the License.
455
- *
456
- * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
457
- * Copyright 2021 - Finnish Meteorological Institute (FMI)
458
- * */
459
-
460
- var prependZeroes = function prependZeroes(value, totalDigits) {
461
- var valueAsString = value.toString();
462
- return __spreadArray([], __read(Array(totalDigits - valueAsString.length))).reduce(function (newVal) {
463
- return "0" + newVal;
464
- }, valueAsString);
465
- };
466
-
467
618
  var config$1 = [{
468
619
  key: 'range',
469
620
  size: 4
@@ -495,7 +646,7 @@
495
646
  // returns object with validity if passed numbers - returns object with cavOK: true if passed CAVOK
496
647
 
497
648
  var parseVisibilityToObject = function parseVisibilityToObject(value) {
498
- var trimmedValue = value.trim();
649
+ var trimmedValue = getFieldValue(value);
499
650
 
500
651
  if (trimmedValue === 'CAVOK') {
501
652
  return {
@@ -543,7 +694,7 @@
543
694
 
544
695
 
545
696
  var validateVisibilityField = function validateVisibilityField(value) {
546
- var trimmedValue = value.trim();
697
+ var trimmedValue = getFieldValue(value);
547
698
 
548
699
  if (!trimmedValue.length) {
549
700
  return true;
@@ -556,7 +707,7 @@
556
707
 
557
708
 
558
709
  if (!trimmedValue.match(/^[0-9]+$/)) {
559
- return value === 'CAVOK' || invalidVisibilityMessage;
710
+ return trimmedValue === 'CAVOK' || invalidVisibilityMessage;
560
711
  } // validate range
561
712
 
562
713
 
@@ -1022,12 +1173,13 @@
1022
1173
  var invalidWeatherFGVisibility = 'Invalid weather input, weather code FG needs to be combined with a visibility below 1000m'; // validations
1023
1174
 
1024
1175
  var WeatherVisibilityBelow5000 = [WeatherPhenomena.FU, WeatherPhenomena.DU, WeatherPhenomena.HZ, WeatherPhenomena.DRDU, WeatherPhenomena.BLDU];
1025
- var validateWeatherField = function validateWeatherField(value, visibilityValue, NSWAllowed) {
1176
+ var validateWeatherField = function validateWeatherField(value, visibilityFieldValue, NSWAllowed) {
1026
1177
  if (NSWAllowed === void 0) {
1027
1178
  NSWAllowed = true;
1028
1179
  }
1029
1180
 
1030
- var trimmedValue = value.trim(); // if empty, validate as true
1181
+ var trimmedValue = getFieldValue(value);
1182
+ var visibilityValue = getFieldValue(visibilityFieldValue); // if empty, validate as true
1031
1183
 
1032
1184
  if (trimmedValue === '') {
1033
1185
  return true;
@@ -1066,14 +1218,15 @@
1066
1218
 
1067
1219
  return true;
1068
1220
  };
1069
- var validateSecondWeatherField = function validateSecondWeatherField(weather1Value, weather2Value, visibilityValue) {
1070
- var trimmedWeather2Value = weather2Value.trim(); // Field can be left empty
1221
+ var validateSecondWeatherField = function validateSecondWeatherField(weather1Value, weather2Value, visibilityFieldValue) {
1222
+ var trimmedWeather2Value = getFieldValue(weather2Value);
1223
+ var visibilityValue = getFieldValue(visibilityFieldValue); // Field can be left empty
1071
1224
 
1072
1225
  if (!trimmedWeather2Value.length) {
1073
1226
  return true;
1074
1227
  }
1075
1228
 
1076
- var trimmedWeather1Value = weather1Value.trim(); // If weather1 is NSW weather2 should be empty
1229
+ var trimmedWeather1Value = getFieldValue(weather1Value); // If weather1 is NSW weather2 should be empty
1077
1230
 
1078
1231
  if (trimmedWeather1Value === 'NSW' && trimmedWeather2Value !== '') {
1079
1232
  return invalidWeatherNonEmptyNSWGroups;
@@ -1091,15 +1244,16 @@
1091
1244
 
1092
1245
  return validateWeatherField(weather2Value, visibilityValue, false);
1093
1246
  };
1094
- var validateThirdWeatherField = function validateThirdWeatherField(weather1Value, weather2Value, weather3Value, visibilityValue) {
1095
- var trimmedWeather3Value = weather3Value.trim(); // Field can be left empty
1247
+ var validateThirdWeatherField = function validateThirdWeatherField(weather1Value, weather2Value, weather3Value, visibilityFieldValue) {
1248
+ var trimmedWeather3Value = getFieldValue(weather3Value);
1249
+ var visibilityValue = getFieldValue(visibilityFieldValue); // Field can be left empty
1096
1250
 
1097
1251
  if (!trimmedWeather3Value.length) {
1098
1252
  return true;
1099
1253
  }
1100
1254
 
1101
- var trimmedWeather1Value = weather1Value.trim();
1102
- var trimmedWeather2Value = weather2Value.trim(); // If weather1 is NSW weather3 should be empty
1255
+ var trimmedWeather1Value = getFieldValue(weather1Value);
1256
+ var trimmedWeather2Value = getFieldValue(weather2Value); // If weather1 is NSW weather3 should be empty
1103
1257
 
1104
1258
  if (trimmedWeather1Value === 'NSW' && trimmedWeather3Value !== '') {
1105
1259
  return invalidWeatherNonEmptyNSWGroups;
@@ -1461,10 +1615,10 @@
1461
1615
 
1462
1616
 
1463
1617
  var validateWindField = function validateWindField(value, weatherfield1, weatherfield2, weatherfield3) {
1464
- var trimmedWindValue = value.trim();
1465
- var trimmedWeather1Value = weatherfield1.trim();
1466
- var trimmedWeather2Value = weatherfield2.trim();
1467
- var trimmedWeather3Value = weatherfield3.trim();
1618
+ var trimmedWindValue = getFieldValue(value);
1619
+ var trimmedWeather1Value = getFieldValue(weatherfield1);
1620
+ var trimmedWeather2Value = getFieldValue(weatherfield2);
1621
+ var trimmedWeather3Value = getFieldValue(weatherfield3);
1468
1622
 
1469
1623
  if (!trimmedWindValue.length) {
1470
1624
  return true;
@@ -1735,11 +1889,11 @@
1735
1889
  };
1736
1890
 
1737
1891
  var validateFirstCloud = function validateFirstCloud(value, visibilityValue, weatherfield1, weatherfield2, weatherfield3) {
1738
- var trimmedValueFirstCloud = value.trim();
1739
- var trimmedValueVisibility = visibilityValue.trim();
1740
- var trimmedWeather1Value = weatherfield1.trim();
1741
- var trimmedWeather2Value = weatherfield2.trim();
1742
- var trimmedWeather3Value = weatherfield3.trim(); // Field can be left empty
1892
+ var trimmedValueFirstCloud = getFieldValue(value);
1893
+ var trimmedValueVisibility = getFieldValue(visibilityValue);
1894
+ var trimmedWeather1Value = getFieldValue(weatherfield1);
1895
+ var trimmedWeather2Value = getFieldValue(weatherfield2);
1896
+ var trimmedWeather3Value = getFieldValue(weatherfield3); // Field can be left empty
1743
1897
 
1744
1898
  if (!trimmedValueFirstCloud.length) {
1745
1899
  return true;
@@ -1773,9 +1927,10 @@
1773
1927
 
1774
1928
  return errorMessages.length ? errorMessages[0] : true;
1775
1929
  };
1776
- var validateSecondCloud = function validateSecondCloud(firstCloudValue, secondCloudValue, visibilityValue) {
1777
- var trimmedValueFirstCloud = firstCloudValue.trim();
1778
- var trimmedValueSecondCloud = secondCloudValue.trim(); // Field can be left empty
1930
+ var validateSecondCloud = function validateSecondCloud(firstCloudValue, secondCloudValue, visibilityFieldValue) {
1931
+ var trimmedValueFirstCloud = getFieldValue(firstCloudValue);
1932
+ var trimmedValueSecondCloud = getFieldValue(secondCloudValue);
1933
+ var visibilityValue = getFieldValue(visibilityFieldValue); // Field can be left empty
1779
1934
 
1780
1935
  if (!trimmedValueSecondCloud.length) {
1781
1936
  return true;
@@ -1842,10 +1997,11 @@
1842
1997
 
1843
1998
  return true;
1844
1999
  };
1845
- var validateThirdCloud = function validateThirdCloud(firstCloudValue, secondCloudValue, thirdCloudValue, visibilityValue) {
1846
- var trimmedValueFirstCloud = firstCloudValue.trim();
1847
- var trimmedValueSecondCloud = secondCloudValue.trim();
1848
- var trimmedValueThirdCloud = thirdCloudValue.trim(); // Field can be left empty
2000
+ var validateThirdCloud = function validateThirdCloud(firstCloudValue, secondCloudValue, thirdCloudValue, visibilityFieldValue) {
2001
+ var trimmedValueFirstCloud = getFieldValue(firstCloudValue);
2002
+ var trimmedValueSecondCloud = getFieldValue(secondCloudValue);
2003
+ var trimmedValueThirdCloud = getFieldValue(thirdCloudValue);
2004
+ var visibilityValue = getFieldValue(visibilityFieldValue); // Field can be left empty
1849
2005
 
1850
2006
  if (!trimmedValueThirdCloud.length) {
1851
2007
  return true;
@@ -1920,11 +2076,12 @@
1920
2076
 
1921
2077
  return true;
1922
2078
  };
1923
- var validateFourthCloud = function validateFourthCloud(firstCloudValue, secondCloudValue, thirdCloudValue, fourthCloudValue, visibilityValue) {
1924
- var trimmedValueFirstCloud = firstCloudValue.trim();
1925
- var trimmedValueSecondCloud = secondCloudValue.trim();
1926
- var trimmedValueThirdCloud = thirdCloudValue.trim();
1927
- var trimmedValueFourthCloud = fourthCloudValue.trim(); // Field can be left empty
2079
+ var validateFourthCloud = function validateFourthCloud(firstCloudValue, secondCloudValue, thirdCloudValue, fourthCloudValue, visibilityFieldValue) {
2080
+ var trimmedValueFirstCloud = getFieldValue(firstCloudValue);
2081
+ var trimmedValueSecondCloud = getFieldValue(secondCloudValue);
2082
+ var trimmedValueThirdCloud = getFieldValue(thirdCloudValue);
2083
+ var trimmedValueFourthCloud = getFieldValue(fourthCloudValue);
2084
+ var visibilityValue = getFieldValue(visibilityFieldValue); // Field can be left empty
1928
2085
 
1929
2086
  if (!trimmedValueFourthCloud.length) {
1930
2087
  return true;
@@ -2433,7 +2590,8 @@
2433
2590
  }; // Check if the amended/corrected TAF has been changed. Only compare the fields users are able to fill in
2434
2591
  // (i.e. exclude baseforecast valid time as that gets updated when doing an amendment automatically outside of the users influence)
2435
2592
 
2436
- var isTafAmendedCorrectedChanged = function isTafAmendedCorrectedChanged(isFormDirty, originalTaf, currentTaf) {
2593
+ var isTafAmendedCorrectedChanged = function isTafAmendedCorrectedChanged(originalTaf, currentTaf) {
2594
+ if (originalTaf === null || currentTaf === null) return false;
2437
2595
  var originalBaseF = originalTaf.baseForecast,
2438
2596
  originalChG = originalTaf.changeGroups;
2439
2597
  var currentBaseF = currentTaf.baseForecast,
@@ -2445,7 +2603,7 @@
2445
2603
  currentBaseF.valid;
2446
2604
  var currentNoValid = __rest(currentBaseF, ["valid"]);
2447
2605
 
2448
- return isFormDirty && (!lodash.isEqual(originalNoValid, currentNoValid) || !lodash.isEqual(originalChG, currentChG));
2606
+ return !lodash.isEqual(originalNoValid, currentNoValid) || !lodash.isEqual(originalChG, currentChG);
2449
2607
  };
2450
2608
  var getConfirmationDialogContent = function getConfirmationDialogContent(action, isFormDirty) {
2451
2609
  switch (action) {
@@ -2497,13 +2655,30 @@
2497
2655
  change: '',
2498
2656
  probability: ''
2499
2657
  };
2500
- var getTafStatusLabel = function getTafStatusLabel(status) {
2658
+ var getTafStatusLabel = function getTafStatusLabel(status, action, isFormDisabled) {
2659
+ // See if we need to base status label on action if form is not disabled and action passed
2660
+ var baseOnAction = isFormDisabled !== undefined && !isFormDisabled && action;
2661
+
2662
+ if (baseOnAction && action === 'AMEND' && (status === 'PUBLISHED' || status === 'AMENDED' || status === 'CORRECTED')) {
2663
+ return 'new amendment';
2664
+ }
2665
+
2666
+ if (baseOnAction && action === 'CORRECT' && (status === 'PUBLISHED' || status === 'AMENDED' || status === 'CORRECTED')) {
2667
+ return 'new correction';
2668
+ }
2669
+
2501
2670
  switch (status) {
2502
2671
  case 'DRAFT_AMENDED':
2503
- return 'draft amended';
2672
+ return 'draft amendment';
2504
2673
 
2505
2674
  case 'DRAFT_CORRECTED':
2506
- return 'draft corrected';
2675
+ return 'draft correction';
2676
+
2677
+ case 'AMENDED':
2678
+ return 'published amendment';
2679
+
2680
+ case 'CORRECTED':
2681
+ return 'published correction';
2507
2682
 
2508
2683
  default:
2509
2684
  return status.toLocaleLowerCase();
@@ -2648,192 +2823,18 @@
2648
2823
  var isFormDirty = function isFormDirty(dirtyFields) {
2649
2824
  return Object.keys(dirtyFields).length > 0;
2650
2825
  };
2826
+ var getFormRowPosition = function getFormRowPosition(formRow) {
2827
+ var _a = formRow.getBoundingClientRect(),
2828
+ top = _a.top,
2829
+ left = _a.left,
2830
+ height = _a.height;
2651
2831
 
2652
- var textFieldStyle = function textFieldStyle(theme) {
2832
+ var newTop = top + height;
2653
2833
  return {
2654
- // input
2655
- marginRight: '2px',
2656
- marginBottom: '4px',
2657
- width: 56,
2658
- height: 46,
2659
- input: {
2660
- textAlign: 'center',
2661
- fontSize: 10,
2662
- fontWeight: 500,
2663
- paddingLeft: 0,
2664
- paddingRight: 0,
2665
- '&.Mui-disabled': {
2666
- color: 'geowebColors.typographyAndIcons.text',
2667
- WebkitTextFillColor: theme.palette.geowebColors.typographyAndIcons.text
2668
- },
2669
- // TODO: https://gitlab.com/opengeoweb/opengeoweb/-/issues/1995 disables the default autofill styling, should be a better fix
2670
- '&:-webkit-autofill': {
2671
- WebkitTransitionDelay: '86400s' // 1 day delay
2672
-
2673
- }
2674
- },
2675
- label: {
2676
- transformOrigin: 'center top',
2677
- right: 0,
2678
- textAlign: 'center',
2679
- fontSize: '10px',
2680
- '&.Mui-disabled': {
2681
- color: 'geowebColors.captions.captionStatus.rgba'
2682
- },
2683
- whiteSpace: 'nowrap',
2684
- maxWidth: '100%',
2685
- transform: 'translate(0px, 16px) scale(1)'
2686
- },
2687
- // shrink
2688
- ' .MuiInputLabel-shrink': {
2689
- transform: 'translate(2px, 10px) scale(0.75) !important',
2690
- letterSpacing: '0.33px',
2691
- textAlign: 'left'
2692
- },
2693
- // root
2694
- '&': {
2695
- '.Mui-error.MuiFilledInput-root': {
2696
- backgroundColor: 'geowebColors.captions.captionErrorBackground.rgba'
2697
- },
2698
- '.Mui-disabled:before': {
2699
- borderColor: 'transparent'
2700
- }
2701
- }
2702
- };
2703
- };
2704
-
2705
- var getTafErrors = function getTafErrors(name, errors) {
2706
- var nameAsArray = name.split('.');
2707
-
2708
- if (nameAsArray[0].includes('changeGroups')) {
2709
- if (errors.changeGroups) {
2710
- var changeGroupNum = nameAsArray[0].slice(13, nameAsArray[0].length - 1);
2711
- var restArray = nameAsArray.slice(1);
2712
- return formFields.getDeepProperty(restArray, errors.changeGroups[changeGroupNum]);
2713
- } // No changegroup errors
2714
-
2715
-
2716
- return null;
2717
- }
2718
-
2719
- return formFields.getDeepProperty(nameAsArray, errors);
2720
- };
2721
-
2722
- var getDisplayValue = function getDisplayValue(value, disabled) {
2723
- return disabled && !value ? '-' : value;
2724
- };
2725
- var BaseTextField = /*#__PURE__*/React__default["default"].memo(function (props) {
2726
- return /*#__PURE__*/React__default["default"].createElement(material.TextField, __assign({
2727
- type: "text",
2728
- variant: "filled",
2729
- sx: textFieldStyle
2730
- }, props));
2731
- }, function (prevProps, nextProps) {
2732
- return prevProps.value === nextProps.value && prevProps.error === nextProps.error && prevProps.name === nextProps.name && prevProps.disabled === nextProps.disabled;
2733
- });
2734
-
2735
- var TafFormTextField = function TafFormTextField(_a) {
2736
- var label = _a.label,
2737
- _b = _a.disabled,
2738
- disabled = _b === void 0 ? false : _b,
2739
- _c = _a.name,
2740
- name = _c === void 0 ? '' : _c,
2741
- _d = _a.onChange,
2742
- onChange = _d === void 0 ? function () {} : _d,
2743
- _e = _a.onBlur,
2744
- onBlur = _e === void 0 ? function () {} : _e,
2745
- _f = _a.defaultValue,
2746
- defaultValue = _f === void 0 ? '' : _f,
2747
- _g = _a.formatter,
2748
- formatter = _g === void 0 ? null : _g,
2749
- rules = _a.rules,
2750
- _h = _a.autoComplete,
2751
- autoComplete = _h === void 0 ? [] : _h,
2752
- _j = _a.autoFocus,
2753
- autoFocus = _j === void 0 ? false : _j;
2754
-
2755
- var _k = reactHookForm.useFormContext(),
2756
- control = _k.control,
2757
- setValue = _k.setValue,
2758
- errors = _k.formState.errors;
2759
-
2760
- var fieldErrors = getTafErrors(name, errors);
2761
-
2762
- var _l = __read(React__default["default"].useState(null), 2),
2763
- maxLength = _l[0],
2764
- setMaxLength = _l[1];
2765
-
2766
- var onKeyDown = React__default["default"].useCallback(function (event) {
2767
- var target = event.target;
2768
- var currentValue = target.value,
2769
- selectionStart = target.selectionStart,
2770
- selectionEnd = target.selectionEnd;
2771
- var textSelection = currentValue.substring(selectionStart, selectionEnd);
2772
-
2773
- if (autoComplete && !currentValue.length || textSelection.length && currentValue.length && textSelection === currentValue) {
2774
- var pressedKey_1 = event.key.toString().toUpperCase();
2775
- var foundValue = autoComplete.find(function (el) {
2776
- return el.key === pressedKey_1;
2777
- }) || null;
2778
-
2779
- if (foundValue) {
2780
- setValue(name, foundValue.value, {
2781
- shouldDirty: true
2782
- });
2783
- setMaxLength(foundValue.value.length);
2784
- event.preventDefault();
2785
- }
2786
- }
2787
- }, [name, autoComplete, setValue]);
2788
- var onChangeField = React__default["default"].useCallback(function (event, callback) {
2789
- var valueUppercase = event.currentTarget.value.toUpperCase();
2790
-
2791
- if (autoComplete) {
2792
- var exist = autoComplete.find(function (e) {
2793
- return e.value === valueUppercase;
2794
- });
2795
- var newMaxLength = exist ? valueUppercase.length : null;
2796
- setMaxLength(newMaxLength);
2797
- }
2798
-
2799
- callback(valueUppercase);
2800
- onChange(valueUppercase);
2801
- }, [onChange, autoComplete]);
2802
- var onBlurField = React__default["default"].useCallback(function (callback) {
2803
- callback();
2804
- onBlur();
2805
- }, [onBlur]);
2806
- var hasError = !!fieldErrors;
2807
- return /*#__PURE__*/React__default["default"].createElement(reactHookForm.Controller, {
2808
- render: function render(_a) {
2809
- var field = _a.field;
2810
- var displayValue = formatter ? formatter(field.value) : getDisplayValue(field.value, disabled);
2811
- return /*#__PURE__*/React__default["default"].createElement(BaseTextField, {
2812
- label: label,
2813
- disabled: disabled,
2814
- name: name,
2815
- value: displayValue,
2816
- inputRef: field.ref,
2817
- onChange: function onChange(e) {
2818
- return onChangeField(e, field.onChange);
2819
- },
2820
- onKeyDown: onKeyDown,
2821
- error: hasError,
2822
- onBlur: function onBlur() {
2823
- return onBlurField(field.onBlur);
2824
- },
2825
- inputProps: {
2826
- maxLength: maxLength
2827
- },
2828
- autoFocus: autoFocus
2829
- });
2830
- },
2831
- name: name,
2832
- control: control,
2833
- defaultValue: defaultValue,
2834
- rules: rules
2835
- });
2836
- };
2834
+ top: newTop,
2835
+ left: left
2836
+ };
2837
+ };
2837
2838
 
2838
2839
  /* *
2839
2840
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -2851,24 +2852,27 @@
2851
2852
  * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2852
2853
  * Copyright 2021 - Finnish Meteorological Institute (FMI)
2853
2854
  * */
2854
- // messages
2855
- var invalidChangeMessage = 'Invalid Change input, only BECMG, TEMPO or FM are allowed';
2856
- var invalidChangeProbCombinationMessage = 'A probability is only allowed in combination with TEMPO or an empty Change input'; // validations
2857
-
2858
- var validateChangeField = function validateChangeField(value) {
2859
- var trimmedValue = value.trim();
2860
- var isValid = trimmedValue === '' || trimmedValue === 'FM' || trimmedValue === 'TEMPO' || trimmedValue === 'BECMG';
2861
- return isValid ? true : invalidChangeMessage;
2862
- };
2863
- var validateChangeFieldInterField = function validateChangeFieldInterField(value, valueProb) {
2864
- var trimmedProbValue = valueProb.trim();
2865
- var trimmedValue = value.trim();
2866
-
2867
- if (trimmedProbValue !== '' && trimmedValue !== '' && trimmedValue !== 'TEMPO') {
2868
- return invalidChangeProbCombinationMessage;
2869
- }
2870
2855
 
2871
- return true;
2856
+ var DragHandle = function DragHandle(_a) {
2857
+ var _b = _a.isSorting,
2858
+ isSorting = _b === void 0 ? false : _b,
2859
+ _c = _a.isDisabled,
2860
+ isDisabled = _c === void 0 ? false : _c,
2861
+ index = _a.index;
2862
+ return /*#__PURE__*/React__default["default"].createElement(material.IconButton, {
2863
+ className: "handle",
2864
+ "data-testid": "dragHandle-" + index,
2865
+ disableRipple: true,
2866
+ disabled: isDisabled,
2867
+ size: "large",
2868
+ sx: {
2869
+ backgroundColor: 'transparent',
2870
+ '&:hover': {
2871
+ backgroundColor: 'transparent'
2872
+ },
2873
+ cursor: isSorting ? 'grabbing' : 'grab'
2874
+ }
2875
+ }, /*#__PURE__*/React__default["default"].createElement(theme.DragHandle, null));
2872
2876
  };
2873
2877
 
2874
2878
  /* *
@@ -2884,16 +2888,82 @@
2884
2888
  * See the License for the specific language governing permissions and
2885
2889
  * limitations under the License.
2886
2890
  *
2887
- * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2888
- * Copyright 2021 - Finnish Meteorological Institute (FMI)
2891
+ * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2892
+ * Copyright 2022 - Finnish Meteorological Institute (FMI)
2889
2893
  * */
2890
- // messages
2891
- var invalidProbabilityMessage = 'Invalid Probability input, only PROB30 or PROB40 are allowed'; // validations
2894
+ var getCustomError = function getCustomError(error, isChangeGroup, rowIndex) {
2895
+ return __assign(__assign({}, error), {
2896
+ isChangeGroup: isChangeGroup,
2897
+ rowIndex: rowIndex
2898
+ });
2899
+ };
2900
+ var getIssuesLabel = function getIssuesLabel(sumOfErrors) {
2901
+ switch (sumOfErrors) {
2902
+ case 0:
2903
+ return '0 issues';
2892
2904
 
2893
- var validateProbabilityField = function validateProbabilityField(value) {
2894
- var trimmedValue = value.trim();
2895
- var isValid = trimmedValue === '' || trimmedValue === 'PROB30' || trimmedValue === 'PROB40';
2896
- return isValid ? true : invalidProbabilityMessage;
2905
+ case 1:
2906
+ return '1 issue';
2907
+
2908
+ default:
2909
+ return sumOfErrors + " issues";
2910
+ }
2911
+ };
2912
+ var getErrorValues = function getErrorValues(fieldErrors, isChangeGroup, rowIndex) {
2913
+ if (isChangeGroup === void 0) {
2914
+ isChangeGroup = false;
2915
+ }
2916
+
2917
+ if (rowIndex === void 0) {
2918
+ rowIndex = -1;
2919
+ }
2920
+
2921
+ if (!fieldErrors) return [];
2922
+ return Object.keys(fieldErrors).reduce(function (list, key) {
2923
+ var error = __assign({}, fieldErrors[key]);
2924
+
2925
+ if (error.ref) {
2926
+ return list.concat(getCustomError(error, isChangeGroup, rowIndex));
2927
+ }
2928
+
2929
+ return list.concat(getErrorValues(error, isChangeGroup, rowIndex));
2930
+ }, []);
2931
+ };
2932
+ var filterDuplicateErrors = function filterDuplicateErrors(errors) {
2933
+ return errors.reduce(function (list, error) {
2934
+ // check on type validateRequiredSub and validateRequiredMainOptional since these are giving 'duplicates'
2935
+ if (error.type === 'validateRequiredSub') {
2936
+ var exist = list.find(function (e) {
2937
+ return e.type === 'validateRequiredSub' && e.rowIndex === error.rowIndex;
2938
+ });
2939
+ return exist ? list : list.concat(error);
2940
+ }
2941
+
2942
+ if (error.type === 'validateRequiredMainOptional') {
2943
+ var exist = list.find(function (e) {
2944
+ return e.type === 'validateRequiredMainOptional' && e.rowIndex === error.rowIndex;
2945
+ });
2946
+ return exist ? list : list.concat(error);
2947
+ }
2948
+
2949
+ return list.concat(error);
2950
+ }, []);
2951
+ };
2952
+ var getErrors = function getErrors(errors) {
2953
+ var errorList = Object.keys(errors).reduce(function (list, key) {
2954
+ var errorValue = errors[key]; // changeGroups
2955
+
2956
+ if (Array.isArray(errorValue)) {
2957
+ var errorValues = errorValue.reduce(function (changeGroupErrors, changeGroupError, index) {
2958
+ return changeGroupErrors.concat(getErrorValues(changeGroupError, true, index));
2959
+ }, []);
2960
+ return list.concat.apply(list, __spreadArray([], __read(errorValues)));
2961
+ } // baseForecast
2962
+
2963
+
2964
+ return list.concat(getErrorValues(errorValue, false, -1));
2965
+ }, []);
2966
+ return errorList;
2897
2967
  };
2898
2968
 
2899
2969
  /* *
@@ -2909,499 +2979,499 @@
2909
2979
  * See the License for the specific language governing permissions and
2910
2980
  * limitations under the License.
2911
2981
  *
2912
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2913
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
2982
+ * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2983
+ * Copyright 2021 - Finnish Meteorological Institute (FMI)
2914
2984
  * */
2915
2985
 
2916
- var TafFormOptionsButton = function TafFormOptionsButton(_a) {
2917
- var isChangeGroup = _a.isChangeGroup,
2918
- addChangeGroupBelow = _a.addChangeGroupBelow,
2919
- addChangeGroupAbove = _a.addChangeGroupAbove,
2920
- removeChangeGroup = _a.removeChangeGroup,
2921
- clearRow = _a.clearRow,
2922
- index = _a.index;
2923
- var insertAbove = {
2924
- text: 'Insert 1 row above',
2925
- icon: /*#__PURE__*/React__namespace.createElement(theme.Add, null),
2926
- action: addChangeGroupAbove
2927
- };
2928
- var insertBelow = {
2929
- text: 'Insert 1 row below',
2930
- icon: /*#__PURE__*/React__namespace.createElement(theme.Add, null),
2931
- action: addChangeGroupBelow
2932
- };
2933
- var deleteRow = {
2934
- text: 'Delete row',
2935
- icon: /*#__PURE__*/React__namespace.createElement(theme.Delete, null),
2936
- action: removeChangeGroup
2937
- };
2938
- var clear = {
2939
- text: 'Clear row',
2940
- icon: /*#__PURE__*/React__namespace.createElement(theme.Close, null),
2941
- action: clearRow
2942
- };
2943
- var menuItemsBaseForecast = [insertBelow, clear];
2944
- var menuItemsChangeGroup = [insertAbove, insertBelow, deleteRow, clear];
2945
- return /*#__PURE__*/React__namespace.createElement(shared.ToggleMenu, {
2946
- buttonTestId: "tafFormOptions[" + index + "]",
2947
- buttonSx: {
2948
- marginTop: '10px',
2949
- marginLeft: '4px'
2950
- },
2951
- menuItems: isChangeGroup ? menuItemsChangeGroup : menuItemsBaseForecast
2952
- });
2953
- };
2954
-
2955
- var getDefaultValue = function getDefaultValue(fieldName, data) {
2956
- if (!data) {
2957
- return '';
2958
- }
2959
-
2960
- return formFields.getDeepProperty(fieldName.split('.'), data) || '';
2961
- };
2962
-
2963
- var getRequiredCrossFields = function getRequiredCrossFields(fieldNames) {
2964
- return [[fieldNames.valid], [fieldNames.change, fieldNames.probability], [fieldNames.wind, fieldNames.visibility, fieldNames.weather1, fieldNames.cloud1] // sub fields
2965
- ];
2966
- };
2967
-
2968
- var TafFormRow = /*#__PURE__*/React__default["default"].forwardRef(function (_a, ref) {
2969
- var isNotRequiredForAction = _a.isNotRequiredForAction,
2970
- _b = _a.isChangeGroup,
2971
- isChangeGroup = _b === void 0 ? false : _b,
2972
- _c = _a.disabled,
2973
- disabled = _c === void 0 ? false : _c,
2974
- _d = _a.index,
2975
- index = _d === void 0 ? -1 : _d,
2976
- onRemoveChangeGroup = _a.onRemoveChangeGroup,
2977
- _e = _a.field,
2978
- field = _e === void 0 ? null : _e,
2979
- _f = _a.dragHandle,
2980
- dragHandle = _f === void 0 ? null : _f,
2981
- onAddChangeGroupBelow = _a.onAddChangeGroupBelow,
2982
- onAddChangeGroupAbove = _a.onAddChangeGroupAbove,
2983
- onClearRow = _a.onClearRow,
2984
- props = __rest(_a, ["isNotRequiredForAction", "isChangeGroup", "disabled", "index", "onRemoveChangeGroup", "field", "dragHandle", "onAddChangeGroupBelow", "onAddChangeGroupAbove", "onClearRow"]);
2985
-
2986
- var namePrefix = !isChangeGroup ? 'baseForecast' : "changeGroups[" + index + "]";
2987
- var fieldNames = getFieldNames(isChangeGroup, index);
2988
-
2989
- var _g = reactHookForm.useFormContext(),
2990
- getValues = _g.getValues,
2991
- trigger = _g.trigger; // cross-field required validation
2992
-
2993
-
2994
- var _h = __read(getRequiredCrossFields(fieldNames), 3),
2995
- mainFields = _h[0],
2996
- mainOptionalFields = _h[1],
2997
- subFields = _h[2];
2998
-
2999
- var hasFieldsValue = function hasFieldsValue(fields) {
3000
- return fields.map(getValues).find(function (field) {
3001
- return !!field;
3002
- });
3003
- }; // Used to validate the required field for change groups: Valid
2986
+ var IssuesButton = function IssuesButton(_a) {
2987
+ var _b = _a.errors,
2988
+ errors = _b === void 0 ? {} : _b,
2989
+ _c = _a.isIssuesPaneOpen,
2990
+ isIssuesPaneOpen = _c === void 0 ? false : _c,
2991
+ _d = _a.setIsIssuesPaneOpen,
2992
+ setIsIssuesPaneOpen = _d === void 0 ? function () {
2993
+ return null;
2994
+ } : _d;
2995
+ var errorList = filterDuplicateErrors(getErrors(errors));
2996
+ var totalErrors = errorList.length;
2997
+ var errorStatus = totalErrors > 0 ? 'error' : 'success';
2998
+ var buttonColor = "geowebColors.functional." + errorStatus;
3004
2999
 
3000
+ var toggleIssuesPane = function toggleIssuesPane(newPosition) {
3001
+ return setIsIssuesPaneOpen(!isIssuesPaneOpen, newPosition);
3002
+ };
3005
3003
 
3006
- var validateRequiredMain = function validateRequiredMain(value) {
3007
- return isNotRequiredForAction(value) !== true && isChangeGroup && !value.length && (hasFieldsValue(subFields) || hasFieldsValue(mainFields) || hasFieldsValue(mainOptionalFields)) ? 'Valid is required' : true;
3008
- }; // Used to ensure either probability or change is entered, or both
3004
+ var onClickButton = function onClickButton(event) {
3005
+ var _a;
3009
3006
 
3007
+ var _b = event.currentTarget.getBoundingClientRect(),
3008
+ left = _b.left,
3009
+ top = _b.top;
3010
3010
 
3011
- var validateRequiredMainOptional = function validateRequiredMainOptional(value) {
3012
- return isNotRequiredForAction(value) !== true && isChangeGroup && (hasFieldsValue(mainFields) || hasFieldsValue(subFields)) && !hasFieldsValue(mainOptionalFields) ? 'Probability or change is required' : true;
3013
- }; // Used to ensure one wind, visibility, weather or cloud is entered when start editing a changegroup and all of these are empty
3011
+ var parentOffset = ((_a = document.getElementById('tafmodule')) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) || {
3012
+ top: 0,
3013
+ left: 0
3014
+ };
3015
+ var newPosition = {
3016
+ left: left - parentOffset.left + 100,
3017
+ top: top - parentOffset.top
3018
+ };
3019
+ toggleIssuesPane(newPosition);
3020
+ };
3014
3021
 
3022
+ return /*#__PURE__*/React__namespace.createElement(shared.CustomTooltip, {
3023
+ title: "View details"
3024
+ }, /*#__PURE__*/React__namespace.createElement(material.Chip, {
3025
+ "data-testid": "issuesButton",
3026
+ className: "status-" + errorStatus,
3027
+ size: "small",
3028
+ label: getIssuesLabel(totalErrors),
3029
+ onClick: onClickButton,
3030
+ sx: {
3031
+ width: '74px',
3032
+ color: '#ffffff',
3033
+ backgroundColor: buttonColor,
3034
+ '&:hover': {
3035
+ backgroundColor: buttonColor
3036
+ },
3037
+ '&:focus': {
3038
+ backgroundColor: buttonColor
3039
+ },
3040
+ fontSize: 12
3041
+ }
3042
+ }));
3043
+ };
3015
3044
 
3016
- var validateRequiredSub = function validateRequiredSub(value) {
3017
- return isNotRequiredForAction(value) !== true && isChangeGroup && (hasFieldsValue(mainFields) || hasFieldsValue(mainOptionalFields)) && !hasFieldsValue(subFields) ? 'Wind, visibility, weather or cloud is required' : true;
3018
- }; // Used to validate the combination of change group and wind, visibility, weather and/or cloud data entered
3045
+ var getPaneTitle = function getPaneTitle(sumOfErrors) {
3046
+ switch (sumOfErrors) {
3047
+ case 0:
3048
+ return 'Looks good';
3019
3049
 
3050
+ case 1:
3051
+ return 'There is an issue to address';
3020
3052
 
3021
- var _validateRequiredMainFields = function validateRequiredMainFields(value, fieldName) {
3022
- var changeField = getValues(namePrefix + ".change");
3023
- var visibilityField = getValues(namePrefix + ".visibility");
3024
- var isFM = changeField && changeField.trim() === 'FM';
3025
- var isCAVOK = visibilityField && visibilityField.trim() === 'CAVOK';
3053
+ default:
3054
+ return 'There are a few issues to address';
3055
+ }
3056
+ };
3026
3057
 
3027
- if (isNotRequiredForAction(value) !== true && !value.length) {
3028
- if (isChangeGroup && isFM || !isChangeGroup) {
3029
- // exception for CavOK
3030
- if (isCAVOK && (fieldName === 'Clouds' || fieldName === 'Weather')) {
3031
- return true;
3032
- } // exception for visibility > 5000
3058
+ var humanizeErrorMessage = function humanizeErrorMessage(errorTitle, fieldNumberedValue) {
3059
+ if (fieldNumberedValue !== undefined && fieldNumberedValue >= 0) {
3060
+ // when name contains a number we assume it's a formgroup and we add a index +1 for human readability
3061
+ var fieldNumber = fieldNumberedValue + 1;
3062
+ return errorTitle + " " + fieldNumber;
3063
+ }
3033
3064
 
3065
+ return errorTitle;
3066
+ };
3067
+ var getErrorMessage = function getErrorMessage(error, index) {
3068
+ var errorTitleCategory = error.isChangeGroup ? 'Changegroups' : 'Baseforecast';
3069
+ var fieldErrorTitle = humanizeErrorMessage(errorTitleCategory, error.rowIndex);
3070
+ return index + 1 + ". " + fieldErrorTitle + ": " + error.message;
3071
+ };
3072
+ var MODAL_DIALOG_ELEMENT = 'modal-dialog';
3073
+ var useIssuesPane = function useIssuesPane() {
3074
+ var _a = __read(React__namespace.useState(false), 2),
3075
+ isIssuesPaneOpen = _a[0],
3076
+ setIsIssuesPaneOpen = _a[1];
3034
3077
 
3035
- if (visibilityField && parseInt(visibilityField.trim(), 10) >= 5000 && fieldName === 'Weather') {
3036
- return true;
3037
- }
3078
+ var _b = __read(React__namespace.useState(null), 2),
3079
+ startPosition = _b[0],
3080
+ setStartPosition = _b[1];
3038
3081
 
3039
- return fieldName + " is required";
3040
- }
3041
- }
3082
+ var _c = __read(React__namespace.useState(false), 2),
3083
+ hasUserDragged = _c[0],
3084
+ setHasUserDragged = _c[1];
3042
3085
 
3043
- return true;
3086
+ var onUserHasDragged = function onUserHasDragged() {
3087
+ return setHasUserDragged(true);
3044
3088
  };
3045
3089
 
3046
- var validatePreviousRow = React__default["default"].useCallback(function () {
3047
- if (isChangeGroup && index > 0) {
3048
- var _a = getValues(),
3049
- validDateEnd = _a.validDateEnd,
3050
- validDateStart = _a.validDateStart,
3051
- changeGroups = _a.changeGroups;
3052
-
3053
- var currentChangeGroup = changeGroups[index];
3054
- var previousChangeGroup = changeGroups[index - 1];
3055
- return validatePreviousChangeGroup(currentChangeGroup, previousChangeGroup, validDateStart, validDateEnd);
3090
+ var onToggleIssuesPane = function onToggleIssuesPane(isOpen, newPosition) {
3091
+ if (!hasUserDragged) {
3092
+ setStartPosition(newPosition);
3056
3093
  }
3057
3094
 
3058
- return true;
3059
- }, [index, isChangeGroup, getValues]);
3060
-
3061
- var getFieldFromRow = function getFieldFromRow(fieldname, rowIndex) {
3062
- var indexedFieldName = "changeGroups[" + rowIndex + "]." + fieldname;
3063
- var rowValue = getValues(indexedFieldName);
3064
- return rowValue ? [indexedFieldName] : [];
3095
+ setIsIssuesPaneOpen(isOpen);
3065
3096
  };
3066
3097
 
3067
- var getValidFieldFromNextRow = function getValidFieldFromNextRow() {
3068
- return getFieldFromRow('valid', index + 1);
3098
+ var onCloseIssuesPane = function onCloseIssuesPane() {
3099
+ return setIsIssuesPaneOpen(false);
3069
3100
  };
3070
3101
 
3071
- var validateNextRows = React__default["default"].useCallback(function () {
3072
- if (isChangeGroup) {
3073
- var _a = getValues(),
3074
- validDateEnd = _a.validDateEnd,
3075
- validDateStart = _a.validDateStart,
3076
- changeGroups = _a.changeGroups;
3077
-
3078
- var currentChangeGroup = changeGroups[index];
3079
- var nextChangeGroups = changeGroups.slice(index + 1);
3080
- return validateOverlapWithFM(currentChangeGroup, nextChangeGroups, validDateStart, validDateEnd);
3081
- }
3082
-
3083
- return true;
3084
- }, [index, isChangeGroup, getValues]);
3085
-
3086
- var getPreviousValidFields = function getPreviousValidFields(rowIndex) {
3087
- var changeGroups = getValues().changeGroups;
3088
- var previousChangeGroups = changeGroups.slice(0, rowIndex);
3089
- var validFields = previousChangeGroups.map(function (_element, index) {
3090
- return getFieldFromRow('valid', index)[0];
3091
- });
3092
- return validFields;
3102
+ return {
3103
+ isIssuesPaneOpen: isIssuesPaneOpen,
3104
+ startPosition: startPosition,
3105
+ onToggleIssuesPane: onToggleIssuesPane,
3106
+ onCloseIssuesPane: onCloseIssuesPane,
3107
+ onUserHasDragged: onUserHasDragged
3093
3108
  };
3109
+ };
3094
3110
 
3095
- var addChangeGroupBelow = React__default["default"].useCallback(function () {
3096
- onAddChangeGroupBelow(index);
3097
- }, [onAddChangeGroupBelow, index]);
3098
- var addChangeGroupAbove = React__default["default"].useCallback(function () {
3099
- onAddChangeGroupAbove(index);
3100
- }, [onAddChangeGroupAbove, index]);
3101
- var clearRow = React__default["default"].useCallback(function () {
3102
- onClearRow(index);
3103
- }, [onClearRow, index]);
3104
- return /*#__PURE__*/React__default["default"].createElement(material.Grid, __assign({
3105
- sx: {
3106
- marginTop: '8px',
3107
- backgroundColor: 'geowebColors.cards.cardContainer',
3108
- position: 'relative',
3109
- '&.sortable-chosen': {
3110
- boxShadow: 1
3111
- },
3112
- '&.sortable-ghost': {
3113
- opacity: 0.5
3111
+ var IssuesPane = function IssuesPane(_a) {
3112
+ var _b = _a.errorList,
3113
+ errorList = _b === void 0 ? [] : _b,
3114
+ isOpen = _a.isOpen,
3115
+ handleClose = _a.handleClose,
3116
+ _c = _a.startPosition,
3117
+ startPosition = _c === void 0 ? {
3118
+ left: 20,
3119
+ top: 50
3120
+ } : _c,
3121
+ _d = _a.onUserHasDragged,
3122
+ onUserHasDragged = _d === void 0 ? function () {} : _d;
3123
+ var rootElement = document.getElementById(MODAL_DIALOG_ELEMENT) || document.body;
3124
+ return /*#__PURE__*/ReactDOM__default["default"].createPortal( /*#__PURE__*/React__namespace.createElement(shared.ToolContainerDraggable, {
3125
+ startSize: {
3126
+ width: '577px',
3127
+ height: '200px'
3128
+ },
3129
+ startPosition: startPosition,
3130
+ minWidth: 300,
3131
+ onClose: handleClose,
3132
+ title: getPaneTitle(errorList.length),
3133
+ headerSize: "xs",
3134
+ isOpen: isOpen,
3135
+ "data-testid": "moveable-issues-pane",
3136
+ bounds: "parent",
3137
+ onDragEnd: function onDragEnd(event) {
3138
+ if (event.x !== 0 && event.y !== 0) {
3139
+ onUserHasDragged();
3114
3140
  }
3141
+ }
3142
+ }, /*#__PURE__*/React__namespace.createElement(material.Box, {
3143
+ component: "div",
3144
+ sx: {
3145
+ marginTop: '16px',
3146
+ marginLeft: '24px'
3147
+ }
3148
+ }, errorList.length === 0 && /*#__PURE__*/React__namespace.createElement(material.Box, {
3149
+ component: "div",
3150
+ sx: {
3151
+ fontSize: '4rem'
3115
3152
  },
3116
- justifyContent: "flex-start",
3117
- "data-testid": "row-" + namePrefix,
3118
- container: true,
3119
- ref: ref
3120
- }, props), /*#__PURE__*/React__default["default"].createElement(material.Grid, {
3121
- columns: 24,
3122
- item: true,
3123
- container: true,
3124
- justifyContent: "flex-end",
3125
- xs: 24,
3126
- sm: 23
3127
- }, !isChangeGroup && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3128
- label: "Type",
3129
- name: fieldNames.messageType,
3130
- disabled: true
3131
- }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3132
- label: "Location",
3133
- name: "location",
3134
- disabled: true
3135
- }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3136
- formatter: formatIssueTime,
3137
- label: "Issue time",
3138
- name: "issueDate",
3139
- disabled: true
3140
- })), isChangeGroup && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(material.Box, {
3153
+ "data-testid": "zeroIssuesImage"
3154
+ }, /*#__PURE__*/React__namespace.createElement(theme.ThumbsUp, {
3141
3155
  sx: {
3142
- width: 56,
3143
- marginRight: '2px'
3156
+ height: '69px',
3157
+ width: '58px'
3144
3158
  }
3145
- }, !disabled && dragHandle), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3146
- label: "Prob",
3147
- name: fieldNames.probability,
3148
- disabled: disabled,
3149
- defaultValue: getDefaultValue('probability', field),
3150
- rules: {
3151
- validate: {
3152
- validateRequiredMainOptional: validateRequiredMainOptional,
3153
- validateProbabilityField: validateProbabilityField
3159
+ })), errorList.length > 0 && errorList.map(function (error, index) {
3160
+ return /*#__PURE__*/React__namespace.createElement(material.Typography // eslint-disable-next-line react/no-array-index-key
3161
+ , {
3162
+ // eslint-disable-next-line react/no-array-index-key
3163
+ key: "message-" + index,
3164
+ variant: "body1",
3165
+ "data-testid": "errorMessage"
3166
+ }, getErrorMessage(error, index));
3167
+ }))), rootElement);
3168
+ };
3169
+
3170
+ /* *
3171
+ * Licensed under the Apache License, Version 2.0 (the "License");
3172
+ * you may not use this file except in compliance with the License.
3173
+ * You may obtain a copy of the License at
3174
+ *
3175
+ * http://www.apache.org/licenses/LICENSE-2.0
3176
+ *
3177
+ * Unless required by applicable law or agreed to in writing, software
3178
+ * distributed under the License is distributed on an "AS IS" BASIS,
3179
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3180
+ * See the License for the specific language governing permissions and
3181
+ * limitations under the License.
3182
+ *
3183
+ * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3184
+ * Copyright 2022 - Finnish Meteorological Institute (FMI)
3185
+ * */
3186
+ var TafModuleContext = /*#__PURE__*/React__namespace.createContext({
3187
+ onValidateForm: null,
3188
+ registerValidateForm: null,
3189
+ tafAction: null,
3190
+ setTafAction: null,
3191
+ onPreventCloseView: null
3192
+ });
3193
+ var useTafModuleContext = function useTafModuleContext() {
3194
+ return React__namespace.useContext(TafModuleContext);
3195
+ };
3196
+ var useTafModuleState = function useTafModuleState(_a) {
3197
+ var onPreventCloseView = _a.onPreventCloseView;
3198
+
3199
+ var _b = __read(React__namespace.useState(function () {
3200
+ return new Promise(function () {
3201
+ return true;
3202
+ });
3203
+ }), 2),
3204
+ onValidateForm = _b[0],
3205
+ registerValidateForm = _b[1];
3206
+
3207
+ var _c = __read(React__namespace.useState(), 2),
3208
+ tafAction = _c[0],
3209
+ setTafAction = _c[1];
3210
+
3211
+ var onRegisterValidateForm = function onRegisterValidateForm(promiseToRegister) {
3212
+ registerValidateForm(function () {
3213
+ return promiseToRegister;
3214
+ });
3215
+ };
3216
+
3217
+ return {
3218
+ onValidateForm: onValidateForm,
3219
+ registerValidateForm: onRegisterValidateForm,
3220
+ tafAction: tafAction,
3221
+ setTafAction: setTafAction,
3222
+ onPreventCloseView: onPreventCloseView
3223
+ };
3224
+ };
3225
+ var TafModuleProvider = function TafModuleProvider(_a) {
3226
+ var children = _a.children,
3227
+ _b = _a.onPreventCloseView,
3228
+ onPreventCloseView = _b === void 0 ? function () {} : _b;
3229
+ var contextState = useTafModuleState({
3230
+ onPreventCloseView: onPreventCloseView
3231
+ });
3232
+ return /*#__PURE__*/React__namespace.createElement(TafModuleContext.Provider, {
3233
+ value: contextState
3234
+ }, children);
3235
+ };
3236
+
3237
+ var styles = {
3238
+ label: {
3239
+ color: 'geowebColors.buttons.tertiary.default.color',
3240
+ opacity: 1,
3241
+ fontSize: '12px',
3242
+ fontWeight: 500
3243
+ }
3244
+ };
3245
+
3246
+ var SwitchButton = function SwitchButton(props) {
3247
+ return /*#__PURE__*/React__namespace.createElement(shared.CustomTooltip, {
3248
+ title: "Switch mode"
3249
+ }, /*#__PURE__*/React__namespace.createElement("span", null, /*#__PURE__*/React__namespace.createElement(material.FormLabel, {
3250
+ sx: styles.label
3251
+ }, "Viewer"), /*#__PURE__*/React__namespace.createElement(material.Switch, __assign({
3252
+ "data-testid": "switchMode"
3253
+ }, props)), /*#__PURE__*/React__namespace.createElement(material.FormLabel, {
3254
+ sx: styles.label
3255
+ }, "Editor")));
3256
+ };
3257
+
3258
+ var TafAvatar = function TafAvatar(_a) {
3259
+ var editor = _a.editor,
3260
+ _b = _a.tooltipPlacement,
3261
+ tooltipPlacement = _b === void 0 ? 'bottom' : _b;
3262
+ return /*#__PURE__*/React__namespace.createElement(shared.CustomTooltip, {
3263
+ title: "Editor: " + editor,
3264
+ placement: tooltipPlacement
3265
+ }, /*#__PURE__*/React__namespace.createElement("span", null, /*#__PURE__*/React__namespace.createElement(shared.Avatar, {
3266
+ size: "small"
3267
+ }, shared.getInitials(editor))));
3268
+ };
3269
+
3270
+ var textFieldStyle = function textFieldStyle(theme, shouldPreventUppercase) {
3271
+ return {
3272
+ // input
3273
+ marginRight: '2px',
3274
+ marginBottom: '4px',
3275
+ width: 56,
3276
+ height: 46,
3277
+ input: {
3278
+ textAlign: 'center',
3279
+ textTransform: shouldPreventUppercase ? 'none' : 'uppercase',
3280
+ fontSize: 10,
3281
+ fontWeight: 500,
3282
+ paddingLeft: 0,
3283
+ paddingRight: 0,
3284
+ '&.Mui-disabled': {
3285
+ color: 'geowebColors.typographyAndIcons.text',
3286
+ WebkitTextFillColor: theme.palette.geowebColors.typographyAndIcons.text
3287
+ },
3288
+ // TODO: https://gitlab.com/opengeoweb/opengeoweb/-/issues/1995 disables the default autofill styling, should be a better fix
3289
+ '&:-webkit-autofill': {
3290
+ WebkitTransitionDelay: '86400s' // 1 day delay
3291
+
3154
3292
  }
3155
3293
  },
3156
- autoComplete: [{
3157
- key: '3',
3158
- value: 'PROB30'
3159
- }, {
3160
- key: '4',
3161
- value: 'PROB40'
3162
- }],
3163
- onBlur: function onBlur() {
3164
- if (isChangeGroup) {
3165
- var nextValidFieldName = getValidFieldFromNextRow();
3166
- trigger(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(subFields)), __read(mainOptionalFields)), __read(mainFields)), __read(nextValidFieldName)));
3294
+ label: {
3295
+ transformOrigin: 'center top',
3296
+ right: 0,
3297
+ textAlign: 'center',
3298
+ fontSize: '10px',
3299
+ '&.Mui-disabled': {
3300
+ color: 'geowebColors.captions.captionStatus.rgba'
3301
+ },
3302
+ whiteSpace: 'nowrap',
3303
+ maxWidth: '100%',
3304
+ transform: 'translate(0px, 16px) scale(1)'
3305
+ },
3306
+ // shrink
3307
+ ' .MuiInputLabel-shrink': {
3308
+ transform: 'translate(2px, 10px) scale(0.75) !important',
3309
+ letterSpacing: '0.33px',
3310
+ textAlign: 'left'
3311
+ },
3312
+ // root
3313
+ '&': {
3314
+ '.Mui-error.MuiFilledInput-root': {
3315
+ backgroundColor: 'geowebColors.captions.captionErrorBackground.rgba'
3316
+ },
3317
+ '.Mui-disabled:before': {
3318
+ borderColor: 'transparent'
3167
3319
  }
3168
3320
  }
3169
- }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3170
- label: "Change",
3171
- name: fieldNames.change,
3172
- disabled: disabled,
3173
- defaultValue: getDefaultValue('change', field),
3174
- rules: {
3175
- validate: {
3176
- validateRequiredMainOptional: validateRequiredMainOptional,
3177
- validateChangeField: validateChangeField,
3178
- validateChangeFieldInterField: function validateChangeFieldInterField$1(value) {
3179
- return validateChangeFieldInterField(value, getValues(fieldNames.probability));
3180
- }
3181
- }
3182
- },
3183
- autoComplete: [{
3184
- key: 'T',
3185
- value: 'TEMPO'
3186
- }, {
3187
- key: 'B',
3188
- value: 'BECMG'
3189
- }, {
3190
- key: 'F',
3191
- value: 'FM'
3192
- }],
3193
- onBlur: function onBlur() {
3194
- if (isChangeGroup) {
3195
- var nextValidFieldName = getValidFieldFromNextRow();
3196
- var previousValidFieldNames = getPreviousValidFields(index);
3197
- trigger(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(subFields)), __read(mainOptionalFields)), __read(mainFields)), __read(nextValidFieldName)), __read(previousValidFieldNames)));
3321
+ };
3322
+ };
3323
+
3324
+ var getTafErrors = function getTafErrors(name, errors) {
3325
+ var nameAsArray = name.split('.');
3326
+
3327
+ if (nameAsArray[0].includes('changeGroups')) {
3328
+ if (errors.changeGroups) {
3329
+ var changeGroupNum = nameAsArray[0].slice(13, nameAsArray[0].length - 1);
3330
+ var restArray = nameAsArray.slice(1);
3331
+ return formFields.getDeepProperty(restArray, errors.changeGroups[changeGroupNum]);
3332
+ } // No changegroup errors
3333
+
3334
+
3335
+ return null;
3336
+ }
3337
+
3338
+ return formFields.getDeepProperty(nameAsArray, errors);
3339
+ };
3340
+
3341
+ var getDisplayValue = function getDisplayValue(value, disabled) {
3342
+ return disabled && !value ? '-' : value;
3343
+ };
3344
+ var BaseTextField = /*#__PURE__*/React__default["default"].memo(function (_a) {
3345
+ var _b = _a.shouldPreventUppercase,
3346
+ shouldPreventUppercase = _b === void 0 ? false : _b,
3347
+ props = __rest(_a, ["shouldPreventUppercase"]);
3348
+
3349
+ var theme = react.useTheme();
3350
+ var styling = textFieldStyle(theme, shouldPreventUppercase);
3351
+ return /*#__PURE__*/React__default["default"].createElement(material.TextField, __assign({
3352
+ type: "text",
3353
+ variant: "filled",
3354
+ sx: styling
3355
+ }, props));
3356
+ }, function (prevProps, nextProps) {
3357
+ return prevProps.value === nextProps.value && prevProps.error === nextProps.error && prevProps.name === nextProps.name && prevProps.disabled === nextProps.disabled;
3358
+ });
3359
+
3360
+ var TafFormTextField = function TafFormTextField(_a) {
3361
+ var label = _a.label,
3362
+ _b = _a.disabled,
3363
+ disabled = _b === void 0 ? false : _b,
3364
+ _c = _a.name,
3365
+ name = _c === void 0 ? '' : _c,
3366
+ _d = _a.onChange,
3367
+ onChange = _d === void 0 ? function () {} : _d,
3368
+ _e = _a.onBlur,
3369
+ onBlur = _e === void 0 ? function () {} : _e,
3370
+ _f = _a.defaultValue,
3371
+ defaultValue = _f === void 0 ? '' : _f,
3372
+ _g = _a.formatter,
3373
+ formatter = _g === void 0 ? null : _g,
3374
+ rules = _a.rules,
3375
+ _h = _a.autoComplete,
3376
+ autoComplete = _h === void 0 ? [] : _h,
3377
+ _j = _a.autoFocus,
3378
+ autoFocus = _j === void 0 ? false : _j,
3379
+ _k = _a.shouldPreventUppercase,
3380
+ shouldPreventUppercase = _k === void 0 ? false : _k;
3381
+
3382
+ var _l = reactHookForm.useFormContext(),
3383
+ control = _l.control,
3384
+ setValue = _l.setValue,
3385
+ errors = _l.formState.errors;
3386
+
3387
+ var fieldErrors = getTafErrors(name, errors);
3388
+
3389
+ var _m = __read(React__default["default"].useState(null), 2),
3390
+ maxLength = _m[0],
3391
+ setMaxLength = _m[1];
3392
+
3393
+ var onKeyDown = React__default["default"].useCallback(function (event) {
3394
+ var target = event.target;
3395
+ var currentValue = target.value,
3396
+ selectionStart = target.selectionStart,
3397
+ selectionEnd = target.selectionEnd;
3398
+ var textSelection = currentValue.substring(selectionStart, selectionEnd);
3399
+
3400
+ if (autoComplete && !currentValue.length || textSelection.length && currentValue.length && textSelection === currentValue) {
3401
+ var pressedKey_1 = event.key.toString().toUpperCase();
3402
+ var foundValue = autoComplete.find(function (el) {
3403
+ return el.key === pressedKey_1;
3404
+ }) || null;
3405
+
3406
+ if (foundValue) {
3407
+ setValue(name, foundValue.value, {
3408
+ shouldDirty: true
3409
+ });
3410
+ setMaxLength(foundValue.value.length);
3411
+ event.preventDefault();
3198
3412
  }
3199
3413
  }
3200
- })), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3201
- label: "Valid",
3202
- name: fieldNames.valid,
3203
- // always disabled for baseforecast row
3204
- disabled: !isChangeGroup ? true : disabled,
3205
- defaultValue: getDefaultValue('valid', field),
3206
- rules: {
3207
- validate: {
3208
- validateRequiredMain: validateRequiredMain,
3209
- validateValidField: function validateValidField$1(value) {
3210
- return isChangeGroup ? validateValidField(value, getValues('validDateStart'), getValues('validDateEnd')) : true;
3211
- },
3212
- validateValidChangeGroupInterField: function validateValidChangeGroupInterField$1(value) {
3213
- return isChangeGroup ? validateValidChangeGroupInterField(value, getValues(fieldNames.change), getValues(fieldNames.probability), getValues('validDateStart'), getValues('validDateEnd')) : true;
3214
- },
3215
- validatePreviousRow: validatePreviousRow,
3216
- validateNextRows: validateNextRows
3217
- }
3218
- },
3219
- onBlur: function onBlur() {
3220
- if (isChangeGroup) {
3221
- var nextValidFieldName = getValidFieldFromNextRow();
3222
- var previousValidFieldNames = getPreviousValidFields(index);
3223
- trigger(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(subFields)), __read(mainOptionalFields)), __read(mainFields)), __read(nextValidFieldName)), __read(previousValidFieldNames)));
3224
- }
3414
+ }, [name, autoComplete, setValue]);
3415
+ var onChangeField = React__default["default"].useCallback(function (event, callback) {
3416
+ var value = event.currentTarget.value;
3417
+
3418
+ if (autoComplete) {
3419
+ var valueUppercase_1 = value.toUpperCase();
3420
+ var exist = autoComplete.find(function (e) {
3421
+ return e.value === valueUppercase_1;
3422
+ });
3423
+ var newMaxLength = exist ? valueUppercase_1.length : null;
3424
+ setMaxLength(newMaxLength);
3225
3425
  }
3226
- }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3227
- label: "Wind",
3228
- name: fieldNames.wind,
3229
- disabled: disabled,
3230
- defaultValue: getDefaultValue('wind', field),
3231
- rules: {
3232
- validate: {
3233
- validateRequiredMainFields: function validateRequiredMainFields(value) {
3234
- return _validateRequiredMainFields(value, 'Wind');
3235
- },
3236
- validateRequiredSub: validateRequiredSub,
3237
- validateWindField: function validateWindField$1(value) {
3238
- return validateWindField(value, getValues(fieldNames.weather1), getValues(fieldNames.weather2), getValues(fieldNames.weather3));
3239
- }
3240
- }
3241
- },
3242
- onBlur: function onBlur() {
3243
- if (isChangeGroup) {
3244
- trigger(__spreadArray(__spreadArray([], __read(subFields)), __read(mainFields)));
3245
- }
3246
- },
3247
- autoFocus: !isChangeGroup
3248
- }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3249
- label: "Visibility",
3250
- name: fieldNames.visibility,
3251
- disabled: disabled,
3252
- defaultValue: getDefaultValue('visibility', field),
3253
- rules: {
3254
- validate: {
3255
- validateRequiredMainFields: function validateRequiredMainFields(value) {
3256
- return _validateRequiredMainFields(value, 'Visibility');
3257
- },
3258
- validateRequiredSub: validateRequiredSub,
3259
- validateVisibilityField: validateVisibilityField
3260
- }
3261
- },
3262
- autoComplete: [{
3263
- key: 'C',
3264
- value: 'CAVOK'
3265
- }],
3266
- onBlur: function onBlur() {
3267
- var fields = isChangeGroup ? __spreadArray(__spreadArray([], __read(subFields)), __read(mainFields)) : subFields;
3268
- trigger(__spreadArray(__spreadArray([], __read(fields)), [fieldNames.weather1, fieldNames.weather2, fieldNames.weather3]));
3426
+
3427
+ callback(value);
3428
+ onChange(value);
3429
+ }, [onChange, autoComplete]);
3430
+ var onBlurField = React__default["default"].useCallback(function (event, callback) {
3431
+ var value = event.target.value;
3432
+ var valueUppercase = value.toUpperCase();
3433
+
3434
+ if (value !== valueUppercase && !shouldPreventUppercase) {
3435
+ setValue(name, valueUppercase, {
3436
+ shouldValidate: true
3437
+ });
3269
3438
  }
3270
- }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3271
- label: "Weather",
3272
- name: fieldNames.weather1,
3273
- disabled: disabled,
3274
- defaultValue: getDefaultValue('weather.weather1', field),
3275
- rules: {
3276
- validate: {
3277
- validateRequiredMainFields: function validateRequiredMainFields(value) {
3278
- return _validateRequiredMainFields(value, 'Weather');
3439
+
3440
+ callback();
3441
+ onBlur();
3442
+ }, [onBlur, name, setValue, shouldPreventUppercase]);
3443
+ var hasError = !!fieldErrors;
3444
+ return /*#__PURE__*/React__default["default"].createElement(reactHookForm.Controller, {
3445
+ render: function render(_a) {
3446
+ var field = _a.field;
3447
+ var displayValue = formatter ? formatter(field.value) : getDisplayValue(field.value, disabled);
3448
+ return /*#__PURE__*/React__default["default"].createElement(BaseTextField, {
3449
+ label: label,
3450
+ disabled: disabled,
3451
+ name: name,
3452
+ value: displayValue,
3453
+ inputRef: field.ref,
3454
+ onChange: function onChange(event) {
3455
+ return onChangeField(event, field.onChange);
3279
3456
  },
3280
- validateRequiredSub: validateRequiredSub,
3281
- validateWeatherField: function validateWeatherField$1(value) {
3282
- return validateWeatherField(value, getValues(fieldNames.visibility), !!isChangeGroup);
3283
- }
3284
- }
3285
- },
3286
- onBlur: function onBlur() {
3287
- var fields = isChangeGroup ? __spreadArray(__spreadArray([], __read(subFields)), __read(mainFields)) : [];
3288
- return trigger(__spreadArray(__spreadArray([], __read(fields)), [fieldNames.weather2, fieldNames.weather3, fieldNames.wind, fieldNames.cloud1]));
3289
- }
3290
- }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3291
- label: "Weather",
3292
- name: fieldNames.weather2,
3293
- disabled: disabled,
3294
- defaultValue: getDefaultValue('weather.weather2', field),
3295
- rules: {
3296
- validate: {
3297
- validateSecondWeatherField: function validateSecondWeatherField$1(value) {
3298
- return validateSecondWeatherField(getValues(fieldNames.weather1), value, getValues(fieldNames.visibility));
3299
- }
3300
- }
3301
- },
3302
- onBlur: function onBlur() {
3303
- var fields = isChangeGroup ? __spreadArray(__spreadArray([], __read(subFields)), __read(mainFields)) : [];
3304
- return trigger(__spreadArray(__spreadArray([], __read(fields)), [fieldNames.weather3, fieldNames.wind, fieldNames.cloud1]));
3305
- }
3306
- }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3307
- label: "Weather",
3308
- name: fieldNames.weather3,
3309
- disabled: disabled,
3310
- defaultValue: getDefaultValue('weather.weather3', field),
3311
- rules: {
3312
- validate: {
3313
- validateThirdWeatherField: function validateThirdWeatherField$1(value) {
3314
- return validateThirdWeatherField(getValues(fieldNames.weather1), getValues(fieldNames.weather2), value, getValues(fieldNames.visibility));
3315
- }
3316
- }
3317
- },
3318
- onBlur: function onBlur() {
3319
- return trigger([fieldNames.wind, fieldNames.cloud1]);
3320
- }
3321
- }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3322
- label: "Cloud",
3323
- name: fieldNames.cloud1,
3324
- disabled: disabled,
3325
- defaultValue: getDefaultValue('cloud.cloud1', field),
3326
- rules: {
3327
- validate: {
3328
- validateRequiredMainFields: function validateRequiredMainFields(value) {
3329
- return _validateRequiredMainFields(value, 'Clouds');
3457
+ onKeyDown: onKeyDown,
3458
+ error: hasError,
3459
+ onBlur: function onBlur(event) {
3460
+ return onBlurField(event, field.onBlur);
3330
3461
  },
3331
- validateRequiredSub: validateRequiredSub,
3332
- validateFirstCloud: function validateFirstCloud$1(value) {
3333
- return validateFirstCloud(value, getValues(fieldNames.visibility), getValues(fieldNames.weather1), getValues(fieldNames.weather2), getValues(fieldNames.weather3));
3334
- }
3335
- }
3462
+ inputProps: {
3463
+ maxLength: maxLength
3464
+ },
3465
+ autoFocus: autoFocus,
3466
+ shouldPreventUppercase: shouldPreventUppercase
3467
+ });
3336
3468
  },
3337
- onBlur: function onBlur() {
3338
- var fields = isChangeGroup ? __spreadArray(__spreadArray([], __read(subFields)), __read(mainFields)) : [];
3339
- return trigger(__spreadArray(__spreadArray([], __read(fields)), [fieldNames.cloud2, fieldNames.cloud3, fieldNames.cloud4]));
3340
- }
3341
- }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3342
- label: "Cloud",
3343
- name: fieldNames.cloud2,
3344
- disabled: disabled,
3345
- defaultValue: getDefaultValue('cloud.cloud2', field),
3346
- rules: {
3347
- validate: {
3348
- validateSecondCloud: function validateSecondCloud$1(value) {
3349
- return validateSecondCloud(getValues(fieldNames.cloud1), value, getValues(fieldNames.visibility));
3350
- }
3351
- }
3352
- },
3353
- onBlur: function onBlur() {
3354
- return trigger([fieldNames.cloud3, fieldNames.cloud4]);
3355
- }
3356
- }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3357
- label: "Cloud",
3358
- name: fieldNames.cloud3,
3359
- disabled: disabled,
3360
- defaultValue: getDefaultValue('cloud.cloud3', field),
3361
- rules: {
3362
- validate: {
3363
- validateThirdCloud: function validateThirdCloud$1(value) {
3364
- return validateThirdCloud(getValues(fieldNames.cloud1), getValues(fieldNames.cloud2), value, getValues(fieldNames.visibility));
3365
- }
3366
- }
3367
- },
3368
- onBlur: function onBlur() {
3369
- return trigger(fieldNames.cloud4);
3370
- }
3371
- }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3372
- label: "Cloud",
3373
- name: fieldNames.cloud4,
3374
- disabled: disabled,
3375
- defaultValue: getDefaultValue('cloud.cloud4', field),
3376
- rules: {
3377
- validate: {
3378
- validateFourthCloud: function validateFourthCloud$1(value) {
3379
- return validateFourthCloud(getValues(fieldNames.cloud1), getValues(fieldNames.cloud2), getValues(fieldNames.cloud3), value, getValues(fieldNames.visibility));
3380
- }
3381
- }
3382
- }
3383
- })), !disabled && /*#__PURE__*/React__default["default"].createElement(material.Grid, {
3384
- item: true,
3385
- container: true,
3386
- justifyContent: "flex-end",
3387
- alignItems: "flex-end",
3388
- xs: 24,
3389
- sm: 1,
3390
- sx: {
3391
- marginBottom: '16px'
3392
- },
3393
- columns: 24
3394
- }, /*#__PURE__*/React__default["default"].createElement(TafFormOptionsButton, {
3395
- isChangeGroup: isChangeGroup,
3396
- addChangeGroupBelow: addChangeGroupBelow,
3397
- addChangeGroupAbove: addChangeGroupAbove,
3398
- removeChangeGroup: function removeChangeGroup() {
3399
- return onRemoveChangeGroup(index);
3400
- },
3401
- clearRow: clearRow,
3402
- index: index
3403
- })));
3404
- });
3469
+ name: name,
3470
+ control: control,
3471
+ defaultValue: defaultValue,
3472
+ rules: rules
3473
+ });
3474
+ };
3405
3475
 
3406
3476
  /* *
3407
3477
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -3416,143 +3486,27 @@
3416
3486
  * See the License for the specific language governing permissions and
3417
3487
  * limitations under the License.
3418
3488
  *
3419
- * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3420
- * Copyright 2021 - Finnish Meteorological Institute (FMI)
3489
+ * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3490
+ * Copyright 2023 - Finnish Meteorological Institute (FMI)
3421
3491
  * */
3422
- var tafActionToDraftAction = function tafActionToDraftAction(tafAction) {
3423
- switch (tafAction) {
3424
- case 'AMEND':
3425
- case 'DRAFT_AMEND':
3426
- return 'DRAFT_AMEND';
3427
-
3428
- case 'CORRECT':
3429
- case 'DRAFT_CORRECT':
3430
- return 'DRAFT_CORRECT';
3431
-
3432
- default:
3433
- return 'DRAFT';
3434
- }
3435
- };
3436
-
3437
- var tafActionToPublishAction = function tafActionToPublishAction(tafAction) {
3438
- switch (tafAction) {
3439
- case 'AMEND':
3440
- case 'DRAFT_AMEND':
3441
- return 'AMEND';
3442
3492
 
3443
- case 'CORRECT':
3444
- case 'DRAFT_CORRECT':
3445
- return 'CORRECT';
3493
+ var invalidChangeMessage = 'Invalid Change input, only BECMG, TEMPO or FM are allowed';
3494
+ var invalidChangeProbCombinationMessage = 'A probability is only allowed in combination with TEMPO or an empty Change input'; // validations
3446
3495
 
3447
- default:
3448
- return 'PUBLISH';
3449
- }
3496
+ var validateChangeField = function validateChangeField(value) {
3497
+ var trimmedValue = getFieldValue(value);
3498
+ var isValid = trimmedValue === '' || trimmedValue === 'FM' || trimmedValue === 'TEMPO' || trimmedValue === 'BECMG';
3499
+ return isValid ? true : invalidChangeMessage;
3450
3500
  };
3501
+ var validateChangeFieldInterField = function validateChangeFieldInterField(value, valueProb) {
3502
+ var trimmedProbValue = getFieldValue(valueProb);
3503
+ var trimmedValue = getFieldValue(value);
3451
3504
 
3452
- var buttonsStyle = {
3453
- button: {
3454
- minWidth: {
3455
- xs: '56px',
3456
- sm: '64px'
3457
- },
3458
- width: {
3459
- xs: '56px',
3460
- sm: '64px'
3461
- },
3462
- marginLeft: {
3463
- xs: 0.5,
3464
- sm: 1
3465
- },
3466
- marginTop: 3,
3467
- marginBottom: 3
3505
+ if (trimmedProbValue !== '' && trimmedValue !== '' && trimmedValue !== 'TEMPO') {
3506
+ return invalidChangeProbCombinationMessage;
3468
3507
  }
3469
- };
3470
3508
 
3471
- var ViewModeButtons = function ViewModeButtons(_a) {
3472
- var canBe = _a.canBe,
3473
- onTafViewModeButtonPress = _a.onTafViewModeButtonPress;
3474
- return !canBe.includes('CANCELLED') && !canBe.includes('CORRECTED') && !canBe.includes('AMENDED') ? null : /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, canBe.includes('CANCELLED') && /*#__PURE__*/React__default["default"].createElement(material.Button, {
3475
- "data-testid": "canceltaf",
3476
- variant: "tertiary",
3477
- onClick: function onClick() {
3478
- return onTafViewModeButtonPress('CANCEL');
3479
- }
3480
- }, "Cancel"), canBe.includes('CORRECTED') && /*#__PURE__*/React__default["default"].createElement(material.Button, {
3481
- "data-testid": "correcttaf",
3482
- variant: "tertiary",
3483
- onClick: function onClick() {
3484
- return onTafViewModeButtonPress('CORRECT');
3485
- }
3486
- }, "Correct"), canBe.includes('AMENDED') && /*#__PURE__*/React__default["default"].createElement(material.Button, {
3487
- "data-testid": "amendtaf",
3488
- variant: "tertiary",
3489
- onClick: function onClick() {
3490
- return onTafViewModeButtonPress('AMEND');
3491
- }
3492
- }, "Amend"));
3493
- };
3494
-
3495
- var TafFormButtons = function TafFormButtons(_a) {
3496
- var _b = _a.isFormDisabled,
3497
- isFormDisabled = _b === void 0 ? false : _b,
3498
- tafAction = _a.tafAction,
3499
- _c = _a.canBe,
3500
- canBe = _c === void 0 ? [] : _c,
3501
- onTafEditModeButtonPress = _a.onTafEditModeButtonPress,
3502
- onTafViewModeButtonPress = _a.onTafViewModeButtonPress;
3503
- return /*#__PURE__*/React__default["default"].createElement(material.Grid, {
3504
- container: true,
3505
- justifyContent: "flex-end",
3506
- sx: buttonsStyle,
3507
- columns: 24
3508
- }, /*#__PURE__*/React__default["default"].createElement(material.Grid, {
3509
- item: true,
3510
- container: true,
3511
- justifyContent: "flex-end",
3512
- columns: 24,
3513
- xs: 24,
3514
- sm: 23
3515
- }, isFormDisabled ? /*#__PURE__*/React__default["default"].createElement(ViewModeButtons, {
3516
- canBe: canBe,
3517
- onTafViewModeButtonPress: onTafViewModeButtonPress
3518
- }) : /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(material.Button, {
3519
- "data-testid": "cleartaf",
3520
- variant: "tertiary",
3521
- onClick: function onClick() {
3522
- // Simply discard the changes and close the dialog.
3523
- onTafEditModeButtonPress('CLEAR');
3524
- }
3525
- }, "Clear"), /*#__PURE__*/React__default["default"].createElement(material.Button, {
3526
- "data-testid": "savedrafttaf",
3527
- variant: "tertiary",
3528
- onClick: function onClick() {
3529
- /* Save the TAF as draft:
3530
- if action NEW or DRAFT - new status will be DRAFT -- default
3531
- if action AMEND - new status will be DRAFT_AMENDED
3532
- if action CORRECT - new status will be DRAFT_CORRECTED
3533
- if action DRAFT_AMEND - new status will be DRAFT_AMENDED
3534
- if action DRAFT_CORRECT - new status will be DRAFT_CORRECTED
3535
- */
3536
- onTafEditModeButtonPress(tafActionToDraftAction(tafAction));
3537
- }
3538
- }, "Save"), /*#__PURE__*/React__default["default"].createElement(material.Button, {
3539
- "data-testid": "publishtaf",
3540
- variant: "tertiary",
3541
- onClick: function onClick() {
3542
- /* Publish the TAF:
3543
- if action NEW or DRAFT - new status will be PUBLISHED -- default
3544
- if action AMEND - new status will be AMENDED
3545
- if action CORRECT - new status will be CORRECTED
3546
- if action DRAFT_AMEND - new status will be AMENDED
3547
- if action DRAFT_CORRECT - new status will be CORRECTED
3548
- */
3549
- onTafEditModeButtonPress(tafActionToPublishAction(tafAction));
3550
- }
3551
- }, "Publish"))), /*#__PURE__*/React__default["default"].createElement(material.Grid, {
3552
- item: true,
3553
- columns: 24,
3554
- sm: 1
3555
- }));
3509
+ return true;
3556
3510
  };
3557
3511
 
3558
3512
  /* *
@@ -3568,30 +3522,16 @@
3568
3522
  * See the License for the specific language governing permissions and
3569
3523
  * limitations under the License.
3570
3524
  *
3571
- * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3572
- * Copyright 2021 - Finnish Meteorological Institute (FMI)
3525
+ * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3526
+ * Copyright 2023 - Finnish Meteorological Institute (FMI)
3573
3527
  * */
3574
3528
 
3575
- var DragHandle = function DragHandle(_a) {
3576
- var _b = _a.isSorting,
3577
- isSorting = _b === void 0 ? false : _b,
3578
- _c = _a.isDisabled,
3579
- isDisabled = _c === void 0 ? false : _c,
3580
- index = _a.index;
3581
- return /*#__PURE__*/React__default["default"].createElement(material.IconButton, {
3582
- className: "handle",
3583
- "data-testid": "dragHandle-" + index,
3584
- disableRipple: true,
3585
- disabled: isDisabled,
3586
- size: "large",
3587
- sx: {
3588
- backgroundColor: 'transparent',
3589
- '&:hover': {
3590
- backgroundColor: 'transparent'
3591
- },
3592
- cursor: isSorting ? 'grabbing' : 'grab'
3593
- }
3594
- }, /*#__PURE__*/React__default["default"].createElement(theme.DragHandle, null));
3529
+ var invalidProbabilityMessage = 'Invalid Probability input, only PROB30 or PROB40 are allowed'; // validations
3530
+
3531
+ var validateProbabilityField = function validateProbabilityField(value) {
3532
+ var trimmedValue = getFieldValue(value);
3533
+ var isValid = trimmedValue === '' || trimmedValue === 'PROB30' || trimmedValue === 'PROB40';
3534
+ return isValid ? true : invalidProbabilityMessage;
3595
3535
  };
3596
3536
 
3597
3537
  /* *
@@ -3610,365 +3550,499 @@
3610
3550
  * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3611
3551
  * Copyright 2022 - Finnish Meteorological Institute (FMI)
3612
3552
  * */
3613
- var getCustomError = function getCustomError(error, isChangeGroup, rowIndex) {
3614
- return __assign(__assign({}, error), {
3615
- isChangeGroup: isChangeGroup,
3616
- rowIndex: rowIndex
3617
- });
3618
- };
3619
- var getIssuesLabel = function getIssuesLabel(sumOfErrors) {
3620
- switch (sumOfErrors) {
3621
- case 0:
3622
- return '0 issues';
3623
-
3624
- case 1:
3625
- return '1 issue';
3626
3553
 
3627
- default:
3628
- return sumOfErrors + " issues";
3629
- }
3554
+ var TafFormOptionsButton = function TafFormOptionsButton(_a) {
3555
+ var isChangeGroup = _a.isChangeGroup,
3556
+ addChangeGroupBelow = _a.addChangeGroupBelow,
3557
+ addChangeGroupAbove = _a.addChangeGroupAbove,
3558
+ removeChangeGroup = _a.removeChangeGroup,
3559
+ clearRow = _a.clearRow,
3560
+ index = _a.index;
3561
+ var insertAbove = {
3562
+ text: 'Insert 1 row above',
3563
+ icon: /*#__PURE__*/React__namespace.createElement(theme.Add, null),
3564
+ action: addChangeGroupAbove
3565
+ };
3566
+ var insertBelow = {
3567
+ text: 'Insert 1 row below',
3568
+ icon: /*#__PURE__*/React__namespace.createElement(theme.Add, null),
3569
+ action: addChangeGroupBelow
3570
+ };
3571
+ var deleteRow = {
3572
+ text: 'Delete row',
3573
+ icon: /*#__PURE__*/React__namespace.createElement(theme.Delete, null),
3574
+ action: removeChangeGroup
3575
+ };
3576
+ var clear = {
3577
+ text: 'Clear row',
3578
+ icon: /*#__PURE__*/React__namespace.createElement(theme.Close, null),
3579
+ action: clearRow
3580
+ };
3581
+ var menuItemsBaseForecast = [insertBelow, clear];
3582
+ var menuItemsChangeGroup = [insertAbove, insertBelow, deleteRow, clear];
3583
+ return /*#__PURE__*/React__namespace.createElement(shared.ToggleMenu, {
3584
+ buttonTestId: "tafFormOptions[" + index + "]",
3585
+ buttonSx: {
3586
+ marginTop: '10px',
3587
+ marginLeft: '4px'
3588
+ },
3589
+ menuItems: isChangeGroup ? menuItemsChangeGroup : menuItemsBaseForecast
3590
+ });
3630
3591
  };
3631
- var getErrorValues = function getErrorValues(fieldErrors, isChangeGroup, rowIndex) {
3632
- if (isChangeGroup === void 0) {
3633
- isChangeGroup = false;
3634
- }
3635
3592
 
3636
- if (rowIndex === void 0) {
3637
- rowIndex = -1;
3593
+ var getDefaultValue = function getDefaultValue(fieldName, data) {
3594
+ if (!data) {
3595
+ return '';
3638
3596
  }
3639
3597
 
3640
- if (!fieldErrors) return [];
3641
- return Object.keys(fieldErrors).reduce(function (list, key) {
3642
- var error = __assign({}, fieldErrors[key]);
3643
-
3644
- if (error.ref) {
3645
- return list.concat(getCustomError(error, isChangeGroup, rowIndex));
3646
- }
3598
+ return formFields.getDeepProperty(fieldName.split('.'), data) || '';
3599
+ };
3647
3600
 
3648
- return list.concat(getErrorValues(error, isChangeGroup, rowIndex));
3649
- }, []);
3601
+ var getRequiredCrossFields = function getRequiredCrossFields(fieldNames) {
3602
+ return [[fieldNames.valid], [fieldNames.change, fieldNames.probability], [fieldNames.wind, fieldNames.visibility, fieldNames.weather1, fieldNames.cloud1] // sub fields
3603
+ ];
3650
3604
  };
3651
- var filterDuplicateErrors = function filterDuplicateErrors(errors) {
3652
- return errors.reduce(function (list, error) {
3653
- // check on type validateRequiredSub and validateRequiredMainOptional since these are giving 'duplicates'
3654
- if (error.type === 'validateRequiredSub') {
3655
- var exist = list.find(function (e) {
3656
- return e.type === 'validateRequiredSub' && e.rowIndex === error.rowIndex;
3657
- });
3658
- return exist ? list : list.concat(error);
3659
- }
3660
3605
 
3661
- if (error.type === 'validateRequiredMainOptional') {
3662
- var exist = list.find(function (e) {
3663
- return e.type === 'validateRequiredMainOptional' && e.rowIndex === error.rowIndex;
3664
- });
3665
- return exist ? list : list.concat(error);
3666
- }
3606
+ var TafFormRow = /*#__PURE__*/React__default["default"].forwardRef(function (_a, ref) {
3607
+ var isNotRequiredForAction = _a.isNotRequiredForAction,
3608
+ _b = _a.isChangeGroup,
3609
+ isChangeGroup = _b === void 0 ? false : _b,
3610
+ _c = _a.disabled,
3611
+ disabled = _c === void 0 ? false : _c,
3612
+ _d = _a.index,
3613
+ index = _d === void 0 ? -1 : _d,
3614
+ onRemoveChangeGroup = _a.onRemoveChangeGroup,
3615
+ _e = _a.field,
3616
+ field = _e === void 0 ? null : _e,
3617
+ _f = _a.dragHandle,
3618
+ dragHandle = _f === void 0 ? null : _f,
3619
+ onAddChangeGroupBelow = _a.onAddChangeGroupBelow,
3620
+ onAddChangeGroupAbove = _a.onAddChangeGroupAbove,
3621
+ onClearRow = _a.onClearRow,
3622
+ props = __rest(_a, ["isNotRequiredForAction", "isChangeGroup", "disabled", "index", "onRemoveChangeGroup", "field", "dragHandle", "onAddChangeGroupBelow", "onAddChangeGroupAbove", "onClearRow"]);
3667
3623
 
3668
- return list.concat(error);
3669
- }, []);
3670
- };
3671
- var getErrors = function getErrors(errors) {
3672
- var errorList = Object.keys(errors).reduce(function (list, key) {
3673
- var errorValue = errors[key]; // changeGroups
3624
+ var namePrefix = !isChangeGroup ? 'baseForecast' : "changeGroups[" + index + "]";
3625
+ var fieldNames = getFieldNames(isChangeGroup, index);
3674
3626
 
3675
- if (Array.isArray(errorValue)) {
3676
- var errorValues = errorValue.reduce(function (changeGroupErrors, changeGroupError, index) {
3677
- return changeGroupErrors.concat(getErrorValues(changeGroupError, true, index));
3678
- }, []);
3679
- return list.concat.apply(list, __spreadArray([], __read(errorValues)));
3680
- } // baseForecast
3627
+ var _g = reactHookForm.useFormContext(),
3628
+ getValues = _g.getValues,
3629
+ trigger = _g.trigger; // cross-field required validation
3681
3630
 
3682
3631
 
3683
- return list.concat(getErrorValues(errorValue, false, -1));
3684
- }, []);
3685
- return errorList;
3686
- };
3632
+ var _h = __read(getRequiredCrossFields(fieldNames), 3),
3633
+ mainFields = _h[0],
3634
+ mainOptionalFields = _h[1],
3635
+ subFields = _h[2];
3687
3636
 
3688
- /* *
3689
- * Licensed under the Apache License, Version 2.0 (the "License");
3690
- * you may not use this file except in compliance with the License.
3691
- * You may obtain a copy of the License at
3692
- *
3693
- * http://www.apache.org/licenses/LICENSE-2.0
3694
- *
3695
- * Unless required by applicable law or agreed to in writing, software
3696
- * distributed under the License is distributed on an "AS IS" BASIS,
3697
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3698
- * See the License for the specific language governing permissions and
3699
- * limitations under the License.
3700
- *
3701
- * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3702
- * Copyright 2021 - Finnish Meteorological Institute (FMI)
3703
- * */
3637
+ var hasFieldsValue = function hasFieldsValue(fields) {
3638
+ return fields.map(getValues).find(function (field) {
3639
+ return !!field;
3640
+ });
3641
+ }; // Used to validate the required field for change groups: Valid
3704
3642
 
3705
- var IssuesButton = function IssuesButton(_a) {
3706
- var _b = _a.errors,
3707
- errors = _b === void 0 ? {} : _b,
3708
- _c = _a.isIssuesPaneOpen,
3709
- isIssuesPaneOpen = _c === void 0 ? false : _c,
3710
- _d = _a.setIsIssuesPaneOpen,
3711
- setIsIssuesPaneOpen = _d === void 0 ? function () {
3712
- return null;
3713
- } : _d;
3714
- var errorList = filterDuplicateErrors(getErrors(errors));
3715
- var totalErrors = errorList.length;
3716
- var errorStatus = totalErrors > 0 ? 'error' : 'success';
3717
- var buttonColor = "geowebColors.functional." + errorStatus;
3718
3643
 
3719
- var toggleIssuesPane = function toggleIssuesPane(newPosition) {
3720
- return setIsIssuesPaneOpen(!isIssuesPaneOpen, newPosition);
3721
- };
3644
+ var validateRequiredMain = function validateRequiredMain(value) {
3645
+ return isNotRequiredForAction(value) !== true && isChangeGroup && !value.length && (hasFieldsValue(subFields) || hasFieldsValue(mainFields) || hasFieldsValue(mainOptionalFields)) ? 'Valid is required' : true;
3646
+ }; // Used to ensure either probability or change is entered, or both
3722
3647
 
3723
- var onClickButton = function onClickButton(event) {
3724
- var _a;
3725
3648
 
3726
- var _b = event.currentTarget.getBoundingClientRect(),
3727
- left = _b.left,
3728
- top = _b.top;
3649
+ var validateRequiredMainOptional = function validateRequiredMainOptional(value) {
3650
+ return isNotRequiredForAction(value) !== true && isChangeGroup && (hasFieldsValue(mainFields) || hasFieldsValue(subFields)) && !hasFieldsValue(mainOptionalFields) ? 'Probability or change is required' : true;
3651
+ }; // Used to ensure one wind, visibility, weather or cloud is entered when start editing a changegroup and all of these are empty
3729
3652
 
3730
- var parentOffset = ((_a = document.getElementById('tafmodule')) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) || {
3731
- top: 0,
3732
- left: 0
3733
- };
3734
- var newPosition = {
3735
- left: left - parentOffset.left + 100,
3736
- top: top - parentOffset.top
3737
- };
3738
- toggleIssuesPane(newPosition);
3739
- };
3740
3653
 
3741
- return /*#__PURE__*/React__namespace.createElement(shared.CustomTooltip, {
3742
- title: "View details"
3743
- }, /*#__PURE__*/React__namespace.createElement(material.Chip, {
3744
- "data-testid": "issuesButton",
3745
- className: "status-" + errorStatus,
3746
- size: "small",
3747
- label: getIssuesLabel(totalErrors),
3748
- onClick: onClickButton,
3749
- sx: {
3750
- width: '74px',
3751
- color: '#ffffff',
3752
- backgroundColor: buttonColor,
3753
- '&:hover': {
3754
- backgroundColor: buttonColor
3755
- },
3756
- '&:focus': {
3757
- backgroundColor: buttonColor
3758
- },
3759
- fontSize: 12
3760
- }
3761
- }));
3762
- };
3654
+ var validateRequiredSub = function validateRequiredSub(value) {
3655
+ return isNotRequiredForAction(value) !== true && isChangeGroup && (hasFieldsValue(mainFields) || hasFieldsValue(mainOptionalFields)) && !hasFieldsValue(subFields) ? 'Wind, visibility, weather or cloud is required' : true;
3656
+ }; // Used to validate the combination of change group and wind, visibility, weather and/or cloud data entered
3763
3657
 
3764
- var getPaneTitle = function getPaneTitle(sumOfErrors) {
3765
- switch (sumOfErrors) {
3766
- case 0:
3767
- return 'Looks good';
3768
3658
 
3769
- case 1:
3770
- return 'There is an issue to address';
3659
+ var _validateRequiredMainFields = function validateRequiredMainFields(value, fieldName) {
3660
+ var changeField = getValues(namePrefix + ".change");
3661
+ var visibilityField = getValues(namePrefix + ".visibility");
3662
+ var isFM = changeField && changeField.trim() === 'FM';
3663
+ var isCAVOK = visibilityField && visibilityField.trim() === 'CAVOK';
3771
3664
 
3772
- default:
3773
- return 'There are a few issues to address';
3774
- }
3775
- };
3665
+ if (isNotRequiredForAction(value) !== true && !value.length) {
3666
+ if (isChangeGroup && isFM || !isChangeGroup) {
3667
+ // exception for CavOK
3668
+ if (isCAVOK && (fieldName === 'Clouds' || fieldName === 'Weather')) {
3669
+ return true;
3670
+ } // exception for visibility > 5000
3776
3671
 
3777
- var humanizeErrorMessage = function humanizeErrorMessage(errorTitle, fieldNumberedValue) {
3778
- if (fieldNumberedValue !== undefined && fieldNumberedValue >= 0) {
3779
- // when name contains a number we assume it's a formgroup and we add a index +1 for human readability
3780
- var fieldNumber = fieldNumberedValue + 1;
3781
- return errorTitle + " " + fieldNumber;
3782
- }
3783
3672
 
3784
- return errorTitle;
3785
- };
3786
- var getErrorMessage = function getErrorMessage(error, index) {
3787
- var errorTitleCategory = error.isChangeGroup ? 'Changegroups' : 'Baseforecast';
3788
- var fieldErrorTitle = humanizeErrorMessage(errorTitleCategory, error.rowIndex);
3789
- return index + 1 + ". " + fieldErrorTitle + ": " + error.message;
3790
- };
3791
- var MODAL_DIALOG_ELEMENT = 'modal-dialog';
3792
- var useIssuesPane = function useIssuesPane() {
3793
- var _a = __read(React__namespace.useState(false), 2),
3794
- isIssuesPaneOpen = _a[0],
3795
- setIsIssuesPaneOpen = _a[1];
3673
+ if (visibilityField && parseInt(visibilityField.trim(), 10) >= 5000 && fieldName === 'Weather') {
3674
+ return true;
3675
+ }
3796
3676
 
3797
- var _b = __read(React__namespace.useState(null), 2),
3798
- startPosition = _b[0],
3799
- setStartPosition = _b[1];
3677
+ return fieldName + " is required";
3678
+ }
3679
+ }
3800
3680
 
3801
- var onToggleIssuesPane = function onToggleIssuesPane(isOpen, newPosition) {
3802
- if (!startPosition) {
3803
- setStartPosition(newPosition);
3681
+ return true;
3682
+ };
3683
+
3684
+ var validatePreviousRow = React__default["default"].useCallback(function () {
3685
+ if (isChangeGroup && index > 0) {
3686
+ var _a = getValues(),
3687
+ validDateEnd = _a.validDateEnd,
3688
+ validDateStart = _a.validDateStart,
3689
+ changeGroups = _a.changeGroups;
3690
+
3691
+ var currentChangeGroup = changeGroups[index];
3692
+ var previousChangeGroup = changeGroups[index - 1];
3693
+ return validatePreviousChangeGroup(currentChangeGroup, previousChangeGroup, validDateStart, validDateEnd);
3694
+ }
3695
+
3696
+ return true;
3697
+ }, [index, isChangeGroup, getValues]);
3698
+
3699
+ var getFieldFromRow = function getFieldFromRow(fieldname, rowIndex) {
3700
+ var indexedFieldName = "changeGroups[" + rowIndex + "]." + fieldname;
3701
+ var rowValue = getValues(indexedFieldName);
3702
+ return rowValue ? [indexedFieldName] : [];
3703
+ };
3704
+
3705
+ var getValidFieldFromNextRow = function getValidFieldFromNextRow() {
3706
+ return getFieldFromRow('valid', index + 1);
3707
+ };
3708
+
3709
+ var validateNextRows = React__default["default"].useCallback(function () {
3710
+ if (isChangeGroup) {
3711
+ var _a = getValues(),
3712
+ validDateEnd = _a.validDateEnd,
3713
+ validDateStart = _a.validDateStart,
3714
+ changeGroups = _a.changeGroups;
3715
+
3716
+ var currentChangeGroup = changeGroups[index];
3717
+ var nextChangeGroups = changeGroups.slice(index + 1);
3718
+ return validateOverlapWithFM(currentChangeGroup, nextChangeGroups, validDateStart, validDateEnd);
3719
+ }
3720
+
3721
+ return true;
3722
+ }, [index, isChangeGroup, getValues]);
3723
+
3724
+ var getPreviousValidFields = function getPreviousValidFields(rowIndex) {
3725
+ var changeGroups = getValues().changeGroups;
3726
+ var previousChangeGroups = changeGroups.slice(0, rowIndex);
3727
+ var validFields = previousChangeGroups.map(function (_element, index) {
3728
+ return getFieldFromRow('valid', index)[0];
3729
+ });
3730
+ return validFields;
3731
+ };
3732
+
3733
+ var addChangeGroupBelow = React__default["default"].useCallback(function () {
3734
+ onAddChangeGroupBelow(index);
3735
+ }, [onAddChangeGroupBelow, index]);
3736
+ var addChangeGroupAbove = React__default["default"].useCallback(function () {
3737
+ onAddChangeGroupAbove(index);
3738
+ }, [onAddChangeGroupAbove, index]);
3739
+ var clearRow = React__default["default"].useCallback(function () {
3740
+ onClearRow(index);
3741
+ }, [onClearRow, index]);
3742
+ return /*#__PURE__*/React__default["default"].createElement(material.Grid, __assign({
3743
+ sx: {
3744
+ marginTop: '8px',
3745
+ backgroundColor: 'geowebColors.cards.cardContainer',
3746
+ position: 'relative',
3747
+ '&.sortable-chosen': {
3748
+ boxShadow: 1
3749
+ },
3750
+ '&.sortable-ghost': {
3751
+ opacity: 0.5
3752
+ }
3753
+ },
3754
+ justifyContent: "flex-start",
3755
+ "data-testid": "row-" + namePrefix,
3756
+ container: true,
3757
+ ref: ref
3758
+ }, props, {
3759
+ className: "formRow"
3760
+ }), /*#__PURE__*/React__default["default"].createElement(material.Grid, {
3761
+ columns: 24,
3762
+ item: true,
3763
+ container: true,
3764
+ justifyContent: "flex-end",
3765
+ xs: 24,
3766
+ sm: 23
3767
+ }, !isChangeGroup && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3768
+ label: "Type",
3769
+ name: fieldNames.messageType,
3770
+ disabled: true
3771
+ }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3772
+ label: "Location",
3773
+ name: "location",
3774
+ disabled: true
3775
+ }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3776
+ formatter: formatIssueTime,
3777
+ label: "Issue time",
3778
+ name: "issueDate",
3779
+ disabled: true,
3780
+ shouldPreventUppercase: true
3781
+ })), isChangeGroup && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(material.Box, {
3782
+ sx: {
3783
+ width: 56,
3784
+ marginRight: '2px'
3785
+ }
3786
+ }, !disabled && dragHandle), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3787
+ label: "Prob",
3788
+ name: fieldNames.probability,
3789
+ disabled: disabled,
3790
+ defaultValue: getDefaultValue('probability', field),
3791
+ rules: {
3792
+ validate: {
3793
+ validateRequiredMainOptional: validateRequiredMainOptional,
3794
+ validateProbabilityField: validateProbabilityField
3795
+ }
3796
+ },
3797
+ autoComplete: [{
3798
+ key: '3',
3799
+ value: 'PROB30'
3800
+ }, {
3801
+ key: '4',
3802
+ value: 'PROB40'
3803
+ }],
3804
+ onBlur: function onBlur() {
3805
+ if (isChangeGroup) {
3806
+ var nextValidFieldName = getValidFieldFromNextRow();
3807
+ trigger(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(subFields)), __read(mainOptionalFields)), __read(mainFields)), __read(nextValidFieldName)));
3808
+ }
3809
+ }
3810
+ }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3811
+ label: "Change",
3812
+ name: fieldNames.change,
3813
+ disabled: disabled,
3814
+ defaultValue: getDefaultValue('change', field),
3815
+ rules: {
3816
+ validate: {
3817
+ validateRequiredMainOptional: validateRequiredMainOptional,
3818
+ validateChangeField: validateChangeField,
3819
+ validateChangeFieldInterField: function validateChangeFieldInterField$1(value) {
3820
+ return validateChangeFieldInterField(value, getValues(fieldNames.probability));
3821
+ }
3822
+ }
3823
+ },
3824
+ autoComplete: [{
3825
+ key: 'T',
3826
+ value: 'TEMPO'
3827
+ }, {
3828
+ key: 'B',
3829
+ value: 'BECMG'
3830
+ }, {
3831
+ key: 'F',
3832
+ value: 'FM'
3833
+ }],
3834
+ onBlur: function onBlur() {
3835
+ if (isChangeGroup) {
3836
+ var nextValidFieldName = getValidFieldFromNextRow();
3837
+ var previousValidFieldNames = getPreviousValidFields(index);
3838
+ trigger(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(subFields)), __read(mainOptionalFields)), __read(mainFields)), __read(nextValidFieldName)), __read(previousValidFieldNames)));
3839
+ }
3840
+ }
3841
+ })), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3842
+ label: "Valid",
3843
+ name: fieldNames.valid,
3844
+ // always disabled for baseforecast row
3845
+ disabled: !isChangeGroup ? true : disabled,
3846
+ defaultValue: getDefaultValue('valid', field),
3847
+ rules: {
3848
+ validate: {
3849
+ validateRequiredMain: validateRequiredMain,
3850
+ validateValidField: function validateValidField$1(value) {
3851
+ return isChangeGroup ? validateValidField(value, getValues('validDateStart'), getValues('validDateEnd')) : true;
3852
+ },
3853
+ validateValidChangeGroupInterField: function validateValidChangeGroupInterField$1(value) {
3854
+ return isChangeGroup ? validateValidChangeGroupInterField(value, getValues(fieldNames.change), getValues(fieldNames.probability), getValues('validDateStart'), getValues('validDateEnd')) : true;
3855
+ },
3856
+ validatePreviousRow: validatePreviousRow,
3857
+ validateNextRows: validateNextRows
3858
+ }
3859
+ },
3860
+ onBlur: function onBlur() {
3861
+ if (isChangeGroup) {
3862
+ var nextValidFieldName = getValidFieldFromNextRow();
3863
+ var previousValidFieldNames = getPreviousValidFields(index);
3864
+ trigger(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(subFields)), __read(mainOptionalFields)), __read(mainFields)), __read(nextValidFieldName)), __read(previousValidFieldNames)));
3865
+ }
3866
+ }
3867
+ }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3868
+ label: "Wind",
3869
+ name: fieldNames.wind,
3870
+ disabled: disabled,
3871
+ defaultValue: getDefaultValue('wind', field),
3872
+ rules: {
3873
+ validate: {
3874
+ validateRequiredMainFields: function validateRequiredMainFields(value) {
3875
+ return _validateRequiredMainFields(value, 'Wind');
3876
+ },
3877
+ validateRequiredSub: validateRequiredSub,
3878
+ validateWindField: function validateWindField$1(value) {
3879
+ return validateWindField(value, getValues(fieldNames.weather1), getValues(fieldNames.weather2), getValues(fieldNames.weather3));
3880
+ }
3881
+ }
3882
+ },
3883
+ onBlur: function onBlur() {
3884
+ if (isChangeGroup) {
3885
+ trigger(__spreadArray(__spreadArray([], __read(subFields)), __read(mainFields)));
3886
+ }
3887
+ },
3888
+ autoFocus: !isChangeGroup
3889
+ }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3890
+ label: "Visibility",
3891
+ name: fieldNames.visibility,
3892
+ disabled: disabled,
3893
+ defaultValue: getDefaultValue('visibility', field),
3894
+ rules: {
3895
+ validate: {
3896
+ validateRequiredMainFields: function validateRequiredMainFields(value) {
3897
+ return _validateRequiredMainFields(value, 'Visibility');
3898
+ },
3899
+ validateRequiredSub: validateRequiredSub,
3900
+ validateVisibilityField: validateVisibilityField
3901
+ }
3902
+ },
3903
+ autoComplete: [{
3904
+ key: 'C',
3905
+ value: 'CAVOK'
3906
+ }],
3907
+ onBlur: function onBlur() {
3908
+ var fields = isChangeGroup ? __spreadArray(__spreadArray([], __read(subFields)), __read(mainFields)) : subFields;
3909
+ trigger(__spreadArray(__spreadArray([], __read(fields)), [fieldNames.weather1, fieldNames.weather2, fieldNames.weather3]));
3910
+ }
3911
+ }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3912
+ label: "Weather",
3913
+ name: fieldNames.weather1,
3914
+ disabled: disabled,
3915
+ defaultValue: getDefaultValue('weather.weather1', field),
3916
+ rules: {
3917
+ validate: {
3918
+ validateRequiredMainFields: function validateRequiredMainFields(value) {
3919
+ return _validateRequiredMainFields(value, 'Weather');
3920
+ },
3921
+ validateRequiredSub: validateRequiredSub,
3922
+ validateWeatherField: function validateWeatherField$1(value) {
3923
+ return validateWeatherField(value, getValues(fieldNames.visibility), !!isChangeGroup);
3924
+ }
3925
+ }
3926
+ },
3927
+ onBlur: function onBlur() {
3928
+ var fields = isChangeGroup ? __spreadArray(__spreadArray([], __read(subFields)), __read(mainFields)) : [];
3929
+ return trigger(__spreadArray(__spreadArray([], __read(fields)), [fieldNames.weather2, fieldNames.weather3, fieldNames.wind, fieldNames.cloud1]));
3930
+ }
3931
+ }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3932
+ label: "Weather",
3933
+ name: fieldNames.weather2,
3934
+ disabled: disabled,
3935
+ defaultValue: getDefaultValue('weather.weather2', field),
3936
+ rules: {
3937
+ validate: {
3938
+ validateSecondWeatherField: function validateSecondWeatherField$1(value) {
3939
+ return validateSecondWeatherField(getValues(fieldNames.weather1), value, getValues(fieldNames.visibility));
3940
+ }
3941
+ }
3942
+ },
3943
+ onBlur: function onBlur() {
3944
+ var fields = isChangeGroup ? __spreadArray(__spreadArray([], __read(subFields)), __read(mainFields)) : [];
3945
+ return trigger(__spreadArray(__spreadArray([], __read(fields)), [fieldNames.weather3, fieldNames.wind, fieldNames.cloud1]));
3946
+ }
3947
+ }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3948
+ label: "Weather",
3949
+ name: fieldNames.weather3,
3950
+ disabled: disabled,
3951
+ defaultValue: getDefaultValue('weather.weather3', field),
3952
+ rules: {
3953
+ validate: {
3954
+ validateThirdWeatherField: function validateThirdWeatherField$1(value) {
3955
+ return validateThirdWeatherField(getValues(fieldNames.weather1), getValues(fieldNames.weather2), value, getValues(fieldNames.visibility));
3956
+ }
3957
+ }
3958
+ },
3959
+ onBlur: function onBlur() {
3960
+ return trigger([fieldNames.wind, fieldNames.cloud1]);
3961
+ }
3962
+ }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3963
+ label: "Cloud",
3964
+ name: fieldNames.cloud1,
3965
+ disabled: disabled,
3966
+ defaultValue: getDefaultValue('cloud.cloud1', field),
3967
+ rules: {
3968
+ validate: {
3969
+ validateRequiredMainFields: function validateRequiredMainFields(value) {
3970
+ return _validateRequiredMainFields(value, 'Clouds');
3971
+ },
3972
+ validateRequiredSub: validateRequiredSub,
3973
+ validateFirstCloud: function validateFirstCloud$1(value) {
3974
+ return validateFirstCloud(value, getValues(fieldNames.visibility), getValues(fieldNames.weather1), getValues(fieldNames.weather2), getValues(fieldNames.weather3));
3975
+ }
3976
+ }
3977
+ },
3978
+ onBlur: function onBlur() {
3979
+ var fields = isChangeGroup ? __spreadArray(__spreadArray([], __read(subFields)), __read(mainFields)) : [];
3980
+ return trigger(__spreadArray(__spreadArray([], __read(fields)), [fieldNames.cloud2, fieldNames.cloud3, fieldNames.cloud4]));
3981
+ }
3982
+ }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3983
+ label: "Cloud",
3984
+ name: fieldNames.cloud2,
3985
+ disabled: disabled,
3986
+ defaultValue: getDefaultValue('cloud.cloud2', field),
3987
+ rules: {
3988
+ validate: {
3989
+ validateSecondCloud: function validateSecondCloud$1(value) {
3990
+ return validateSecondCloud(getValues(fieldNames.cloud1), value, getValues(fieldNames.visibility));
3991
+ }
3992
+ }
3993
+ },
3994
+ onBlur: function onBlur() {
3995
+ return trigger([fieldNames.cloud3, fieldNames.cloud4]);
3804
3996
  }
3805
-
3806
- setIsIssuesPaneOpen(isOpen);
3807
- };
3808
-
3809
- var onCloseIssuesPane = function onCloseIssuesPane() {
3810
- return setIsIssuesPaneOpen(false);
3811
- };
3812
-
3813
- return {
3814
- isIssuesPaneOpen: isIssuesPaneOpen,
3815
- startPosition: startPosition,
3816
- onToggleIssuesPane: onToggleIssuesPane,
3817
- onCloseIssuesPane: onCloseIssuesPane
3818
- };
3819
- };
3820
-
3821
- var IssuesPane = function IssuesPane(_a) {
3822
- var _b = _a.errorList,
3823
- errorList = _b === void 0 ? [] : _b,
3824
- isOpen = _a.isOpen,
3825
- handleClose = _a.handleClose,
3826
- _c = _a.startPosition,
3827
- startPosition = _c === void 0 ? {
3828
- left: 20,
3829
- top: 50
3830
- } : _c;
3831
- var rootElement = document.getElementById(MODAL_DIALOG_ELEMENT) || document.body;
3832
- return /*#__PURE__*/ReactDOM__default["default"].createPortal( /*#__PURE__*/React__namespace.createElement(shared.ToolContainerDraggable, {
3833
- startSize: {
3834
- width: '577px',
3835
- height: '200px'
3997
+ }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
3998
+ label: "Cloud",
3999
+ name: fieldNames.cloud3,
4000
+ disabled: disabled,
4001
+ defaultValue: getDefaultValue('cloud.cloud3', field),
4002
+ rules: {
4003
+ validate: {
4004
+ validateThirdCloud: function validateThirdCloud$1(value) {
4005
+ return validateThirdCloud(getValues(fieldNames.cloud1), getValues(fieldNames.cloud2), value, getValues(fieldNames.visibility));
4006
+ }
4007
+ }
3836
4008
  },
3837
- startPosition: startPosition,
3838
- minWidth: 300,
3839
- onClose: handleClose,
3840
- title: getPaneTitle(errorList.length),
3841
- headerSize: "xs",
3842
- isOpen: isOpen,
3843
- "data-testid": "moveable-issues-pane",
3844
- bounds: "parent"
3845
- }, /*#__PURE__*/React__namespace.createElement(material.Box, {
3846
- component: "div",
3847
- sx: {
3848
- marginTop: '16px',
3849
- marginLeft: '24px'
4009
+ onBlur: function onBlur() {
4010
+ return trigger(fieldNames.cloud4);
3850
4011
  }
3851
- }, errorList.length === 0 && /*#__PURE__*/React__namespace.createElement(material.Box, {
3852
- component: "div",
4012
+ }), /*#__PURE__*/React__default["default"].createElement(TafFormTextField, {
4013
+ label: "Cloud",
4014
+ name: fieldNames.cloud4,
4015
+ disabled: disabled,
4016
+ defaultValue: getDefaultValue('cloud.cloud4', field),
4017
+ rules: {
4018
+ validate: {
4019
+ validateFourthCloud: function validateFourthCloud$1(value) {
4020
+ return validateFourthCloud(getValues(fieldNames.cloud1), getValues(fieldNames.cloud2), getValues(fieldNames.cloud3), value, getValues(fieldNames.visibility));
4021
+ }
4022
+ }
4023
+ }
4024
+ })), !disabled && /*#__PURE__*/React__default["default"].createElement(material.Grid, {
4025
+ item: true,
4026
+ container: true,
4027
+ justifyContent: "flex-end",
4028
+ alignItems: "flex-end",
4029
+ xs: 24,
4030
+ sm: 1,
3853
4031
  sx: {
3854
- fontSize: '4rem'
4032
+ marginBottom: '16px'
3855
4033
  },
3856
- "data-testid": "zeroIssuesImage"
3857
- }, /*#__PURE__*/React__namespace.createElement(theme.ThumbsUp, {
3858
- sx: {
3859
- height: '69px',
3860
- width: '58px'
3861
- }
3862
- })), errorList.length > 0 && errorList.map(function (error, index) {
3863
- return /*#__PURE__*/React__namespace.createElement(material.Typography // eslint-disable-next-line react/no-array-index-key
3864
- , {
3865
- // eslint-disable-next-line react/no-array-index-key
3866
- key: "message-" + index,
3867
- variant: "body1",
3868
- "data-testid": "errorMessage"
3869
- }, getErrorMessage(error, index));
3870
- }))), rootElement);
3871
- };
3872
-
3873
- /* *
3874
- * Licensed under the Apache License, Version 2.0 (the "License");
3875
- * you may not use this file except in compliance with the License.
3876
- * You may obtain a copy of the License at
3877
- *
3878
- * http://www.apache.org/licenses/LICENSE-2.0
3879
- *
3880
- * Unless required by applicable law or agreed to in writing, software
3881
- * distributed under the License is distributed on an "AS IS" BASIS,
3882
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3883
- * See the License for the specific language governing permissions and
3884
- * limitations under the License.
3885
- *
3886
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3887
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
3888
- * */
3889
- var TafModuleContext = /*#__PURE__*/React__namespace.createContext({
3890
- onValidateForm: null,
3891
- registerValidateForm: null,
3892
- tafAction: null,
3893
- setTafAction: null,
3894
- onPreventCloseView: null
4034
+ columns: 24
4035
+ }, /*#__PURE__*/React__default["default"].createElement(TafFormOptionsButton, {
4036
+ isChangeGroup: isChangeGroup,
4037
+ addChangeGroupBelow: addChangeGroupBelow,
4038
+ addChangeGroupAbove: addChangeGroupAbove,
4039
+ removeChangeGroup: function removeChangeGroup() {
4040
+ return onRemoveChangeGroup(index);
4041
+ },
4042
+ clearRow: clearRow,
4043
+ index: index
4044
+ })));
3895
4045
  });
3896
- var useTafModuleContext = function useTafModuleContext() {
3897
- return React__namespace.useContext(TafModuleContext);
3898
- };
3899
- var useTafModuleState = function useTafModuleState(_a) {
3900
- var onPreventCloseView = _a.onPreventCloseView;
3901
-
3902
- var _b = __read(React__namespace.useState(function () {
3903
- return new Promise(function () {
3904
- return true;
3905
- });
3906
- }), 2),
3907
- onValidateForm = _b[0],
3908
- registerValidateForm = _b[1];
3909
-
3910
- var _c = __read(React__namespace.useState(), 2),
3911
- tafAction = _c[0],
3912
- setTafAction = _c[1];
3913
-
3914
- var onRegisterValidateForm = function onRegisterValidateForm(promiseToRegister) {
3915
- registerValidateForm(function () {
3916
- return promiseToRegister;
3917
- });
3918
- };
3919
-
3920
- return {
3921
- onValidateForm: onValidateForm,
3922
- registerValidateForm: onRegisterValidateForm,
3923
- tafAction: tafAction,
3924
- setTafAction: setTafAction,
3925
- onPreventCloseView: onPreventCloseView
3926
- };
3927
- };
3928
- var TafModuleProvider = function TafModuleProvider(_a) {
3929
- var children = _a.children,
3930
- _b = _a.onPreventCloseView,
3931
- onPreventCloseView = _b === void 0 ? function () {} : _b;
3932
- var contextState = useTafModuleState({
3933
- onPreventCloseView: onPreventCloseView
3934
- });
3935
- return /*#__PURE__*/React__namespace.createElement(TafModuleContext.Provider, {
3936
- value: contextState
3937
- }, children);
3938
- };
3939
-
3940
- var styles = {
3941
- label: {
3942
- color: 'geowebColors.buttons.tertiary.default.color',
3943
- opacity: 1,
3944
- fontSize: '12px',
3945
- fontWeight: 500
3946
- }
3947
- };
3948
-
3949
- var SwitchButton = function SwitchButton(props) {
3950
- return /*#__PURE__*/React__namespace.createElement(shared.CustomTooltip, {
3951
- title: "Switch mode"
3952
- }, /*#__PURE__*/React__namespace.createElement("span", null, /*#__PURE__*/React__namespace.createElement(material.FormLabel, {
3953
- sx: styles.label
3954
- }, "Viewer"), /*#__PURE__*/React__namespace.createElement(material.Switch, __assign({
3955
- "data-testid": "switchMode"
3956
- }, props)), /*#__PURE__*/React__namespace.createElement(material.FormLabel, {
3957
- sx: styles.label
3958
- }, "Editor")));
3959
- };
3960
-
3961
- var TafAvatar = function TafAvatar(_a) {
3962
- var editor = _a.editor,
3963
- _b = _a.tooltipPlacement,
3964
- tooltipPlacement = _b === void 0 ? 'bottom' : _b;
3965
- return /*#__PURE__*/React__namespace.createElement(shared.CustomTooltip, {
3966
- title: "Editor: " + editor,
3967
- placement: tooltipPlacement
3968
- }, /*#__PURE__*/React__namespace.createElement("span", null, /*#__PURE__*/React__namespace.createElement(shared.Avatar, {
3969
- size: "small"
3970
- }, shared.getInitials(editor))));
3971
- };
3972
4046
 
3973
4047
  var noop = function noop() {};
3974
4048
 
@@ -4000,7 +4074,10 @@
4000
4074
  _h = _a.fetchNewTafList,
4001
4075
  fetchNewTafList = _h === void 0 ? function () {
4002
4076
  return null;
4003
- } : _h;
4077
+ } : _h,
4078
+ _j = _a.previousTaf,
4079
+ previousTaf = _j === void 0 ? null : _j;
4080
+ var formRef = React__default["default"].useRef();
4004
4081
  var originalTaf = tafFromBackend.taf,
4005
4082
  editor = tafFromBackend.editor;
4006
4083
  var auth = authentication.useAuthenticationContext().auth;
@@ -4009,41 +4086,41 @@
4009
4086
  var isDefaultDisabled = getIsFormDefaultDisabled(originalTaf.status);
4010
4087
  var confirmDialog = shared.useConfirmationDialog();
4011
4088
 
4012
- var _j = shared.useDraftFormHelpers(),
4013
- toggleIsDraft = _j.toggleIsDraft,
4014
- isNotRequiredForAction = _j.isRequired;
4015
-
4016
- var _k = useTafModuleContext(),
4017
- registerValidateForm = _k.registerValidateForm,
4018
- tafAction = _k.tafAction,
4019
- setTafAction = _k.setTafAction,
4020
- onPreventCloseView = _k.onPreventCloseView;
4021
-
4022
- var _l = reactHookForm.useFormContext(),
4023
- control = _l.control,
4024
- handleSubmit = _l.handleSubmit,
4025
- trigger = _l.trigger,
4026
- formState = _l.formState,
4027
- getValues = _l.getValues,
4028
- setValue = _l.setValue,
4029
- resetField = _l.resetField; // added this ignore as the build is failing otherwise on: Type instantiation is excessively deep and possibly infinite.
4089
+ var _k = shared.useDraftFormHelpers(),
4090
+ toggleIsDraft = _k.toggleIsDraft,
4091
+ isNotRequiredForAction = _k.isRequired;
4092
+
4093
+ var _l = useTafModuleContext(),
4094
+ registerValidateForm = _l.registerValidateForm,
4095
+ tafAction = _l.tafAction,
4096
+ setTafAction = _l.setTafAction,
4097
+ onPreventCloseView = _l.onPreventCloseView;
4098
+
4099
+ var _m = reactHookForm.useFormContext(),
4100
+ control = _m.control,
4101
+ handleSubmit = _m.handleSubmit,
4102
+ trigger = _m.trigger,
4103
+ formState = _m.formState,
4104
+ getValues = _m.getValues,
4105
+ setValue = _m.setValue,
4106
+ resetField = _m.resetField; // added this ignore as the build is failing otherwise on: Type instantiation is excessively deep and possibly infinite.
4030
4107
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4031
4108
  // @ts-ignore
4032
4109
 
4033
4110
 
4034
- var _m = reactHookForm.useFieldArray({
4111
+ var _o = reactHookForm.useFieldArray({
4035
4112
  control: control,
4036
4113
  name: 'changeGroups'
4037
4114
  }),
4038
- fields = _m.fields,
4039
- insert = _m.insert,
4040
- remove = _m.remove,
4041
- move = _m.move;
4115
+ fields = _o.fields,
4116
+ insert = _o.insert,
4117
+ remove = _o.remove,
4118
+ move = _o.move;
4042
4119
 
4043
- var _o = useDragOrder(trigger, move),
4044
- onChangeOrder = _o.onChangeOrder,
4045
- onStartDrag = _o.onStartDrag,
4046
- activeDraggingIndex = _o.activeDraggingIndex;
4120
+ var _p = useDragOrder(trigger, move),
4121
+ onChangeOrder = _p.onChangeOrder,
4122
+ onStartDrag = _p.onStartDrag,
4123
+ activeDraggingIndex = _p.activeDraggingIndex;
4047
4124
 
4048
4125
  var dirtyFields = formState.dirtyFields,
4049
4126
  errors = formState.errors;
@@ -4064,7 +4141,8 @@
4064
4141
  return confirmDialog({
4065
4142
  title: getConfirmationDialogTitle(action),
4066
4143
  description: getConfirmationDialogContent(action, function () {
4067
- return isTafAmendedCorrectedChanged(isFormDirty$1, originalTaf, convertTafValuesToObject(getValues()));
4144
+ return isTafAmendedCorrectedChanged( // If already saved as draft amd/cor then send over the previous taf
4145
+ originalTaf.status === 'DRAFT_AMENDED' || originalTaf.status === 'DRAFT_CORRECTED' ? previousTaf : originalTaf, convertTafValuesToObject(getValues()));
4068
4146
  }),
4069
4147
  confirmLabel: getConfirmationDialogButtonLabel(action)
4070
4148
  });
@@ -4271,11 +4349,32 @@
4271
4349
 
4272
4350
  return [2
4273
4351
  /*return*/
4274
- ];
4352
+ , true];
4275
4353
  }
4276
4354
  });
4277
4355
  });
4278
- })();
4356
+ })().then(function () {
4357
+ var hasFormErrors = Object.keys(errors).length;
4358
+ var formNodeRef = formRef.current;
4359
+
4360
+ if (hasFormErrors && formNodeRef) {
4361
+ var inputsWithError = formNodeRef.querySelectorAll('.Mui-error');
4362
+ var firstFormGroupWithError = inputsWithError.length ? inputsWithError[inputsWithError.length - 1].closest('.formRow') : null;
4363
+
4364
+ if (firstFormGroupWithError) {
4365
+ var _a = getFormRowPosition(firstFormGroupWithError),
4366
+ top_1 = _a.top,
4367
+ left = _a.left;
4368
+
4369
+ var tafModuleNode = formNodeRef.closest('#tafmodule');
4370
+ var newTop = top_1 - (tafModuleNode === null || tafModuleNode === void 0 ? void 0 : tafModuleNode.getBoundingClientRect().top) || 0;
4371
+ setIsIssuesPaneOpen(true, {
4372
+ top: newTop,
4373
+ left: left
4374
+ });
4375
+ }
4376
+ }
4377
+ });
4279
4378
  break;
4280
4379
 
4281
4380
  default:
@@ -4395,9 +4494,9 @@
4395
4494
  });
4396
4495
  };
4397
4496
 
4398
- var _p = __read(React__default["default"].useState(false), 2),
4399
- shouldValidate = _p[0],
4400
- setShouldValidate = _p[1];
4497
+ var _q = __read(React__default["default"].useState(false), 2),
4498
+ shouldValidate = _q[0],
4499
+ setShouldValidate = _q[1];
4401
4500
 
4402
4501
  React__default["default"].useEffect(function () {
4403
4502
  setIsDisabled(!isEditor || isDefaultDisabled); // set validate flag to validate after the values have been set
@@ -4474,7 +4573,8 @@
4474
4573
  editor: editor
4475
4574
  }))), /*#__PURE__*/React__default["default"].createElement("form", {
4476
4575
  "data-testid": "taf-form",
4477
- onSubmit: handleSubmit(onSubmit)
4576
+ onSubmit: handleSubmit(onSubmit),
4577
+ ref: formRef
4478
4578
  }, /*#__PURE__*/React__default["default"].createElement(TafFormRow, {
4479
4579
  disabled: isDisabled,
4480
4580
  onAddChangeGroupBelow: onAddRow,
@@ -4771,6 +4871,14 @@
4771
4871
 
4772
4872
  return 0;
4773
4873
  };
4874
+ var getPreviousTaf = function getPreviousTaf(tafList, currentTaf) {
4875
+ var previousId = currentTaf.taf.previousId;
4876
+ if (!previousId) return null;
4877
+ var previousTaf = tafList.find(function (taf) {
4878
+ return taf.taf.uuid === previousId;
4879
+ });
4880
+ return previousTaf ? previousTaf.taf : null;
4881
+ };
4774
4882
 
4775
4883
  /* *
4776
4884
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -5574,7 +5682,10 @@
5574
5682
  _j = _a.fetchNewTafList,
5575
5683
  fetchNewTafList = _j === void 0 ? function () {
5576
5684
  return null;
5577
- } : _j;
5685
+ } : _j,
5686
+ _k = _a.previousTaf,
5687
+ previousTaf = _k === void 0 ? null : _k,
5688
+ tafAction = _a.tafAction;
5578
5689
  var severity = isWarning(error) ? 'warning' : 'error';
5579
5690
 
5580
5691
  var onTafAction = function onTafAction(action, taf) {
@@ -5676,7 +5787,7 @@
5676
5787
  index: index,
5677
5788
  "data-testid": "taf-panel" + (activeTafIndex === index ? '-active' : '')
5678
5789
  }, /*#__PURE__*/React__default["default"].createElement(TafHeader, {
5679
- title: getTafStatusLabel(tafFromBackend.taf.status),
5790
+ title: getTafStatusLabel(tafFromBackend.taf.status, tafAction, isFormDisabled),
5680
5791
  sx: {
5681
5792
  marginBottom: '4px'
5682
5793
  }
@@ -5709,7 +5820,8 @@
5709
5820
  isDisabled: isFormDisabled,
5710
5821
  setIsDisabled: setIsFormDisabled,
5711
5822
  onSwitchEditor: patchTaf,
5712
- fetchNewTafList: fetchNewTafList
5823
+ fetchNewTafList: fetchNewTafList,
5824
+ previousTaf: previousTaf
5713
5825
  })));
5714
5826
  };
5715
5827
 
@@ -5804,7 +5916,7 @@
5804
5916
  return 'Saved as draft';
5805
5917
 
5806
5918
  case 'DRAFT_AMENDED':
5807
- return 'Saved as draft amended';
5919
+ return 'Saved as draft amendment';
5808
5920
 
5809
5921
  case 'DRAFT_CORRECTED':
5810
5922
  return 'Saved as draft correction';
@@ -5842,7 +5954,8 @@
5842
5954
  isIssuesPaneOpen = _d.isIssuesPaneOpen,
5843
5955
  onToggleIssuesPane = _d.onToggleIssuesPane,
5844
5956
  onCloseIssuesPane = _d.onCloseIssuesPane,
5845
- startPosition = _d.startPosition;
5957
+ startPosition = _d.startPosition,
5958
+ onUserHasDragged = _d.onUserHasDragged;
5846
5959
 
5847
5960
  var _e = usePostTafRequest(api$1.postTaf),
5848
5961
  isLoading = _e.isLoading,
@@ -6182,7 +6295,9 @@
6182
6295
  patchTaf: patchTaf,
6183
6296
  isLoading: isLoading,
6184
6297
  error: error,
6185
- fetchNewTafList: onUpdateTaf
6298
+ fetchNewTafList: onUpdateTaf,
6299
+ previousTaf: getPreviousTaf(tafList, tafFromBackend),
6300
+ tafAction: tafAction
6186
6301
  });
6187
6302
  }))), /*#__PURE__*/React__default["default"].createElement(material.Grid, {
6188
6303
  item: true,
@@ -6205,7 +6320,8 @@
6205
6320
  })))))), /*#__PURE__*/React__default["default"].createElement(IssuesPaneWrapper, {
6206
6321
  handleClose: onCloseIssuesPane,
6207
6322
  isOpen: isIssuesPaneOpen,
6208
- startPosition: startPosition
6323
+ startPosition: startPosition,
6324
+ onUserHasDragged: onUserHasDragged
6209
6325
  }));
6210
6326
  };
6211
6327
 
@@ -7197,15 +7313,21 @@
7197
7313
  }
7198
7314
  };
7199
7315
 
7316
+ var _d = fakeDraftAmendmentTaf.taf;
7317
+ _d.changeGroups;
7318
+ var fakeDraftAmendmentWithoutChangeGroups = __rest(_d, ["changeGroups"]); // Only use for display purposes in the list!
7319
+
7320
+
7200
7321
  ({
7201
7322
  creationDate: "2022-01-06T14:00:00Z",
7202
7323
  canbe: ['DRAFTED', 'DISCARDED', 'PUBLISHED'],
7203
7324
  editor: null,
7204
- taf: __assign(__assign({}, fakeDraftAmendmentTaf.taf), {
7325
+ taf: __assign(__assign({}, fakeDraftAmendmentWithoutChangeGroups), {
7205
7326
  location: 'EHRD',
7206
7327
  baseTime: "2022-01-06T12:00:00Z",
7207
7328
  validDateStart: "2022-01-06T14:00:00Z",
7208
7329
  validDateEnd: "2022-01-07T18:00:00Z",
7330
+ previousId: "previousIdOfPreviousTAF",
7209
7331
  previousValidDateStart: "2022-01-06T12:00:00Z",
7210
7332
  previousValidDateEnd: "2022-01-07T18:00:00Z",
7211
7333
  baseForecast: __assign(__assign({}, fakeDraftAmendmentTaf.taf.baseForecast), {
@@ -7213,8 +7335,32 @@
7213
7335
  start: "2022-01-06T14:00:00Z",
7214
7336
  end: "2022-01-07T18:00:00Z"
7215
7337
  }
7216
- }),
7217
- changeGroups: []
7338
+ })
7339
+ })
7340
+ }); // Use as the original previous TAF for TAF above
7341
+
7342
+ ({
7343
+ creationDate: "2022-01-06T14:00:00Z",
7344
+ canbe: ['DRAFTED', 'DISCARDED', 'PUBLISHED'],
7345
+ editor: null,
7346
+ taf: __assign(__assign({}, fakeDraftAmendmentWithoutChangeGroups), {
7347
+ status: 'AMENDED',
7348
+ uuid: 'previousIdOfPreviousTAF',
7349
+ location: 'EHRD',
7350
+ baseTime: "2022-01-06T12:00:00Z",
7351
+ validDateStart: "2022-01-06T14:00:00Z",
7352
+ validDateEnd: "2022-01-07T18:00:00Z",
7353
+ baseForecast: __assign(__assign({}, fakeDraftAmendmentTaf.taf.baseForecast), {
7354
+ valid: {
7355
+ start: "2022-01-06T14:00:00Z",
7356
+ end: "2022-01-07T18:00:00Z"
7357
+ },
7358
+ wind: {
7359
+ direction: 344,
7360
+ speed: 90,
7361
+ unit: 'KT'
7362
+ }
7363
+ })
7218
7364
  })
7219
7365
  });
7220
7366
  var fakeAmendmentTaf = {