@pega/dx-component-builder-sdk 0.1.7 → 0.1.8
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/package.json +1 -1
- package/src/tasks/build/helper.js +1 -1
- package/src/tasks/create/index.js +8 -1
- package/src/tasks/create/templates/Constellation/Field/Boolean/boolean-format.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Field/Boolean/demo.stories.jsx.mustache +60 -0
- package/src/tasks/create/templates/Constellation/Field/Boolean/index.jsx.mustache +1 -2
- package/src/tasks/create/templates/Constellation/Field/Boolean/mock.stories.js.mustache +21 -0
- package/src/tasks/create/templates/Constellation/Field/Date/DateFormatter.js.mustache +61 -0
- package/src/tasks/create/templates/Constellation/Field/Date/FormattedText.jsx.mustache +41 -0
- package/src/tasks/create/templates/Constellation/Field/Date/date.js.mustache +179 -67
- package/src/tasks/create/templates/Constellation/Field/Date/demo.stories.jsx.mustache +40 -16
- package/src/tasks/create/templates/Constellation/Field/Date/index.jsx.mustache +3 -1
- package/src/tasks/create/templates/Constellation/Field/Date/mock.stories.js.mustache +23 -0
- package/src/tasks/create/templates/Constellation/Field/DateTime/date-time.js.mustache +0 -1
- package/src/tasks/create/templates/Constellation/Field/DateTime/{date-utils.js → date-utils.js.mustache} +1 -0
- package/src/tasks/create/templates/Constellation/Field/DateTime/date.js.mustache +1 -0
- package/src/tasks/create/templates/Constellation/Field/DateTime/demo.stories.jsx.mustache +40 -15
- package/src/tasks/create/templates/Constellation/Field/DateTime/index.jsx.mustache +2 -0
- package/src/tasks/create/templates/Constellation/Field/DateTime/mock.stories.js.mustache +23 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal/demo.stories.jsx.mustache +22 -17
- package/src/tasks/create/templates/Constellation/Field/Decimal/index.jsx.mustache +2 -1
- package/src/tasks/create/templates/Constellation/Field/Decimal/mock.stories.js.mustache +21 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/demo.stories.jsx.mustache +25 -17
- package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/index.jsx.mustache +3 -4
- package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/mock.stories.js.mustache +23 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/demo.stories.jsx.mustache +22 -17
- package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/index.jsx.mustache +8 -2
- package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/mock.stories.js.mustache +21 -0
- package/src/tasks/create/templates/Constellation/Field/Integer/demo.stories.jsx.mustache +22 -17
- package/src/tasks/create/templates/Constellation/Field/Integer/index.jsx.mustache +2 -1
- package/src/tasks/create/templates/Constellation/Field/Integer/mock.stories.js.mustache +21 -0
- package/src/tasks/create/templates/Constellation/Field/Picklist/demo.stories.jsx.mustache +42 -14
- package/src/tasks/create/templates/Constellation/Field/Picklist/index.jsx.mustache +44 -1
- package/src/tasks/create/templates/Constellation/Field/Picklist/mock.stories.js.mustache +67 -0
- package/src/tasks/create/templates/Constellation/Field/Text/demo.stories.jsx.mustache +21 -16
- package/src/tasks/create/templates/Constellation/Field/Text/mock.stories.js.mustache +13 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Email/demo.stories.jsx.mustache +20 -16
- package/src/tasks/create/templates/Constellation/Field/Text-Email/index.jsx.mustache +44 -2
- package/src/tasks/create/templates/Constellation/Field/Text-Email/mock.stories.js.mustache +22 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Input/{StatusWork.js → StatusWork.jsx} +0 -1
- package/src/tasks/create/templates/Constellation/Field/Text-Input/demo.stories.jsx.mustache +21 -17
- package/src/tasks/create/templates/Constellation/Field/Text-Input/index.jsx.mustache +46 -3
- package/src/tasks/create/templates/Constellation/Field/Text-Input/mock.stories.js.mustache +21 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/demo.stories.jsx.mustache +21 -17
- package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/index.jsx.mustache +44 -2
- package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/mock.stories.js.mustache +20 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Phone/demo.stories.jsx.mustache +19 -17
- package/src/tasks/create/templates/Constellation/Field/Text-Phone/index.jsx.mustache +46 -2
- package/src/tasks/create/templates/Constellation/Field/Text-Phone/mock.stories.js.mustache +37 -0
- package/src/tasks/create/templates/Constellation/Field/Text-URL/demo.stories.jsx.mustache +19 -17
- package/src/tasks/create/templates/Constellation/Field/Text-URL/index.jsx.mustache +174 -3
- package/src/tasks/create/templates/Constellation/Field/Text-URL/mock.stories.js.mustache +22 -0
- package/src/tasks/create/templates/Constellation/Field/TimeofDay/demo.stories.jsx.mustache +24 -16
- package/src/tasks/create/templates/Constellation/Field/TimeofDay/mock.stories.js.mustache +20 -0
- package/src/tasks/create/templates/Constellation/Field/TimeofDay/time-of-day.js.mustache +1 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS/StatusWork.jsx.mustache +26 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS/demo.stories.jsx.mustache +110 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS/index.jsx.mustache +3 -5
- package/src/tasks/create/templates/Constellation/Template/DETAILS/mock.stories.js.mustache +179 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS/utils.js.mustache +3 -6
- package/src/tasks/create/templates/Constellation/Template/DETAILS-region/StatusWork.jsx.mustache +26 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS-region/demo.stories.jsx.mustache +118 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS-region/index.jsx.mustache +3 -5
- package/src/tasks/create/templates/Constellation/Template/DETAILS-region/mock.stories.js.mustache +215 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS-region/utils.js.mustache +3 -3
- package/src/tasks/create/templates/Constellation/Template/FORM/demo.stories.jsx.mustache +89 -0
- package/src/tasks/create/templates/Constellation/Template/FORM/index.jsx.mustache +6 -10
- package/src/tasks/create/templates/Constellation/Template/FORM/mock.stories.js.mustache +125 -0
- package/src/tasks/create/templates/Constellation/Template/FORM-region/demo.stories.jsx.mustache +100 -0
- package/src/tasks/create/templates/Constellation/Template/FORM-region/index.jsx.mustache +5 -11
- package/src/tasks/create/templates/Constellation/Template/FORM-region/mock.stories.js.mustache +131 -0
- package/src/tasks/create/templates/Constellation/Template/PAGE/{GetNextWork.js.mustache → GetNextWork.jsx.mustache} +6 -0
- package/src/tasks/create/templates/Constellation/Template/PAGE/demo.stories.jsx.mustache +102 -0
- package/src/tasks/create/templates/Constellation/Template/PAGE/index.jsx.mustache +9 -7
- package/src/tasks/create/templates/Constellation/Template/PAGE/mock.stories.js.mustache +94 -0
- package/src/tasks/create/templates/Constellation/Template/PAGE/utils.js.mustache +4 -1
- package/src/tasks/create/templates/Constellation/Widget/CASE/demo.stories.jsx.mustache +78 -0
- package/src/tasks/create/templates/Constellation/Widget/CASE/index.jsx.mustache +1 -0
- package/src/tasks/create/templates/Constellation/Widget/CASE/mock.stories.js.mustache +389 -0
- package/src/tasks/create/templates/Constellation/Widget/PAGE/demo.stories.jsx.mustache +30 -0
- package/src/tasks/create/templates/Constellation/Widget/PAGE/mock.stories.js.mustache +22 -0
- package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/{Avatar.js.mustache → Avatar.jsx.mustache} +2 -0
- package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/{Operator.js.mustache → Operator.jsx.mustache} +2 -1
- package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/demo.stories.jsx.mustache +68 -0
- package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/index.jsx.mustache +9 -9
- package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/mock.stories.js.mustache +51 -0
- package/src/tasks/map/map.js +0 -7
- package/src/tasks/override/index.js +38 -9
- package/src/tasks/create/templates/Constellation/Field/Picklist/picklist.js.mustache +0 -43
- package/src/tasks/create/templates/Constellation/Field/Text-Email/text-email.js.mustache +0 -43
- package/src/tasks/create/templates/Constellation/Field/Text-Input/text-input.js.mustache +0 -43
- package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/text-paragraph.js.mustache +0 -43
- package/src/tasks/create/templates/Constellation/Field/Text-Phone/text-phone.js.mustache +0 -43
- package/src/tasks/create/templates/Constellation/Field/Text-URL/text-url.js.mustache +0 -172
package/package.json
CHANGED
|
@@ -78,7 +78,7 @@ export const zipComponent = async (componentKey, category = CATEGORY_CUSTOM) =>
|
|
|
78
78
|
const zipContent = zip.toBuffer().toString('base64');
|
|
79
79
|
|
|
80
80
|
const configContent = Buffer.from(fs.readFileSync(`${srcDirectory}/config.json`)).toString();
|
|
81
|
-
fs.
|
|
81
|
+
fs.rmd('dist', { recursive: true }, err => {
|
|
82
82
|
if (err) {
|
|
83
83
|
throw err;
|
|
84
84
|
}
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
convertIntoPascalCase,
|
|
23
23
|
compileMustacheTemplate,
|
|
24
24
|
getComponentDirectoryPath,
|
|
25
|
+
getPegaConfig,
|
|
25
26
|
getComponents,
|
|
26
27
|
getComponentDefaults,
|
|
27
28
|
sanitize,
|
|
@@ -157,7 +158,13 @@ const validateCompile = async (
|
|
|
157
158
|
|
|
158
159
|
framework = internalData.sdkType;
|
|
159
160
|
|
|
160
|
-
|
|
161
|
+
let pegaConfig = await getPegaConfig();
|
|
162
|
+
let templateParentDir = `./templates/${framework}`;
|
|
163
|
+
if (pegaConfig['custom-templates-path'] && pegaConfig['custom-templates-path'] != "") {
|
|
164
|
+
templateParentDir = pegaConfig['custom-templates-path'];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const templateDir = `${templateParentDir}/${type}/${sSubType}`;
|
|
161
168
|
const templateDirectory = fileURLToPath(new URL(templateDir, import.meta.url));
|
|
162
169
|
|
|
163
170
|
const templateDirConstellation = `./templates/Constellation/${type}/${sSubType}`;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { withKnobs } from '@storybook/addon-knobs';
|
|
3
|
+
|
|
4
|
+
import { configProps, stateProps } from './mock.stories';
|
|
5
|
+
|
|
6
|
+
import {{COMPONENT_CLASS_NAME}} from './index';
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
title: '{{COMPONENT_CLASS_NAME}}',
|
|
10
|
+
decorators: [withKnobs],
|
|
11
|
+
component: {{COMPONENT_CLASS_NAME}}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const base{{COMPONENT_CLASS_NAME}} = () => {
|
|
15
|
+
const [value, setValue] = useState(configProps.value);
|
|
16
|
+
|
|
17
|
+
const props = {
|
|
18
|
+
value,
|
|
19
|
+
label: configProps.label,
|
|
20
|
+
helperText: configProps.helperText,
|
|
21
|
+
caption: configProps.caption,
|
|
22
|
+
validatemessage: configProps.validatemessage,
|
|
23
|
+
hideLabel: configProps.hideLabel,
|
|
24
|
+
testId: configProps.testId,
|
|
25
|
+
additionalProps: configProps.additionalProps,
|
|
26
|
+
displayMode: configProps.displayMode,
|
|
27
|
+
variant: configProps.variant,
|
|
28
|
+
trueLabel: configProps.trueLabel,
|
|
29
|
+
falseLabel: configProps.falseLabel,
|
|
30
|
+
disabled: configProps.disabled,
|
|
31
|
+
readOnly: configProps.readOnly,
|
|
32
|
+
required: configProps.required,
|
|
33
|
+
getPConnect: () => {
|
|
34
|
+
return {
|
|
35
|
+
getStateProps: () => {
|
|
36
|
+
return stateProps;
|
|
37
|
+
},
|
|
38
|
+
getActionsApi: () => {
|
|
39
|
+
return {
|
|
40
|
+
updateFieldValue: (propName, theValue) => {
|
|
41
|
+
setValue(theValue);
|
|
42
|
+
},
|
|
43
|
+
triggerFieldChange: () => { /* nothing */}
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
getValidationApi: () => {
|
|
47
|
+
return {
|
|
48
|
+
validate: () => { /* nothing */}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<>
|
|
57
|
+
<{{COMPONENT_CLASS_NAME}} {...props} />
|
|
58
|
+
</>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
import PropTypes from "prop-types";
|
|
8
8
|
|
|
9
9
|
// includes in bundle
|
|
10
|
-
import { format } from "./boolean-format";
|
|
11
10
|
import handleEvent from "./event-utils";
|
|
12
11
|
|
|
13
12
|
import Styled{{COMPONENT_CLASS_NAME}}Wrapper from './styles';
|
|
@@ -70,7 +69,7 @@ const {{COMPONENT_CLASS_NAME}} = props => {
|
|
|
70
69
|
|
|
71
70
|
let displayComponent;
|
|
72
71
|
if (displayMode) {
|
|
73
|
-
displayComponent = <
|
|
72
|
+
displayComponent = <{{COMPONENT_CLASS_NAME}} value={value} trueLabel={trueLabel} falseLabel={falseLabel} />;
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
if (displayMode === 'DISPLAY_ONLY') {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const configProps = {
|
|
2
|
+
value: true,
|
|
3
|
+
label: 'Boolean label',
|
|
4
|
+
helperText: 'Test helper text',
|
|
5
|
+
caption: 'Boolean caption',
|
|
6
|
+
validatemessage: '',
|
|
7
|
+
hideLabel: false,
|
|
8
|
+
testId: '12345678',
|
|
9
|
+
additionalProps: {},
|
|
10
|
+
displayMode: '',
|
|
11
|
+
variant: '',
|
|
12
|
+
trueLabel: 'True',
|
|
13
|
+
falseLabel: 'False',
|
|
14
|
+
disabled: false,
|
|
15
|
+
readOnly: false,
|
|
16
|
+
required: true
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const stateProps = {
|
|
20
|
+
value: '.Test'
|
|
21
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
3
|
+
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
|
4
|
+
import utc from 'dayjs/plugin/utc';
|
|
5
|
+
import tzone from 'dayjs/plugin/timezone';
|
|
6
|
+
|
|
7
|
+
dayjs.extend(relativeTime);
|
|
8
|
+
dayjs.extend(localizedFormat);
|
|
9
|
+
dayjs.extend(utc);
|
|
10
|
+
dayjs.extend(tzone);
|
|
11
|
+
|
|
12
|
+
const types = ['fromNow', 'customFormat'];
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
// value should be in ISO 8601 format.
|
|
17
|
+
function DateFormatter(
|
|
18
|
+
value,
|
|
19
|
+
{ type = types[1], format = "DD/MM/YYYY", timezone } = {}
|
|
20
|
+
) {
|
|
21
|
+
if (!value) return value;
|
|
22
|
+
switch (type) {
|
|
23
|
+
case types[1]:
|
|
24
|
+
if (timezone) return dayjs(value).tz(timezone).format(format);
|
|
25
|
+
return dayjs(value).format(format);
|
|
26
|
+
case types[0]:
|
|
27
|
+
return dayjs(value).from(dayjs());
|
|
28
|
+
default:
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// value should be in hh:mm:ss format (00:00:00 - 23:59:59).
|
|
34
|
+
function TimeFormatter(value, options) {
|
|
35
|
+
if (!value) return value;
|
|
36
|
+
const { locale = "en-US" } = options;
|
|
37
|
+
const timeOnlyRegex = /^(?:[01]\d|2[0123]):(?:[012345]\d):(?:[012345]\d)$/;
|
|
38
|
+
if (value.length === 8 && timeOnlyRegex.test(value)) {
|
|
39
|
+
const tempDate = new Date();
|
|
40
|
+
const hours = parseInt(value.substr(0, 2), 10);
|
|
41
|
+
const minutes = parseInt(value.substr(3, 2), 10);
|
|
42
|
+
const seconds = parseInt(value.substr(6, 2), 10);
|
|
43
|
+
tempDate.setHours(hours);
|
|
44
|
+
tempDate.setMinutes(minutes);
|
|
45
|
+
tempDate.setSeconds(seconds);
|
|
46
|
+
return tempDate.toLocaleTimeString(locale);
|
|
47
|
+
}
|
|
48
|
+
return DateFormatter(value, options);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default {
|
|
52
|
+
Date: (value, options) => DateFormatter(value, { type: 'customFormat', ...options }),
|
|
53
|
+
'Date-Time-Default': (value, options) =>
|
|
54
|
+
DateFormatter(value, { ...options, type: 'customFormat', format: 'lll' }),
|
|
55
|
+
'Time-Default': (value, options) =>
|
|
56
|
+
TimeFormatter(value, {
|
|
57
|
+
...options,
|
|
58
|
+
type: 'customFormat',
|
|
59
|
+
format: 'hh:mm A'
|
|
60
|
+
})
|
|
61
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { FieldValueList } from '@pega/cosmos-react-core';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
import { format } from './date.js';
|
|
5
|
+
|
|
6
|
+
export default function FormattedText(props) {
|
|
7
|
+
const { formatType, label, value, testId, hideLabel, variant, additionalProps } = props;
|
|
8
|
+
|
|
9
|
+
let text = value;
|
|
10
|
+
|
|
11
|
+
text = format(text, formatType, additionalProps);
|
|
12
|
+
|
|
13
|
+
const fields = [
|
|
14
|
+
{
|
|
15
|
+
id: label.toLowerCase(),
|
|
16
|
+
name: hideLabel ? '' : label,
|
|
17
|
+
value: text
|
|
18
|
+
}
|
|
19
|
+
];
|
|
20
|
+
return <FieldValueList variant={variant} fields={fields} data-testid={testId} />;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
FormattedText.defaultProps = {
|
|
24
|
+
formatType: 'none',
|
|
25
|
+
variant: 'stacked',
|
|
26
|
+
value: undefined,
|
|
27
|
+
label: '',
|
|
28
|
+
testId: null,
|
|
29
|
+
hideLabel: false,
|
|
30
|
+
additionalProps: {}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
FormattedText.propTypes = {
|
|
34
|
+
formatType: PropTypes.string,
|
|
35
|
+
variant: PropTypes.oneOf(['inline', 'stacked']),
|
|
36
|
+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
|
|
37
|
+
label: PropTypes.string,
|
|
38
|
+
testId: PropTypes.string,
|
|
39
|
+
additionalProps: PropTypes.objectOf(PropTypes.any),
|
|
40
|
+
hideLabel: PropTypes.bool
|
|
41
|
+
};
|
|
@@ -1,31 +1,90 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
1
2
|
import dayjs from 'dayjs';
|
|
3
|
+
import DateFormatter from './DateFormatter';
|
|
2
4
|
|
|
3
5
|
const relativeTime = require('dayjs/plugin/relativeTime');
|
|
4
6
|
const utc = require('dayjs/plugin/utc');
|
|
7
|
+
const localizedFormat = require('dayjs/plugin/localizedFormat');
|
|
8
|
+
const tzone = require('dayjs/plugin/timezone');
|
|
5
9
|
|
|
6
10
|
dayjs.extend(relativeTime);
|
|
11
|
+
dayjs.extend(localizedFormat);
|
|
7
12
|
dayjs.extend(utc);
|
|
13
|
+
dayjs.extend(tzone);
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
function isIsoDate(str) {
|
|
16
|
+
if (!/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(str)) return false;
|
|
17
|
+
const d = new Date(str);
|
|
18
|
+
return d.toISOString() === str;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getDateObject(text) {
|
|
22
|
+
// TODO - cleanup formatters util functions as DX APIs are returning values per ISO std now.
|
|
23
|
+
const timeStamp = text.replace(/-/g, '');
|
|
24
|
+
const isDateTime = timeStamp.indexOf('GMT') !== -1;
|
|
25
|
+
const year = parseInt(timeStamp.substr(0, 4), 10);
|
|
26
|
+
const month = parseInt(timeStamp.substr(4, 2), 10) - 1;
|
|
27
|
+
const day = parseInt(timeStamp.substr(6, 2), 10);
|
|
28
|
+
|
|
29
|
+
const date = new Date();
|
|
30
|
+
|
|
31
|
+
date.setDate(day);
|
|
32
|
+
date.setMonth(month);
|
|
33
|
+
date.setFullYear(year);
|
|
34
|
+
|
|
35
|
+
if (isDateTime) {
|
|
36
|
+
const hours = parseInt(timeStamp.substr(9, 2), 10);
|
|
37
|
+
const minutes = parseInt(timeStamp.substr(11, 2), 10);
|
|
38
|
+
const seconds = parseInt(timeStamp.substr(13, 2), 10);
|
|
39
|
+
const ms = parseInt(timeStamp.substr(16, 3), 10);
|
|
40
|
+
date.setHours(hours);
|
|
41
|
+
date.setMinutes(minutes);
|
|
42
|
+
date.setSeconds(seconds);
|
|
43
|
+
date.setMilliseconds(ms);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return date;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function parseDateInISO(value) {
|
|
50
|
+
const isMilliSeconds = new RegExp('^[0-9]+$').exec(value);
|
|
51
|
+
if (isMilliSeconds) {
|
|
52
|
+
const date = new Date(parseInt(value, 10));
|
|
53
|
+
return date.toISOString();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (isIsoDate(value)) {
|
|
57
|
+
const date = new Date(value);
|
|
58
|
+
return date.toISOString();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return value ? getDateObject(value).toISOString() : value;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default {
|
|
65
|
+
...DateFormatter
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const datetimedisplayformatter = formatter => {
|
|
10
69
|
const objectvalues = {};
|
|
11
70
|
switch (formatter) {
|
|
12
|
-
case
|
|
13
|
-
objectvalues.variantVal =
|
|
14
|
-
objectvalues.formatVal =
|
|
71
|
+
case 'DateTime-Long': {
|
|
72
|
+
objectvalues.variantVal = 'datetime';
|
|
73
|
+
objectvalues.formatVal = 'long';
|
|
15
74
|
break;
|
|
16
75
|
}
|
|
17
|
-
case
|
|
18
|
-
objectvalues.variantVal =
|
|
19
|
-
objectvalues.formatVal =
|
|
76
|
+
case 'DateTime-Short': {
|
|
77
|
+
objectvalues.variantVal = 'date';
|
|
78
|
+
objectvalues.formatVal = 'short';
|
|
20
79
|
break;
|
|
21
80
|
}
|
|
22
|
-
case
|
|
23
|
-
objectvalues.variantVal =
|
|
81
|
+
case 'DateTime-Since': {
|
|
82
|
+
objectvalues.variantVal = 'relative';
|
|
24
83
|
break;
|
|
25
84
|
}
|
|
26
|
-
case
|
|
27
|
-
objectvalues.variantVal =
|
|
28
|
-
objectvalues.formatVal =
|
|
85
|
+
case 'Time-Only': {
|
|
86
|
+
objectvalues.variantVal = 'time';
|
|
87
|
+
objectvalues.formatVal = 'short';
|
|
29
88
|
break;
|
|
30
89
|
}
|
|
31
90
|
// no default
|
|
@@ -33,13 +92,8 @@ export const datetimedisplayformatter = (formatter) => {
|
|
|
33
92
|
return objectvalues;
|
|
34
93
|
};
|
|
35
94
|
|
|
36
|
-
export const formatExists =
|
|
37
|
-
const formatterValues = [
|
|
38
|
-
"DateTime-Long",
|
|
39
|
-
"DateTime-Short",
|
|
40
|
-
"DateTime-Since",
|
|
41
|
-
"Time-Only"
|
|
42
|
-
];
|
|
95
|
+
export const formatExists = formatterVal => {
|
|
96
|
+
const formatterValues = ['DateTime-Long', 'DateTime-Short', 'DateTime-Since', 'Time-Only'];
|
|
43
97
|
let isformatter = false;
|
|
44
98
|
if (formatterValues.includes(formatterVal)) {
|
|
45
99
|
isformatter = true;
|
|
@@ -47,8 +101,6 @@ export const formatExists = (formatterVal) => {
|
|
|
47
101
|
return isformatter;
|
|
48
102
|
};
|
|
49
103
|
|
|
50
|
-
|
|
51
|
-
|
|
52
104
|
/**
|
|
53
105
|
* Return relative time in fromNow for the given datetime
|
|
54
106
|
* @description Convert and return the given datetime in dayJSObject
|
|
@@ -56,11 +108,11 @@ export const formatExists = (formatterVal) => {
|
|
|
56
108
|
* @param {string} text datetime
|
|
57
109
|
* @returns {object} datetime as a dayjs object
|
|
58
110
|
*/
|
|
59
|
-
export const getDayJSObject =
|
|
111
|
+
export const getDayJSObject = text => {
|
|
60
112
|
const momObj = dayjs(text);
|
|
61
113
|
if (momObj.isValid()) return momObj;
|
|
62
114
|
const timeStamp = text;
|
|
63
|
-
const isDateTime = timeStamp.indexOf(
|
|
115
|
+
const isDateTime = timeStamp.indexOf('GMT') !== -1;
|
|
64
116
|
const year = parseInt(timeStamp.substr(0, 4), 10);
|
|
65
117
|
const month = parseInt(timeStamp.substr(4, 2), 10) - 1;
|
|
66
118
|
const day = parseInt(timeStamp.substr(6, 2), 10);
|
|
@@ -86,7 +138,7 @@ export const getDayJSObject = (text) => {
|
|
|
86
138
|
}
|
|
87
139
|
|
|
88
140
|
mom = dayjs(
|
|
89
|
-
mom.toLocaleString(
|
|
141
|
+
mom.toLocaleString('en-US', {
|
|
90
142
|
timeZone: CurrentTz
|
|
91
143
|
})
|
|
92
144
|
);
|
|
@@ -100,8 +152,8 @@ export const getDayJSObject = (text) => {
|
|
|
100
152
|
* @param {string} time datetime
|
|
101
153
|
* @returns {object} relative time from now
|
|
102
154
|
*/
|
|
103
|
-
export const getRelativeTime =
|
|
104
|
-
let relativetime =
|
|
155
|
+
export const getRelativeTime = time => {
|
|
156
|
+
let relativetime = '';
|
|
105
157
|
if (dayjs(time).isUTC()) {
|
|
106
158
|
relativetime = dayjs(time).fromNow();
|
|
107
159
|
} else {
|
|
@@ -117,7 +169,7 @@ export const getRelativeTime = (time) => {
|
|
|
117
169
|
* @param {string} value from which Year needs to be taken out
|
|
118
170
|
* @returns {number} year for the date passed
|
|
119
171
|
*/
|
|
120
|
-
export const getFullYear =
|
|
172
|
+
export const getFullYear = value =>
|
|
121
173
|
value ? new Date(value).getFullYear() : new Date().getFullYear();
|
|
122
174
|
|
|
123
175
|
/**
|
|
@@ -167,8 +219,8 @@ export const getMinDate = (previousYears, currentYear, yearFromValue) => {
|
|
|
167
219
|
*
|
|
168
220
|
* @returns {number} clockFormat
|
|
169
221
|
*/
|
|
170
|
-
export const parseClockFormat =
|
|
171
|
-
typeof clockFormat ===
|
|
222
|
+
export const parseClockFormat = clockFormat =>
|
|
223
|
+
typeof clockFormat === 'string' ? parseInt(clockFormat, 10) : clockFormat;
|
|
172
224
|
|
|
173
225
|
/**
|
|
174
226
|
* Return datetime value string off to seconds
|
|
@@ -180,9 +232,9 @@ export const parseClockFormat = (clockFormat) =>
|
|
|
180
232
|
*/
|
|
181
233
|
export const correctDateTimeToSeconds = (datetime, withSeconds) => {
|
|
182
234
|
if (withSeconds) {
|
|
183
|
-
return `${datetime.substring(0, datetime.indexOf(
|
|
235
|
+
return `${datetime.substring(0, datetime.indexOf('Z'))}.000Z`;
|
|
184
236
|
}
|
|
185
|
-
return `${datetime.substring(0, datetime.lastIndexOf(
|
|
237
|
+
return `${datetime.substring(0, datetime.lastIndexOf(':'))}:00.000Z`;
|
|
186
238
|
};
|
|
187
239
|
|
|
188
240
|
/**
|
|
@@ -195,12 +247,9 @@ export const correctDateTimeToSeconds = (datetime, withSeconds) => {
|
|
|
195
247
|
*/
|
|
196
248
|
export const timeCorrectedToSeconds = (datetime, withSeconds) => {
|
|
197
249
|
if (withSeconds) {
|
|
198
|
-
return datetime.substring(datetime.indexOf(
|
|
250
|
+
return datetime.substring(datetime.indexOf('T') + 1, datetime.indexOf('.'));
|
|
199
251
|
}
|
|
200
|
-
return `${datetime.substring(
|
|
201
|
-
datetime.indexOf("T") + 1,
|
|
202
|
-
datetime.lastIndexOf(":")
|
|
203
|
-
)}:00`;
|
|
252
|
+
return `${datetime.substring(datetime.indexOf('T') + 1, datetime.lastIndexOf(':'))}:00`;
|
|
204
253
|
};
|
|
205
254
|
|
|
206
255
|
/**
|
|
@@ -223,14 +272,13 @@ export const datetimeFireChangeBlurEvents = (
|
|
|
223
272
|
propName,
|
|
224
273
|
pConn
|
|
225
274
|
) => {
|
|
226
|
-
|
|
227
275
|
// TODO - clean up, we should not rely on timestamp from cosmos to check InComplete validation
|
|
228
276
|
// above triggerFieldChange should have validated this
|
|
229
277
|
if (errorState) {
|
|
230
278
|
pConn.getValidationApi().validate(errorState);
|
|
231
279
|
}
|
|
232
280
|
// BUG-640834 In errorState presist old values avoiding store update & re-render.
|
|
233
|
-
else{
|
|
281
|
+
else {
|
|
234
282
|
if (formattedValue !== actualValue) {
|
|
235
283
|
actions.updateFieldValue(propName, formattedValue);
|
|
236
284
|
}
|
|
@@ -251,27 +299,27 @@ export const getDateFormat = (locale, options) => {
|
|
|
251
299
|
.formatToParts()
|
|
252
300
|
.map(({ type, value }) => {
|
|
253
301
|
switch (type) {
|
|
254
|
-
case
|
|
255
|
-
return
|
|
256
|
-
case
|
|
257
|
-
return
|
|
258
|
-
case
|
|
259
|
-
return
|
|
260
|
-
case
|
|
261
|
-
return
|
|
262
|
-
case
|
|
263
|
-
return
|
|
264
|
-
case
|
|
265
|
-
return
|
|
266
|
-
case
|
|
267
|
-
return
|
|
268
|
-
case
|
|
302
|
+
case 'day':
|
|
303
|
+
return 'DD';
|
|
304
|
+
case 'month':
|
|
305
|
+
return 'MM';
|
|
306
|
+
case 'year':
|
|
307
|
+
return 'YYYY';
|
|
308
|
+
case 'hour':
|
|
309
|
+
return 'hh';
|
|
310
|
+
case 'minute':
|
|
311
|
+
return 'mm';
|
|
312
|
+
case 'second':
|
|
313
|
+
return 'ss';
|
|
314
|
+
case 'dayPeriod':
|
|
315
|
+
return 'A';
|
|
316
|
+
case 'literal':
|
|
269
317
|
return value;
|
|
270
318
|
default:
|
|
271
|
-
return
|
|
319
|
+
return '';
|
|
272
320
|
}
|
|
273
321
|
})
|
|
274
|
-
.join(
|
|
322
|
+
.join('');
|
|
275
323
|
};
|
|
276
324
|
|
|
277
325
|
/**
|
|
@@ -281,15 +329,13 @@ export const getDateFormat = (locale, options) => {
|
|
|
281
329
|
* @returns {boolean} True or False for the locale
|
|
282
330
|
* Example : getDateFormat("pl-PL") returns false
|
|
283
331
|
*/
|
|
284
|
-
export const is12HClockFormat =
|
|
332
|
+
export const is12HClockFormat = locale => {
|
|
285
333
|
const meridiem = new Intl.DateTimeFormat(locale, {
|
|
286
|
-
hour:
|
|
334
|
+
hour: 'numeric'
|
|
287
335
|
})
|
|
288
336
|
.formatToParts()
|
|
289
|
-
.find(({ type }) => type ===
|
|
290
|
-
return !!(meridiem === null || meridiem === undefined
|
|
291
|
-
? undefined
|
|
292
|
-
: meridiem.value);
|
|
337
|
+
.find(({ type }) => type === 'dayPeriod');
|
|
338
|
+
return !!(meridiem === null || meridiem === undefined ? undefined : meridiem.value);
|
|
293
339
|
};
|
|
294
340
|
|
|
295
341
|
/**
|
|
@@ -302,9 +348,9 @@ export const is12HClockFormat = (locale) => {
|
|
|
302
348
|
*/
|
|
303
349
|
export const getTimeOptions = (withSeconds, is12h = false) => {
|
|
304
350
|
return {
|
|
305
|
-
hour:
|
|
306
|
-
minute:
|
|
307
|
-
...(withSeconds && { second:
|
|
351
|
+
hour: 'numeric',
|
|
352
|
+
minute: 'numeric',
|
|
353
|
+
...(withSeconds && { second: 'numeric' }),
|
|
308
354
|
hour12: is12h
|
|
309
355
|
};
|
|
310
356
|
};
|
|
@@ -319,9 +365,75 @@ export const getTimeOptions = (withSeconds, is12h = false) => {
|
|
|
319
365
|
*/
|
|
320
366
|
export const getDateTimeOptions = (withSeconds, is12h = false) => {
|
|
321
367
|
return {
|
|
322
|
-
year:
|
|
323
|
-
month:
|
|
324
|
-
day:
|
|
368
|
+
year: 'numeric',
|
|
369
|
+
month: 'numeric',
|
|
370
|
+
day: 'numeric',
|
|
325
371
|
...getTimeOptions(withSeconds, is12h)
|
|
326
372
|
};
|
|
327
373
|
};
|
|
374
|
+
|
|
375
|
+
export function getCurrentTimezone(timezone) {
|
|
376
|
+
if (timezone) return timezone;
|
|
377
|
+
return PCore?.getLocaleUtils?.().getTimeZoneInUse?.();
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export function format(value, type, options) {
|
|
381
|
+
let formattedValue;
|
|
382
|
+
|
|
383
|
+
switch (type?.toLowerCase()) {
|
|
384
|
+
case 'currency': {
|
|
385
|
+
const defaultOptions = {
|
|
386
|
+
locale: getLocale(),
|
|
387
|
+
position: 'before',
|
|
388
|
+
decPlaces: 2
|
|
389
|
+
};
|
|
390
|
+
const params = { ...defaultOptions, ...options };
|
|
391
|
+
formattedValue = Currency.Currency(value, params);
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
case 'decimal': {
|
|
396
|
+
const defaultOptions = { locale: getLocale(), decPlaces: 2 };
|
|
397
|
+
const params = { ...defaultOptions, ...options };
|
|
398
|
+
formattedValue = Currency.Decimal(value, params);
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
case 'integer': {
|
|
403
|
+
const defaultOptions = { locale: getLocale() };
|
|
404
|
+
const params = { ...defaultOptions, ...options };
|
|
405
|
+
formattedValue = Currency.Integer(value, params);
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
case 'date': {
|
|
410
|
+
const defaultOptions = {
|
|
411
|
+
format: 'MMM DD, YYYY',
|
|
412
|
+
timezone: getCurrentTimezone()
|
|
413
|
+
};
|
|
414
|
+
const params = { ...defaultOptions, ...options };
|
|
415
|
+
formattedValue = DateFormatter.Date(parseDateInISO(value), params);
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
case 'datetime': {
|
|
420
|
+
const defaultOptions = {
|
|
421
|
+
format: 'MMM DD, YYYY h:mm A',
|
|
422
|
+
timezone: getCurrentTimezone()
|
|
423
|
+
};
|
|
424
|
+
const params = { ...defaultOptions, ...options };
|
|
425
|
+
formattedValue = DateFormatter.Date(parseDateInISO(value), params);
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
case 'boolean':
|
|
430
|
+
case 'checkbox': {
|
|
431
|
+
formattedValue = Boolean.TrueFalse(value, { allowEmpty: false });
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
default:
|
|
436
|
+
formattedValue = value;
|
|
437
|
+
}
|
|
438
|
+
return formattedValue;
|
|
439
|
+
}
|