techsbcn-storybook 0.15.1 → 0.16.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.
@@ -58,6 +58,7 @@ interface ColumnProps {
58
58
  hasColor?: boolean;
59
59
  enumSuffix?: string;
60
60
  };
61
+ rowViewFormat?: (row: any) => any;
61
62
  }
62
63
  interface ActionProps {
63
64
  children: React.ReactNode;
@@ -61,6 +61,7 @@ interface ColumnProps {
61
61
  enumSuffix?: string;
62
62
  };
63
63
  orderBy?: string;
64
+ rowViewFormat?: (row: any) => any;
64
65
  }
65
66
  interface ActionProps {
66
67
  children: React.ReactNode;
@@ -3,6 +3,7 @@ interface UserList {
3
3
  id: number;
4
4
  name: string;
5
5
  image: string;
6
+ imageGuid: string;
6
7
  skills: string[];
7
8
  information: string;
8
9
  email: string;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ export declare const usePrevious: (value: any) => undefined;
3
+ export declare const useIsMounted: () => import("react").MutableRefObject<boolean>;
@@ -1,3 +1,4 @@
1
1
  export * from './CheckPermission';
2
2
  export * from './GroupBy';
3
3
  export * from './FileDownloader';
4
+ export * from './hooks';
@@ -135,14 +135,14 @@ var SearchComponent = function SearchComponent(props) {
135
135
  alignItems: "center"
136
136
  }, React__default.createElement(material.Grid, {
137
137
  item: true,
138
- xs: props.actions ? 6 : 12,
138
+ xs: props.actions ? 8 : 12,
139
139
  md: props.searchBar ? 4 : props.actions ? 6 : 12
140
140
  }, React__default.createElement(material.Box, {
141
141
  px: 1,
142
142
  className: (props.enableAfter ? 'main-background-color-after' : '') + " title"
143
143
  }, props.title)), props.actions && React__default.createElement(material.Grid, {
144
144
  item: true,
145
- xs: props.title ? 6 : 12,
145
+ xs: props.title ? 4 : 12,
146
146
  sx: {
147
147
  display: {
148
148
  xs: 'block',
@@ -153,14 +153,14 @@ var SearchComponent = function SearchComponent(props) {
153
153
  sx: {
154
154
  display: {
155
155
  xs: 'none',
156
- sm: 'flex'
156
+ md: 'flex'
157
157
  }
158
158
  }
159
159
  }, ActionsList(props.actions)), React__default.createElement(material.Box, {
160
160
  sx: {
161
161
  display: {
162
162
  xs: 'flex',
163
- sm: 'none'
163
+ md: 'none'
164
164
  }
165
165
  }
166
166
  }, props.actions.length > 1 ? React__default.createElement(material.Box, {
@@ -365,6 +365,50 @@ TextFieldComponent.defaultProps = {
365
365
  type: 'text'
366
366
  };
367
367
 
368
+ var checkPermission = function checkPermission(persmisionAvailable, userRoles) {
369
+ if (persmisionAvailable === null || persmisionAvailable === undefined || persmisionAvailable.length === 0) {
370
+ return true;
371
+ } else {
372
+ if (userRoles === undefined || userRoles === null || userRoles === 0) {
373
+ return false;
374
+ }
375
+ }
376
+
377
+ if (userRoles && Array.isArray(userRoles) && Array.isArray(persmisionAvailable)) {
378
+ return persmisionAvailable.some(function (r) {
379
+ return userRoles.indexOf(r) >= 0;
380
+ });
381
+ }
382
+
383
+ if (userRoles && !Array.isArray(userRoles) && !Array.isArray(persmisionAvailable)) {
384
+ return userRoles === persmisionAvailable;
385
+ }
386
+
387
+ if (userRoles && !Array.isArray(userRoles) && Array.isArray(persmisionAvailable)) {
388
+ return persmisionAvailable.indexOf(userRoles) >= 0;
389
+ }
390
+
391
+ return userRoles.indexOf(persmisionAvailable) >= 0;
392
+ };
393
+
394
+ var usePrevious = function usePrevious(value) {
395
+ var ref = React.useRef();
396
+ React.useEffect(function () {
397
+ ref.current = value;
398
+ });
399
+ return ref.current;
400
+ };
401
+ var useIsMounted = function useIsMounted() {
402
+ var isMounted = React.useRef(false);
403
+ React.useEffect(function () {
404
+ isMounted.current = true;
405
+ return function () {
406
+ isMounted.current = false;
407
+ };
408
+ }, []);
409
+ return isMounted;
410
+ };
411
+
368
412
  var ImageTableComponent = function ImageTableComponent(props) {
369
413
  var _useState = React.useState(false),
370
414
  loading = _useState[0],
@@ -374,17 +418,21 @@ var ImageTableComponent = function ImageTableComponent(props) {
374
418
  image = _useState2[0],
375
419
  setImage = _useState2[1];
376
420
 
421
+ var prevGuidState = usePrevious(props.guid);
422
+ var isMounted = useIsMounted();
377
423
  React.useEffect(function () {
378
- if (!image) {
424
+ if (prevGuidState !== props.guid) {
379
425
  setLoading(true);
380
426
  props.readFile(props.guid).then(function (result) {
381
- setImage(props.convertImage ? props.convertImage(result) : result);
382
- setLoading(false);
427
+ if (isMounted.current) {
428
+ setImage(props.convertImage ? props.convertImage(result) : result);
429
+ setLoading(false);
430
+ }
383
431
  })["catch"](function () {
384
432
  return setLoading(false);
385
433
  });
386
434
  }
387
- }, [props, image]);
435
+ }, [props, prevGuidState, isMounted]);
388
436
  return React__default.createElement(material.Box, {
389
437
  className: "images-table-component"
390
438
  }, loading ? React__default.createElement(material.Box, {
@@ -585,6 +633,16 @@ var TableComponent = function TableComponent(props) {
585
633
  return o;
586
634
  };
587
635
 
636
+ var checkFormat = function checkFormat(o, f) {
637
+ try {
638
+ o = f(o);
639
+ } catch (_error) {
640
+ return undefined;
641
+ }
642
+
643
+ return o;
644
+ };
645
+
588
646
  var EditableTableCell = function EditableTableCell(row, value, fieldName, editableCell) {
589
647
  var rowEdit = JSON.parse(JSON.stringify(row));
590
648
 
@@ -688,7 +746,7 @@ var TableComponent = function TableComponent(props) {
688
746
  tabIndex: -1,
689
747
  key: index
690
748
  }, props.columns.map(function (column) {
691
- var value = ObjectbyString(row, column.id);
749
+ var value = column.rowViewFormat ? checkFormat(row, column.rowViewFormat) : ObjectbyString(row, column.id);
692
750
  var isItemSelected = column.isCheck && isSelected(row.id);
693
751
  var guid = Math.random().toString(36).substring(7);
694
752
  return React__default.createElement(_.TableCell, {
@@ -708,7 +766,9 @@ var TableComponent = function TableComponent(props) {
708
766
  }, column.label !== '-' && React__default.createElement(_.Box, {
709
767
  display: "inline-block",
710
768
  className: "label-cell"
711
- }, column.label)), column.action ? React__default.createElement(_.Box, null, React__default.createElement(_.Box, {
769
+ }, column.label)), column.rowViewFormat ? React__default.createElement(_.Box, {
770
+ className: "format-value"
771
+ }, value) : column.action ? React__default.createElement(_.Box, null, React__default.createElement(_.Box, {
712
772
  display: "flex",
713
773
  className: "actions"
714
774
  }, column.action && column.action.map(function (action, i) {
@@ -969,6 +1029,18 @@ var SimpleTableComponent = function SimpleTableComponent(props) {
969
1029
  return o;
970
1030
  };
971
1031
 
1032
+ var checkFormat = function checkFormat(o, f) {
1033
+ var result = o;
1034
+
1035
+ try {
1036
+ result = f(o);
1037
+ } catch (_error) {
1038
+ return undefined;
1039
+ }
1040
+
1041
+ return result;
1042
+ };
1043
+
972
1044
  var EditableTableCell = function EditableTableCell(row, value, fieldName, editableCell) {
973
1045
  var rowEdit = JSON.parse(JSON.stringify(row));
974
1046
 
@@ -1052,7 +1124,6 @@ var SimpleTableComponent = function SimpleTableComponent(props) {
1052
1124
  }))), props.rows && props.rows.length > 0 ? props.rows.map(function (row, index) {
1053
1125
  var _props$isCheckTable17;
1054
1126
 
1055
- //const key = props.rows[index + 1] && props.rows[index + 1].id === row.id ? index : row.id;
1056
1127
  var rowColor = props.rowsColorColumn && ObjectbyString(row, props.rowsColorColumn.columnName) === props.rowsColorColumn.columnValue ? "row-color-" + props.rowsColorColumn.columnValue : '';
1057
1128
  var isRowSelected = ((_props$isCheckTable17 = props.isCheckTable) == null ? void 0 : _props$isCheckTable17.rowsChecked) && isSelected(row.id);
1058
1129
  return React__default.createElement(_.TableRow, {
@@ -1064,7 +1135,7 @@ var SimpleTableComponent = function SimpleTableComponent(props) {
1064
1135
  key: index
1065
1136
  }, props.columns.map(function (column) {
1066
1137
  if (column.id) {
1067
- var value = ObjectbyString(row, column.id);
1138
+ var value = column.rowViewFormat ? checkFormat(row, column.rowViewFormat) : ObjectbyString(row, column.id);
1068
1139
  var isItemSelected = column.isCheck && isSelected(row.id);
1069
1140
  var guid = Math.random().toString(36).substring(7);
1070
1141
  return React__default.createElement(_.TableCell, {
@@ -1087,7 +1158,9 @@ var SimpleTableComponent = function SimpleTableComponent(props) {
1087
1158
  }, column.label)), column.action ? React__default.createElement(_.Box, null, React__default.createElement(_.Box, {
1088
1159
  display: "flex",
1089
1160
  className: "actions"
1090
- }, column.action && column.action.map(function (action, i) {
1161
+ }, column.rowViewFormat ? React__default.createElement(_.Box, {
1162
+ className: "format-value"
1163
+ }, value) : column.action && column.action.map(function (action, i) {
1091
1164
  return React__default.createElement(_.Box, {
1092
1165
  key: i
1093
1166
  }, action.onClick && React__default.createElement(_.Box, {
@@ -1151,32 +1224,6 @@ var MainLayoutSimple = function MainLayoutSimple(props) {
1151
1224
  }, props.mainComponent))));
1152
1225
  };
1153
1226
 
1154
- var checkPermission = function checkPermission(persmisionAvailable, userRoles) {
1155
- if (persmisionAvailable === null || persmisionAvailable === undefined || persmisionAvailable.length === 0) {
1156
- return true;
1157
- } else {
1158
- if (userRoles === undefined || userRoles === null || userRoles === 0) {
1159
- return false;
1160
- }
1161
- }
1162
-
1163
- if (userRoles && Array.isArray(userRoles) && Array.isArray(persmisionAvailable)) {
1164
- return persmisionAvailable.some(function (r) {
1165
- return userRoles.indexOf(r) >= 0;
1166
- });
1167
- }
1168
-
1169
- if (userRoles && !Array.isArray(userRoles) && !Array.isArray(persmisionAvailable)) {
1170
- return userRoles === persmisionAvailable;
1171
- }
1172
-
1173
- if (userRoles && !Array.isArray(userRoles) && Array.isArray(persmisionAvailable)) {
1174
- return persmisionAvailable.indexOf(userRoles) >= 0;
1175
- }
1176
-
1177
- return userRoles.indexOf(persmisionAvailable) >= 0;
1178
- };
1179
-
1180
1227
  var VerticalNavItem = function VerticalNavItem(props) {
1181
1228
  var _useLocation = reactRouterDom.useLocation(),
1182
1229
  pathname = _useLocation.pathname;