@pega/custom-dx-components 2.0.8 → 2.0.10
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/constants.js +29 -7
- package/src/tasks/create/index.js +46 -6
- package/src/tasks/create/templates/Constellation/Field/Boolean/Boolean.js.mustache +38 -0
- package/src/tasks/create/templates/Constellation/Field/Boolean/boolean-format.js.mustache +26 -0
- package/src/tasks/create/templates/Constellation/Field/Boolean/config.json.mustache +145 -0
- package/src/tasks/create/templates/Constellation/Field/Boolean/demo.stories.jsx.mustache +44 -0
- package/src/tasks/create/templates/Constellation/Field/Boolean/event-utils.js.mustache +18 -0
- package/src/tasks/create/templates/Constellation/Field/Boolean/index.jsx.mustache +171 -0
- package/src/tasks/create/templates/Constellation/Field/Boolean/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Field/Date/config.json.mustache +195 -0
- package/src/tasks/create/templates/Constellation/Field/Date/date.js.mustache +327 -0
- package/src/tasks/create/templates/Constellation/Field/Date/demo.stories.jsx.mustache +44 -0
- package/src/tasks/create/templates/Constellation/Field/Date/index.jsx.mustache +254 -0
- package/src/tasks/create/templates/Constellation/Field/Date/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Field/Date/suggestions-handler.js +10 -0
- package/src/tasks/create/templates/Constellation/Field/DateTime/config.json.mustache +256 -0
- package/src/tasks/create/templates/Constellation/Field/DateTime/date-time.js.mustache +93 -0
- package/src/tasks/create/templates/Constellation/Field/DateTime/date-utils.js +286 -0
- package/src/tasks/create/templates/Constellation/Field/DateTime/date.js.mustache +327 -0
- package/src/tasks/create/templates/Constellation/Field/DateTime/demo.stories.jsx.mustache +44 -0
- package/src/tasks/create/templates/Constellation/Field/DateTime/index.jsx.mustache +252 -0
- package/src/tasks/create/templates/Constellation/Field/DateTime/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Field/DateTime/suggestions-handler.js +10 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal/config.json.mustache +278 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal/demo.stories.jsx.mustache +44 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal/event-utils.js.mustache +18 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal/index.jsx.mustache +272 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal/suggestions-handler.js +10 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/config.json.mustache +291 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/demo.stories.jsx.mustache +44 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/event-utils.js.mustache +18 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/index.jsx.mustache +300 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/suggestions-handler.js +10 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/config.json.mustache +93 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/demo.stories.jsx.mustache +44 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/event-utils.js.mustache +18 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/index.jsx.mustache +275 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/suggestions-handler.js +10 -0
- package/src/tasks/create/templates/Constellation/Field/Integer/config.json.mustache +347 -0
- package/src/tasks/create/templates/Constellation/Field/Integer/demo.stories.jsx.mustache +44 -0
- package/src/tasks/create/templates/Constellation/Field/Integer/event-utils.js.mustache +18 -0
- package/src/tasks/create/templates/Constellation/Field/Integer/index.jsx.mustache +335 -0
- package/src/tasks/create/templates/Constellation/Field/Integer/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Field/Integer/suggestions-handler.js +10 -0
- package/src/tasks/create/templates/Constellation/Field/Picklist/config.json.mustache +114 -0
- package/src/tasks/create/templates/Constellation/Field/Picklist/demo.stories.jsx.mustache +44 -0
- package/src/tasks/create/templates/Constellation/Field/Picklist/event-utils.js.mustache +18 -0
- package/src/tasks/create/templates/Constellation/Field/Picklist/index.jsx.mustache +308 -0
- package/src/tasks/create/templates/Constellation/Field/Picklist/picklist.js.mustache +43 -0
- package/src/tasks/create/templates/Constellation/Field/Picklist/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Field/Picklist/suggestions-handler.js +10 -0
- package/src/tasks/create/templates/Constellation/Field/Text/config.json.mustache +62 -0
- package/src/tasks/create/templates/Constellation/Field/Text/demo.stories.jsx.mustache +44 -0
- package/src/tasks/create/templates/Constellation/Field/Text/index.jsx.mustache +60 -0
- package/src/tasks/create/templates/Constellation/Field/Text/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Email/config.json.mustache +111 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Email/demo.stories.jsx.mustache +44 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Email/event-utils.js.mustache +18 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Email/index.jsx.mustache +189 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Email/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Email/suggestions-handler.js +10 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Email/text-email.js.mustache +43 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Input/StatusWork.js +27 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Input/config.json.mustache +111 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Input/demo.stories.jsx.mustache +44 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Input/event-utils.js.mustache +18 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Input/index.jsx.mustache +196 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Input/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Input/suggestions-handler.js +10 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Input/text-input.js.mustache +43 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/config.json.mustache +111 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/demo.stories.jsx.mustache +44 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/event-utils.js.mustache +18 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/index.jsx.mustache +189 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/suggestions-handler.js +10 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/text-paragraph.js.mustache +43 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Phone/config.json.mustache +123 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Phone/demo.stories.jsx.mustache +44 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Phone/event-utils.js.mustache +18 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Phone/index.jsx.mustache +223 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Phone/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Phone/suggestions-handler.js +10 -0
- package/src/tasks/create/templates/Constellation/Field/Text-Phone/text-phone.js.mustache +43 -0
- package/src/tasks/create/templates/Constellation/Field/Text-URL/config.json.mustache +237 -0
- package/src/tasks/create/templates/Constellation/Field/Text-URL/demo.stories.jsx.mustache +44 -0
- package/src/tasks/create/templates/Constellation/Field/Text-URL/event-utils.js.mustache +18 -0
- package/src/tasks/create/templates/Constellation/Field/Text-URL/index.jsx.mustache +232 -0
- package/src/tasks/create/templates/Constellation/Field/Text-URL/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Field/Text-URL/suggestions-handler.js +10 -0
- package/src/tasks/create/templates/Constellation/Field/Text-URL/text-url.js.mustache +172 -0
- package/src/tasks/create/templates/Constellation/Field/TimeofDay/config.json.mustache +185 -0
- package/src/tasks/create/templates/Constellation/Field/TimeofDay/demo.stories.jsx.mustache +44 -0
- package/src/tasks/create/templates/Constellation/Field/TimeofDay/index.jsx.mustache +213 -0
- package/src/tasks/create/templates/Constellation/Field/TimeofDay/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Field/TimeofDay/suggestions-handler.js +10 -0
- package/src/tasks/create/templates/Constellation/Field/TimeofDay/time-of-day.js.mustache +286 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS/OneColumnDetails.svg +22 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS/config.json.mustache +35 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS/index.jsx.mustache +101 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS/utils.js.mustache +226 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS-region/TwoColumnDetails.svg +28 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS-region/config.json.mustache +42 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS-region/index.jsx.mustache +101 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS-region/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Template/DETAILS-region/utils.js.mustache +226 -0
- package/src/tasks/create/templates/Constellation/Template/FORM/DefaultForm.svg +29 -0
- package/src/tasks/create/templates/Constellation/Template/FORM/config.json.mustache +45 -0
- package/src/tasks/create/templates/Constellation/Template/FORM/index.jsx.mustache +49 -0
- package/src/tasks/create/templates/Constellation/Template/FORM/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Template/FORM-region/TwoColumn.svg +38 -0
- package/src/tasks/create/templates/Constellation/Template/FORM-region/config.json.mustache +27 -0
- package/src/tasks/create/templates/Constellation/Template/FORM-region/index.jsx.mustache +43 -0
- package/src/tasks/create/templates/Constellation/Template/FORM-region/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Template/PAGE/GetNextWork.js.mustache +29 -0
- package/src/tasks/create/templates/Constellation/Template/PAGE/OneColumnPage.svg +36 -0
- package/src/tasks/create/templates/Constellation/Template/PAGE/config.json.mustache +32 -0
- package/src/tasks/create/templates/Constellation/Template/PAGE/index.jsx.mustache +68 -0
- package/src/tasks/create/templates/Constellation/Template/PAGE/localizations.json.mustache +4 -0
- package/src/tasks/create/templates/Constellation/Template/PAGE/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Template/PAGE/utils.js.mustache +226 -0
- package/src/tasks/create/templates/Constellation/Widget/CASE/OneColumnPage.svg +36 -0
- package/src/tasks/create/templates/Constellation/Widget/CASE/config.json.mustache +23 -0
- package/src/tasks/create/templates/Constellation/Widget/CASE/index.jsx.mustache +75 -0
- package/src/tasks/create/templates/Constellation/Widget/CASE/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Widget/PAGE/OneColumnPage.svg +36 -0
- package/src/tasks/create/templates/Constellation/Widget/PAGE/config.json.mustache +59 -0
- package/src/tasks/create/templates/Constellation/Widget/PAGE/index.jsx.mustache +48 -0
- package/src/tasks/create/templates/Constellation/Widget/PAGE/styles.js.mustache +7 -0
- package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/Avatar.js.mustache +73 -0
- package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/OneColumnPage.svg +36 -0
- package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/Operator.js.mustache +239 -0
- package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/config.json.mustache +66 -0
- package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/index.jsx.mustache +110 -0
- package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/styles.js.mustache +7 -0
- package/src/tasks/init/template/package.json.mustache +6 -1
- package/src/tasks/publish/bundle/builder/index.js +49 -5
- package/src/tasks/publish/bundle/builder/webpack.config.js +7 -3
- package/src/tasks/validator/index.js +107 -8
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
|
|
3
|
+
const relativeTime = require("dayjs/plugin/relativeTime");
|
|
4
|
+
|
|
5
|
+
dayjs.extend(relativeTime);
|
|
6
|
+
|
|
7
|
+
const utc = require("dayjs/plugin/utc");
|
|
8
|
+
|
|
9
|
+
dayjs.extend(utc);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Return relative time in fromNow for the given datetime
|
|
13
|
+
* @description Convert and return the given datetime in dayJSObject
|
|
14
|
+
*
|
|
15
|
+
* @param {string} text datetime
|
|
16
|
+
* @returns {object} datetime as a dayjs object
|
|
17
|
+
*/
|
|
18
|
+
export const getDayJSObject = (text) => {
|
|
19
|
+
const momObj = dayjs(text);
|
|
20
|
+
if (momObj.isValid()) return momObj;
|
|
21
|
+
const timeStamp = text;
|
|
22
|
+
const isDateTime = timeStamp.indexOf("GMT") !== -1;
|
|
23
|
+
const year = parseInt(timeStamp.substr(0, 4), 10);
|
|
24
|
+
const month = parseInt(timeStamp.substr(4, 2), 10) - 1;
|
|
25
|
+
const day = parseInt(timeStamp.substr(6, 2), 10);
|
|
26
|
+
|
|
27
|
+
const CurrentTz = PCore.getLocaleUtils().getTimeZoneInUse();
|
|
28
|
+
|
|
29
|
+
let mom = new Date();
|
|
30
|
+
|
|
31
|
+
mom.setUTCDate(day);
|
|
32
|
+
mom.setUTCMonth(month);
|
|
33
|
+
mom.setUTCFullYear(year);
|
|
34
|
+
|
|
35
|
+
/* istanbul ignore else */
|
|
36
|
+
if (isDateTime) {
|
|
37
|
+
const hours = parseInt(timeStamp.substr(9, 2), 10);
|
|
38
|
+
const minutes = parseInt(timeStamp.substr(11, 2), 10);
|
|
39
|
+
const seconds = parseInt(timeStamp.substr(13, 2), 10);
|
|
40
|
+
const ms = parseInt(timeStamp.substr(16, 3), 10);
|
|
41
|
+
mom.setUTCHours(hours);
|
|
42
|
+
mom.setUTCMinutes(minutes);
|
|
43
|
+
mom.setUTCSeconds(seconds);
|
|
44
|
+
mom.setUTCMilliseconds(ms);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
mom = dayjs(
|
|
48
|
+
mom.toLocaleString("en-US", {
|
|
49
|
+
timeZone: CurrentTz
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return mom;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Return relative time in fromNow for the given datetime
|
|
58
|
+
*
|
|
59
|
+
* @param {string} time datetime
|
|
60
|
+
* @returns {object} relative time from now
|
|
61
|
+
*/
|
|
62
|
+
export const getRelativeTime = (time) => {
|
|
63
|
+
let relativetime = "";
|
|
64
|
+
if (dayjs(time).isUTC()) {
|
|
65
|
+
relativetime = dayjs(time).fromNow();
|
|
66
|
+
} else {
|
|
67
|
+
const dayjstime = getDayJSObject(time);
|
|
68
|
+
relativetime = dayjs(dayjstime).fromNow();
|
|
69
|
+
}
|
|
70
|
+
return relativetime;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Return year for the date passed
|
|
75
|
+
*
|
|
76
|
+
* @param {string} value from which Year needs to be taken out
|
|
77
|
+
* @returns {number} year for the date passed
|
|
78
|
+
*/
|
|
79
|
+
export const getFullYear = (value) =>
|
|
80
|
+
value ? new Date(value).getFullYear() : new Date().getFullYear();
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Return maxDate for the date passed
|
|
84
|
+
*
|
|
85
|
+
* @param {number} nextYears next number of years
|
|
86
|
+
* @param {number} currentYear current year
|
|
87
|
+
* @param {number} yearFromValue year set on value in redux
|
|
88
|
+
*
|
|
89
|
+
* @returns {string} maxDate calculated based on inputs
|
|
90
|
+
*/
|
|
91
|
+
export const getMaxDate = (nextYears, currentYear, yearFromValue) => {
|
|
92
|
+
if (Number.isNaN(nextYears)) {
|
|
93
|
+
nextYears = 20;
|
|
94
|
+
}
|
|
95
|
+
let maxYear = currentYear + nextYears;
|
|
96
|
+
if (yearFromValue > maxYear) {
|
|
97
|
+
maxYear = yearFromValue;
|
|
98
|
+
}
|
|
99
|
+
return `${maxYear}-01-01`;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Return minDate for the date passed
|
|
104
|
+
*
|
|
105
|
+
* @param {number} previousYears previous number of years
|
|
106
|
+
* @param {number} currentYear current year
|
|
107
|
+
* @param {number} yearFromValue year set on value in redux
|
|
108
|
+
*
|
|
109
|
+
* @returns {string} minDate calculated based on inputs
|
|
110
|
+
*/
|
|
111
|
+
export const getMinDate = (previousYears, currentYear, yearFromValue) => {
|
|
112
|
+
if (Number.isNaN(previousYears)) {
|
|
113
|
+
previousYears = 100;
|
|
114
|
+
}
|
|
115
|
+
let minYear = currentYear - previousYears;
|
|
116
|
+
if (yearFromValue < minYear) {
|
|
117
|
+
minYear = yearFromValue;
|
|
118
|
+
}
|
|
119
|
+
return `${minYear}-12-31`;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Return clockFormat after parsing
|
|
124
|
+
*
|
|
125
|
+
* @param {number | string} clockFormat chosen by user
|
|
126
|
+
*
|
|
127
|
+
* @returns {number} clockFormat
|
|
128
|
+
*/
|
|
129
|
+
export const parseClockFormat = (clockFormat) =>
|
|
130
|
+
typeof clockFormat === "string" ? parseInt(clockFormat, 10) : clockFormat;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Return datetime value string off to seconds
|
|
134
|
+
*
|
|
135
|
+
* @param {string} datetime in ISO format
|
|
136
|
+
* @param {boolean} withSeconds to specify if seconds is needed or not
|
|
137
|
+
*
|
|
138
|
+
* @returns {string} datetime after stripping of ms and seconds if selected to
|
|
139
|
+
*/
|
|
140
|
+
export const correctDateTimeToSeconds = (datetime, withSeconds) => {
|
|
141
|
+
if (withSeconds) {
|
|
142
|
+
return `${datetime.substring(0, datetime.indexOf("Z"))}.000Z`;
|
|
143
|
+
}
|
|
144
|
+
return `${datetime.substring(0, datetime.lastIndexOf(":"))}:00.000Z`;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Return time value string off to seconds
|
|
149
|
+
*
|
|
150
|
+
* @param {string} datetime in ISO format
|
|
151
|
+
* @param {boolean} withSeconds to specify if seconds is needed or not
|
|
152
|
+
*
|
|
153
|
+
* @returns {string} just time after stripping of ms and seconds if selected to
|
|
154
|
+
*/
|
|
155
|
+
export const timeCorrectedToSeconds = (datetime, withSeconds) => {
|
|
156
|
+
if (withSeconds) {
|
|
157
|
+
return datetime.substring(datetime.indexOf("T") + 1, datetime.indexOf("."));
|
|
158
|
+
}
|
|
159
|
+
return `${datetime.substring(
|
|
160
|
+
datetime.indexOf("T") + 1,
|
|
161
|
+
datetime.lastIndexOf(":")
|
|
162
|
+
)}:00`;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* This function handles the cosmos blur handler of DateTime components
|
|
167
|
+
*
|
|
168
|
+
* @param {string | undefined} errorState for the selected datetime value
|
|
169
|
+
* @param {string} actualValue present in redux
|
|
170
|
+
* @param {string} formattedValue retrieved by trimming ISO to just Date/Time, also applying timezone if DateTime
|
|
171
|
+
* @param {object} actions object which has fire and blur callbacks
|
|
172
|
+
* @param {string} propName name of the property bound
|
|
173
|
+
* @param {object} pConn component's PConnect object which is useful to invoke validationApi
|
|
174
|
+
*
|
|
175
|
+
* @returns {void}
|
|
176
|
+
*/
|
|
177
|
+
export const datetimeFireChangeBlurEvents = (
|
|
178
|
+
errorState,
|
|
179
|
+
actualValue,
|
|
180
|
+
formattedValue,
|
|
181
|
+
actions,
|
|
182
|
+
propName,
|
|
183
|
+
pConn
|
|
184
|
+
) => {
|
|
185
|
+
|
|
186
|
+
// TODO - clean up, we should not rely on timestamp from cosmos to check InComplete validation
|
|
187
|
+
// above triggerFieldChange should have validated this
|
|
188
|
+
if (errorState) {
|
|
189
|
+
pConn.getValidationApi().validate(errorState);
|
|
190
|
+
}
|
|
191
|
+
// BUG-640834 In errorState presist old values avoiding store update & re-render.
|
|
192
|
+
else{
|
|
193
|
+
if (formattedValue !== actualValue) {
|
|
194
|
+
actions.updateFieldValue(propName, formattedValue);
|
|
195
|
+
}
|
|
196
|
+
actions.triggerFieldChange(propName, formattedValue);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Return Date format for the locale passed
|
|
202
|
+
*
|
|
203
|
+
* @param {string} locale locale string
|
|
204
|
+
* @param {object} options options for format string
|
|
205
|
+
* @returns {string} dateformat for the locale
|
|
206
|
+
* Example : getDateFormat("pl-PL") returns "DD.MM.YYYY"
|
|
207
|
+
*/
|
|
208
|
+
export const getDateFormat = (locale, options) => {
|
|
209
|
+
return new Intl.DateTimeFormat(locale, options)
|
|
210
|
+
.formatToParts()
|
|
211
|
+
.map(({ type, value }) => {
|
|
212
|
+
switch (type) {
|
|
213
|
+
case "day":
|
|
214
|
+
return "DD";
|
|
215
|
+
case "month":
|
|
216
|
+
return "MM";
|
|
217
|
+
case "year":
|
|
218
|
+
return "YYYY";
|
|
219
|
+
case "hour":
|
|
220
|
+
return "hh";
|
|
221
|
+
case "minute":
|
|
222
|
+
return "mm";
|
|
223
|
+
case "second":
|
|
224
|
+
return "ss";
|
|
225
|
+
case "dayPeriod":
|
|
226
|
+
return "A";
|
|
227
|
+
case "literal":
|
|
228
|
+
return value;
|
|
229
|
+
default:
|
|
230
|
+
return "";
|
|
231
|
+
}
|
|
232
|
+
})
|
|
233
|
+
.join("");
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Return boolean for the locale passed to specify if locale uses 12 hour format
|
|
238
|
+
*
|
|
239
|
+
* @param {string} locale locale string
|
|
240
|
+
* @returns {boolean} True or False for the locale
|
|
241
|
+
* Example : getDateFormat("pl-PL") returns false
|
|
242
|
+
*/
|
|
243
|
+
export const is12HClockFormat = (locale) => {
|
|
244
|
+
const meridiem = new Intl.DateTimeFormat(locale, {
|
|
245
|
+
hour: "numeric"
|
|
246
|
+
})
|
|
247
|
+
.formatToParts()
|
|
248
|
+
.find(({ type }) => type === "dayPeriod");
|
|
249
|
+
return !!(meridiem === null || meridiem === undefined
|
|
250
|
+
? undefined
|
|
251
|
+
: meridiem.value);
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Return Option object for Time formatting
|
|
256
|
+
*
|
|
257
|
+
* @param {boolean} withSeconds true or false depending on seconds to be included
|
|
258
|
+
* @param {boolean} is12h 12 hour format
|
|
259
|
+
* @returns {object} options object time formatting
|
|
260
|
+
* Example : getTimeOptions(false, true) returns {hour: 'numeric',minute: 'numeric',hour12: true}
|
|
261
|
+
*/
|
|
262
|
+
export const getTimeOptions = (withSeconds, is12h = false) => {
|
|
263
|
+
return {
|
|
264
|
+
hour: "numeric",
|
|
265
|
+
minute: "numeric",
|
|
266
|
+
...(withSeconds && { second: "numeric" }),
|
|
267
|
+
hour12: is12h
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Return Option object for Datetime formatting
|
|
273
|
+
*
|
|
274
|
+
* @param {boolean} withSeconds true or false depending on seconds to be included
|
|
275
|
+
* @param {boolean} is12h 12 hour format
|
|
276
|
+
* @returns {object} options object datetime formatting
|
|
277
|
+
* Example : getDateTimeOptions(false, true) returns {year: 'numeric',month: 'numeric',day: 'numeric',hour: 'numeric',minute: 'numeric',hour12: true}
|
|
278
|
+
*/
|
|
279
|
+
export const getDateTimeOptions = (withSeconds, is12h = false) => {
|
|
280
|
+
return {
|
|
281
|
+
year: "numeric",
|
|
282
|
+
month: "numeric",
|
|
283
|
+
day: "numeric",
|
|
284
|
+
...getTimeOptions(withSeconds, is12h)
|
|
285
|
+
};
|
|
286
|
+
};
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
|
|
3
|
+
const relativeTime = require('dayjs/plugin/relativeTime');
|
|
4
|
+
const utc = require('dayjs/plugin/utc');
|
|
5
|
+
|
|
6
|
+
dayjs.extend(relativeTime);
|
|
7
|
+
dayjs.extend(utc);
|
|
8
|
+
|
|
9
|
+
export const datetimedisplayformatter = (formatter) => {
|
|
10
|
+
const objectvalues = {};
|
|
11
|
+
switch (formatter) {
|
|
12
|
+
case "DateTime-Long": {
|
|
13
|
+
objectvalues.variantVal = "datetime";
|
|
14
|
+
objectvalues.formatVal = "long";
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
case "DateTime-Short": {
|
|
18
|
+
objectvalues.variantVal = "date";
|
|
19
|
+
objectvalues.formatVal = "short";
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
case "DateTime-Since": {
|
|
23
|
+
objectvalues.variantVal = "relative";
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
case "Time-Only": {
|
|
27
|
+
objectvalues.variantVal = "time";
|
|
28
|
+
objectvalues.formatVal = "short";
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
// no default
|
|
32
|
+
}
|
|
33
|
+
return objectvalues;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const formatExists = (formatterVal) => {
|
|
37
|
+
const formatterValues = [
|
|
38
|
+
"DateTime-Long",
|
|
39
|
+
"DateTime-Short",
|
|
40
|
+
"DateTime-Since",
|
|
41
|
+
"Time-Only"
|
|
42
|
+
];
|
|
43
|
+
let isformatter = false;
|
|
44
|
+
if (formatterValues.includes(formatterVal)) {
|
|
45
|
+
isformatter = true;
|
|
46
|
+
}
|
|
47
|
+
return isformatter;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Return relative time in fromNow for the given datetime
|
|
54
|
+
* @description Convert and return the given datetime in dayJSObject
|
|
55
|
+
*
|
|
56
|
+
* @param {string} text datetime
|
|
57
|
+
* @returns {object} datetime as a dayjs object
|
|
58
|
+
*/
|
|
59
|
+
export const getDayJSObject = (text) => {
|
|
60
|
+
const momObj = dayjs(text);
|
|
61
|
+
if (momObj.isValid()) return momObj;
|
|
62
|
+
const timeStamp = text;
|
|
63
|
+
const isDateTime = timeStamp.indexOf("GMT") !== -1;
|
|
64
|
+
const year = parseInt(timeStamp.substr(0, 4), 10);
|
|
65
|
+
const month = parseInt(timeStamp.substr(4, 2), 10) - 1;
|
|
66
|
+
const day = parseInt(timeStamp.substr(6, 2), 10);
|
|
67
|
+
|
|
68
|
+
const CurrentTz = PCore.getLocaleUtils().getTimeZoneInUse();
|
|
69
|
+
|
|
70
|
+
let mom = new Date();
|
|
71
|
+
|
|
72
|
+
mom.setUTCDate(day);
|
|
73
|
+
mom.setUTCMonth(month);
|
|
74
|
+
mom.setUTCFullYear(year);
|
|
75
|
+
|
|
76
|
+
/* istanbul ignore else */
|
|
77
|
+
if (isDateTime) {
|
|
78
|
+
const hours = parseInt(timeStamp.substr(9, 2), 10);
|
|
79
|
+
const minutes = parseInt(timeStamp.substr(11, 2), 10);
|
|
80
|
+
const seconds = parseInt(timeStamp.substr(13, 2), 10);
|
|
81
|
+
const ms = parseInt(timeStamp.substr(16, 3), 10);
|
|
82
|
+
mom.setUTCHours(hours);
|
|
83
|
+
mom.setUTCMinutes(minutes);
|
|
84
|
+
mom.setUTCSeconds(seconds);
|
|
85
|
+
mom.setUTCMilliseconds(ms);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
mom = dayjs(
|
|
89
|
+
mom.toLocaleString("en-US", {
|
|
90
|
+
timeZone: CurrentTz
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
return mom;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Return relative time in fromNow for the given datetime
|
|
99
|
+
*
|
|
100
|
+
* @param {string} time datetime
|
|
101
|
+
* @returns {object} relative time from now
|
|
102
|
+
*/
|
|
103
|
+
export const getRelativeTime = (time) => {
|
|
104
|
+
let relativetime = "";
|
|
105
|
+
if (dayjs(time).isUTC()) {
|
|
106
|
+
relativetime = dayjs(time).fromNow();
|
|
107
|
+
} else {
|
|
108
|
+
const dayjstime = getDayJSObject(time);
|
|
109
|
+
relativetime = dayjs(dayjstime).fromNow();
|
|
110
|
+
}
|
|
111
|
+
return relativetime;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Return year for the date passed
|
|
116
|
+
*
|
|
117
|
+
* @param {string} value from which Year needs to be taken out
|
|
118
|
+
* @returns {number} year for the date passed
|
|
119
|
+
*/
|
|
120
|
+
export const getFullYear = (value) =>
|
|
121
|
+
value ? new Date(value).getFullYear() : new Date().getFullYear();
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Return maxDate for the date passed
|
|
125
|
+
*
|
|
126
|
+
* @param {number} nextYears next number of years
|
|
127
|
+
* @param {number} currentYear current year
|
|
128
|
+
* @param {number} yearFromValue year set on value in redux
|
|
129
|
+
*
|
|
130
|
+
* @returns {string} maxDate calculated based on inputs
|
|
131
|
+
*/
|
|
132
|
+
export const getMaxDate = (nextYears, currentYear, yearFromValue) => {
|
|
133
|
+
if (Number.isNaN(nextYears)) {
|
|
134
|
+
nextYears = 20;
|
|
135
|
+
}
|
|
136
|
+
let maxYear = currentYear + nextYears;
|
|
137
|
+
if (yearFromValue > maxYear) {
|
|
138
|
+
maxYear = yearFromValue;
|
|
139
|
+
}
|
|
140
|
+
return `${maxYear}-01-01`;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Return minDate for the date passed
|
|
145
|
+
*
|
|
146
|
+
* @param {number} previousYears previous number of years
|
|
147
|
+
* @param {number} currentYear current year
|
|
148
|
+
* @param {number} yearFromValue year set on value in redux
|
|
149
|
+
*
|
|
150
|
+
* @returns {string} minDate calculated based on inputs
|
|
151
|
+
*/
|
|
152
|
+
export const getMinDate = (previousYears, currentYear, yearFromValue) => {
|
|
153
|
+
if (Number.isNaN(previousYears)) {
|
|
154
|
+
previousYears = 100;
|
|
155
|
+
}
|
|
156
|
+
let minYear = currentYear - previousYears;
|
|
157
|
+
if (yearFromValue < minYear) {
|
|
158
|
+
minYear = yearFromValue;
|
|
159
|
+
}
|
|
160
|
+
return `${minYear}-12-31`;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Return clockFormat after parsing
|
|
165
|
+
*
|
|
166
|
+
* @param {number | string} clockFormat chosen by user
|
|
167
|
+
*
|
|
168
|
+
* @returns {number} clockFormat
|
|
169
|
+
*/
|
|
170
|
+
export const parseClockFormat = (clockFormat) =>
|
|
171
|
+
typeof clockFormat === "string" ? parseInt(clockFormat, 10) : clockFormat;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Return datetime value string off to seconds
|
|
175
|
+
*
|
|
176
|
+
* @param {string} datetime in ISO format
|
|
177
|
+
* @param {boolean} withSeconds to specify if seconds is needed or not
|
|
178
|
+
*
|
|
179
|
+
* @returns {string} datetime after stripping of ms and seconds if selected to
|
|
180
|
+
*/
|
|
181
|
+
export const correctDateTimeToSeconds = (datetime, withSeconds) => {
|
|
182
|
+
if (withSeconds) {
|
|
183
|
+
return `${datetime.substring(0, datetime.indexOf("Z"))}.000Z`;
|
|
184
|
+
}
|
|
185
|
+
return `${datetime.substring(0, datetime.lastIndexOf(":"))}:00.000Z`;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Return time value string off to seconds
|
|
190
|
+
*
|
|
191
|
+
* @param {string} datetime in ISO format
|
|
192
|
+
* @param {boolean} withSeconds to specify if seconds is needed or not
|
|
193
|
+
*
|
|
194
|
+
* @returns {string} just time after stripping of ms and seconds if selected to
|
|
195
|
+
*/
|
|
196
|
+
export const timeCorrectedToSeconds = (datetime, withSeconds) => {
|
|
197
|
+
if (withSeconds) {
|
|
198
|
+
return datetime.substring(datetime.indexOf("T") + 1, datetime.indexOf("."));
|
|
199
|
+
}
|
|
200
|
+
return `${datetime.substring(
|
|
201
|
+
datetime.indexOf("T") + 1,
|
|
202
|
+
datetime.lastIndexOf(":")
|
|
203
|
+
)}:00`;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* This function handles the cosmos blur handler of DateTime components
|
|
208
|
+
*
|
|
209
|
+
* @param {string | undefined} errorState for the selected datetime value
|
|
210
|
+
* @param {string} actualValue present in redux
|
|
211
|
+
* @param {string} formattedValue retrieved by trimming ISO to just Date/Time, also applying timezone if DateTime
|
|
212
|
+
* @param {object} actions object which has fire and blur callbacks
|
|
213
|
+
* @param {string} propName name of the property bound
|
|
214
|
+
* @param {object} pConn component's PConnect object which is useful to invoke validationApi
|
|
215
|
+
*
|
|
216
|
+
* @returns {void}
|
|
217
|
+
*/
|
|
218
|
+
export const datetimeFireChangeBlurEvents = (
|
|
219
|
+
errorState,
|
|
220
|
+
actualValue,
|
|
221
|
+
formattedValue,
|
|
222
|
+
actions,
|
|
223
|
+
propName,
|
|
224
|
+
pConn
|
|
225
|
+
) => {
|
|
226
|
+
|
|
227
|
+
// TODO - clean up, we should not rely on timestamp from cosmos to check InComplete validation
|
|
228
|
+
// above triggerFieldChange should have validated this
|
|
229
|
+
if (errorState) {
|
|
230
|
+
pConn.getValidationApi().validate(errorState);
|
|
231
|
+
}
|
|
232
|
+
// BUG-640834 In errorState presist old values avoiding store update & re-render.
|
|
233
|
+
else{
|
|
234
|
+
if (formattedValue !== actualValue) {
|
|
235
|
+
actions.updateFieldValue(propName, formattedValue);
|
|
236
|
+
}
|
|
237
|
+
actions.triggerFieldChange(propName, formattedValue);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Return Date format for the locale passed
|
|
243
|
+
*
|
|
244
|
+
* @param {string} locale locale string
|
|
245
|
+
* @param {object} options options for format string
|
|
246
|
+
* @returns {string} dateformat for the locale
|
|
247
|
+
* Example : getDateFormat("pl-PL") returns "DD.MM.YYYY"
|
|
248
|
+
*/
|
|
249
|
+
export const getDateFormat = (locale, options) => {
|
|
250
|
+
return new Intl.DateTimeFormat(locale, options)
|
|
251
|
+
.formatToParts()
|
|
252
|
+
.map(({ type, value }) => {
|
|
253
|
+
switch (type) {
|
|
254
|
+
case "day":
|
|
255
|
+
return "DD";
|
|
256
|
+
case "month":
|
|
257
|
+
return "MM";
|
|
258
|
+
case "year":
|
|
259
|
+
return "YYYY";
|
|
260
|
+
case "hour":
|
|
261
|
+
return "hh";
|
|
262
|
+
case "minute":
|
|
263
|
+
return "mm";
|
|
264
|
+
case "second":
|
|
265
|
+
return "ss";
|
|
266
|
+
case "dayPeriod":
|
|
267
|
+
return "A";
|
|
268
|
+
case "literal":
|
|
269
|
+
return value;
|
|
270
|
+
default:
|
|
271
|
+
return "";
|
|
272
|
+
}
|
|
273
|
+
})
|
|
274
|
+
.join("");
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Return boolean for the locale passed to specify if locale uses 12 hour format
|
|
279
|
+
*
|
|
280
|
+
* @param {string} locale locale string
|
|
281
|
+
* @returns {boolean} True or False for the locale
|
|
282
|
+
* Example : getDateFormat("pl-PL") returns false
|
|
283
|
+
*/
|
|
284
|
+
export const is12HClockFormat = (locale) => {
|
|
285
|
+
const meridiem = new Intl.DateTimeFormat(locale, {
|
|
286
|
+
hour: "numeric"
|
|
287
|
+
})
|
|
288
|
+
.formatToParts()
|
|
289
|
+
.find(({ type }) => type === "dayPeriod");
|
|
290
|
+
return !!(meridiem === null || meridiem === undefined
|
|
291
|
+
? undefined
|
|
292
|
+
: meridiem.value);
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Return Option object for Time formatting
|
|
297
|
+
*
|
|
298
|
+
* @param {boolean} withSeconds true or false depending on seconds to be included
|
|
299
|
+
* @param {boolean} is12h 12 hour format
|
|
300
|
+
* @returns {object} options object time formatting
|
|
301
|
+
* Example : getTimeOptions(false, true) returns {hour: 'numeric',minute: 'numeric',hour12: true}
|
|
302
|
+
*/
|
|
303
|
+
export const getTimeOptions = (withSeconds, is12h = false) => {
|
|
304
|
+
return {
|
|
305
|
+
hour: "numeric",
|
|
306
|
+
minute: "numeric",
|
|
307
|
+
...(withSeconds && { second: "numeric" }),
|
|
308
|
+
hour12: is12h
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Return Option object for Datetime formatting
|
|
314
|
+
*
|
|
315
|
+
* @param {boolean} withSeconds true or false depending on seconds to be included
|
|
316
|
+
* @param {boolean} is12h 12 hour format
|
|
317
|
+
* @returns {object} options object datetime formatting
|
|
318
|
+
* Example : getDateTimeOptions(false, true) returns {year: 'numeric',month: 'numeric',day: 'numeric',hour: 'numeric',minute: 'numeric',hour12: true}
|
|
319
|
+
*/
|
|
320
|
+
export const getDateTimeOptions = (withSeconds, is12h = false) => {
|
|
321
|
+
return {
|
|
322
|
+
year: "numeric",
|
|
323
|
+
month: "numeric",
|
|
324
|
+
day: "numeric",
|
|
325
|
+
...getTimeOptions(withSeconds, is12h)
|
|
326
|
+
};
|
|
327
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { withKnobs, text, boolean } from '@storybook/addon-knobs';
|
|
3
|
+
|
|
4
|
+
import {{COMPONENT_CLASS_NAME}} from './index.jsx';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: '{{COMPONENT_CLASS_NAME}}',
|
|
8
|
+
decorators: [withKnobs],
|
|
9
|
+
component: {{COMPONENT_CLASS_NAME}}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const base{{COMPONENT_CLASS_NAME}} = () => {
|
|
13
|
+
const [value, setValue] = useState('test value');
|
|
14
|
+
|
|
15
|
+
const props = {
|
|
16
|
+
getPConnect: () => {
|
|
17
|
+
return {
|
|
18
|
+
getActionsApi: () => {
|
|
19
|
+
return {
|
|
20
|
+
updateFieldValue: (propName, value) => {
|
|
21
|
+
setValue(value);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
getStateProps: () => {
|
|
26
|
+
return { value: '.name' };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
value,
|
|
31
|
+
placeholder: text('Placeholder', 'Test placeholder'),
|
|
32
|
+
disabled: boolean('Disabled', false),
|
|
33
|
+
readOnly: boolean('Disabled', false),
|
|
34
|
+
required: boolean('Disabled', false),
|
|
35
|
+
label: text('Label', 'Sample Label'),
|
|
36
|
+
testId: text('Test id', 'text-12344566')
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<>
|
|
41
|
+
<{{COMPONENT_CLASS_NAME}} {...props} />
|
|
42
|
+
</>
|
|
43
|
+
);
|
|
44
|
+
};
|