@opengeoweb/sigmet-airmet 12.4.2 → 12.5.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
@@ -6727,7 +6727,9 @@ var ValidFrom = function ValidFrom(_ref) {
6727
6727
  isDisabled = _ref.isDisabled,
6728
6728
  isReadOnly = _ref.isReadOnly,
6729
6729
  _ref$onChange = _ref.onChange,
6730
- _onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange;
6730
+ _onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
6731
+ _ref$onUserChange = _ref.onUserChange,
6732
+ onUserChange = _ref$onUserChange === void 0 ? function () {} : _ref$onUserChange;
6731
6733
  var _useSigmetAirmetTrans = useSigmetAirmetTranslation(),
6732
6734
  t = _useSigmetAirmetTrans.t;
6733
6735
  var _useFormContext = useFormContext(),
@@ -6753,11 +6755,13 @@ var ValidFrom = function ValidFrom(_ref) {
6753
6755
  },
6754
6756
  // The current time can be no more than 4 hours before the validity start (12 for VA/TC SIGMET)
6755
6757
  isCurrentTimeXHoursBeforeValue: function isCurrentTimeXHoursBeforeValue(value) {
6756
- return isXHoursBefore(dateUtils.getCurrentTimeAsString(), value, getHoursBeforeValidity(getValues('phenomenon'), getValues('locationIndicatorATSR'), productConfig)) || getValidFromXHoursBeforeMessage(t, getHoursBeforeValidity(getValues('phenomenon'), getValues('locationIndicatorATSR'), productConfig));
6758
+ var isValid = isXHoursBefore(dateUtils.getCurrentTimeAsString(), value, getHoursBeforeValidity(getValues('phenomenon'), getValues('locationIndicatorATSR'), productConfig));
6759
+ return isValid ? true : getValidFromXHoursBeforeMessage(t, getHoursBeforeValidity(getValues('phenomenon'), getValues('locationIndicatorATSR'), productConfig));
6757
6760
  }
6758
6761
  }
6759
6762
  },
6760
6763
  onChange: function onChange() {
6764
+ onUserChange == null || onUserChange();
6761
6765
  triggerValidations(['validDateEnd', 'observationOrForecastTime'], getValues, trigger);
6762
6766
  _onChange();
6763
6767
  },
