@capillarytech/cap-ui-utils 1.4.10 → 1.4.11

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/index.js CHANGED
@@ -7,4 +7,3 @@ export { default as formatter } from "./utils/formatter";
7
7
  export { default as validationHelper } from "./utils/validationHelper";
8
8
  export { default as loadable, FORCE_REFRESH_NOTIFIER, FORCE_REFRESH_SECONDS } from './utils/loadable';
9
9
  export { default as GTMTracker } from './utils/gtmTracker';
10
- export { default as compileHandlebars } from './utils/compileHandlebars';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capillarytech/cap-ui-utils",
3
- "version": "1.4.10",
3
+ "version": "1.4.11",
4
4
  "description": "Utility functions shared accross all the modules",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,7 +13,6 @@
13
13
  "tti-polyfill": "^0.2.2",
14
14
  "moment-timezone": "^0.5.25",
15
15
  "react-intl": "2.7.2",
16
- "lodash": "4.17.11",
17
- "handlebars": "4.0.11"
16
+ "lodash": "4.17.11"
18
17
  }
19
18
  }
package/utils/loadable.js CHANGED
@@ -1,8 +1,14 @@
1
- import { lazy } from 'react';
1
+ import React, { lazy } from 'react';
2
2
 
3
3
  export const FORCE_REFRESH_NOTIFIER = 'showForceRefreshNotifier';
4
4
  export const FORCE_REFRESH_SECONDS = 5;
5
5
 
6
+ class DummyComponent extends React.Component {
7
+ render() {
8
+ return <></>
9
+ }
10
+ }
11
+
6
12
  const reloadWithDelay = (delay = FORCE_REFRESH_SECONDS) =>
7
13
  new Promise((resolve) => {
8
14
  setTimeout(() => {
@@ -37,7 +43,8 @@ export const lazyWithRetry = (importFunction) =>
37
43
  // Notify the main app to show notification if needed
38
44
  window.postMessage(FORCE_REFRESH_NOTIFIER, window.location.origin);
39
45
  // Let's refresh the page immediately.
40
- return reloadWithDelay();
46
+ await reloadWithDelay();
47
+ return { default: DummyComponent };
41
48
  }
42
49
  // The page has already been reloaded
43
50
  // Assuming that user is already using the latest version of the application.
@@ -1,54 +0,0 @@
1
- import Handlebars from 'handlebars';
2
- import moment from 'moment';
3
- import { unescape } from 'lodash-es';
4
-
5
- const DATE_FORMAT = 'YYYY-MM-DD';
6
- const DATE_FORMAT_DISPLAY = 'DD MMM, YYYY';
7
-
8
- // register helper functions
9
- Handlebars.registerHelper('makeBold', (name) => `<strong>${name}</strong>`);
10
-
11
- Handlebars.registerHelper('currentDate', () => moment().format(DATE_FORMAT));
12
-
13
- Handlebars.registerHelper('formatDate', (value, dtf = DATE_FORMAT_DISPLAY) => {
14
- const dateValue = moment(value, DATE_FORMAT);
15
- if (!dateValue.isValid()) return moment().format(dtf);
16
- return dateValue.format(dtf);
17
- });
18
-
19
- Handlebars.registerHelper('compareDate', (value, compareWith, operator = 'equals') => {
20
- let result = false;
21
- const dateValue = resetTimeParams(moment(value, DATE_FORMAT));
22
- const compareWithValue = resetTimeParams(moment(compareWith, DATE_FORMAT));
23
- switch (operator) {
24
- case 'equals': result = dateValue.diff(compareWithValue, 'day') === 0; break;
25
- case 'greaterThan': result = dateValue.isAfter(compareWithValue); break;
26
- case 'lessThan': result = dateValue.isBefore(compareWithValue); break;
27
- case 'greaterThanEquals': result = (dateValue.isAfter(compareWithValue) || dateValue.diff(compareWithValue, 'day') === 0); break;
28
- case 'lessThanEquals': result = (dateValue.isBefore(compareWithValue) || dateValue.diff(compareWithValue, 'day') === 0); break;
29
- default: dateValue.diff(compareWithValue, 'day') === 0; break;
30
- }
31
- return result;
32
- });
33
-
34
- // util functions
35
- const resetTimeParams = (date) => date.hours(0).minutes(0).seconds(0).milliseconds(0);
36
-
37
- const replaceBraces = (str) => str
38
- .replace(new RegExp('<%', 'g'), '{{')
39
- .replace(new RegExp('%>', 'g'), '}}');
40
-
41
- // format and compile template
42
- const compileMessage = (template, context = {}) => {
43
- try {
44
- const compiledTemplate = Handlebars.compile(replaceBraces(template));
45
- return unescape(compiledTemplate(context));
46
- }
47
- catch(err) {
48
- const error = `[TemplateHandler util function] Error in template parsing: ${err}`;
49
- console.error(error);
50
- return error;
51
- }
52
- };
53
-
54
- export default compileMessage;