techsbcn-storybook 0.14.9 → 0.15.2

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.
@@ -60,6 +60,7 @@ interface ColumnProps {
60
60
  hasColor?: boolean;
61
61
  enumSuffix?: string;
62
62
  };
63
+ orderBy?: string;
63
64
  }
64
65
  interface ActionProps {
65
66
  children: React.ReactNode;
@@ -0,0 +1,2 @@
1
+ import { ObjectKey } from '../interfaces';
2
+ export declare const ROUTES: ObjectKey;
@@ -6,4 +6,6 @@ interface ColourOption {
6
6
  export declare const colourOptions: ColourOption[];
7
7
  export declare const ResponseHandler: (response: any) => any;
8
8
  export declare const SearchSimple: (_filters: SearchFilters) => Promise<SearchSimpleResult[]>;
9
+ export declare const ResponseBlobHandler: (response: any) => any;
10
+ export declare const readFile: (guid: string) => Promise<any>;
9
11
  export {};
@@ -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;
@@ -1,5 +1,6 @@
1
1
  export * from './SelectMock';
2
2
  export * from './UserList';
3
3
  export * from './Values';
4
+ export * from './Routes';
4
5
  export * from './enums/scopes';
5
6
  export * from './enums/ActiveStatus';
@@ -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';
@@ -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,13 +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
- setLoading(true);
379
- props.readFile(props.guid).then(function (result) {
380
- setImage(props.convertImage ? props.convertImage(result) : result);
381
- setLoading(false);
382
- });
383
- }, [props]);
424
+ if (prevGuidState !== props.guid) {
425
+ setLoading(true);
426
+ props.readFile(props.guid).then(function (result) {
427
+ if (isMounted.current) {
428
+ setImage(props.convertImage ? props.convertImage(result) : result);
429
+ setLoading(false);
430
+ }
431
+ })["catch"](function () {
432
+ return setLoading(false);
433
+ });
434
+ }
435
+ }, [props, prevGuidState, isMounted]);
384
436
  return React__default.createElement(material.Box, {
385
437
  className: "images-table-component"
386
438
  }, loading ? React__default.createElement(material.Box, {
@@ -635,11 +687,12 @@ var TableComponent = function TableComponent(props) {
635
687
  }, React__default.createElement(_.Hidden, {
636
688
  smDown: true
637
689
  }, React__default.createElement(_.TableHead, null, React__default.createElement(_.TableRow, null, props.columns.map(function (column) {
638
- var _props$isCheckTable10, _props$isCheckTable11, _props$isCheckTable12;
690
+ var _ref, _props$isCheckTable10, _props$isCheckTable11, _props$isCheckTable12;
639
691
 
692
+ var guid = Math.random().toString(36).substring(7);
640
693
  return React__default.createElement(_.TableCell, {
641
694
  className: "table-column",
642
- key: column.isUnique ? column.id + "-unique" : column.id,
695
+ key: column.isUnique ? guid : column.id,
643
696
  align: column.align ? column.align : 'center',
644
697
  style: {
645
698
  minWidth: column.minWidth,
@@ -647,10 +700,12 @@ var TableComponent = function TableComponent(props) {
647
700
  }
648
701
  }, column.id !== 'actions' && !column.isCheck && !column.isActiveFunction && !column.noSort ? React__default.createElement(_.TableSortLabel, {
649
702
  className: "table-header-cell",
650
- active: filters.orderBy === column.id,
703
+ active: (_ref = filters.orderBy === column.orderBy) != null ? _ref : column.id,
651
704
  direction: filters.orderAsc ? 'asc' : 'desc',
652
705
  onClick: function onClick() {
653
- return createSortHandler(column.id);
706
+ var _column$orderBy;
707
+
708
+ return createSortHandler((_column$orderBy = column.orderBy) != null ? _column$orderBy : column.id);
654
709
  },
655
710
  hideSortIcon: true
656
711
  }, column.label) : column.isCheck ? React__default.createElement(_.Box, {
@@ -679,13 +734,14 @@ var TableComponent = function TableComponent(props) {
679
734
  className: "table-rows " + rowColor + " " + (props.onClickRow || props.onClickRowData ? 'row-click' : ''),
680
735
  role: "checkbox",
681
736
  tabIndex: -1,
682
- key: row.id || index
737
+ key: index
683
738
  }, props.columns.map(function (column) {
684
739
  var value = ObjectbyString(row, column.id);
685
740
  var isItemSelected = column.isCheck && isSelected(row.id);
741
+ var guid = Math.random().toString(36).substring(7);
686
742
  return React__default.createElement(_.TableCell, {
687
743
  className: "table-cell",
688
- key: column.isUnique ? column.id + "-unique" : column.id,
744
+ key: column.isUnique ? guid : column.id,
689
745
  sx: {
690
746
  textAlign: {
691
747
  xs: 'left',
@@ -749,10 +805,10 @@ var TableComponent = function TableComponent(props) {
749
805
  count: props.totalCount,
750
806
  rowsPerPage: props.baseFilters.limit,
751
807
  labelRowsPerPage: props.values.SHOWING,
752
- labelDisplayedRows: function labelDisplayedRows(_ref) {
753
- var from = _ref.from,
754
- to = _ref.to,
755
- count = _ref.count;
808
+ labelDisplayedRows: function labelDisplayedRows(_ref2) {
809
+ var from = _ref2.from,
810
+ to = _ref2.to,
811
+ count = _ref2.count;
756
812
  return props.values.TABLE_LABEL_DISPLAY(from, to, count);
757
813
  },
758
814
  page: props.baseFilters.page - 1,
@@ -1011,9 +1067,10 @@ var SimpleTableComponent = function SimpleTableComponent(props) {
1011
1067
  if (column.id) {
1012
1068
  var _props$isCheckTable13, _props$isCheckTable14, _props$isCheckTable15, _props$isCheckTable16;
1013
1069
 
1070
+ var guid = Math.random().toString(36).substring(7);
1014
1071
  return React__default.createElement(_.TableCell, {
1015
1072
  className: "table-column",
1016
- key: column.isUnique ? column.id + "-unique" : column.id,
1073
+ key: column.isUnique ? guid : column.id,
1017
1074
  align: column.align ? column.align : 'center',
1018
1075
  style: {
1019
1076
  minWidth: column.minWidth,
@@ -1043,7 +1100,7 @@ var SimpleTableComponent = function SimpleTableComponent(props) {
1043
1100
  }))), props.rows && props.rows.length > 0 ? props.rows.map(function (row, index) {
1044
1101
  var _props$isCheckTable17;
1045
1102
 
1046
- var key = props.rows[index + 1] && props.rows[index + 1].id === row.id ? index : row.id;
1103
+ //const key = props.rows[index + 1] && props.rows[index + 1].id === row.id ? index : row.id;
1047
1104
  var rowColor = props.rowsColorColumn && ObjectbyString(row, props.rowsColorColumn.columnName) === props.rowsColorColumn.columnValue ? "row-color-" + props.rowsColorColumn.columnValue : '';
1048
1105
  var isRowSelected = ((_props$isCheckTable17 = props.isCheckTable) == null ? void 0 : _props$isCheckTable17.rowsChecked) && isSelected(row.id);
1049
1106
  return React__default.createElement(_.TableRow, {
@@ -1052,14 +1109,15 @@ var SimpleTableComponent = function SimpleTableComponent(props) {
1052
1109
  tabIndex: -1,
1053
1110
  selected: isRowSelected,
1054
1111
  "aria-checked": isRowSelected,
1055
- key: key || index
1112
+ key: index
1056
1113
  }, props.columns.map(function (column) {
1057
1114
  if (column.id) {
1058
1115
  var value = ObjectbyString(row, column.id);
1059
1116
  var isItemSelected = column.isCheck && isSelected(row.id);
1117
+ var guid = Math.random().toString(36).substring(7);
1060
1118
  return React__default.createElement(_.TableCell, {
1061
1119
  className: "table-cell",
1062
- key: column.isUnique ? column.id + "-unique" : column.id,
1120
+ key: column.isUnique ? guid : column.id,
1063
1121
  sx: {
1064
1122
  textAlign: {
1065
1123
  xs: 'left',
@@ -1141,32 +1199,6 @@ var MainLayoutSimple = function MainLayoutSimple(props) {
1141
1199
  }, props.mainComponent))));
1142
1200
  };
1143
1201
 
1144
- var checkPermission = function checkPermission(persmisionAvailable, userRoles) {
1145
- if (persmisionAvailable === null || persmisionAvailable === undefined || persmisionAvailable.length === 0) {
1146
- return true;
1147
- } else {
1148
- if (userRoles === undefined || userRoles === null || userRoles === 0) {
1149
- return false;
1150
- }
1151
- }
1152
-
1153
- if (userRoles && Array.isArray(userRoles) && Array.isArray(persmisionAvailable)) {
1154
- return persmisionAvailable.some(function (r) {
1155
- return userRoles.indexOf(r) >= 0;
1156
- });
1157
- }
1158
-
1159
- if (userRoles && !Array.isArray(userRoles) && !Array.isArray(persmisionAvailable)) {
1160
- return userRoles === persmisionAvailable;
1161
- }
1162
-
1163
- if (userRoles && !Array.isArray(userRoles) && Array.isArray(persmisionAvailable)) {
1164
- return persmisionAvailable.indexOf(userRoles) >= 0;
1165
- }
1166
-
1167
- return userRoles.indexOf(persmisionAvailable) >= 0;
1168
- };
1169
-
1170
1202
  var VerticalNavItem = function VerticalNavItem(props) {
1171
1203
  var _useLocation = reactRouterDom.useLocation(),
1172
1204
  pathname = _useLocation.pathname;