@@ -6789,7 +6793,10 @@ var ValidUntil = function ValidUntil(_ref) {
6789
6793
  isDisabled = _ref.isDisabled,
6790
6794
  isReadOnly = _ref.isReadOnly,
6791
6795
  _ref$onChange = _ref.onChange,
6792
- _onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange;
6796
+ _onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
6797
+ _ref$onUserChange = _ref.onUserChange,
6798
+ onUserChange = _ref$onUserChange === void 0 ? function () {} : _ref$onUserChange,
6799
+ hasUserChangedTime = _ref.hasUserChangedTime;
6793
6800
  var _useSigmetAirmetTrans = useSigmetAirmetTranslation(),
6794
6801
  t = _useSigmetAirmetTrans.t;
6795
6802
  var _useFormContext = useFormContext(),
@@ -6808,19 +6815,18 @@ var ValidUntil = function ValidUntil(_ref) {
6808
6815
  var locationIndicatorATSR = watch('locationIndicatorATSR');
6809
6816
  var validFrom = watch('validDateStart');
6810
6817
  React__default.useEffect(function () {
6811
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
6812
- var updateValues = function updateValues() {
6813
- var newDefaultValidUntilValue = getDefaultValidUntilValue(productConfig, phenomenon, locationIndicatorATSR, validFrom);
6814
- if (newDefaultValidUntilValue !== defaultValidUntilValue) {
6815
- setDefaultValidUntilValue(newDefaultValidUntilValue);
6816
- setValue('validDateEnd', newDefaultValidUntilValue, {
6817
- shouldValidate: false
6818
- });
6819
- void trigger('validDateEnd');
6820
- }
6821
- };
6822
- updateValues();
6823
- }, [phenomenon, locationIndicatorATSR, validFrom, setValue, productConfig, trigger, defaultValidUntilValue]);
6818
+ if (hasUserChangedTime) {
6819
+ return;
6820
+ }
6821
+ var newDefaultValidUntilValue = getDefaultValidUntilValue(productConfig, phenomenon, locationIndicatorATSR, validFrom);
6822
+ if (newDefaultValidUntilValue !== defaultValidUntilValue) {
6823
+ setDefaultValidUntilValue(newDefaultValidUntilValue);
6824
+ setValue('validDateEnd', newDefaultValidUntilValue, {
6825
+ shouldValidate: false
6826
+ });
6827
+ void trigger('validDateEnd');
6828
+ }
6829
+ }, [phenomenon, locationIndicatorATSR, validFrom, setValue, productConfig, trigger, defaultValidUntilValue, hasUserChangedTime]);
6824
6830
  return jsx(ProductFormFieldLayout, {
6825
6831
  title: t('valid-until'),
6826
6832
  children: jsx(ReactHookFormDateTime, {
@@ -6845,7 +6851,7 @@ var ValidUntil = function ValidUntil(_ref) {
6845
6851
  disabled: isDisabled,
6846
6852
  isReadOnly: isReadOnly,
6847
6853
  onChange: function onChange() {
6848
- // Trigger validation after any change
6854
+ onUserChange == null || onUserChange(); // Track manual change
6849
6855
  triggerValidations(['validDateStart', 'observationOrForecastTime'], getValues, trigger);
6850
6856
  _onChange();
6851
6857
  },
@@ -8221,10 +8227,13 @@ var SigmetForm = function SigmetForm(_ref) {
8221
8227
  setValue = _useFormContext2.setValue,
8222
8228
  handleSubmit = _useFormContext2.handleSubmit,
8223
8229
  errors = _useFormContext2.formState.errors;
8230
+ var _React$useState = React__default.useState(false),
8231
+ hasUserChangedTime = _React$useState[0],
8232
+ setHasUserChangedTime = _React$useState[1];
8224
8233
  var firBorderAtStart = initialSigmet ? initialSigmet.locationIndicatorATSR : productConfig.active_firs[0];
8225
- var _React$useState = React__default.useState(getDefaultPhenomena(productConfig).phenomena),
8226
- phenomenaList = _React$useState[0],
8227
- setPhenomenaList = _React$useState[1];
8234
+ var _React$useState2 = React__default.useState(getDefaultPhenomena(productConfig).phenomena),
8235
+ phenomenaList = _React$useState2[0],
8236
+ setPhenomenaList = _React$useState2[1];
8228
8237
  var _useMapDrawTool = useMapDrawTool({
8229
8238
  defaultDrawModes: getDrawTools(t, StartOrEndDrawing.start, getFir(productConfig, firBorderAtStart)),
8230
8239
  defaultGeoJSON: !isCancelSigmet && initialSigmet && initialSigmet.startGeometry ? addFeatureProperties(initialSigmet.startGeometry, featurePropsStart) : undefined,
@@ -8335,9 +8344,9 @@ var SigmetForm = function SigmetForm(_ref) {
8335
8344
  updateGeojson: updateStartGeoJson
8336
8345
  }), getEndLayer('geoJSONIntersection', 'geojsonlayer-intersection-end'), getStartLayer('geoJSONIntersection', 'geojsonlayer-intersection-start')];
8337
8346
  useFormLayers(layers);
8338
- var _React$useState2 = React__default.useState(mode === 'view'),
8339
- isDisabled = _React$useState2[0],
8340
- setIsDisabled = _React$useState2[1];
8347
+ var _React$useState3 = React__default.useState(mode === 'view'),
8348
+ isDisabled = _React$useState3[0],
8349
+ setIsDisabled = _React$useState3[1];
8341
8350
  var isReadOnly = mode === 'view';
8342
8351
  var helperText = isReadOnly ? '' : 'Optional';
8343
8352
  React__default.useEffect(function () {
@@ -8407,12 +8416,19 @@ var SigmetForm = function SigmetForm(_ref) {
8407
8416
  productConfig: productConfig,
8408
8417
  isDisabled: isDisabled,
8409
8418
  isReadOnly: isReadOnly,
8410
- onChange: onChangeForm
8419
+ onChange: onChangeForm,
8420
+ onUserChange: function onUserChange() {
8421
+ return setHasUserChangedTime(true);
8422
+ }
8411
8423
  }), jsx(ValidUntil, {
8412
8424
  productConfig: productConfig,
8413
8425
  isDisabled: isDisabled,
8414
8426
  isReadOnly: isReadOnly,
8415
- onChange: onChangeForm
8427
+ onChange: onChangeForm,
8428
+ hasUserChangedTime: hasUserChangedTime,
8429
+ onUserChange: function onUserChange() {
8430
+ return setHasUserChangedTime(true);
8431
+ }
8416
8432
  }), jsx(SelectFIR, {
8417
8433
  productConfig: productConfig,
8418
8434
  isDisabled: isDisabled,
@@ -8567,6 +8583,9 @@ var AirmetForm = function AirmetForm(_ref) {
8567
8583
  var _React$useState = React__default.useState(getDefaultPhenomena(productConfig).phenomena),
8568
8584
  phenomenaList = _React$useState[0],
8569
8585
  setPhenomenaList = _React$useState[1];
8586
+ var _React$useState2 = React__default.useState(false),
8587
+ hasUserChangedTime = _React$useState2[0],
8588
+ setHasUserChangedTime = _React$useState2[1];
8570
8589
  var _useSigmetAirmetTrans = useSigmetAirmetTranslation(),
8571
8590
  t = _useSigmetAirmetTrans.t;
8572
8591
  var _useApiContext = useApiContext(),
@@ -8635,9 +8654,9 @@ var AirmetForm = function AirmetForm(_ref) {
8635
8654
  updateGeojson: updateStartGeoJson
8636
8655
  }), getStartLayer('geoJSONIntersection', 'geojsonlayer-intersection-start')];
8637
8656
  useFormLayers(layers);
8638
- var _React$useState2 = React__default.useState(mode === 'view'),
8639
- isDisabled = _React$useState2[0],
8640
- setIsDisabled = _React$useState2[1];
8657
+ var _React$useState3 = React__default.useState(mode === 'view'),
8658
+ isDisabled = _React$useState3[0],
8659
+ setIsDisabled = _React$useState3[1];
8641
8660
  var isReadOnly = mode === 'view';
8642
8661
  var helperText = isReadOnly ? '' : 'Optional';
8643
8662
  React__default.useEffect(function () {
@@ -8707,15 +8726,22 @@ var AirmetForm = function AirmetForm(_ref) {
8707
8726
  helperText: helperText,
8708
8727
  onChange: onChangeForm
8709
8728
  }), jsx(ValidFrom, {
8710
- isReadOnly: isReadOnly,
8729
+ productConfig: productConfig,
8711
8730
  isDisabled: isDisabled,
8731
+ isReadOnly: isReadOnly,
8712
8732
  onChange: onChangeForm,
8713
- productConfig: productConfig
8733
+ onUserChange: function onUserChange() {
8734
+ return setHasUserChangedTime(true);
8735
+ }
8714
8736
  }), jsx(ValidUntil, {
8715
- isReadOnly: isReadOnly,
8737
+ productConfig: productConfig,
8716
8738
  isDisabled: isDisabled,
8739
+ isReadOnly: isReadOnly,
8717
8740
  onChange: onChangeForm,
8718
- productConfig: productConfig
8741
+ hasUserChangedTime: hasUserChangedTime,
8742
+ onUserChange: function onUserChange() {
8743
+ return setHasUserChangedTime(true);
8744
+ }
8719
8745
  }), jsx(SelectFIR, {
8720
8746
  isReadOnly: isReadOnly,
8721
8747
  isDisabled: isDisabled,
@@ -8858,7 +8884,9 @@ var ProductFormDialogContent = function ProductFormDialogContent(_ref) {
8858
8884
  var _useFormContext = useFormContext(),
8859
8885
  handleSubmit = _useFormContext.handleSubmit,
8860
8886
  formState = _useFormContext.formState,
8861
- watch = _useFormContext.watch;
8887
+ watch = _useFormContext.watch,
8888
+ trigger = _useFormContext.trigger,
8889
+ getValues = _useFormContext.getValues;
8862
8890
  var dirtyFields = formState.dirtyFields;
8863
8891
  var isDirty = Object.keys(dirtyFields).length > 0;
8864
8892
  var _useDraftFormHelpers = useDraftFormHelpers(),
@@ -8916,66 +8944,89 @@ var ProductFormDialogContent = function ProductFormDialogContent(_ref) {
8916
8944
  }) : null
8917
8945
  });
8918
8946
  };
8919
- var onProductButtonPress = function onProductButtonPress(action) {
8920
- switch (action) {
8921
- case ProductAction.CLOSE:
8922
- if (mode === 'view' || !isDirty) {
8923
- onToggleDialog(false);
8924
- } else {
8925
- toggleIsDraft(true);
8926
- showConfirmDialog(action).then(function () {
8927
- void handleSubmit(function (formValues) {
8928
- postProduct(formValues, 'DRAFT');
8929
- })();
8930
- })["catch"](function (reason) {
8931
- if (reason === 'CANCELLED') {
8932
- // close without save
8947
+ var onProductButtonPress = /*#__PURE__*/function () {
8948
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(action) {
8949
+ var isDraft, formValues;
8950
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
8951
+ while (1) switch (_context.prev = _context.next) {
8952
+ case 0:
8953
+ _context.t0 = action;
8954
+ _context.next = _context.t0 === ProductAction.CLOSE ? 3 : _context.t0 === ProductAction.CANCEL ? 5 : _context.t0 === ProductAction.DISCARD ? 7 : _context.t0 === ProductAction.RENEW ? 9 : 11;
8955
+ break;
8956
+ case 3:
8957
+ if (mode === 'view' || !isDirty) {
8933
8958
  onToggleDialog(false);
8959
+ } else {
8960
+ toggleIsDraft(true);
8961
+ showConfirmDialog(action).then(function () {
8962
+ void handleSubmit(function (formValues) {
8963
+ postProduct(formValues, 'DRAFT');
8964
+ })();
8965
+ })["catch"](function (reason) {
8966
+ if (reason === 'CANCELLED') {
8967
+ // close without save
8968
+ onToggleDialog(false);
8969
+ }
8970
+ });
8934
8971
  }
8935
- });
8936
- }
8937
- break;
8938
- case ProductAction.CANCEL:
8939
- void showConfirmDialog(action).then(function () {
8940
- // if volcanic sigmet - add to which FIR it's moving
8941
- if (isVAPhenomenon(product, action)) {
8942
- postProduct(prepareCancelSigmet(product, watch('vaSigmetMoveToFIR')), 'CANCELLED');
8943
- } else {
8944
- postProduct(product, 'CANCELLED');
8945
- }
8946
- });
8947
- break;
8948
- case ProductAction.DISCARD:
8949
- void showConfirmDialog(action).then(function () {
8950
- // If we're discarding a new SIGMET/AIRMET - just close the dialog
8951
- if (mode === 'new' || !(product != null && product.uuid)) {
8952
- onToggleDialog(false);
8953
- } else {
8954
- // If we're discarding an existing SIGMET/AIRMET - make call to BE
8955
- postProduct(product, 'DISCARDED');
8956
- }
8957
- });
8958
- break;
8959
- case ProductAction.RENEW:
8960
- onRenewClick();
8961
- break;
8962
- default:
8963
- toggleIsDraft(action === ProductAction.SAVE);
8964
- // validate form
8965
- void handleSubmit(function (formValues) {
8966
- if (action === ProductAction.SAVE) {
8967
- // NO MODAL, SAVE DIRECTLY
8968
- postProduct(formValues, 'DRAFT');
8969
- } else {
8970
- // YES MODAL
8972
+ return _context.abrupt("break", 22);
8973
+ case 5:
8971
8974
  void showConfirmDialog(action).then(function () {
8972
- postProduct(formValues, 'PUBLISHED');
8975
+ // if volcanic sigmet - add to which FIR it's moving
8976
+ if (isVAPhenomenon(product, action)) {
8977
+ postProduct(prepareCancelSigmet(product, watch('vaSigmetMoveToFIR')), 'CANCELLED');
8978
+ } else {
8979
+ postProduct(product, 'CANCELLED');
8980
+ }
8973
8981
  });
8974
- }
8975
- })();
8976
- break;
8977
- }
8978
- };
8982
+ return _context.abrupt("break", 22);
8983
+ case 7:
8984
+ void showConfirmDialog(action).then(function () {
8985
+ // If we're discarding a new SIGMET/AIRMET - just close the dialog
8986
+ if (mode === 'new' || !(product != null && product.uuid)) {
8987
+ onToggleDialog(false);
8988
+ } else {
8989
+ // If we're discarding an existing SIGMET/AIRMET - make call to BE
8990
+ postProduct(product, 'DISCARDED');
8991
+ }
8992
+ });
8993
+ return _context.abrupt("break", 22);
8994
+ case 9:
8995
+ onRenewClick();
8996
+ return _context.abrupt("break", 22);
8997
+ case 11:
8998
+ isDraft = action === ProductAction.SAVE;
8999
+ toggleIsDraft(isDraft);
9000
+ if (!isDraft) {
9001
+ _context.next = 20;
9002
+ break;
9003
+ }
9004
+ _context.next = 16;
9005
+ return trigger();
9006
+ case 16:
9007
+ formValues = getValues(); // Save draft without blocking on validation
9008
+ postProduct(formValues, 'DRAFT');
9009
+ _context.next = 21;
9010
+ break;
9011
+ case 20:
9012
+ // Validate and submit normally (will block if invalid)
9013
+ void handleSubmit(function (formValues) {
9014
+ void showConfirmDialog(action).then(function () {
9015
+ postProduct(formValues, 'PUBLISHED');
9016
+ });
9017
+ })();
9018
+ case 21:
9019
+ return _context.abrupt("break", 22);
9020
+ case 22:
9021
+ case "end":
9022
+ return _context.stop();
9023
+ }
9024
+ }, _callee);
9025
+ }));
9026
+ return function onProductButtonPress(_x) {
9027
+ return _ref2.apply(this, arguments);
9028
+ };
9029
+ }();
8979
9030
  var title = getDialogtitle(t, product, productType, productConfig);
8980
9031
  return jsxs(CustomDialog, {
8981
9032
  open: isOpen,
@@ -8986,7 +9037,7 @@ var ProductFormDialogContent = function ProductFormDialogContent(_ref) {
8986
9037
  disableEnforceFocus: true,
8987
9038
  disableEscapeKeyDown: true,
8988
9039
  onClose: function onClose() {
8989
- return onProductButtonPress(ProductAction.CLOSE);
9040
+ void onProductButtonPress(ProductAction.CLOSE);
8990
9041
  },
8991
9042
  headerActions: getLifecycleActions({
8992
9043
  canBe: productCanBe,
@@ -9043,8 +9094,8 @@ var ProductFormDialogContent = function ProductFormDialogContent(_ref) {
9043
9094
  })]
9044
9095
  });
9045
9096
  };
9046
- var Wrapper = function Wrapper(_ref2) {
9047
- var props = Object.assign({}, (_objectDestructuringEmpty(_ref2), _ref2));
9097
+ var Wrapper = function Wrapper(_ref3) {
9098
+ var props = Object.assign({}, (_objectDestructuringEmpty(_ref3), _ref3));
9048
9099
  return jsx(ReactHookFormProvider, {
9049
9100
  options: Object.assign({}, defaultFormOptions, {
9050
9101
  defaultValues: props.product,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/sigmet-airmet",
3
- "version": "12.4.2",
3
+ "version": "12.5.0",
4
4
  "description": "GeoWeb Sigmet/Airmet library for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -8,17 +8,17 @@
8
8
  "url": "git@gitlab.com:opengeoweb/opengeoweb.git"
9
9
  },
10
10
  "dependencies": {
11
- "@opengeoweb/api": "12.4.2",
12
- "@opengeoweb/shared": "12.4.2",
13
- "@opengeoweb/theme": "12.4.2",
14
- "@opengeoweb/store": "12.4.2",
15
- "@opengeoweb/webmap": "12.4.2",
16
- "@opengeoweb/webmap-react": "12.4.2",
11
+ "@opengeoweb/api": "12.5.0",
12
+ "@opengeoweb/shared": "12.5.0",
13
+ "@opengeoweb/theme": "12.5.0",
14
+ "@opengeoweb/store": "12.5.0",
15
+ "@opengeoweb/webmap": "12.5.0",
16
+ "@opengeoweb/webmap-react": "12.5.0",
17
17
  "react-redux": "^9.2.0",
18
- "@opengeoweb/core": "12.4.2",
19
- "@opengeoweb/authentication": "12.4.2",
18
+ "@opengeoweb/core": "12.5.0",
19
+ "@opengeoweb/authentication": "12.5.0",
20
20
  "@mui/system": "^7.0.1",
21
- "@opengeoweb/form-fields": "12.4.2",
21
+ "@opengeoweb/form-fields": "12.5.0",
22
22
  "react-hook-form": "^7.50.1",
23
23
  "axios": "^1.7.7",
24
24
  "lodash": "^4.17.21",
@@ -299,6 +299,8 @@ export interface FormFieldProps {
299
299
  onChange?: (event?: React.ChangeEvent<HTMLInputElement>, phenomenaList?: AviationPhenomenon[]) => void;
300
300
  isDisabled: boolean;
301
301
  isReadOnly?: boolean;
302
+ onUserChange?: () => void;
303
+ hasUserChangedTime?: boolean;
302
304
  }
303
305
  export interface ConfigurableFormFieldProps extends FormFieldProps {
304
306
  productConfig: ProductConfig;