@onehat/ui 0.3.112 → 0.3.114

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.112",
3
+ "version": "0.3.114",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -20,7 +20,7 @@ import _ from 'lodash';
20
20
  function TagComponent(props) {
21
21
 
22
22
  const {
23
- isEditor = false,
23
+ isViewOnly = false,
24
24
  isValueAlwaysArray,
25
25
  isValueAsStringifiedJson,
26
26
  Editor,
@@ -143,7 +143,7 @@ function TagComponent(props) {
143
143
  key={ix}
144
144
  text={val.text}
145
145
  onView={() => onView(val)}
146
- onDelete={() => onDelete(val)}
146
+ onDelete={!isViewOnly ? () => onDelete(val) : null}
147
147
  />;
148
148
  });
149
149
 
@@ -187,14 +187,14 @@ function TagComponent(props) {
187
187
  minHeight={10}
188
188
  flexWrap="wrap"
189
189
  >{valueBoxes}</Row>
190
- <WhichCombo
191
- Repository={props.Repository}
192
- Editor={props.Editor}
193
- onChangeValue={onChangeComboValue}
194
- parent={self}
195
- reference="combo"
196
- {..._combo}
197
- />
190
+ {!isViewOnly && <WhichCombo
191
+ Repository={props.Repository}
192
+ Editor={props.Editor}
193
+ onChangeValue={onChangeComboValue}
194
+ parent={self}
195
+ reference="combo"
196
+ {..._combo}
197
+ />}
198
198
  </Column>
199
199
  {isViewerShown &&
200
200
  <Modal
@@ -42,6 +42,8 @@ import withMultiSelection from '../Hoc/withMultiSelection.js';
42
42
  import withSelection from '../Hoc/withSelection.js';
43
43
  import withWindowedEditor from '../Hoc/withWindowedEditor.js';
44
44
  import withInlineEditor from '../Hoc/withInlineEditor.js';
45
+ import getSaved from '../../Functions/getSaved.js';
46
+ import setSaved from '../../Functions/setSaved.js';
45
47
  import getIconButtonFromConfig from '../../Functions/getIconButtonFromConfig.js';
46
48
  import testProps from '../../Functions/testProps.js';
47
49
  import nbToRgb from '../../Functions/nbToRgb.js';
@@ -167,6 +169,8 @@ function GridComponent(props) {
167
169
 
168
170
  } = props,
169
171
  styles = UiGlobals.styles,
172
+ id = props.id || props.self?.path,
173
+ localColumnsConfigKey = id && id + '-localColumnsConfig',
170
174
  forceUpdate = useForceUpdate(),
171
175
  containerRef = useRef(),
172
176
  gridRef = useRef(),
@@ -180,6 +184,10 @@ function GridComponent(props) {
180
184
  [dragRowSlot, setDragRowSlot] = useState(null),
181
185
  [dragRowIx, setDragRowIx] = useState(),
182
186
  setLocalColumnsConfig = (config) => {
187
+ if (localColumnsConfigKey) {
188
+ setSaved(localColumnsConfigKey, config);
189
+ }
190
+
183
191
  setLocalColumnsConfigRaw(config);
184
192
  if (onChangeColumnsConfig) {
185
193
  onChangeColumnsConfig(config);
@@ -718,79 +726,92 @@ function GridComponent(props) {
718
726
  return () => {};
719
727
  }
720
728
 
721
- // second call -- do other necessary setup
722
- function calculateLocalColumnsConfig() {
723
- // convert json config into actual elements
724
- const localColumnsConfig = [];
725
- if (_.isEmpty(columnsConfig)) {
726
- if (Repository) {
727
- // create a column for the displayProperty
728
- localColumnsConfig.push({
729
- fieldName: Repository.schema.model.displayProperty,
730
- });
731
- } else {
732
- localColumnsConfig.push({
733
- fieldName: displayField,
734
- });
735
- }
729
+ (async () => {
730
+
731
+ // second call -- do other necessary setup
732
+
733
+ // calculate localColumnsConfig
734
+ let localColumnsConfig = [];
735
+ let savedLocalColumnsConfig;
736
+ if (localColumnsConfigKey) {
737
+ savedLocalColumnsConfig = await getSaved(localColumnsConfigKey);
738
+ }
739
+ if (savedLocalColumnsConfig) {
740
+ // use saved
741
+ localColumnsConfig = savedLocalColumnsConfig;
736
742
  } else {
737
- _.each(columnsConfig, (columnConfig) => {
738
- if (!_.isPlainObject(columnConfig)) {
739
- localColumnsConfig.push(columnConfig);
740
- return;
743
+ // calculate new
744
+
745
+ // convert json config into actual elements
746
+ if (_.isEmpty(columnsConfig)) {
747
+ if (Repository) {
748
+ // create a column for the displayProperty
749
+ localColumnsConfig.push({
750
+ fieldName: Repository.schema.model.displayProperty,
751
+ });
752
+ } else {
753
+ localColumnsConfig.push({
754
+ fieldName: displayField,
755
+ });
741
756
  }
757
+ } else {
758
+ _.each(columnsConfig, (columnConfig) => {
759
+ if (!_.isPlainObject(columnConfig)) {
760
+ localColumnsConfig.push(columnConfig);
761
+ return;
762
+ }
742
763
 
743
- // destructure so we can set defaults
744
- const {
745
- header,
746
- fieldName, // from @onehat/data model
747
- type, // specify which column type to use (custom or built-in)
748
- isEditable = false,
749
- editor,
750
- format,
751
- renderer, // React component will render the output
752
- reorderable = true,
753
- resizable = true,
754
- sortable = true,
755
- w,
756
- flex,
757
- ...propsToPass
758
- } = columnConfig,
759
-
760
- config = {
761
- columnId: uuid(),
762
- header,
763
- fieldName,
764
- type,
765
- isEditable,
766
- editor,
767
- format,
768
- renderer,
769
- reorderable,
770
- resizable,
771
- sortable,
772
- w,
773
- flex,
774
- showDragHandles: false,
775
- ...propsToPass,
776
- };
777
-
778
- if (!(config.w || config.width) && !config.flex) {
779
- // Neither is set
780
- config.w = 100; // default
781
- } else if (config.flex && (config.w || config.width)) {
782
- // Both are set. Width overrules flex.
783
- delete config.flex;
784
- }
764
+ // destructure so we can set defaults
765
+ const {
766
+ header,
767
+ fieldName, // from @onehat/data model
768
+ type, // specify which column type to use (custom or built-in)
769
+ isEditable = false,
770
+ editor,
771
+ format,
772
+ renderer, // React component will render the output
773
+ reorderable = true,
774
+ resizable = true,
775
+ sortable = true,
776
+ w,
777
+ flex,
778
+ ...propsToPass
779
+ } = columnConfig,
780
+
781
+ config = {
782
+ columnId: uuid(),
783
+ header,
784
+ fieldName,
785
+ type,
786
+ isEditable,
787
+ editor,
788
+ format,
789
+ renderer,
790
+ reorderable,
791
+ resizable,
792
+ sortable,
793
+ w,
794
+ flex,
795
+ showDragHandles: false,
796
+ ...propsToPass,
797
+ };
798
+
799
+ if (!(config.w || config.width) && !config.flex) {
800
+ // Neither is set
801
+ config.w = 100; // default
802
+ } else if (config.flex && (config.w || config.width)) {
803
+ // Both are set. Width overrules flex.
804
+ delete config.flex;
805
+ }
785
806
 
786
- localColumnsConfig.push(config);
787
- });
807
+ localColumnsConfig.push(config);
808
+ });
809
+ }
788
810
  }
789
- return localColumnsConfig;
790
- }
791
- setLocalColumnsConfig(calculateLocalColumnsConfig());
811
+ setLocalColumnsConfig(localColumnsConfig);
792
812
 
793
- setIsReady(true);
813
+ setIsReady(true);
814
+ })();
794
815
 
795
816
  if (!Repository) {
796
817
  return () => {};
@@ -103,13 +103,17 @@ export default function GridRow(props) {
103
103
  if (item?.properties && item.properties[config.fieldName]) {
104
104
  const property = item.properties[config.fieldName];
105
105
  value = property.displayValue;
106
+ const type = property?.viewerType?.type;
106
107
 
107
- if (property?.viewerType?.type) {
108
- const Element = getComponentFromType(property?.viewerType?.type);
108
+ if (type) {
109
+ const Element = getComponentFromType(type);
109
110
  const elementProps = {};
110
111
  if (UiGlobals.mode === UI_MODE_WEB) {
111
112
  elementProps.textOverflow = 'ellipsis';
112
113
  }
114
+ if (type.match(/(Tag|TagEditor)$/)) {
115
+ elementProps.isViewOnly = true; // TODO: this won't work for InlineGridEditor, bc that Grid can't use isViewOnly when actually editing
116
+ }
113
117
  return <Element
114
118
  value={value}
115
119
  key={key}