@plusscommunities/pluss-core-web 1.6.19-beta.0 → 1.6.19-beta.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.
package/dist/index.cjs.js CHANGED
@@ -24,6 +24,7 @@ var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProp
24
24
  var reactColor = require('react-color');
25
25
  var tinycolor = require('tinycolor2');
26
26
  var reactRouterDom = require('react-router-dom');
27
+ var recharts = require('recharts');
27
28
  var freeSolidSvgIcons = require('@fortawesome/free-solid-svg-icons');
28
29
 
29
30
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -357,25 +358,25 @@ var session = /*#__PURE__*/Object.freeze({
357
358
  });
358
359
 
359
360
  // Distinct colour palette for multi-site comparison charts
360
- const SITE_COLOURS = ['#5e9efc',
361
+ const SITE_COLOURS = ["#5e9efc",
361
362
  // Blue
362
- '#49bdbb',
363
+ "#49bdbb",
363
364
  // Teal
364
- '#ff8c75',
365
+ "#ff8c75",
365
366
  // Tangerine
366
- '#6e79c5',
367
+ "#6e79c5",
367
368
  // Purple
368
- '#00cc9c',
369
+ "#00cc9c",
369
370
  // Green
370
- '#c02743',
371
+ "#c02743",
371
372
  // Red
372
- '#bdbd27',
373
+ "#bdbd27",
373
374
  // Citron
374
- '#191e78',
375
+ "#191e78",
375
376
  // Dark Blue
376
- '#ff6363',
377
+ "#ff6363",
377
378
  // Grapefruit
378
- '#536280' // Dusk
379
+ "#536280" // Dusk
379
380
  ];
380
381
  const getSiteColour = index => {
381
382
  return SITE_COLOURS[index % SITE_COLOURS.length];
@@ -443,33 +444,33 @@ const getInsight = (stats, previousStats, source, key, activity) => {
443
444
  };
444
445
  const getAnalyticsFilterOptions = () => {
445
446
  return [{
446
- text: 'Yesterday',
447
+ text: "Yesterday",
447
448
  dayCount: 1,
448
- prevText: 'day before'
449
+ prevText: "day before"
449
450
  }, {
450
- text: 'Last 7 days',
451
+ text: "Last 7 days",
451
452
  dayCount: 7,
452
- prevText: 'previous 7 days'
453
+ prevText: "previous 7 days"
453
454
  }, {
454
- text: 'Last 14 days',
455
+ text: "Last 14 days",
455
456
  dayCount: 14,
456
- prevText: 'previous 14 days'
457
+ prevText: "previous 14 days"
457
458
  }, {
458
- text: 'Last 30 days',
459
+ text: "Last 30 days",
459
460
  dayCount: 30,
460
- prevText: 'previous 30 days'
461
+ prevText: "previous 30 days"
461
462
  }, {
462
- text: 'Last 90 days',
463
+ text: "Last 90 days",
463
464
  dayCount: 90,
464
- prevText: 'previous 90 days'
465
+ prevText: "previous 90 days"
465
466
  }, {
466
- text: 'Last 365 days',
467
+ text: "Last 365 days",
467
468
  dayCount: 365,
468
- prevText: 'previous 365 days'
469
+ prevText: "previous 365 days"
469
470
  }, {
470
- text: 'Custom Range',
471
+ text: "Custom Range",
471
472
  dayCount: 0,
472
- prevText: 'previous * days'
473
+ prevText: "previous * days"
473
474
  }];
474
475
  };
475
476
  const countActivities = (data, activityKey, countType) => {
@@ -480,19 +481,19 @@ const countActivities = (data, activityKey, countType) => {
480
481
  for (const entity in stats) {
481
482
  const entityStats = stats[entity];
482
483
  switch (countType) {
483
- case 'unique':
484
+ case "unique":
484
485
  if (entityStats[activityKey]) {
485
486
  set.add(entity);
486
487
  }
487
488
  break;
488
- case 'uniquearray':
489
+ case "uniquearray":
489
490
  if (entityStats[activityKey]) {
490
491
  ___default["default"].values(entityStats[activityKey]).forEach(value => {
491
492
  set.add(value);
492
493
  });
493
494
  }
494
495
  break;
495
- case 'total':
496
+ case "total":
496
497
  if (entityStats[activityKey]) {
497
498
  count += entityStats[activityKey];
498
499
  }
@@ -501,23 +502,23 @@ const countActivities = (data, activityKey, countType) => {
501
502
  }
502
503
  });
503
504
  switch (countType) {
504
- case 'unique':
505
- case 'uniquearray':
505
+ case "unique":
506
+ case "uniquearray":
506
507
  console.log(countType, set);
507
508
  return set.size;
508
- case 'total':
509
+ case "total":
509
510
  return count;
510
511
  default:
511
512
  return 0;
512
513
  }
513
514
  };
514
515
  const generateDateRangeObjects = function (startTime, endTime) {
515
- let groupBy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
516
+ let groupBy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "day";
516
517
  const startDate = moment__default["default"](startTime);
517
518
  const endDate = moment__default["default"](endTime);
518
519
  const dates = {};
519
520
  while (startDate.isSameOrBefore(endDate)) {
520
- const dateString = startDate.format('DD-MM-YYYY');
521
+ const dateString = startDate.format("DD-MM-YYYY");
521
522
  dates[dateString] = {
522
523
  Date: dateString,
523
524
  Timestamp: startDate.valueOf(),
@@ -528,28 +529,28 @@ const generateDateRangeObjects = function (startTime, endTime) {
528
529
  return dates;
529
530
  };
530
531
  const generateDateActivities = function (data, activityKey, countType, startTime, endTime) {
531
- let groupBy = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'day';
532
+ let groupBy = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : "day";
532
533
  const dates = generateDateRangeObjects(startTime, endTime, groupBy);
533
534
  const result = [];
534
- let formatToUse = 'DD-MM-YYYY';
535
- let labelFormat = 'D MMM';
535
+ let formatToUse = "DD-MM-YYYY";
536
+ let labelFormat = "D MMM";
536
537
  switch (groupBy) {
537
- case 'month':
538
- formatToUse = 'MM-YYYY';
539
- labelFormat = 'MMMM';
538
+ case "month":
539
+ formatToUse = "MM-YYYY";
540
+ labelFormat = "MMMM";
540
541
  break;
541
- case 'week':
542
- formatToUse = 'w-gggg';
543
- labelFormat = '[Week of] D MMM';
542
+ case "week":
543
+ formatToUse = "w-gggg";
544
+ labelFormat = "[Week of] D MMM";
544
545
  break;
545
546
  }
546
547
  Object.keys(dates).forEach(d => {
547
548
  const datesToUse = ___default["default"].filter(data, date => {
548
- return moment__default["default"](date.Date, 'DD-MM-YYYY').format(formatToUse) === moment__default["default"](d, 'DD-MM-YYYY').format(formatToUse);
549
+ return moment__default["default"](date.Date, "DD-MM-YYYY").format(formatToUse) === moment__default["default"](d, "DD-MM-YYYY").format(formatToUse);
549
550
  }) || [dates[d]];
550
551
  const compiledValue = {
551
552
  date: d,
552
- label: moment__default["default"](d, 'DD-MM-YYYY').format(labelFormat),
553
+ label: moment__default["default"](d, "DD-MM-YYYY").format(labelFormat),
553
554
  value: countActivities(datesToUse, activityKey, countType)
554
555
  };
555
556
  result.push(compiledValue);
@@ -1201,8 +1202,8 @@ const addRecentlyCreated = feature => {
1201
1202
  const analyticsActions = {
1202
1203
  log: (site, actionType, entityType, entityId, data) => {
1203
1204
  return authedFunction({
1204
- method: 'POST',
1205
- url: getUrl('analytics', 'log'),
1205
+ method: "POST",
1206
+ url: getUrl("analytics", "log"),
1206
1207
  data: {
1207
1208
  site,
1208
1209
  actionType,
@@ -1214,8 +1215,8 @@ const analyticsActions = {
1214
1215
  },
1215
1216
  getEntityStats: (entityId, entityType) => {
1216
1217
  return authedFunction({
1217
- method: 'GET',
1218
- url: getUrl('analytics', 'getentity', {
1218
+ method: "GET",
1219
+ url: getUrl("analytics", "getentity", {
1219
1220
  entityId,
1220
1221
  entityType
1221
1222
  })
@@ -1240,14 +1241,14 @@ const analyticsActions = {
1240
1241
  if (userType) query.userType = userType;
1241
1242
  if (userCategory) query.userCategory = userCategory;
1242
1243
  return authedFunction({
1243
- method: 'GET',
1244
- url: getUrl('analytics', 'activity', query)
1244
+ method: "GET",
1245
+ url: getUrl("analytics", "activity", query)
1245
1246
  });
1246
1247
  },
1247
1248
  getAggregateUserStats: site => {
1248
1249
  return authedFunction({
1249
- method: 'GET',
1250
- url: getUrl('analytics', 'users', {
1250
+ method: "GET",
1251
+ url: getUrl("analytics", "users", {
1251
1252
  site
1252
1253
  })
1253
1254
  });
@@ -1267,8 +1268,8 @@ const analyticsActions = {
1267
1268
  if (userType) query.userType = userType;
1268
1269
  if (userCategory) query.userCategory = userCategory;
1269
1270
  return authedFunction({
1270
- method: 'GET',
1271
- url: getUrl('analytics', 'aggregate', query)
1271
+ method: "GET",
1272
+ url: getUrl("analytics", "aggregate", query)
1272
1273
  });
1273
1274
  },
1274
1275
  getUserRetention: function (site) {
@@ -1282,8 +1283,8 @@ const analyticsActions = {
1282
1283
  if (userType) query.userType = userType;
1283
1284
  if (userCategory) query.userCategory = userCategory;
1284
1285
  return authedFunction({
1285
- method: 'GET',
1286
- url: getUrl('analytics', 'get/userretention', query)
1286
+ method: "GET",
1287
+ url: getUrl("analytics", "get/userretention", query)
1287
1288
  });
1288
1289
  }
1289
1290
  };
@@ -9019,6 +9020,108 @@ class ColourPicker extends React.Component {
9019
9020
  }
9020
9021
  }
9021
9022
 
9023
+ const BAR_HEIGHT = 36;
9024
+ const CHART_PADDING = 20;
9025
+ const ComparisonStatBox = _ref => {
9026
+ let {
9027
+ title,
9028
+ icon,
9029
+ data,
9030
+ previousValue,
9031
+ prevText,
9032
+ viewGraphLink,
9033
+ isLoading
9034
+ } = _ref;
9035
+ const total = data.reduce((sum, d) => sum + (d.value || 0), 0);
9036
+ let change = (total / previousValue - 1) * 100;
9037
+ if (isNaN(change)) {
9038
+ change = 0;
9039
+ }
9040
+ if (!isFinite(change)) {
9041
+ change = 100;
9042
+ }
9043
+ change = parseInt(change);
9044
+ const chartHeight = data.length * BAR_HEIGHT + CHART_PADDING;
9045
+ const maxLabelLength = data.reduce((max, d) => Math.max(max, d.name.length), 0);
9046
+ const yAxisWidth = Math.min(Math.max(maxLabelLength * 7, 80), 160);
9047
+ const opacity = isLoading ? 0 : 1;
9048
+ return /*#__PURE__*/React__default["default"].createElement("div", {
9049
+ className: "dashboardBox dashboardBox-stats dashboardBox-inline".concat(change > 0 ? ' dashboardBox-stats-positive' : '').concat(change < 0 ? ' dashboardBox-stats-negative' : ''),
9050
+ style: {
9051
+ width: 'auto',
9052
+ minWidth: 300
9053
+ }
9054
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
9055
+ className: "dashboardBox-stats_title"
9056
+ }, /*#__PURE__*/React__default["default"].createElement(Text, {
9057
+ type: "h6"
9058
+ }, title)), /*#__PURE__*/React__default["default"].createElement("div", {
9059
+ className: "dashboardBox-stats_mid",
9060
+ style: {
9061
+ opacity
9062
+ }
9063
+ }, icon && /*#__PURE__*/React__default["default"].createElement(reactFontawesome.FontAwesomeIcon, {
9064
+ className: "dashboardBox-stats_icon",
9065
+ icon: icon
9066
+ }), /*#__PURE__*/React__default["default"].createElement(Text, {
9067
+ type: "h2",
9068
+ className: "dashboardBox-stats_count"
9069
+ }, total), /*#__PURE__*/React__default["default"].createElement("p", {
9070
+ className: "dashboardBox-stats_change"
9071
+ }, change === 0 ? 'No change' : change + '% ' + (change < 0 ? '↓' : '↑'))), /*#__PURE__*/React__default["default"].createElement(Text, {
9072
+ type: "help",
9073
+ style: {
9074
+ opacity
9075
+ }
9076
+ }, "Compared to ", prevText), /*#__PURE__*/React__default["default"].createElement("div", {
9077
+ style: {
9078
+ opacity,
9079
+ marginTop: 12,
9080
+ marginLeft: -8
9081
+ }
9082
+ }, /*#__PURE__*/React__default["default"].createElement(recharts.ResponsiveContainer, {
9083
+ width: "100%",
9084
+ height: chartHeight
9085
+ }, /*#__PURE__*/React__default["default"].createElement(recharts.BarChart, {
9086
+ data: data,
9087
+ layout: "vertical",
9088
+ margin: {
9089
+ top: 4,
9090
+ right: 12,
9091
+ bottom: 0,
9092
+ left: 0
9093
+ }
9094
+ }, /*#__PURE__*/React__default["default"].createElement(recharts.XAxis, {
9095
+ type: "number",
9096
+ hide: true
9097
+ }), /*#__PURE__*/React__default["default"].createElement(recharts.YAxis, {
9098
+ type: "category",
9099
+ dataKey: "name",
9100
+ width: yAxisWidth,
9101
+ tick: {
9102
+ fontSize: 12
9103
+ }
9104
+ }), /*#__PURE__*/React__default["default"].createElement(recharts.Tooltip, {
9105
+ formatter: value => [value, title]
9106
+ }), /*#__PURE__*/React__default["default"].createElement(recharts.Bar, {
9107
+ dataKey: "value",
9108
+ radius: [0, 4, 4, 0]
9109
+ }, data.map((entry, index) => /*#__PURE__*/React__default["default"].createElement(recharts.Cell, {
9110
+ key: entry.name,
9111
+ fill: getSiteColour(index)
9112
+ })))))), viewGraphLink && /*#__PURE__*/React__default["default"].createElement(reactRouterDom.Link, {
9113
+ to: viewGraphLink + '&title=' + title
9114
+ }, /*#__PURE__*/React__default["default"].createElement(Text, {
9115
+ type: "h5-noUpper",
9116
+ className: "text-link marginTop-10"
9117
+ }, /*#__PURE__*/React__default["default"].createElement(reactFontawesome.FontAwesomeIcon, {
9118
+ icon: freeSolidSvgIcons.faChartLine,
9119
+ style: {
9120
+ marginRight: 4
9121
+ }
9122
+ }), "View Graph")));
9123
+ };
9124
+
9022
9125
  // StatBox Component
9023
9126
  const StatBox = _ref => {
9024
9127
  let {
@@ -9120,6 +9223,7 @@ var index = /*#__PURE__*/Object.freeze({
9120
9223
  InputGroup: InputGroup,
9121
9224
  ColourOptions: ColourOptions,
9122
9225
  ColourPicker: ColourPicker,
9226
+ ComparisonStatBox: ComparisonStatBox,
9123
9227
  StatBox: StatBox,
9124
9228
  Tabs: Tabs
9125
9229
  });