@onehat/ui 0.3.163 → 0.3.165

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.163",
3
+ "version": "0.3.165",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -15,6 +15,7 @@ function Editor(props) {
15
15
  onEditorDelete: onDelete,
16
16
  editorMode,
17
17
  onEditMode,
18
+ verifyCanEdit,
18
19
  _viewer = {},
19
20
  _form = {},
20
21
 
@@ -32,8 +33,13 @@ function Editor(props) {
32
33
 
33
34
  const propsToPass = _.omit(props, ['self', 'reference', 'parent']);
34
35
 
36
+ let canEdit = true;
37
+ if (verifyCanEdit && !verifyCanEdit(selection)) {
38
+ canEdit = false;
39
+ }
40
+
35
41
  // Repository?.isRemotePhantomMode && selection.length === 1 &&
36
- if (editorMode === EDITOR_MODE__VIEW || isEditorViewOnly) {
42
+ if (editorMode === EDITOR_MODE__VIEW || isEditorViewOnly || !canEdit) {
37
43
  const record = selection[0];
38
44
  if (record.isDestroyed) {
39
45
  return null;
@@ -336,6 +336,9 @@ function GridComponent(props) {
336
336
  }
337
337
  } else {
338
338
  if (onEdit) {
339
+ if (verifyCanEdit && !verifyCanEdit(selection)) {
340
+ return;
341
+ }
339
342
  onEdit();
340
343
  }
341
344
  }
@@ -31,6 +31,7 @@ function Viewer(props) {
31
31
  columnDefaults = {}, // defaults for each Column defined in items (above)
32
32
  record,
33
33
  additionalViewButtons,
34
+ verifyCanEdit,
34
35
 
35
36
  // withComponent
36
37
  self,
@@ -222,25 +223,30 @@ function Viewer(props) {
222
223
  viewerComponents = null,
223
224
  ancillaryComponents = null;
224
225
 
225
-
226
226
  if (containerWidth) { // we need to render this component twice in order to get the container width. Skip this on first render
227
227
  additionalButtons = buildAdditionalButtons(additionalViewButtons);
228
228
  viewerComponents = buildFromItems();
229
229
  ancillaryComponents = buildAncillary();
230
230
  }
231
231
 
232
+ let canEdit = true;
233
+ if (verifyCanEdit && !verifyCanEdit([record])) {
234
+ canEdit = false;
235
+ }
236
+
232
237
  return <Column flex={flex} {...props} onLayout={onLayout}>
233
238
  {containerWidth && <>
234
239
 
235
240
  <ScrollView _web={{ height: 1 }} width="100%" pb={1} ref={scrollViewRef}>
236
- {onEditMode && <Row px={4} pt={4} alignItems="center" justifyContent="flex-end">
237
- <Button
238
- key="editBtn"
239
- onPress={onEditMode}
240
- leftIcon={<Icon as={Pencil} color="#fff" size="sm" />}
241
- color="#fff"
242
- >To Edit</Button>
243
- </Row>}
241
+ {canEdit && onEditMode &&
242
+ <Row px={4} pt={4} alignItems="center" justifyContent="flex-end">
243
+ <Button
244
+ key="editBtn"
245
+ onPress={onEditMode}
246
+ leftIcon={<Icon as={Pencil} color="#fff" size="sm" />}
247
+ color="#fff"
248
+ >To Edit</Button>
249
+ </Row>}
244
250
  {!_.isEmpty(additionalButtons) &&
245
251
  <Row p={4} alignItems="center" justifyContent="flex-end" flexWrap="wrap">
246
252
  {additionalButtons}