@opengeoweb/taf 4.10.0 → 4.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.esm.js CHANGED
@@ -2637,6 +2637,9 @@ var fromStatusToAction = function fromStatusToAction(tafStatus) {
2637
2637
  return 'NEW';
2638
2638
  }
2639
2639
  };
2640
+ var isFormDirty = function isFormDirty(dirtyFields) {
2641
+ return Object.keys(dirtyFields).length > 0;
2642
+ };
2640
2643
 
2641
2644
  var textFieldStyle = function textFieldStyle(theme) {
2642
2645
  return {
@@ -2767,7 +2770,9 @@ var TafFormTextField = function TafFormTextField(_ref) {
2767
2770
  }) || null;
2768
2771
 
2769
2772
  if (foundValue) {
2770
- setValue(name, foundValue.value);
2773
+ setValue(name, foundValue.value, {
2774
+ shouldDirty: true
2775
+ });
2771
2776
  setMaxLength(foundValue.value.length);
2772
2777
  event.preventDefault();
2773
2778
  }
@@ -4019,7 +4024,7 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4019
4024
  formState = _useFormContext.formState,
4020
4025
  getValues = _useFormContext.getValues,
4021
4026
  setValue = _useFormContext.setValue,
4022
- reset = _useFormContext.reset; // added this ignore as the build is failing otherwise on: Type instantiation is excessively deep and possibly infinite.
4027
+ resetField = _useFormContext.resetField; // added this ignore as the build is failing otherwise on: Type instantiation is excessively deep and possibly infinite.
4023
4028
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4024
4029
  // @ts-ignore
4025
4030
 
@@ -4038,13 +4043,14 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4038
4043
  onStartDrag = _useDragOrder.onStartDrag,
4039
4044
  activeDraggingIndex = _useDragOrder.activeDraggingIndex;
4040
4045
 
4041
- var isFormDirty = formState.isDirty,
4046
+ var dirtyFields = formState.dirtyFields,
4042
4047
  errors = formState.errors;
4043
- usePreventBrowserClose(isFormDirty && !isDisabled); // Needed to be able to show a confirmation dialog on closing parent view
4048
+ var isFormDirty$1 = isFormDirty(dirtyFields);
4049
+ usePreventBrowserClose(isFormDirty$1 && !isDisabled); // Needed to be able to show a confirmation dialog on closing parent view
4044
4050
 
4045
4051
  React__default.useEffect(function () {
4046
- onPreventCloseView(isFormDirty); // eslint-disable-next-line react-hooks/exhaustive-deps
4047
- }, [isFormDirty]);
4052
+ onPreventCloseView(isFormDirty$1); // eslint-disable-next-line react-hooks/exhaustive-deps
4053
+ }, [isFormDirty$1]);
4048
4054
  var hiddenInputFields = ['baseTime', 'issueDate', 'uuid', 'validDateStart', 'validDateEnd', 'status', 'previousId', 'previousValidDateStart', 'previousValidDateEnd', HIDDEN_INPUT_HELPER_IS_DRAFT];
4049
4055
 
