@onehat/ui 0.3.333 → 0.3.335

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.
@@ -13,6 +13,9 @@ import {
13
13
  SELECTION_MODE_SINGLE,
14
14
  SELECTION_MODE_MULTI,
15
15
  } from '../../Constants/Selection.js';
16
+ import {
17
+ EDIT,
18
+ } from '../../Constants/Commands.js';
16
19
  import {
17
20
  VERTICAL,
18
21
  } from '../../Constants/Directions.js';
@@ -31,8 +34,9 @@ import withData from '../Hoc/withData.js';
31
34
  import withEvents from '../Hoc/withEvents.js';
32
35
  import withSideEditor from '../Hoc/withSideEditor.js';
33
36
  import withFilters from '../Hoc/withFilters.js';
34
- import withPresetButtons from '../Hoc/withPresetButtons.js';
35
37
  import withMultiSelection from '../Hoc/withMultiSelection.js';
38
+ import withPresetButtons from '../Hoc/withPresetButtons.js';
39
+ import withPermissions from '../Hoc/withPermissions.js';
36
40
  import withSelection from '../Hoc/withSelection.js';
37
41
  import withWindowedEditor from '../Hoc/withWindowedEditor.js';
38
42
  import getIconButtonFromConfig from '../../Functions/getIconButtonFromConfig.js';
@@ -55,6 +59,7 @@ import PaginationToolbar from '../Toolbar/PaginationToolbar.js';
55
59
  import NoRecordsFound from '../Grid/NoRecordsFound.js';
56
60
  import Toolbar from '../Toolbar/Toolbar.js';
57
61
  import Loading from '../Messages/Loading.js';
62
+ import Unauthorized from '../Messages/Unauthorized.js';
58
63
  import _ from 'lodash';
59
64
 
60
65
  const DEPTH_INDENT_PX = 25;
@@ -105,6 +110,7 @@ function TreeComponent(props) {
105
110
  reload = null, // Whenever this value changes after initial render, the tree will reload from scratch
106
111
  parentIdIx,
107
112
  initialSelection,
113
+ canRecordBeEdited,
108
114
  onTreeLoad,
109
115
 
110
116
  // withComponent
@@ -134,6 +140,9 @@ function TreeComponent(props) {
134
140
  idIx,
135
141
  displayIx,
136
142
 
143
+ // withPermissions
144
+ canUser,
145
+
137
146
  // withSelection
138
147
  selection,
139
148
  setSelection,
@@ -863,6 +872,12 @@ function TreeComponent(props) {
863
872
  onNodeClick(item, e); // so reselect it
864
873
  }
865
874
  if (onEdit) {
875
+ if (canUser && !canUser(EDIT)) { // permissions
876
+ return;
877
+ }
878
+ if (canRecordBeEdited && !canRecordBeEdited(selection)) { // record can be edited
879
+ return;
880
+ }
866
881
  onEdit();
867
882
  }
868
883
  break;
@@ -1176,6 +1191,10 @@ function TreeComponent(props) {
1176
1191
  }
1177
1192
  }, [selectorId, selectorSelected]);
1178
1193
 
