datastake-daf 0.6.535 → 0.6.536
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/dist/hooks/index.js +307 -0
- package/package.json +1 -1
- package/src/@daf/hooks/usePermissions.js +12 -12
- package/src/hooks.js +2 -1
package/dist/hooks/index.js
CHANGED
|
@@ -7,10 +7,17 @@ var g2 = require('@antv/g2');
|
|
|
7
7
|
var g2plot = require('@antv/g2plot');
|
|
8
8
|
require('country-city-location');
|
|
9
9
|
var L = require('leaflet');
|
|
10
|
+
var lodash = require('lodash');
|
|
11
|
+
var PropTypes = require('prop-types');
|
|
12
|
+
var reactIs = require('react-is');
|
|
13
|
+
require('react-dom');
|
|
10
14
|
|
|
11
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
16
|
|
|
17
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
13
18
|
var L__default = /*#__PURE__*/_interopDefaultLegacy(L);
|
|
19
|
+
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
20
|
+
var reactIs__default = /*#__PURE__*/_interopDefaultLegacy(reactIs);
|
|
14
21
|
|
|
15
22
|
const defaultFilterKeys = ["search", "sortDir", "sortBy", "timeframe", "activeTab"];
|
|
16
23
|
function hasJsonStructure(str) {
|
|
@@ -1272,6 +1279,305 @@ const useMapOnExpandableWidget = ({
|
|
|
1272
1279
|
};
|
|
1273
1280
|
};
|
|
1274
1281
|
|
|
1282
|
+
var global$1 = (typeof global !== "undefined" ? global :
|
|
1283
|
+
typeof self !== "undefined" ? self :
|
|
1284
|
+
typeof window !== "undefined" ? window : {});
|
|
1285
|
+
|
|
1286
|
+
// shim for using process in browser
|
|
1287
|
+
// based off https://github.com/defunctzombie/node-process/blob/master/browser.js
|
|
1288
|
+
|
|
1289
|
+
function defaultSetTimout() {
|
|
1290
|
+
throw new Error('setTimeout has not been defined');
|
|
1291
|
+
}
|
|
1292
|
+
function defaultClearTimeout () {
|
|
1293
|
+
throw new Error('clearTimeout has not been defined');
|
|
1294
|
+
}
|
|
1295
|
+
var cachedSetTimeout = defaultSetTimout;
|
|
1296
|
+
var cachedClearTimeout = defaultClearTimeout;
|
|
1297
|
+
if (typeof global$1.setTimeout === 'function') {
|
|
1298
|
+
cachedSetTimeout = setTimeout;
|
|
1299
|
+
}
|
|
1300
|
+
if (typeof global$1.clearTimeout === 'function') {
|
|
1301
|
+
cachedClearTimeout = clearTimeout;
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
function runTimeout(fun) {
|
|
1305
|
+
if (cachedSetTimeout === setTimeout) {
|
|
1306
|
+
//normal enviroments in sane situations
|
|
1307
|
+
return setTimeout(fun, 0);
|
|
1308
|
+
}
|
|
1309
|
+
// if setTimeout wasn't available but was latter defined
|
|
1310
|
+
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
|
1311
|
+
cachedSetTimeout = setTimeout;
|
|
1312
|
+
return setTimeout(fun, 0);
|
|
1313
|
+
}
|
|
1314
|
+
try {
|
|
1315
|
+
// when when somebody has screwed with setTimeout but no I.E. maddness
|
|
1316
|
+
return cachedSetTimeout(fun, 0);
|
|
1317
|
+
} catch(e){
|
|
1318
|
+
try {
|
|
1319
|
+
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
|
1320
|
+
return cachedSetTimeout.call(null, fun, 0);
|
|
1321
|
+
} catch(e){
|
|
1322
|
+
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
|
|
1323
|
+
return cachedSetTimeout.call(this, fun, 0);
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
|
|
1328
|
+
}
|
|
1329
|
+
function runClearTimeout(marker) {
|
|
1330
|
+
if (cachedClearTimeout === clearTimeout) {
|
|
1331
|
+
//normal enviroments in sane situations
|
|
1332
|
+
return clearTimeout(marker);
|
|
1333
|
+
}
|
|
1334
|
+
// if clearTimeout wasn't available but was latter defined
|
|
1335
|
+
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
|
1336
|
+
cachedClearTimeout = clearTimeout;
|
|
1337
|
+
return clearTimeout(marker);
|
|
1338
|
+
}
|
|
1339
|
+
try {
|
|
1340
|
+
// when when somebody has screwed with setTimeout but no I.E. maddness
|
|
1341
|
+
return cachedClearTimeout(marker);
|
|
1342
|
+
} catch (e){
|
|
1343
|
+
try {
|
|
1344
|
+
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
|
1345
|
+
return cachedClearTimeout.call(null, marker);
|
|
1346
|
+
} catch (e){
|
|
1347
|
+
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
|
|
1348
|
+
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
|
|
1349
|
+
return cachedClearTimeout.call(this, marker);
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
|
|
1354
|
+
|
|
1355
|
+
}
|
|
1356
|
+
var queue = [];
|
|
1357
|
+
var draining = false;
|
|
1358
|
+
var currentQueue;
|
|
1359
|
+
var queueIndex = -1;
|
|
1360
|
+
|
|
1361
|
+
function cleanUpNextTick() {
|
|
1362
|
+
if (!draining || !currentQueue) {
|
|
1363
|
+
return;
|
|
1364
|
+
}
|
|
1365
|
+
draining = false;
|
|
1366
|
+
if (currentQueue.length) {
|
|
1367
|
+
queue = currentQueue.concat(queue);
|
|
1368
|
+
} else {
|
|
1369
|
+
queueIndex = -1;
|
|
1370
|
+
}
|
|
1371
|
+
if (queue.length) {
|
|
1372
|
+
drainQueue();
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
function drainQueue() {
|
|
1377
|
+
if (draining) {
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1380
|
+
var timeout = runTimeout(cleanUpNextTick);
|
|
1381
|
+
draining = true;
|
|
1382
|
+
|
|
1383
|
+
var len = queue.length;
|
|
1384
|
+
while(len) {
|
|
1385
|
+
currentQueue = queue;
|
|
1386
|
+
queue = [];
|
|
1387
|
+
while (++queueIndex < len) {
|
|
1388
|
+
if (currentQueue) {
|
|
1389
|
+
currentQueue[queueIndex].run();
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
queueIndex = -1;
|
|
1393
|
+
len = queue.length;
|
|
1394
|
+
}
|
|
1395
|
+
currentQueue = null;
|
|
1396
|
+
draining = false;
|
|
1397
|
+
runClearTimeout(timeout);
|
|
1398
|
+
}
|
|
1399
|
+
function nextTick(fun) {
|
|
1400
|
+
var args = new Array(arguments.length - 1);
|
|
1401
|
+
if (arguments.length > 1) {
|
|
1402
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
1403
|
+
args[i - 1] = arguments[i];
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
queue.push(new Item(fun, args));
|
|
1407
|
+
if (queue.length === 1 && !draining) {
|
|
1408
|
+
runTimeout(drainQueue);
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
// v8 likes predictible objects
|
|
1412
|
+
function Item(fun, array) {
|
|
1413
|
+
this.fun = fun;
|
|
1414
|
+
this.array = array;
|
|
1415
|
+
}
|
|
1416
|
+
Item.prototype.run = function () {
|
|
1417
|
+
this.fun.apply(null, this.array);
|
|
1418
|
+
};
|
|
1419
|
+
var title = 'browser';
|
|
1420
|
+
var platform = 'browser';
|
|
1421
|
+
var browser = true;
|
|
1422
|
+
var env = {};
|
|
1423
|
+
var argv = [];
|
|
1424
|
+
var version = ''; // empty string to avoid regexp issues
|
|
1425
|
+
var versions = {};
|
|
1426
|
+
var release = {};
|
|
1427
|
+
var config = {};
|
|
1428
|
+
|
|
1429
|
+
function noop() {}
|
|
1430
|
+
|
|
1431
|
+
var on = noop;
|
|
1432
|
+
var addListener = noop;
|
|
1433
|
+
var once = noop;
|
|
1434
|
+
var off = noop;
|
|
1435
|
+
var removeListener = noop;
|
|
1436
|
+
var removeAllListeners = noop;
|
|
1437
|
+
var emit = noop;
|
|
1438
|
+
|
|
1439
|
+
function binding(name) {
|
|
1440
|
+
throw new Error('process.binding is not supported');
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
function cwd () { return '/' }
|
|
1444
|
+
function chdir (dir) {
|
|
1445
|
+
throw new Error('process.chdir is not supported');
|
|
1446
|
+
}function umask() { return 0; }
|
|
1447
|
+
|
|
1448
|
+
// from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
|
|
1449
|
+
var performance = global$1.performance || {};
|
|
1450
|
+
var performanceNow =
|
|
1451
|
+
performance.now ||
|
|
1452
|
+
performance.mozNow ||
|
|
1453
|
+
performance.msNow ||
|
|
1454
|
+
performance.oNow ||
|
|
1455
|
+
performance.webkitNow ||
|
|
1456
|
+
function(){ return (new Date()).getTime() };
|
|
1457
|
+
|
|
1458
|
+
// generate timestamp or delta
|
|
1459
|
+
// see http://nodejs.org/api/process.html#process_process_hrtime
|
|
1460
|
+
function hrtime(previousTimestamp){
|
|
1461
|
+
var clocktime = performanceNow.call(performance)*1e-3;
|
|
1462
|
+
var seconds = Math.floor(clocktime);
|
|
1463
|
+
var nanoseconds = Math.floor((clocktime%1)*1e9);
|
|
1464
|
+
if (previousTimestamp) {
|
|
1465
|
+
seconds = seconds - previousTimestamp[0];
|
|
1466
|
+
nanoseconds = nanoseconds - previousTimestamp[1];
|
|
1467
|
+
if (nanoseconds<0) {
|
|
1468
|
+
seconds--;
|
|
1469
|
+
nanoseconds += 1e9;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
return [seconds,nanoseconds]
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
var startTime = new Date();
|
|
1476
|
+
function uptime() {
|
|
1477
|
+
var currentTime = new Date();
|
|
1478
|
+
var dif = currentTime - startTime;
|
|
1479
|
+
return dif / 1000;
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
var browser$1 = {
|
|
1483
|
+
nextTick: nextTick,
|
|
1484
|
+
title: title,
|
|
1485
|
+
browser: browser,
|
|
1486
|
+
env: env,
|
|
1487
|
+
argv: argv,
|
|
1488
|
+
version: version,
|
|
1489
|
+
versions: versions,
|
|
1490
|
+
on: on,
|
|
1491
|
+
addListener: addListener,
|
|
1492
|
+
once: once,
|
|
1493
|
+
off: off,
|
|
1494
|
+
removeListener: removeListener,
|
|
1495
|
+
removeAllListeners: removeAllListeners,
|
|
1496
|
+
emit: emit,
|
|
1497
|
+
binding: binding,
|
|
1498
|
+
cwd: cwd,
|
|
1499
|
+
chdir: chdir,
|
|
1500
|
+
umask: umask,
|
|
1501
|
+
hrtime: hrtime,
|
|
1502
|
+
platform: platform,
|
|
1503
|
+
release: release,
|
|
1504
|
+
config: config,
|
|
1505
|
+
uptime: uptime
|
|
1506
|
+
};
|
|
1507
|
+
|
|
1508
|
+
var process = browser$1;
|
|
1509
|
+
|
|
1510
|
+
var ReactReduxContext = /*#__PURE__*/React__default["default"].createContext(null);
|
|
1511
|
+
|
|
1512
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1513
|
+
ReactReduxContext.displayName = 'ReactRedux';
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1517
|
+
({
|
|
1518
|
+
store: PropTypes__default["default"].shape({
|
|
1519
|
+
subscribe: PropTypes__default["default"].func.isRequired,
|
|
1520
|
+
dispatch: PropTypes__default["default"].func.isRequired,
|
|
1521
|
+
getState: PropTypes__default["default"].func.isRequired
|
|
1522
|
+
}),
|
|
1523
|
+
context: PropTypes__default["default"].object,
|
|
1524
|
+
children: PropTypes__default["default"].any
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
var FORWARD_REF_STATICS = {
|
|
1529
|
+
'$$typeof': true,
|
|
1530
|
+
render: true,
|
|
1531
|
+
defaultProps: true,
|
|
1532
|
+
displayName: true,
|
|
1533
|
+
propTypes: true
|
|
1534
|
+
};
|
|
1535
|
+
var MEMO_STATICS = {
|
|
1536
|
+
'$$typeof': true,
|
|
1537
|
+
compare: true,
|
|
1538
|
+
defaultProps: true,
|
|
1539
|
+
displayName: true,
|
|
1540
|
+
propTypes: true,
|
|
1541
|
+
type: true
|
|
1542
|
+
};
|
|
1543
|
+
var TYPE_STATICS = {};
|
|
1544
|
+
TYPE_STATICS[reactIs__default["default"].ForwardRef] = FORWARD_REF_STATICS;
|
|
1545
|
+
TYPE_STATICS[reactIs__default["default"].Memo] = MEMO_STATICS;
|
|
1546
|
+
|
|
1547
|
+
const checkPermission = ({
|
|
1548
|
+
permission = '',
|
|
1549
|
+
defaultValue = false,
|
|
1550
|
+
permissions = {}
|
|
1551
|
+
}) => {
|
|
1552
|
+
return lodash.result(permissions, permission, defaultValue);
|
|
1553
|
+
};
|
|
1554
|
+
const checkPermissionList = ({
|
|
1555
|
+
permissionsList = [],
|
|
1556
|
+
defaultValue = false,
|
|
1557
|
+
permissions = {}
|
|
1558
|
+
}) => {
|
|
1559
|
+
return !!permissionsList.map(permission => checkPermission({
|
|
1560
|
+
permission,
|
|
1561
|
+
defaultValue,
|
|
1562
|
+
permissions
|
|
1563
|
+
})).filter(v => !!v).length;
|
|
1564
|
+
};
|
|
1565
|
+
const usePermissions = ({
|
|
1566
|
+
permission = '',
|
|
1567
|
+
defaultValue = false,
|
|
1568
|
+
user = {}
|
|
1569
|
+
}) => {
|
|
1570
|
+
const permissions = React.useMemo(() => user?.role?.permissions || {}, [user]);
|
|
1571
|
+
const value = React.useMemo(() => checkPermission({
|
|
1572
|
+
permissions,
|
|
1573
|
+
permission,
|
|
1574
|
+
defaultValue
|
|
1575
|
+
}), [permissions]);
|
|
1576
|
+
return value;
|
|
1577
|
+
};
|
|
1578
|
+
|
|
1579
|
+
exports.checkPermission = checkPermission;
|
|
1580
|
+
exports.checkPermissionList = checkPermissionList;
|
|
1275
1581
|
exports.useFilters = useFilters;
|
|
1276
1582
|
exports.useHeight = useHeight;
|
|
1277
1583
|
exports.useIsMobile = useIsMobile;
|
|
@@ -1279,6 +1585,7 @@ exports.useLinearGradientAreaChart = useLinearGradientAreaChart;
|
|
|
1279
1585
|
exports.useMapConfig = useMapConfig;
|
|
1280
1586
|
exports.useMapOnExpandableWidget = useMapOnExpandableWidget;
|
|
1281
1587
|
exports.usePagination = usePagination;
|
|
1588
|
+
exports.usePermissions = usePermissions;
|
|
1282
1589
|
exports.useRadialBarChart = useRadialBarChart;
|
|
1283
1590
|
exports.useSource = useSource;
|
|
1284
1591
|
exports.useThemeLayout = useThemeLayout;
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { result } from "lodash";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { useSelector } from "react-redux";
|
|
2
4
|
|
|
3
|
-
export const checkPermission = ({
|
|
4
|
-
permission = '',
|
|
5
|
-
defaultValue = false,
|
|
6
|
-
permissions = {}
|
|
7
|
-
}) => {
|
|
5
|
+
export const checkPermission = ({ permission = '', defaultValue = false, permissions = {} }) => {
|
|
8
6
|
return result(permissions, permission, defaultValue);
|
|
9
|
-
}
|
|
7
|
+
}
|
|
10
8
|
|
|
11
|
-
export const checkPermissionList = ({
|
|
12
|
-
permissionsList = [],
|
|
13
|
-
defaultValue = false,
|
|
14
|
-
permissions = {}
|
|
15
|
-
}) => {
|
|
9
|
+
export const checkPermissionList = ({ permissionsList = [], defaultValue = false, permissions = {} }) => {
|
|
16
10
|
return !!permissionsList
|
|
17
11
|
.map((permission) => checkPermission({ permission, defaultValue, permissions }))
|
|
18
12
|
.filter((v) => !!v)
|
|
19
13
|
.length;
|
|
20
|
-
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const usePermissions = ({ permission = '', defaultValue = false, user = {} }) => {
|
|
17
|
+
const permissions = useMemo(() => user?.role?.permissions || {}, [user]);
|
|
18
|
+
const value = useMemo(() => checkPermission({ permissions, permission, defaultValue }), [permissions]);
|
|
19
|
+
return value;
|
|
20
|
+
};
|
package/src/hooks.js
CHANGED
|
@@ -7,4 +7,5 @@ export { default as useRadialBarChart } from "./@daf/hooks/useRadialBarChart";
|
|
|
7
7
|
export { useMapConfig } from "./@daf/hooks/useMapHelper.js";
|
|
8
8
|
export { useIsMobile } from "./@daf/hooks/useIsMobile";
|
|
9
9
|
export { default as useSource } from "./@daf/hooks/useSources.js";
|
|
10
|
-
export { useMapOnExpandableWidget } from "./@daf/hooks/useMapOnExpandableWidget";
|
|
10
|
+
export { useMapOnExpandableWidget } from "./@daf/hooks/useMapOnExpandableWidget";
|
|
11
|
+
export { checkPermission, checkPermissionList, usePermissions } from "./@daf/hooks/usePermissions";
|