@plusscommunities/pluss-core-web 1.4.19 → 1.4.21

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
@@ -32,6 +32,9 @@ var reactCsv = require('react-csv');
32
32
  var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
33
33
  var reactColor = require('react-color');
34
34
  var tinycolor = require('tinycolor2');
35
+ var reactRouterDom = require('react-router-dom');
36
+ var reactFontawesome = require('@fortawesome/react-fontawesome');
37
+ var freeSolidSvgIcons = require('@fortawesome/free-solid-svg-icons');
35
38
 
36
39
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
37
40
 
@@ -549,6 +552,10 @@ var getAnalyticsFilterOptions = function getAnalyticsFilterOptions() {
549
552
  text: 'Last 90 days',
550
553
  dayCount: 90,
551
554
  prevText: 'previous 90 days'
555
+ }, {
556
+ text: 'Last 365 days',
557
+ dayCount: 365,
558
+ prevText: 'previous 365 days'
552
559
  }, {
553
560
  text: 'Custom Range',
554
561
  dayCount: 0,
@@ -572,6 +579,15 @@ var countActivities = function countActivities(data, activityKey, countType) {
572
579
 
573
580
  break;
574
581
 
582
+ case 'uniquearray':
583
+ if (entityStats[activityKey]) {
584
+ ___default['default'].values(entityStats[activityKey]).forEach(function (value) {
585
+ set.add(value);
586
+ });
587
+ }
588
+
589
+ break;
590
+
575
591
  case 'total':
576
592
  if (entityStats[activityKey]) {
577
593
  count += entityStats[activityKey];
@@ -584,6 +600,8 @@ var countActivities = function countActivities(data, activityKey, countType) {
584
600
 
585
601
  switch (countType) {
586
602
  case 'unique':
603
+ case 'uniquearray':
604
+ console.log(countType, set);
587
605
  return set.size;
588
606
 
589
607
  case 'total':
@@ -594,6 +612,7 @@ var countActivities = function countActivities(data, activityKey, countType) {
594
612
  }
595
613
  };
596
614
  var generateDateRangeObjects = function generateDateRangeObjects(startTime, endTime) {
615
+ var groupBy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
597
616
  var startDate = moment__default['default'](startTime);
598
617
  var endDate = moment__default['default'](endTime);
599
618
  var dates = {};
@@ -605,24 +624,42 @@ var generateDateRangeObjects = function generateDateRangeObjects(startTime, endT
605
624
  Timestamp: startDate.valueOf(),
606
625
  Stats: {}
607
626
  };
608
- startDate.add(1, 'days');
627
+ startDate.add(1, groupBy);
609
628
  }
610
629
 
611
630
  return dates;
612
631
  };
613
632
  var generateDateActivities = function generateDateActivities(data, activityKey, countType, startTime, endTime) {
614
- var dates = generateDateRangeObjects(startTime, endTime);
633
+ var groupBy = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'day';
634
+ var dates = generateDateRangeObjects(startTime, endTime, groupBy);
615
635
  var result = [];
636
+ var formatToUse = 'DD-MM-YYYY';
637
+ var labelFormat = 'D MMM';
638
+
639
+ switch (groupBy) {
640
+ case 'month':
641
+ formatToUse = 'MM-YYYY';
642
+ labelFormat = 'MMMM';
643
+ break;
644
+
645
+ case 'week':
646
+ formatToUse = 'w-gggg';
647
+ labelFormat = '[Week of] D MMM';
648
+ break;
649
+ }
650
+
616
651
  Object.keys(dates).forEach(function (d) {
617
- var dateToUse = ___default['default'].find(data, function (date) {
618
- return date.Date === d;
619
- }) || dates[d];
652
+ var datesToUse = ___default['default'].filter(data, function (date) {
653
+ return moment__default['default'](date.Date, 'DD-MM-YYYY').format(formatToUse) === moment__default['default'](d, 'DD-MM-YYYY').format(formatToUse);
654
+ }) || [dates[d]];
620
655
  var compiledValue = {
621
656
  date: d,
622
- value: countActivities([dateToUse], activityKey, countType)
657
+ label: moment__default['default'](d, 'DD-MM-YYYY').format(labelFormat),
658
+ value: countActivities(datesToUse, activityKey, countType)
623
659
  };
624
660
  result.push(compiledValue);
625
661
  });
662
+ console.log(result);
626
663
  return result;
627
664
  };
628
665
 
@@ -8690,7 +8727,7 @@ var AnalyticsFilter = /*#__PURE__*/function (_PureComponent) {
8690
8727
  _createClass__default['default'](AnalyticsFilter, [{
8691
8728
  key: "render",
8692
8729
  value: function render() {
8693
- return /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("div", {
8730
+ return /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement("div", {
8694
8731
  className: "analyticsFilter__dropDown"
8695
8732
  }, /*#__PURE__*/React__default['default'].createElement(reactBootstrap.DropdownButton, {
8696
8733
  id: "secondLevelSort",
@@ -11513,6 +11550,63 @@ var ColourPicker = /*#__PURE__*/function (_Component) {
11513
11550
  return ColourPicker;
11514
11551
  }(React.Component);
11515
11552
 
11553
+ var StatBox = function StatBox(_ref) {
11554
+ var title = _ref.title,
11555
+ icon = _ref.icon,
11556
+ value = _ref.value,
11557
+ previousValue = _ref.previousValue,
11558
+ prevText = _ref.prevText,
11559
+ viewGraphLink = _ref.viewGraphLink,
11560
+ isLoading = _ref.isLoading;
11561
+ var change = (value / previousValue - 1) * 100;
11562
+
11563
+ if (isNaN(change)) {
11564
+ change = 0;
11565
+ }
11566
+
11567
+ if (!isFinite(change)) {
11568
+ change = 100;
11569
+ }
11570
+
11571
+ change = parseInt(change);
11572
+ var opacity = isLoading ? 0 : 1;
11573
+ return /*#__PURE__*/React__default['default'].createElement("div", {
11574
+ className: "dashboardBox dashboardBox-stats dashboardBox-inline".concat(change > 0 ? ' dashboardBox-stats-positive' : '').concat(change < 0 ? ' dashboardBox-stats-negative' : '')
11575
+ }, /*#__PURE__*/React__default['default'].createElement("div", {
11576
+ className: "dashboardBox-stats_title"
11577
+ }, /*#__PURE__*/React__default['default'].createElement(Text, {
11578
+ type: "h6"
11579
+ }, title)), /*#__PURE__*/React__default['default'].createElement("div", {
11580
+ className: "dashboardBox-stats_mid",
11581
+ style: {
11582
+ opacity: opacity
11583
+ }
11584
+ }, /*#__PURE__*/React__default['default'].createElement(reactFontawesome.FontAwesomeIcon, {
11585
+ className: "dashboardBox-stats_icon",
11586
+ icon: icon
11587
+ }), /*#__PURE__*/React__default['default'].createElement(Text, {
11588
+ type: "h2",
11589
+ className: "dashboardBox-stats_count"
11590
+ }, value), /*#__PURE__*/React__default['default'].createElement("p", {
11591
+ className: "dashboardBox-stats_change"
11592
+ }, change === 0 ? 'No change' : "".concat(change, "% ").concat(change < 0 ? '↓' : '↑'))), /*#__PURE__*/React__default['default'].createElement(Text, {
11593
+ type: "help",
11594
+ style: {
11595
+ opacity: opacity
11596
+ }
11597
+ }, "Compared to ", prevText), viewGraphLink && /*#__PURE__*/React__default['default'].createElement(reactRouterDom.Link, {
11598
+ to: "".concat(viewGraphLink, "&title=").concat(title)
11599
+ }, /*#__PURE__*/React__default['default'].createElement(Text, {
11600
+ type: "h5-noUpper",
11601
+ className: "text-link marginTop-10"
11602
+ }, /*#__PURE__*/React__default['default'].createElement(reactFontawesome.FontAwesomeIcon, {
11603
+ icon: freeSolidSvgIcons.faChartLine,
11604
+ style: {
11605
+ marginRight: 4
11606
+ }
11607
+ }), "View Graph")));
11608
+ };
11609
+
11516
11610
  var index = /*#__PURE__*/Object.freeze({
11517
11611
  __proto__: null,
11518
11612
  AddButton: AddButton,
@@ -11555,6 +11649,7 @@ var index = /*#__PURE__*/Object.freeze({
11555
11649
  ExportCsvPopup: ExportCsvPopup,
11556
11650
  InputGroup: InputGroup,
11557
11651
  ColourPicker: ColourPicker,
11652
+ StatBox: StatBox,
11558
11653
  Tabs: Tabs
11559
11654
  });
11560
11655
 
package/dist/index.esm.js CHANGED
@@ -28,6 +28,9 @@ import { CSVLink } from 'react-csv';
28
28
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
29
29
  import { ChromePicker } from 'react-color';
30
30
  import tinycolor from 'tinycolor2';
31
+ import { Link } from 'react-router-dom';
32
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
33
+ import { faChartLine } from '@fortawesome/free-solid-svg-icons';
31
34
 
32
35
  var CoreConfig = {
33
36
  env: {
@@ -519,6 +522,10 @@ var getAnalyticsFilterOptions = function getAnalyticsFilterOptions() {
519
522
  text: 'Last 90 days',
520
523
  dayCount: 90,
521
524
  prevText: 'previous 90 days'
525
+ }, {
526
+ text: 'Last 365 days',
527
+ dayCount: 365,
528
+ prevText: 'previous 365 days'
522
529
  }, {
523
530
  text: 'Custom Range',
524
531
  dayCount: 0,
@@ -542,6 +549,15 @@ var countActivities = function countActivities(data, activityKey, countType) {
542
549
 
543
550
  break;
544
551
 
552
+ case 'uniquearray':
553
+ if (entityStats[activityKey]) {
554
+ _.values(entityStats[activityKey]).forEach(function (value) {
555
+ set.add(value);
556
+ });
557
+ }
558
+
559
+ break;
560
+
545
561
  case 'total':
546
562
  if (entityStats[activityKey]) {
547
563
  count += entityStats[activityKey];
@@ -554,6 +570,8 @@ var countActivities = function countActivities(data, activityKey, countType) {
554
570
 
555
571
  switch (countType) {
556
572
  case 'unique':
573
+ case 'uniquearray':
574
+ console.log(countType, set);
557
575
  return set.size;
558
576
 
559
577
  case 'total':
@@ -564,6 +582,7 @@ var countActivities = function countActivities(data, activityKey, countType) {
564
582
  }
565
583
  };
566
584
  var generateDateRangeObjects = function generateDateRangeObjects(startTime, endTime) {
585
+ var groupBy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
567
586
  var startDate = moment(startTime);
568
587
  var endDate = moment(endTime);
569
588
  var dates = {};
@@ -575,24 +594,42 @@ var generateDateRangeObjects = function generateDateRangeObjects(startTime, endT
575
594
  Timestamp: startDate.valueOf(),
576
595
  Stats: {}
577
596
  };
578
- startDate.add(1, 'days');
597
+ startDate.add(1, groupBy);
579
598
  }
580
599
 
581
600
  return dates;
582
601
  };
583
602
  var generateDateActivities = function generateDateActivities(data, activityKey, countType, startTime, endTime) {
584
- var dates = generateDateRangeObjects(startTime, endTime);
603
+ var groupBy = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'day';
604
+ var dates = generateDateRangeObjects(startTime, endTime, groupBy);
585
605
  var result = [];
606
+ var formatToUse = 'DD-MM-YYYY';
607
+ var labelFormat = 'D MMM';
608
+
609
+ switch (groupBy) {
610
+ case 'month':
611
+ formatToUse = 'MM-YYYY';
612
+ labelFormat = 'MMMM';
613
+ break;
614
+
615
+ case 'week':
616
+ formatToUse = 'w-gggg';
617
+ labelFormat = '[Week of] D MMM';
618
+ break;
619
+ }
620
+
586
621
  Object.keys(dates).forEach(function (d) {
587
- var dateToUse = _.find(data, function (date) {
588
- return date.Date === d;
589
- }) || dates[d];
622
+ var datesToUse = _.filter(data, function (date) {
623
+ return moment(date.Date, 'DD-MM-YYYY').format(formatToUse) === moment(d, 'DD-MM-YYYY').format(formatToUse);
624
+ }) || [dates[d]];
590
625
  var compiledValue = {
591
626
  date: d,
592
- value: countActivities([dateToUse], activityKey, countType)
627
+ label: moment(d, 'DD-MM-YYYY').format(labelFormat),
628
+ value: countActivities(datesToUse, activityKey, countType)
593
629
  };
594
630
  result.push(compiledValue);
595
631
  });
632
+ console.log(result);
596
633
  return result;
597
634
  };
598
635
 
@@ -8660,7 +8697,7 @@ var AnalyticsFilter = /*#__PURE__*/function (_PureComponent) {
8660
8697
  _createClass(AnalyticsFilter, [{
8661
8698
  key: "render",
8662
8699
  value: function render() {
8663
- return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
8700
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
8664
8701
  className: "analyticsFilter__dropDown"
8665
8702
  }, /*#__PURE__*/React.createElement(DropdownButton, {
8666
8703
  id: "secondLevelSort",
@@ -11483,6 +11520,63 @@ var ColourPicker = /*#__PURE__*/function (_Component) {
11483
11520
  return ColourPicker;
11484
11521
  }(Component);
11485
11522
 
11523
+ var StatBox = function StatBox(_ref) {
11524
+ var title = _ref.title,
11525
+ icon = _ref.icon,
11526
+ value = _ref.value,
11527
+ previousValue = _ref.previousValue,
11528
+ prevText = _ref.prevText,
11529
+ viewGraphLink = _ref.viewGraphLink,
11530
+ isLoading = _ref.isLoading;
11531
+ var change = (value / previousValue - 1) * 100;
11532
+
11533
+ if (isNaN(change)) {
11534
+ change = 0;
11535
+ }
11536
+
11537
+ if (!isFinite(change)) {
11538
+ change = 100;
11539
+ }
11540
+
11541
+ change = parseInt(change);
11542
+ var opacity = isLoading ? 0 : 1;
11543
+ return /*#__PURE__*/React.createElement("div", {
11544
+ className: "dashboardBox dashboardBox-stats dashboardBox-inline".concat(change > 0 ? ' dashboardBox-stats-positive' : '').concat(change < 0 ? ' dashboardBox-stats-negative' : '')
11545
+ }, /*#__PURE__*/React.createElement("div", {
11546
+ className: "dashboardBox-stats_title"
11547
+ }, /*#__PURE__*/React.createElement(Text, {
11548
+ type: "h6"
11549
+ }, title)), /*#__PURE__*/React.createElement("div", {
11550
+ className: "dashboardBox-stats_mid",
11551
+ style: {
11552
+ opacity: opacity
11553
+ }
11554
+ }, /*#__PURE__*/React.createElement(FontAwesomeIcon, {
11555
+ className: "dashboardBox-stats_icon",
11556
+ icon: icon
11557
+ }), /*#__PURE__*/React.createElement(Text, {
11558
+ type: "h2",
11559
+ className: "dashboardBox-stats_count"
11560
+ }, value), /*#__PURE__*/React.createElement("p", {
11561
+ className: "dashboardBox-stats_change"
11562
+ }, change === 0 ? 'No change' : "".concat(change, "% ").concat(change < 0 ? '↓' : '↑'))), /*#__PURE__*/React.createElement(Text, {
11563
+ type: "help",
11564
+ style: {
11565
+ opacity: opacity
11566
+ }
11567
+ }, "Compared to ", prevText), viewGraphLink && /*#__PURE__*/React.createElement(Link, {
11568
+ to: "".concat(viewGraphLink, "&title=").concat(title)
11569
+ }, /*#__PURE__*/React.createElement(Text, {
11570
+ type: "h5-noUpper",
11571
+ className: "text-link marginTop-10"
11572
+ }, /*#__PURE__*/React.createElement(FontAwesomeIcon, {
11573
+ icon: faChartLine,
11574
+ style: {
11575
+ marginRight: 4
11576
+ }
11577
+ }), "View Graph")));
11578
+ };
11579
+
11486
11580
  var index = /*#__PURE__*/Object.freeze({
11487
11581
  __proto__: null,
11488
11582
  AddButton: AddButton,
@@ -11525,6 +11619,7 @@ var index = /*#__PURE__*/Object.freeze({
11525
11619
  ExportCsvPopup: ExportCsvPopup,
11526
11620
  InputGroup: InputGroup,
11527
11621
  ColourPicker: ColourPicker,
11622
+ StatBox: StatBox,
11528
11623
  Tabs: Tabs
11529
11624
  });
11530
11625
 
package/dist/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/helpers/asyncToGenerator'), require('@babel/runtime/regenerator'), require('lodash'), require('axios'), require('aws-amplify'), require('@babel/runtime/helpers/defineProperty'), require('moment'), require('react'), require('jquery'), require('js-cookie'), require('@babel/runtime/helpers/classCallCheck'), require('@babel/runtime/helpers/createClass'), require('@babel/runtime/helpers/inherits'), require('@babel/runtime/helpers/possibleConstructorReturn'), require('@babel/runtime/helpers/getPrototypeOf'), require('react-fontawesome'), require('@babel/runtime/helpers/extends'), require('@babel/runtime/helpers/assertThisInitialized'), require('react-redux'), require('react-textarea-autosize'), require('@babel/runtime/helpers/toConsumableArray'), require('@babel/runtime/helpers/typeof'), require('react-dropzone'), require('react-router'), require('react-bootstrap'), require('@crello/react-lottie'), require('react-csv'), require('@babel/runtime/helpers/objectWithoutProperties'), require('react-color'), require('tinycolor2')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/helpers/asyncToGenerator', '@babel/runtime/regenerator', 'lodash', 'axios', 'aws-amplify', '@babel/runtime/helpers/defineProperty', 'moment', 'react', 'jquery', 'js-cookie', '@babel/runtime/helpers/classCallCheck', '@babel/runtime/helpers/createClass', '@babel/runtime/helpers/inherits', '@babel/runtime/helpers/possibleConstructorReturn', '@babel/runtime/helpers/getPrototypeOf', 'react-fontawesome', '@babel/runtime/helpers/extends', '@babel/runtime/helpers/assertThisInitialized', 'react-redux', 'react-textarea-autosize', '@babel/runtime/helpers/toConsumableArray', '@babel/runtime/helpers/typeof', 'react-dropzone', 'react-router', 'react-bootstrap', '@crello/react-lottie', 'react-csv', '@babel/runtime/helpers/objectWithoutProperties', 'react-color', 'tinycolor2'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['@plusscommunities/pluss-core-web'] = {}, global._asyncToGenerator, global._regeneratorRuntime, global._, global.axios, global.awsAmplify, global._defineProperty, global.moment, global.React, global.$, global.Cookies, global._classCallCheck, global._createClass, global._inherits, global._possibleConstructorReturn, global._getPrototypeOf, global.FontAwesome, global._extends, global._assertThisInitialized, global.reactRedux, global.Textarea, global._toConsumableArray, global._typeof, global.Dropzone, global.reactRouter, global.reactBootstrap, global.reactLottie, global.reactCsv, global._objectWithoutProperties, global.reactColor, global.tinycolor));
5
- }(this, (function (exports, _asyncToGenerator, _regeneratorRuntime, _, axios, awsAmplify, _defineProperty, moment, React, $, Cookies, _classCallCheck, _createClass, _inherits, _possibleConstructorReturn, _getPrototypeOf, FontAwesome, _extends, _assertThisInitialized, reactRedux, Textarea, _toConsumableArray, _typeof, Dropzone, reactRouter, reactBootstrap, reactLottie, reactCsv, _objectWithoutProperties, reactColor, tinycolor) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/helpers/asyncToGenerator'), require('@babel/runtime/regenerator'), require('lodash'), require('axios'), require('aws-amplify'), require('@babel/runtime/helpers/defineProperty'), require('moment'), require('react'), require('jquery'), require('js-cookie'), require('@babel/runtime/helpers/classCallCheck'), require('@babel/runtime/helpers/createClass'), require('@babel/runtime/helpers/inherits'), require('@babel/runtime/helpers/possibleConstructorReturn'), require('@babel/runtime/helpers/getPrototypeOf'), require('react-fontawesome'), require('@babel/runtime/helpers/extends'), require('@babel/runtime/helpers/assertThisInitialized'), require('react-redux'), require('react-textarea-autosize'), require('@babel/runtime/helpers/toConsumableArray'), require('@babel/runtime/helpers/typeof'), require('react-dropzone'), require('react-router'), require('react-bootstrap'), require('@crello/react-lottie'), require('react-csv'), require('@babel/runtime/helpers/objectWithoutProperties'), require('react-color'), require('tinycolor2'), require('react-router-dom'), require('@fortawesome/react-fontawesome'), require('@fortawesome/free-solid-svg-icons')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/helpers/asyncToGenerator', '@babel/runtime/regenerator', 'lodash', 'axios', 'aws-amplify', '@babel/runtime/helpers/defineProperty', 'moment', 'react', 'jquery', 'js-cookie', '@babel/runtime/helpers/classCallCheck', '@babel/runtime/helpers/createClass', '@babel/runtime/helpers/inherits', '@babel/runtime/helpers/possibleConstructorReturn', '@babel/runtime/helpers/getPrototypeOf', 'react-fontawesome', '@babel/runtime/helpers/extends', '@babel/runtime/helpers/assertThisInitialized', 'react-redux', 'react-textarea-autosize', '@babel/runtime/helpers/toConsumableArray', '@babel/runtime/helpers/typeof', 'react-dropzone', 'react-router', 'react-bootstrap', '@crello/react-lottie', 'react-csv', '@babel/runtime/helpers/objectWithoutProperties', 'react-color', 'tinycolor2', 'react-router-dom', '@fortawesome/react-fontawesome', '@fortawesome/free-solid-svg-icons'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['@plusscommunities/pluss-core-web'] = {}, global._asyncToGenerator, global._regeneratorRuntime, global._, global.axios, global.awsAmplify, global._defineProperty, global.moment, global.React, global.$, global.Cookies, global._classCallCheck, global._createClass, global._inherits, global._possibleConstructorReturn, global._getPrototypeOf, global.FontAwesome, global._extends, global._assertThisInitialized, global.reactRedux, global.Textarea, global._toConsumableArray, global._typeof, global.Dropzone, global.reactRouter, global.reactBootstrap, global.reactLottie, global.reactCsv, global._objectWithoutProperties, global.reactColor, global.tinycolor, global.reactRouterDom, global.reactFontawesome, global.freeSolidSvgIcons));
5
+ }(this, (function (exports, _asyncToGenerator, _regeneratorRuntime, _, axios, awsAmplify, _defineProperty, moment, React, $, Cookies, _classCallCheck, _createClass, _inherits, _possibleConstructorReturn, _getPrototypeOf, FontAwesome, _extends, _assertThisInitialized, reactRedux, Textarea, _toConsumableArray, _typeof, Dropzone, reactRouter, reactBootstrap, reactLottie, reactCsv, _objectWithoutProperties, reactColor, tinycolor, reactRouterDom, reactFontawesome, freeSolidSvgIcons) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -520,6 +520,10 @@
520
520
  text: 'Last 90 days',
521
521
  dayCount: 90,
522
522
  prevText: 'previous 90 days'
523
+ }, {
524
+ text: 'Last 365 days',
525
+ dayCount: 365,
526
+ prevText: 'previous 365 days'
523
527
  }, {
524
528
  text: 'Custom Range',
525
529
  dayCount: 0,
@@ -543,6 +547,15 @@
543
547
 
544
548
  break;
545
549
 
550
+ case 'uniquearray':
551
+ if (entityStats[activityKey]) {
552
+ ___default['default'].values(entityStats[activityKey]).forEach(function (value) {
553
+ set.add(value);
554
+ });
555
+ }
556
+
557
+ break;
558
+
546
559
  case 'total':
547
560
  if (entityStats[activityKey]) {
548
561
  count += entityStats[activityKey];
@@ -555,6 +568,8 @@
555
568
 
556
569
  switch (countType) {
557
570
  case 'unique':
571
+ case 'uniquearray':
572
+ console.log(countType, set);
558
573
  return set.size;
559
574
 
560
575
  case 'total':
@@ -565,6 +580,7 @@
565
580
  }
566
581
  };
567
582
  var generateDateRangeObjects = function generateDateRangeObjects(startTime, endTime) {
583
+ var groupBy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
568
584
  var startDate = moment__default['default'](startTime);
569
585
  var endDate = moment__default['default'](endTime);
570
586
  var dates = {};
@@ -576,24 +592,42 @@
576
592
  Timestamp: startDate.valueOf(),
577
593
  Stats: {}
578
594
  };
579
- startDate.add(1, 'days');
595
+ startDate.add(1, groupBy);
580
596
  }
581
597
 
582
598
  return dates;
583
599
  };
584
600
  var generateDateActivities = function generateDateActivities(data, activityKey, countType, startTime, endTime) {
585
- var dates = generateDateRangeObjects(startTime, endTime);
601
+ var groupBy = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'day';
602
+ var dates = generateDateRangeObjects(startTime, endTime, groupBy);
586
603
  var result = [];
604
+ var formatToUse = 'DD-MM-YYYY';
605
+ var labelFormat = 'D MMM';
606
+
607
+ switch (groupBy) {
608
+ case 'month':
609
+ formatToUse = 'MM-YYYY';
610
+ labelFormat = 'MMMM';
611
+ break;
612
+
613
+ case 'week':
614
+ formatToUse = 'w-gggg';
615
+ labelFormat = '[Week of] D MMM';
616
+ break;
617
+ }
618
+
587
619
  Object.keys(dates).forEach(function (d) {
588
- var dateToUse = ___default['default'].find(data, function (date) {
589
- return date.Date === d;
590
- }) || dates[d];
620
+ var datesToUse = ___default['default'].filter(data, function (date) {
621
+ return moment__default['default'](date.Date, 'DD-MM-YYYY').format(formatToUse) === moment__default['default'](d, 'DD-MM-YYYY').format(formatToUse);
622
+ }) || [dates[d]];
591
623
  var compiledValue = {
592
624
  date: d,
593
- value: countActivities([dateToUse], activityKey, countType)
625
+ label: moment__default['default'](d, 'DD-MM-YYYY').format(labelFormat),
626
+ value: countActivities(datesToUse, activityKey, countType)
594
627
  };
595
628
  result.push(compiledValue);
596
629
  });
630
+ console.log(result);
597
631
  return result;
598
632
  };
599
633
 
@@ -8661,7 +8695,7 @@
8661
8695
  _createClass__default['default'](AnalyticsFilter, [{
8662
8696
  key: "render",
8663
8697
  value: function render() {
8664
- return /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("div", {
8698
+ return /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement("div", {
8665
8699
  className: "analyticsFilter__dropDown"
8666
8700
  }, /*#__PURE__*/React__default['default'].createElement(reactBootstrap.DropdownButton, {
8667
8701
  id: "secondLevelSort",
@@ -11484,6 +11518,63 @@
11484
11518
  return ColourPicker;
11485
11519
  }(React.Component);
11486
11520
 
11521
+ var StatBox = function StatBox(_ref) {
11522
+ var title = _ref.title,
11523
+ icon = _ref.icon,
11524
+ value = _ref.value,
11525
+ previousValue = _ref.previousValue,
11526
+ prevText = _ref.prevText,
11527
+ viewGraphLink = _ref.viewGraphLink,
11528
+ isLoading = _ref.isLoading;
11529
+ var change = (value / previousValue - 1) * 100;
11530
+
11531
+ if (isNaN(change)) {
11532
+ change = 0;
11533
+ }
11534
+
11535
+ if (!isFinite(change)) {
11536
+ change = 100;
11537
+ }
11538
+
11539
+ change = parseInt(change);
11540
+ var opacity = isLoading ? 0 : 1;
11541
+ return /*#__PURE__*/React__default['default'].createElement("div", {
11542
+ className: "dashboardBox dashboardBox-stats dashboardBox-inline".concat(change > 0 ? ' dashboardBox-stats-positive' : '').concat(change < 0 ? ' dashboardBox-stats-negative' : '')
11543
+ }, /*#__PURE__*/React__default['default'].createElement("div", {
11544
+ className: "dashboardBox-stats_title"
11545
+ }, /*#__PURE__*/React__default['default'].createElement(Text, {
11546
+ type: "h6"
11547
+ }, title)), /*#__PURE__*/React__default['default'].createElement("div", {
11548
+ className: "dashboardBox-stats_mid",
11549
+ style: {
11550
+ opacity: opacity
11551
+ }
11552
+ }, /*#__PURE__*/React__default['default'].createElement(reactFontawesome.FontAwesomeIcon, {
11553
+ className: "dashboardBox-stats_icon",
11554
+ icon: icon
11555
+ }), /*#__PURE__*/React__default['default'].createElement(Text, {
11556
+ type: "h2",
11557
+ className: "dashboardBox-stats_count"
11558
+ }, value), /*#__PURE__*/React__default['default'].createElement("p", {
11559
+ className: "dashboardBox-stats_change"
11560
+ }, change === 0 ? 'No change' : "".concat(change, "% ").concat(change < 0 ? '↓' : '↑'))), /*#__PURE__*/React__default['default'].createElement(Text, {
11561
+ type: "help",
11562
+ style: {
11563
+ opacity: opacity
11564
+ }
11565
+ }, "Compared to ", prevText), viewGraphLink && /*#__PURE__*/React__default['default'].createElement(reactRouterDom.Link, {
11566
+ to: "".concat(viewGraphLink, "&title=").concat(title)
11567
+ }, /*#__PURE__*/React__default['default'].createElement(Text, {
11568
+ type: "h5-noUpper",
11569
+ className: "text-link marginTop-10"
11570
+ }, /*#__PURE__*/React__default['default'].createElement(reactFontawesome.FontAwesomeIcon, {
11571
+ icon: freeSolidSvgIcons.faChartLine,
11572
+ style: {
11573
+ marginRight: 4
11574
+ }
11575
+ }), "View Graph")));
11576
+ };
11577
+
11487
11578
  var index = /*#__PURE__*/Object.freeze({
11488
11579
  __proto__: null,
11489
11580
  AddButton: AddButton,
@@ -11526,6 +11617,7 @@
11526
11617
  ExportCsvPopup: ExportCsvPopup,
11527
11618
  InputGroup: InputGroup,
11528
11619
  ColourPicker: ColourPicker,
11620
+ StatBox: StatBox,
11529
11621
  Tabs: Tabs
11530
11622
  });
11531
11623
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plusscommunities/pluss-core-web",
3
- "version": "1.4.19",
3
+ "version": "1.4.21",
4
4
  "description": "Core extension package for Pluss Communities platform",
5
5
  "main": "dist/index.cjs.js",
6
6
  "scripts": {
@@ -29,6 +29,9 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@babel/runtime": "^7.14.0",
32
+ "@fortawesome/fontawesome-svg-core": "^6.4.0",
33
+ "@fortawesome/free-solid-svg-icons": "^6.4.0",
34
+ "@fortawesome/react-fontawesome": "^0.2.0",
32
35
  "jquery": "^3.2.1",
33
36
  "js-cookie": "^2.2.0",
34
37
  "lodash": "^4.17.4",
package/src/analytics.js CHANGED
@@ -70,6 +70,11 @@ export const getAnalyticsFilterOptions = () => {
70
70
  dayCount: 90,
71
71
  prevText: 'previous 90 days',
72
72
  },
73
+ {
74
+ text: 'Last 365 days',
75
+ dayCount: 365,
76
+ prevText: 'previous 365 days',
77
+ },
73
78
  {
74
79
  text: 'Custom Range',
75
80
  dayCount: 0,
@@ -94,6 +99,13 @@ export const countActivities = (data, activityKey, countType) => {
94
99
  set.add(entity);
95
100
  }
96
101
  break;
102
+ case 'uniquearray':
103
+ if (entityStats[activityKey]) {
104
+ _.values(entityStats[activityKey]).forEach((value) => {
105
+ set.add(value);
106
+ });
107
+ }
108
+ break;
97
109
  case 'total':
98
110
  if (entityStats[activityKey]) {
99
111
  count += entityStats[activityKey];
@@ -107,6 +119,8 @@ export const countActivities = (data, activityKey, countType) => {
107
119
 
108
120
  switch (countType) {
109
121
  case 'unique':
122
+ case 'uniquearray':
123
+ console.log(countType, set);
110
124
  return set.size;
111
125
  case 'total':
112
126
  return count;
@@ -115,7 +129,7 @@ export const countActivities = (data, activityKey, countType) => {
115
129
  }
116
130
  };
117
131
 
118
- export const generateDateRangeObjects = (startTime, endTime) => {
132
+ export const generateDateRangeObjects = (startTime, endTime, groupBy = 'day') => {
119
133
  const startDate = moment(startTime);
120
134
  const endDate = moment(endTime);
121
135
  const dates = {};
@@ -127,22 +141,43 @@ export const generateDateRangeObjects = (startTime, endTime) => {
127
141
  Timestamp: startDate.valueOf(),
128
142
  Stats: {},
129
143
  };
130
- startDate.add(1, 'days');
144
+ startDate.add(1, groupBy);
131
145
  }
132
146
 
133
147
  return dates;
134
148
  };
135
149
 
136
- export const generateDateActivities = (data, activityKey, countType, startTime, endTime) => {
137
- const dates = generateDateRangeObjects(startTime, endTime);
150
+ export const generateDateActivities = (data, activityKey, countType, startTime, endTime, groupBy = 'day') => {
151
+ const dates = generateDateRangeObjects(startTime, endTime, groupBy);
138
152
 
139
153
  const result = [];
154
+ let formatToUse = 'DD-MM-YYYY';
155
+ let labelFormat = 'D MMM';
156
+ switch (groupBy) {
157
+ case 'month':
158
+ formatToUse = 'MM-YYYY';
159
+ labelFormat = 'MMMM';
160
+ break;
161
+ case 'week':
162
+ formatToUse = 'w-gggg';
163
+ labelFormat = '[Week of] D MMM';
164
+ break;
165
+ default:
166
+ break;
167
+ }
140
168
 
141
169
  Object.keys(dates).forEach((d) => {
142
- const dateToUse = _.find(data, (date) => date.Date === d) || dates[d];
143
- const compiledValue = { date: d, value: countActivities([dateToUse], activityKey, countType) };
170
+ const datesToUse = _.filter(data, (date) => {
171
+ return moment(date.Date, 'DD-MM-YYYY').format(formatToUse) === moment(d, 'DD-MM-YYYY').format(formatToUse);
172
+ }) || [dates[d]];
173
+ const compiledValue = {
174
+ date: d,
175
+ label: moment(d, 'DD-MM-YYYY').format(labelFormat),
176
+ value: countActivities(datesToUse, activityKey, countType),
177
+ };
144
178
 
145
179
  result.push(compiledValue);
146
180
  });
181
+ console.log(result);
147
182
  return result;
148
183
  };
@@ -78,7 +78,7 @@ class AnalyticsFilter extends PureComponent {
78
78
 
79
79
  render() {
80
80
  return (
81
- <div>
81
+ <>
82
82
  <div className="analyticsFilter__dropDown">
83
83
  <DropdownButton
84
84
  id="secondLevelSort"
@@ -106,7 +106,7 @@ class AnalyticsFilter extends PureComponent {
106
106
  <DatePicker hideTop selectedDate={this.state.endDate} selectDate={this.endDateChanged} />
107
107
  </div>
108
108
  )}
109
- </div>
109
+ </>
110
110
  );
111
111
  }
112
112
  }
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+ import { Link } from 'react-router-dom';
3
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
4
+ import { faChartLine } from '@fortawesome/free-solid-svg-icons';
5
+ import { Text } from './Text';
6
+
7
+ // StatBox Component
8
+ const StatBox = ({ title, icon, value, previousValue, prevText, viewGraphLink, isLoading }) => {
9
+ let change = (value / previousValue - 1) * 100;
10
+ if (isNaN(change)) {
11
+ change = 0;
12
+ }
13
+ if (!isFinite(change)) {
14
+ change = 100;
15
+ }
16
+ change = parseInt(change);
17
+ const opacity = isLoading ? 0 : 1;
18
+ return (
19
+ <div
20
+ className={`dashboardBox dashboardBox-stats dashboardBox-inline${change > 0 ? ' dashboardBox-stats-positive' : ''}${
21
+ change < 0 ? ' dashboardBox-stats-negative' : ''
22
+ }`}
23
+ >
24
+ <div className="dashboardBox-stats_title">
25
+ <Text type="h6">{title}</Text>
26
+ </div>
27
+ <div className="dashboardBox-stats_mid" style={{ opacity }}>
28
+ <FontAwesomeIcon className="dashboardBox-stats_icon" icon={icon} />
29
+ <Text type="h2" className="dashboardBox-stats_count">
30
+ {value}
31
+ </Text>
32
+ <p className="dashboardBox-stats_change">{change === 0 ? 'No change' : `${change}% ${change < 0 ? '↓' : '↑'}`}</p>
33
+ </div>
34
+ <Text type="help" style={{ opacity }}>
35
+ Compared to {prevText}
36
+ </Text>
37
+ {viewGraphLink && (
38
+ <Link to={`${viewGraphLink}&title=${title}`}>
39
+ <Text type="h5-noUpper" className="text-link marginTop-10">
40
+ <FontAwesomeIcon icon={faChartLine} style={{ marginRight: 4 }} />
41
+ View Graph
42
+ </Text>
43
+ </Link>
44
+ )}
45
+ </div>
46
+ );
47
+ };
48
+
49
+ export { StatBox };
@@ -40,4 +40,5 @@ export * from './MakerPopup';
40
40
  export * from './ExportCsvPopup';
41
41
  export * from './InputGroup';
42
42
  export * from './ColourPicker';
43
+ export * from './StatBox';
43
44
  export * from './Tabs';