1194
+ if (canUser && !canUser('view')) {
1195
+ return <Unauthorized />;
1196
+ }
1197
+
1179
1198
  if (setWithEditListeners) {
1180
1199
  setWithEditListeners({ // Update withEdit's listeners on every render
1181
1200
  onBeforeAdd,
@@ -1320,15 +1339,17 @@ export const Tree = withComponent(
1320
1339
  withAlert(
1321
1340
  withEvents(
1322
1341
  withData(
1323
- // withMultiSelection(
1324
- withSelection(
1325
- withFilters(
1326
- withContextMenu(
1327
- TreeComponent
1342
+ withPermissions(
1343
+ // withMultiSelection(
1344
+ withSelection(
1345
+ withFilters(
1346
+ withContextMenu(
1347
+ TreeComponent
1348
+ )
1328
1349
  )
1329
1350
  )
1330
- )
1331
- // )
1351
+ // )
1352
+ )
1332
1353
  )
1333
1354
  )
1334
1355
  )
@@ -1338,20 +1359,22 @@ export const SideTreeEditor = withComponent(
1338
1359
  withAlert(
1339
1360
  withEvents(
1340
1361
  withData(
1341
- // withMultiSelection(
1342
- withSelection(
1343
- withSideEditor(
1344
- withFilters(
1345
- withPresetButtons(
1346
- withContextMenu(
1347
- TreeComponent
1362
+ withPermissions(
1363
+ // withMultiSelection(
1364
+ withSelection(
1365
+ withSideEditor(
1366
+ withFilters(
1367
+ withPresetButtons(
1368
+ withContextMenu(
1369
+ TreeComponent
1370
+ )
1348
1371
  )
1349
- )
1350
- ),
1351
- true // isTree
1372
+ ),
1373
+ true // isTree
1374
+ )
1352
1375
  )
1353
- )
1354
- // )
1376
+ // )
1377
+ )
1355
1378
  )
1356
1379
  )
1357
1380
  )
@@ -1361,20 +1384,22 @@ export const WindowedTreeEditor = withComponent(
1361
1384
  withAlert(
1362
1385
  withEvents(
1363
1386
  withData(
1364
- // withMultiSelection(
1365
- withSelection(
1366
- withWindowedEditor(
1367
- withFilters(
1368
- withPresetButtons(
1369
- withContextMenu(
1370
- TreeComponent
1387
+ withPermissions(
1388
+ // withMultiSelection(
1389
+ withSelection(
1390
+ withWindowedEditor(
1391
+ withFilters(
1392
+ withPresetButtons(
1393
+ withContextMenu(
1394
+ TreeComponent
1395
+ )
1371
1396
  )
1372
- )
1373
- ),
1374
- true // isTree
1397
+ ),
1398
+ true // isTree
1399
+ )
1375
1400
  )
1376
- )
1377
- // )
1401
+ // )
1402
+ )
1378
1403
  )
1379
1404
  )
1380
1405
  )
@@ -6,6 +6,9 @@ import {
6
6
  Row,
7
7
  Text,
8
8
  } from 'native-base';
9
+ import {
10
+ EDIT,
11
+ } from '../../Constants/Commands.js';
9
12
  import {
10
13
  EDITOR_TYPE__SIDE,
11
14
  } from '../../Constants/Editor.js';
@@ -33,7 +36,7 @@ function Viewer(props) {
33
36
  columnDefaults = {}, // defaults for each Column defined in items (above)
34
37
  record,
35
38
  additionalViewButtons,
36
- verifyCanEdit,
39
+ canRecordBeEdited,
37
40
 
38
41
  // withComponent
39
42
  self,
@@ -41,6 +44,10 @@ function Viewer(props) {
41
44
  // withData
42
45
  Repository,
43
46
 
47
+ // withPermissions
48
+ canUser,
49
+ showPermissionsError,
50
+
44
51
  // withEditor
45
52
  editorType,
46
53
  onEditMode,
@@ -246,7 +253,7 @@ function Viewer(props) {
246
253
  }
247
254
 
248
255
  let canEdit = true;
249
- if (verifyCanEdit && !verifyCanEdit([record])) {
256
+ if (canRecordBeEdited && !canRecordBeEdited([record])) {
250
257
  canEdit = false;
251
258
  }
252
259
 
@@ -259,13 +266,14 @@ function Viewer(props) {
259
266
  <Row flex={1} alignItems="center">
260
267
  <Text fontSize={20} ml={2} color="trueGray.500">View Mode</Text>
261
268
  </Row>
262
- <Button
263
- {...testProps('toEditBtn')}
264
- key="editBtn"
265
- onPress={onEditMode}
266
- leftIcon={<Icon as={Pencil} color="#fff" size="sm" />}
267
- color="#fff"
268
- >To Edit</Button>
269
+ {(!canUser || canUser(EDIT)) &&
270
+ <Button
271
+ {...testProps('toEditBtn')}
272
+ key="editBtn"
273
+ onPress={onEditMode}
274
+ leftIcon={<Icon as={Pencil} color="#fff" size="sm" />}
275
+ color="#fff"
276
+ >To Edit</Button>}
269
277
  </Toolbar>}
270
278
  {!_.isEmpty(additionalButtons) &&
271
279
  <Toolbar justifyContent="flex-end" flexWrap="wrap">
@@ -0,0 +1,8 @@
1
+ export const ADD = 'add';
2
+ export const EDIT = 'edit';
3
+ export const DELETE = 'delete';
4
+ export const VIEW = 'view';
5
+ export const COPY = 'copy';
6
+ export const DUPLICATE = 'duplicate';
7
+ export const PRINT = 'print';
8
+ export const UPLOAD_DOWNLOAD = 'uploadDownload';
@@ -0,0 +1,7 @@
1
+ export default function chunkArray(array, chunkSize) {
2
+ const result = [];
3
+ for (let i = 0; i < array.length; i += chunkSize) {
4
+ result.push(array.slice(i, i + chunkSize));
5
+ }
6
+ return result;
7
+ }
@@ -1,31 +0,0 @@
1
- import {
2
- Modal,
3
- Row,
4
- Text,
5
- } from 'native-base';
6
- import withRedux from '../Data/hoc/withRedux';
7
- import Loading from './Loading';
8
- import _ from 'lodash';
9
-
10
- export function WaitModal(props) {
11
- const {
12
- textMessage = 'Please wait...',
13
- waitStack,
14
- } = props;
15
-
16
- return <Modal {...props} _backdrop={{ bg: "#000" }}>
17
- <Modal.Content maxWidth="400px">
18
- <Modal.Body>
19
- <Row justifyContent="center" alignItems="center">
20
- <Loading minHeight="auto" h={5} w={5} mr={2} />
21
- <Text color="#000">{textMessage}</Text>
22
- {/* {!!waitStack ? <Text color="#000">{_.keys(waitStack).join(', ')}</Text> : null} */}
23
- </Row>
24
- </Modal.Body>
25
- </Modal.Content>
26
- </Modal>;
27
- }
28
-
29
- export default withRedux(WaitModal, [
30
- 'waitStack',
31
- ]);