@onehat/ui 0.3.143 → 0.3.147

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/ui",
3
- "version": "0.3.143",
3
+ "version": "0.3.147",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -697,7 +697,7 @@ export function ComboComponent(props) {
697
697
  if (selection[0]?.id === value) {
698
698
  setIsSearchMode(false);
699
699
  resetTextInputValue();
700
- if (hideMenuOnSelection) {
700
+ if (hideMenuOnSelection && !isEditor) {
701
701
  hideMenu();
702
702
  }
703
703
  return;
@@ -754,7 +754,7 @@ export function ComboComponent(props) {
754
754
  return;
755
755
  }
756
756
  const id = Repository ? item.id : item[idIx];
757
- if (id === value) {
757
+ if (id === value && !isEditor) {
758
758
  hideMenu();
759
759
  onInputFocus();
760
760
  }
@@ -119,10 +119,15 @@ function Form(props) {
119
119
  } = props,
120
120
  formRef = useRef(),
121
121
  styles = UiGlobals.styles,
122
- record = props.record?.length === 1 ? props.record[0] : props.record,
122
+ record = props.record?.length === 1 ? props.record[0] : props.record;
123
+ let skipAll = false;
124
+ if (record?.isDestroyed) {
125
+ skipAll = true; // if record is destroyed, skip render, but allow hooks to still be called
126
+ }
127
+ const
123
128
  isMultiple = _.isArray(record),
124
129
  isSingle = !isMultiple, // for convenience
125
- isPhantom = !!record?.isPhantom,
130
+ isPhantom = !skipAll && !!record?.isPhantom, //
126
131
  forceUpdate = useForceUpdate(),
127
132
  [previousRecord, setPreviousRecord] = useState(record),
128
133
  [containerWidth, setContainerWidth] = useState(),
@@ -507,7 +512,7 @@ function Form(props) {
507
512
  let message = null;
508
513
  if (error) {
509
514
  message = error.message;
510
- if (label) {
515
+ if (label && error.ref?.name) {
511
516
  message = message.replace(error.ref.name, label);
512
517
  }
513
518
  }
@@ -660,6 +665,9 @@ function Form(props) {
660
665
  };
661
666
 
662
667
  useEffect(() => {
668
+ if (skipAll) {
669
+ return;
670
+ }
663
671
  if (record === previousRecord) {
664
672
  if (onInit) {
665
673
  onInit(initialValues, formSetValue, formGetValues);
@@ -674,6 +682,9 @@ function Form(props) {
674
682
  }, [record]);
675
683
 
676
684
  useEffect(() => {
685
+ if (skipAll) {
686
+ return;
687
+ }
677
688
  if (!Repository) {
678
689
  return () => {
679
690
  if (!_.isNil(editorStateRef)) {
@@ -692,6 +703,10 @@ function Form(props) {
692
703
  };
693
704
  }, [Repository]);
694
705
 
706
+ if (skipAll) {
707
+ return null;
708
+ }
709
+
695
710
  // if (Repository && (!record || _.isEmpty(record) || record.isDestroyed)) {
696
711
  // return null;
697
712
  // }
@@ -765,7 +780,7 @@ function Form(props) {
765
780
  editor = <>
766
781
  {containerWidth >= CONTAINER_THRESHOLD ? <Row p={4} pl={0}>{formComponents}</Row> : null}
767
782
  {containerWidth < CONTAINER_THRESHOLD ? <Column p={4}>{formComponents}</Column> : null}
768
- <Column m={2} pt={4}>{formAncillaryComponents}</Column>
783
+ <Column m={2} pt={4} px={2}>{formAncillaryComponents}</Column>
769
784
  </>;
770
785
 
771
786
  additionalButtons = buildAdditionalButtons(additionalEditButtons);
@@ -76,6 +76,11 @@ export default function withEditor(WrappedComponent, isTree = false) {
76
76
  const formState = editorStateRef.current;
77
77
  if (!_.isEmpty(formState?.dirtyFields) && newSelection !== selection && editorMode === EDITOR_MODE__EDIT) {
78
78
  confirm('This record has unsaved changes. Are you sure you want to cancel editing? Changes will be lost.', doIt);
79
+ } else if (selection && (selection[0]?.isPhantom || selection[0]?.isRemotePhantom)) {
80
+ confirm('This new record is unsaved. Are you sure you want to cancel editing? Changes will be lost.', async () => {
81
+ await selection[0].delete();
82
+ doIt();
83
+ });
79
84
  } else {
80
85
  doIt();
81
86
  }