4050
4056
  var onSubmit = function onSubmit(data) {
@@ -4056,7 +4062,7 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4056
4062
  return confirmDialog({
4057
4063
  title: getConfirmationDialogTitle(action),
4058
4064
  description: getConfirmationDialogContent(action, function () {
4059
- return isTafAmendedCorrectedChanged(isFormDirty, originalTaf, convertTafValuesToObject(getValues()));
4065
+ return isTafAmendedCorrectedChanged(isFormDirty$1, originalTaf, convertTafValuesToObject(getValues()));
4060
4066
  }),
4061
4067
  confirmLabel: getConfirmationDialogButtonLabel(action)
4062
4068
  });
@@ -4064,9 +4070,17 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4064
4070
 
4065
4071
  var resetFormValues = function resetFormValues(formData) {
4066
4072
  var keepDirty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
4067
- reset(formData, {
4068
- keepDirty: keepDirty,
4069
- keepDirtyValues: false
4073
+ Object.keys(formData).forEach(function (key) {
4074
+ if (!keepDirty || key === 'changeGroups') {
4075
+ resetField(key, {
4076
+ keepDirty: keepDirty,
4077
+ defaultValue: formData[key]
4078
+ });
4079
+ }
4080
+
4081
+ setValue(key, formData[key], {
4082
+ shouldDirty: keepDirty
4083
+ });
4070
4084
  });
4071
4085
  };
4072
4086
 
@@ -4165,7 +4179,7 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4165
4179
  var onSwitchMode = function onSwitchMode(event) {
4166
4180
  var checked = event.target.checked;
4167
4181
 
4168
- if (!checked && isFormDirty) {
4182
+ if (!checked && isFormDirty$1) {
4169
4183
  confirmDialog({
4170
4184
  title: 'Whoops',
4171
4185
  description: 'Are you sure you want to switch to viewer mode? Your unsaved changes will be lost.',
@@ -4214,13 +4228,7 @@ var TafForm = /*#__PURE__*/React__default.memo(function (_ref) {
4214
4228
 
4215
4229
  case 'CLEAR':
4216
4230
  showConfirmDialog(action).then(function () {
4217
- var emptiedForm = clearTafFormData(getValues()); // Trigger an invisible change to dirty the form
4218
- // This is needed to trigger the autosave on changing location/time
4219
-
4220
- var baseForecastFields = getFieldNames(false, -1);
4221
- setValue(baseForecastFields.wind, ' ', {
4222
- shouldDirty: true
4223
- });
4231
+ var emptiedForm = clearTafFormData(getValues());
4224
4232
  resetFormValues(emptiedForm, true);
4225
4233
  showSnackbar('TAF has been cleared');
4226
4234
  });
@@ -5261,7 +5269,9 @@ var TopTabs = function TopTabs(_ref) {
5261
5269
  } : _ref$tafFromBackend;
5262
5270
 
5263
5271
  var _useFormContext = useFormContext(),
5264
- isDirty = _useFormContext.formState.isDirty;
5272
+ dirtyFields = _useFormContext.formState.dirtyFields;
5273
+
5274
+ var isDirty = isFormDirty(dirtyFields);
5265
5275
 
5266
5276
  if (!tafFromBackend) {
5267
5277
  return null;
@@ -5329,8 +5339,9 @@ var LocationTabs = function LocationTabs(_ref) {
5329
5339
  timeSlot = _ref.timeSlot;
5330
5340
 
5331
5341
  var _useFormContext = useFormContext(),
5332
- isDirty = _useFormContext.formState.isDirty;
5342
+ dirtyFields = _useFormContext.formState.dirtyFields;
5333
5343
 
5344
+ var isDirty = isFormDirty(dirtyFields);
5334
5345
  return /*#__PURE__*/React.createElement(MenuList, {
5335
5346
  "data-testid": "location-tabs",
5336
5347
  sx: {
package/index.umd.js CHANGED
@@ -2645,6 +2645,9 @@
2645
2645
  return 'NEW';
2646
2646
  }
2647
2647
  };
2648
+ var isFormDirty = function isFormDirty(dirtyFields) {
2649
+ return Object.keys(dirtyFields).length > 0;
2650
+ };
2648
2651
 
2649
2652
  var textFieldStyle = function textFieldStyle(theme) {
2650
2653
  return {
@@ -2774,7 +2777,9 @@
2774
2777
  }) || null;
2775
2778
 
2776
2779
  if (foundValue) {
2777
- setValue(name, foundValue.value);
2780
+ setValue(name, foundValue.value, {
2781
+ shouldDirty: true
2782
+ });
2778
2783
  setMaxLength(foundValue.value.length);
2779
2784
  event.preventDefault();
2780
2785
  }
@@ -4021,7 +4026,7 @@
4021
4026
  formState = _l.formState,
4022
4027
  getValues = _l.getValues,
4023
4028
  setValue = _l.setValue,
4024
- reset = _l.reset; // added this ignore as the build is failing otherwise on: Type instantiation is excessively deep and possibly infinite.
4029
+ resetField = _l.resetField; // added this ignore as the build is failing otherwise on: Type instantiation is excessively deep and possibly infinite.
4025
4030
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4026
4031
  // @ts-ignore
4027
4032
 
@@ -4040,13 +4045,14 @@
4040
4045
  onStartDrag = _o.onStartDrag,
4041
4046
  activeDraggingIndex = _o.activeDraggingIndex;
4042
4047
 
4043
- var isFormDirty = formState.isDirty,
4048
+ var dirtyFields = formState.dirtyFields,
4044
4049
  errors = formState.errors;
4045
- shared.usePreventBrowserClose(isFormDirty && !isDisabled); // Needed to be able to show a confirmation dialog on closing parent view
4050
+ var isFormDirty$1 = isFormDirty(dirtyFields);
4051
+ shared.usePreventBrowserClose(isFormDirty$1 && !isDisabled); // Needed to be able to show a confirmation dialog on closing parent view
4046
4052
 
4047
4053
  React__default["default"].useEffect(function () {
4048
- onPreventCloseView(isFormDirty); // eslint-disable-next-line react-hooks/exhaustive-deps
4049
- }, [isFormDirty]);
4054
+ onPreventCloseView(isFormDirty$1); // eslint-disable-next-line react-hooks/exhaustive-deps
4055
+ }, [isFormDirty$1]);
4050
4056
  var hiddenInputFields = ['baseTime', 'issueDate', 'uuid', 'validDateStart', 'validDateEnd', 'status', 'previousId', 'previousValidDateStart', 'previousValidDateEnd', shared.HIDDEN_INPUT_HELPER_IS_DRAFT];
4051
4057
 
4052
4058
  var onSubmit = function onSubmit(data) {
@@ -4058,7 +4064,7 @@
4058
4064
  return confirmDialog({
4059
4065
  title: getConfirmationDialogTitle(action),
4060
4066
  description: getConfirmationDialogContent(action, function () {
4061
- return isTafAmendedCorrectedChanged(isFormDirty, originalTaf, convertTafValuesToObject(getValues()));
4067
+ return isTafAmendedCorrectedChanged(isFormDirty$1, originalTaf, convertTafValuesToObject(getValues()));
4062
4068
  }),
4063
4069
  confirmLabel: getConfirmationDialogButtonLabel(action)
4064
4070
  });
@@ -4069,9 +4075,17 @@
4069
4075
  keepDirty = false;
4070
4076
  }
4071
4077
 
4072
- reset(formData, {
4073
- keepDirty: keepDirty,
4074
- keepDirtyValues: false
4078
+ Object.keys(formData).forEach(function (key) {
4079
+ if (!keepDirty || key === 'changeGroups') {
4080
+ resetField(key, {
4081
+ keepDirty: keepDirty,
4082
+ defaultValue: formData[key]
4083
+ });
4084
+ }
4085
+
4086
+ setValue(key, formData[key], {
4087
+ shouldDirty: keepDirty
4088
+ });
4075
4089
  });
4076
4090
  };
4077
4091
 
@@ -4173,7 +4187,7 @@
4173
4187
  var onSwitchMode = function onSwitchMode(event) {
4174
4188
  var checked = event.target.checked;
4175
4189
 
4176
- if (!checked && isFormDirty) {
4190
+ if (!checked && isFormDirty$1) {
4177
4191
  confirmDialog({
4178
4192
  title: 'Whoops',
4179
4193
  description: 'Are you sure you want to switch to viewer mode? Your unsaved changes will be lost.',
@@ -4221,13 +4235,7 @@
4221
4235
 
4222
4236
  case 'CLEAR':
4223
4237
  showConfirmDialog(action).then(function () {
4224
- var emptiedForm = clearTafFormData(getValues()); // Trigger an invisible change to dirty the form
4225
- // This is needed to trigger the autosave on changing location/time
4226
-
4227
- var baseForecastFields = getFieldNames(false, -1);
4228
- setValue(baseForecastFields.wind, ' ', {
4229
- shouldDirty: true
4230
- });
4238
+ var emptiedForm = clearTafFormData(getValues());
4231
4239
  resetFormValues(emptiedForm, true);
4232
4240
  showSnackbar('TAF has been cleared');
4233
4241
  });
@@ -5270,7 +5278,8 @@
5270
5278
  location: 'EHAM'
5271
5279
  }
5272
5280
  } : _c;
5273
- var isDirty = reactHookForm.useFormContext().formState.isDirty;
5281
+ var dirtyFields = reactHookForm.useFormContext().formState.dirtyFields;
5282
+ var isDirty = isFormDirty(dirtyFields);
5274
5283
 
5275
5284
  if (!tafFromBackend) {
5276
5285
  return null;
@@ -5336,7 +5345,8 @@
5336
5345
  _c = _a.onChangeTab,
5337
5346
  onChangeTab = _c === void 0 ? function () {} : _c,
5338
5347
  timeSlot = _a.timeSlot;
5339
- var isDirty = reactHookForm.useFormContext().formState.isDirty;
5348
+ var dirtyFields = reactHookForm.useFormContext().formState.dirtyFields;
5349
+ var isDirty = isFormDirty(dirtyFields);
5340
5350
  return /*#__PURE__*/React__namespace.createElement(material.MenuList, {
5341
5351
  "data-testid": "location-tabs",
5342
5352
  sx: {
@@ -72,4 +72,7 @@ export declare const prepareTafValues: (_taf: Taf, tafAction: TafActions, addEmp
72
72
  export declare const clearTafFormData: (tafFormValues: TafFormData) => TafFormData;
73
73
  export declare const getIsFormDefaultDisabled: (status: TafStatus) => boolean;
74
74
  export declare const fromStatusToAction: (tafStatus: TafStatus) => TafActions;
75
+ export declare const isFormDirty: (dirtyFields: Partial<Readonly<{
76
+ [x: string]: unknown;
77
+ }>>) => boolean;
75
78
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/taf",
3
- "version": "4.10.0",
3
+ "version": "4.11.0",
4
4
  "description": "GeoWeb TAF library for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -12,25 +12,25 @@
12
12
  "typings": "./index.d.ts",
13
13
  "dependencies": {},
14
14
  "peerDependencies": {
15
- "@opengeoweb/api": "4.10.0",
15
+ "@opengeoweb/api": "4.11.0",
16
16
  "react": "^17.0.2",
17
17
  "axios": "^0.25.0",
18
- "@opengeoweb/shared": "4.10.0",
18
+ "@opengeoweb/shared": "4.11.0",
19
19
  "@mui/material": "^5.10.8",
20
- "@opengeoweb/theme": "4.10.0",
20
+ "@opengeoweb/theme": "4.11.0",
21
21
  "react-draggable": "^4.4.5",
22
22
  "re-resizable": "^6.9.0",
23
23
  "@redux-eggs/core": "^2.2.0",
24
24
  "react-redux": "^8.0.4",
25
- "@opengeoweb/form-fields": "4.10.0",
25
+ "@opengeoweb/form-fields": "4.11.0",
26
26
  "react-hook-form": "^7.41.5",
27
27
  "moment": "^2.29.0",
28
28
  "moment-timezone": "^0.5.31",
29
29
  "@mui/x-date-pickers": "^5.0.4",
30
30
  "lodash": "^4.17.20",
31
31
  "date-fns": "^2.29.3",
32
- "@opengeoweb/core": "4.10.0",
33
- "@opengeoweb/webmap": "4.10.0",
32
+ "@opengeoweb/core": "4.11.0",
33
+ "@opengeoweb/webmap": "4.11.0",
34
34
  "throttle-debounce": "^3.0.1",
35
35
  "proj4": "^2.6.2",
36
36
  "react-intl": "^5.17.5",
@@ -46,7 +46,7 @@
46
46
  "@redux-eggs/redux-toolkit": "^2.2.0",
47
47
  "@redux-eggs/saga-extension": "^2.2.0",
48
48
  "react-dom": "^17.0.2",
49
- "@opengeoweb/authentication": "4.10.0",
49
+ "@opengeoweb/authentication": "4.11.0",
50
50
  "react-router-dom": "^6.4.2",
51
51
  "query-string": "^6.13.7"
52
52
  }