@qrvey/utils 1.2.9-32 → 1.2.9-35
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/README.md +4483 -0
- package/dist/cjs/filters/adapters/adaptFilterValues.js +1 -1
- package/dist/cjs/filters/adapters/flatUIToFD.js +4 -0
- package/dist/cjs/filters/adapters/flatUIToOldLogic.js +1 -1
- package/dist/cjs/filters/adapters/flatUIToUI.js +4 -0
- package/dist/cjs/filters/helpers/backend/getBackendProperty.js +1 -1
- package/dist/cjs/filters/helpers/backend/getBackendValues.js +1 -1
- package/dist/cjs/filters/interfaces/common/IFSValue.d.ts +1 -1
- package/dist/cjs/filters/interfaces/ui/IFUValue.d.ts +1 -1
- package/dist/cjs/format/format.js +4 -2
- package/dist/cjs/format/localization.js +18 -3
- package/dist/cjs/qrvey/helpers/transformValue.js +3 -0
- package/dist/filters/adapters/adaptFilterValues.js +1 -1
- package/dist/filters/adapters/flatUIToFD.js +4 -0
- package/dist/filters/adapters/flatUIToOldLogic.js +1 -1
- package/dist/filters/adapters/flatUIToUI.js +4 -0
- package/dist/filters/helpers/backend/getBackendProperty.js +1 -1
- package/dist/filters/helpers/backend/getBackendValues.js +1 -1
- package/dist/filters/interfaces/common/IFSValue.d.ts +1 -1
- package/dist/filters/interfaces/ui/IFUValue.d.ts +1 -1
- package/dist/format/format.js +4 -2
- package/dist/format/localization.js +18 -3
- package/dist/qrvey/helpers/transformValue.js +3 -0
- package/package.json +1 -1
- package/src/filters/adapters/adaptFilterValues.ts +1 -1
- package/src/filters/adapters/flatUIToFD.ts +5 -0
- package/src/filters/adapters/flatUIToOldLogic.ts +1 -1
- package/src/filters/adapters/flatUIToUI.ts +5 -0
- package/src/filters/helpers/backend/getBackendProperty.ts +2 -1
- package/src/filters/helpers/backend/getBackendValues.ts +1 -1
- package/src/filters/interfaces/common/IFSValue.ts +1 -1
- package/src/filters/interfaces/ui/IFUValue.ts +1 -1
- package/src/format/format.ts +3 -2
- package/src/format/localization.ts +18 -3
- package/src/qrvey/helpers/transformValue.ts +3 -0
|
@@ -10,7 +10,7 @@ const COLUMN_1 = require("../../columns/constants/COLUMN");
|
|
|
10
10
|
* @returns A new value array with the filled properties.
|
|
11
11
|
*/
|
|
12
12
|
function adaptFilterValues(filter) {
|
|
13
|
-
const setValue = value => (Object.assign(Object.assign({}, value), { enabled: (0, isEmpty_1.isEmpty)(value.enabled) ? true : value.enabled }));
|
|
13
|
+
const setValue = value => (Object.assign(Object.assign({}, value), { value: (0, isEmpty_1.isEmpty)(value.value) ? undefined : value.value, enabled: (0, isEmpty_1.isEmpty)(value.enabled) ? true : value.enabled }));
|
|
14
14
|
if (filter.column.type === COLUMN_1.COLUMN.RANKING && (0, isEmpty_1.isEmpty)(filter.column.aggregate)) {
|
|
15
15
|
return filter.values.map(rValues => rValues.map(setValue));
|
|
16
16
|
}
|
|
@@ -6,6 +6,7 @@ const isEmpty_1 = require("../../general/mix/isEmpty");
|
|
|
6
6
|
const adaptFilterValues_1 = require("./adaptFilterValues");
|
|
7
7
|
const FILTER_SECTION_1 = require("../constants/common/FILTER_SECTION");
|
|
8
8
|
const FILTER_STRUCTURE_VERSION_1 = require("../constants/common/FILTER_STRUCTURE_VERSION");
|
|
9
|
+
const cloneDeep_1 = require("../../general/object/cloneDeep");
|
|
9
10
|
/**
|
|
10
11
|
* Generates a filter data structure from the flatttened UI filters.
|
|
11
12
|
* @param uFilters Array of flattened filters from UI
|
|
@@ -82,8 +83,11 @@ function buildDataset(uFilter) {
|
|
|
82
83
|
* @returns an filter structure
|
|
83
84
|
*/
|
|
84
85
|
function buildFilter(uFilter) {
|
|
86
|
+
uFilter = (0, cloneDeep_1.cloneDeep)(uFilter);
|
|
85
87
|
const info = !(0, isEmpty_1.isEmpty)(uFilter.extras.info) ? { icon: uFilter.extras.info.icon, label: uFilter.extras.info.label } : undefined;
|
|
86
88
|
const property = (0, adaptDateGroupingProperty_1.adaptDateGroupingProperty)(uFilter.property);
|
|
89
|
+
delete uFilter.extras.scopeInfo;
|
|
90
|
+
delete uFilter.extras.dataset;
|
|
87
91
|
return {
|
|
88
92
|
collapsed: uFilter.collapsed,
|
|
89
93
|
column: {
|
|
@@ -343,7 +343,7 @@ function getResultValues(values, props) {
|
|
|
343
343
|
return values.map((value) => {
|
|
344
344
|
if (value.enabled) {
|
|
345
345
|
if (props.column.type === COLUMN_1.COLUMN.IMAGE) {
|
|
346
|
-
return value.valueid;
|
|
346
|
+
return value.valueid || value.imageUrl || value.value;
|
|
347
347
|
}
|
|
348
348
|
else {
|
|
349
349
|
return value.value;
|
|
@@ -7,6 +7,7 @@ const FILTER_SECTION_1 = require("../constants/common/FILTER_SECTION");
|
|
|
7
7
|
const FILTER_STRUCTURE_VERSION_1 = require("../constants/common/FILTER_STRUCTURE_VERSION");
|
|
8
8
|
const getLastIndexFromArray_1 = require("../../general/array/getLastIndexFromArray");
|
|
9
9
|
const isEmpty_1 = require("../../general/mix/isEmpty");
|
|
10
|
+
const cloneDeep_1 = require("../../general/object/cloneDeep");
|
|
10
11
|
/**
|
|
11
12
|
* Generates a UI filter data structure from the flatttened UI filters.
|
|
12
13
|
* @param uFilters Array of flattened filters from UI
|
|
@@ -89,8 +90,11 @@ function buildDataset(uFilter) {
|
|
|
89
90
|
* @returns an filter structure
|
|
90
91
|
*/
|
|
91
92
|
function buildFilter(uFilter) {
|
|
93
|
+
uFilter = (0, cloneDeep_1.cloneDeep)(uFilter);
|
|
92
94
|
const info = !(0, isEmpty_1.isEmpty)(uFilter.extras.info) ? { icon: uFilter.extras.info.icon, label: uFilter.extras.info.label } : undefined;
|
|
93
95
|
const property = (0, adaptDateGroupingProperty_1.adaptDateGroupingProperty)(uFilter.property);
|
|
96
|
+
delete uFilter.extras.scopeInfo;
|
|
97
|
+
delete uFilter.extras.dataset;
|
|
94
98
|
return {
|
|
95
99
|
collapsed: uFilter.collapsed,
|
|
96
100
|
column: {
|
|
@@ -23,7 +23,7 @@ function getBackendProperty(filter) {
|
|
|
23
23
|
return filter.property.concat('_').concat(filter.lookupDisplayIndex.toString());
|
|
24
24
|
}
|
|
25
25
|
else if (filter.column.type === COLUMN_1.COLUMN.IMAGE) {
|
|
26
|
-
return COLUMN_PROPERTY_1.COLUMN_PROPERTY.IMAGE_ANSWER_ID;
|
|
26
|
+
return filter.values.every(value => (0, isEmpty_1.isEmpty)(value.valueid)) ? undefined : COLUMN_PROPERTY_1.COLUMN_PROPERTY.IMAGE_ANSWER_ID;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
return filter.property;
|
|
@@ -75,7 +75,7 @@ function getResultValues(values, filter) {
|
|
|
75
75
|
return values.map((value) => {
|
|
76
76
|
if (value.enabled) {
|
|
77
77
|
if (filter.column.type === COLUMN_1.COLUMN.IMAGE) {
|
|
78
|
-
return value.valueid;
|
|
78
|
+
return value.valueid || value.imageUrl || value.value;
|
|
79
79
|
}
|
|
80
80
|
else {
|
|
81
81
|
return value.value;
|
|
@@ -27,7 +27,8 @@ function formatDate(dateString, format) {
|
|
|
27
27
|
return dateString;
|
|
28
28
|
if (!isValidDateString(dateString))
|
|
29
29
|
return dateString;
|
|
30
|
-
|
|
30
|
+
const dateValue = dateString === null || dateString === void 0 ? void 0 : dateString.replace(/Z$/i, '');
|
|
31
|
+
return (0, dayjs_1.default)(dateValue.split('.')[0]).format(format.replace('HH24:', 'HH:').replace('MI:SS', 'mm:ss').replace('MM:SS', 'mm:ss'));
|
|
31
32
|
}
|
|
32
33
|
exports.formatDate = formatDate;
|
|
33
34
|
function formatAbbreviated(num, decimals) {
|
|
@@ -85,12 +86,13 @@ function formatFileSize(bytes) {
|
|
|
85
86
|
}
|
|
86
87
|
exports.formatFileSize = formatFileSize;
|
|
87
88
|
const addFormat = (value, outputFormat = 'None', config) => {
|
|
89
|
+
var _a, _b;
|
|
88
90
|
if ((0, isEmpty_1.isEmpty)(value) || typeof value === 'object' && (0, isEmpty_1.isEmpty)(value[0]))
|
|
89
91
|
return value;
|
|
90
92
|
switch (outputFormat.type) {
|
|
91
93
|
case 'DATE':
|
|
92
94
|
case 'DATETIME':
|
|
93
|
-
return (config === null || config === void 0 ? void 0 : config.lang) && outputFormat.format === 'Default' ? (0, localization_1.formatWithLocale)(value, outputFormat, config) : formatDate(value, outputFormat.format);
|
|
95
|
+
return (config === null || config === void 0 ? void 0 : config.lang) && outputFormat.format === 'Default' ? (0, localization_1.formatWithLocale)(value, outputFormat, config) : formatDate(value, (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === 'Default' && ((_a = outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.originalFormat) === null || _a === void 0 ? void 0 : _a.format) ? (_b = outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.originalFormat) === null || _b === void 0 ? void 0 : _b.format : outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format);
|
|
94
96
|
case 'NUMERIC': {
|
|
95
97
|
const parse = parseFloat(value);
|
|
96
98
|
const withLocale = outputFormat !== 'None' && (config === null || config === void 0 ? void 0 : config.lang);
|
|
@@ -30,9 +30,11 @@ const formatWithLocale = (value, outputFormat, config = {}) => {
|
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
exports.formatWithLocale = formatWithLocale;
|
|
33
|
+
const DATE_FORMAT_CACHE = [];
|
|
33
34
|
function formatLocaleDate(value, outputFormat, config) {
|
|
34
35
|
const { lang = definition_1.LANG_DEFAULT, options } = config;
|
|
35
|
-
const
|
|
36
|
+
const dateValue = value === null || value === void 0 ? void 0 : value.replace(/Z$/i, '');
|
|
37
|
+
const dateParam = new Date(dateValue);
|
|
36
38
|
let langOpts = options;
|
|
37
39
|
if (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.originalFormat) {
|
|
38
40
|
const { format } = outputFormat.originalFormat;
|
|
@@ -40,18 +42,31 @@ function formatLocaleDate(value, outputFormat, config) {
|
|
|
40
42
|
langOpts = definition_1.DATETIME_OPTIONS;
|
|
41
43
|
}
|
|
42
44
|
try {
|
|
43
|
-
|
|
45
|
+
const key = lang + JSON.stringify(langOpts);
|
|
46
|
+
let formatter = DATE_FORMAT_CACHE[key];
|
|
47
|
+
if (!formatter) {
|
|
48
|
+
formatter = new Intl.DateTimeFormat([lang, definition_1.LANG_DEFAULT], langOpts);
|
|
49
|
+
DATE_FORMAT_CACHE[key] = formatter;
|
|
50
|
+
}
|
|
51
|
+
return formatter.format(dateParam);
|
|
44
52
|
}
|
|
45
53
|
catch (error) {
|
|
46
54
|
return (0, isEmpty_1.isEmpty)(dateParam) ? value : new Intl.DateTimeFormat(definition_1.LANG_DEFAULT, langOpts).format(dateParam);
|
|
47
55
|
}
|
|
48
56
|
}
|
|
57
|
+
const NUMBER_FORMAT_CACHE = [];
|
|
49
58
|
function formatLocaleNumber(value, outputFormat, config) {
|
|
50
59
|
const { lang = definition_1.LANG_DEFAULT, options } = config;
|
|
51
60
|
const langOpts = options || getLocaleOptions(outputFormat);
|
|
52
61
|
const valueToFormat = (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Percentage" /* PERCENTAGE */ ? value / 100 : value;
|
|
53
62
|
try {
|
|
54
|
-
|
|
63
|
+
const key = lang + JSON.stringify(langOpts);
|
|
64
|
+
let formatter = NUMBER_FORMAT_CACHE[key];
|
|
65
|
+
if (!formatter) {
|
|
66
|
+
formatter = new Intl.NumberFormat([lang, definition_1.LANG_DEFAULT], langOpts);
|
|
67
|
+
NUMBER_FORMAT_CACHE[key] = formatter;
|
|
68
|
+
}
|
|
69
|
+
return formatter.format(valueToFormat);
|
|
55
70
|
}
|
|
56
71
|
catch (e) {
|
|
57
72
|
return new Intl.NumberFormat(definition_1.LANG_DEFAULT, langOpts).format(valueToFormat);
|
|
@@ -6,6 +6,7 @@ const isNumericalColumn_1 = require("../../columns/helpers/isNumericalColumn");
|
|
|
6
6
|
const DATE_GROUPING_PROPERTY_1 = require("../../dates/constants/DATE_GROUPING_PROPERTY");
|
|
7
7
|
const DATE_GROUPING_TIME_PROPERTY_1 = require("../../dates/constants/DATE_GROUPING_TIME_PROPERTY");
|
|
8
8
|
const format_1 = require("../../format/format");
|
|
9
|
+
const isEmpty_1 = require("../../general/mix/isEmpty");
|
|
9
10
|
const getI18nDateGroupLabel_1 = require("../../globalization/helpers/getI18nDateGroupLabel");
|
|
10
11
|
const getValueWithSuffixes_1 = require("./getValueWithSuffixes");
|
|
11
12
|
/**
|
|
@@ -15,6 +16,8 @@ const getValueWithSuffixes_1 = require("./getValueWithSuffixes");
|
|
|
15
16
|
* @returns A transformed value
|
|
16
17
|
*/
|
|
17
18
|
function transformValue(value, settings) {
|
|
19
|
+
if ((0, isEmpty_1.isEmpty)(value))
|
|
20
|
+
return value;
|
|
18
21
|
const valueWithI18n = (0, getI18nDateGroupLabel_1.getI18nDateGroupLabel)(value, settings.property, settings.translate);
|
|
19
22
|
const valueWithLocalization = (0, format_1.addFormat)(valueWithI18n, getOutputFormat(settings), getFormatConfig(settings));
|
|
20
23
|
return (0, getValueWithSuffixes_1.getValueWithSuffixes)(valueWithLocalization, { suffixTranslateLabel: settings.suffixTranslateLabel, translate: settings.translate });
|
|
@@ -7,7 +7,7 @@ import { COLUMN } from "../../columns/constants/COLUMN";
|
|
|
7
7
|
* @returns A new value array with the filled properties.
|
|
8
8
|
*/
|
|
9
9
|
export function adaptFilterValues(filter) {
|
|
10
|
-
const setValue = value => (Object.assign(Object.assign({}, value), { enabled: isEmpty(value.enabled) ? true : value.enabled }));
|
|
10
|
+
const setValue = value => (Object.assign(Object.assign({}, value), { value: isEmpty(value.value) ? undefined : value.value, enabled: isEmpty(value.enabled) ? true : value.enabled }));
|
|
11
11
|
if (filter.column.type === COLUMN.RANKING && isEmpty(filter.column.aggregate)) {
|
|
12
12
|
return filter.values.map(rValues => rValues.map(setValue));
|
|
13
13
|
}
|
|
@@ -3,6 +3,7 @@ import { isEmpty } from "../../general/mix/isEmpty";
|
|
|
3
3
|
import { adaptFilterValues } from "./adaptFilterValues";
|
|
4
4
|
import { FILTER_SECTION } from "../constants/common/FILTER_SECTION";
|
|
5
5
|
import { FILTER_STRUCTURE_VERSION } from "../constants/common/FILTER_STRUCTURE_VERSION";
|
|
6
|
+
import { cloneDeep } from "../../general/object/cloneDeep";
|
|
6
7
|
/**
|
|
7
8
|
* Generates a filter data structure from the flatttened UI filters.
|
|
8
9
|
* @param uFilters Array of flattened filters from UI
|
|
@@ -78,8 +79,11 @@ function buildDataset(uFilter) {
|
|
|
78
79
|
* @returns an filter structure
|
|
79
80
|
*/
|
|
80
81
|
function buildFilter(uFilter) {
|
|
82
|
+
uFilter = cloneDeep(uFilter);
|
|
81
83
|
const info = !isEmpty(uFilter.extras.info) ? { icon: uFilter.extras.info.icon, label: uFilter.extras.info.label } : undefined;
|
|
82
84
|
const property = adaptDateGroupingProperty(uFilter.property);
|
|
85
|
+
delete uFilter.extras.scopeInfo;
|
|
86
|
+
delete uFilter.extras.dataset;
|
|
83
87
|
return {
|
|
84
88
|
collapsed: uFilter.collapsed,
|
|
85
89
|
column: {
|
|
@@ -337,7 +337,7 @@ function getResultValues(values, props) {
|
|
|
337
337
|
return values.map((value) => {
|
|
338
338
|
if (value.enabled) {
|
|
339
339
|
if (props.column.type === COLUMN.IMAGE) {
|
|
340
|
-
return value.valueid;
|
|
340
|
+
return value.valueid || value.imageUrl || value.value;
|
|
341
341
|
}
|
|
342
342
|
else {
|
|
343
343
|
return value.value;
|
|
@@ -4,6 +4,7 @@ import { FILTER_SECTION } from "../constants/common/FILTER_SECTION";
|
|
|
4
4
|
import { FILTER_STRUCTURE_VERSION } from "../constants/common/FILTER_STRUCTURE_VERSION";
|
|
5
5
|
import { getLastIndexFromArray } from "../../general/array/getLastIndexFromArray";
|
|
6
6
|
import { isEmpty } from "../../general/mix/isEmpty";
|
|
7
|
+
import { cloneDeep } from "../../general/object/cloneDeep";
|
|
7
8
|
/**
|
|
8
9
|
* Generates a UI filter data structure from the flatttened UI filters.
|
|
9
10
|
* @param uFilters Array of flattened filters from UI
|
|
@@ -85,8 +86,11 @@ function buildDataset(uFilter) {
|
|
|
85
86
|
* @returns an filter structure
|
|
86
87
|
*/
|
|
87
88
|
function buildFilter(uFilter) {
|
|
89
|
+
uFilter = cloneDeep(uFilter);
|
|
88
90
|
const info = !isEmpty(uFilter.extras.info) ? { icon: uFilter.extras.info.icon, label: uFilter.extras.info.label } : undefined;
|
|
89
91
|
const property = adaptDateGroupingProperty(uFilter.property);
|
|
92
|
+
delete uFilter.extras.scopeInfo;
|
|
93
|
+
delete uFilter.extras.dataset;
|
|
90
94
|
return {
|
|
91
95
|
collapsed: uFilter.collapsed,
|
|
92
96
|
column: {
|
|
@@ -20,7 +20,7 @@ export function getBackendProperty(filter) {
|
|
|
20
20
|
return filter.property.concat('_').concat(filter.lookupDisplayIndex.toString());
|
|
21
21
|
}
|
|
22
22
|
else if (filter.column.type === COLUMN.IMAGE) {
|
|
23
|
-
return COLUMN_PROPERTY.IMAGE_ANSWER_ID;
|
|
23
|
+
return filter.values.every(value => isEmpty(value.valueid)) ? undefined : COLUMN_PROPERTY.IMAGE_ANSWER_ID;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
return filter.property;
|
|
@@ -71,7 +71,7 @@ function getResultValues(values, filter) {
|
|
|
71
71
|
return values.map((value) => {
|
|
72
72
|
if (value.enabled) {
|
|
73
73
|
if (filter.column.type === COLUMN.IMAGE) {
|
|
74
|
-
return value.valueid;
|
|
74
|
+
return value.valueid || value.imageUrl || value.value;
|
|
75
75
|
}
|
|
76
76
|
else {
|
|
77
77
|
return value.value;
|
package/dist/format/format.js
CHANGED
|
@@ -21,7 +21,8 @@ export function formatDate(dateString, format) {
|
|
|
21
21
|
return dateString;
|
|
22
22
|
if (!isValidDateString(dateString))
|
|
23
23
|
return dateString;
|
|
24
|
-
|
|
24
|
+
const dateValue = dateString === null || dateString === void 0 ? void 0 : dateString.replace(/Z$/i, '');
|
|
25
|
+
return dayjs(dateValue.split('.')[0]).format(format.replace('HH24:', 'HH:').replace('MI:SS', 'mm:ss').replace('MM:SS', 'mm:ss'));
|
|
25
26
|
}
|
|
26
27
|
export function formatAbbreviated(num, decimals) {
|
|
27
28
|
if (num == 0)
|
|
@@ -76,12 +77,13 @@ export function formatFileSize(bytes) {
|
|
|
76
77
|
return megaBytes < 10 ? `${fixDecimals(megaBytes)} MB` : `${Math.round(megaBytes)} MB`;
|
|
77
78
|
}
|
|
78
79
|
export const addFormat = (value, outputFormat = 'None', config) => {
|
|
80
|
+
var _a, _b;
|
|
79
81
|
if (isEmpty(value) || typeof value === 'object' && isEmpty(value[0]))
|
|
80
82
|
return value;
|
|
81
83
|
switch (outputFormat.type) {
|
|
82
84
|
case 'DATE':
|
|
83
85
|
case 'DATETIME':
|
|
84
|
-
return (config === null || config === void 0 ? void 0 : config.lang) && outputFormat.format === 'Default' ? formatWithLocale(value, outputFormat, config) : formatDate(value, outputFormat.format);
|
|
86
|
+
return (config === null || config === void 0 ? void 0 : config.lang) && outputFormat.format === 'Default' ? formatWithLocale(value, outputFormat, config) : formatDate(value, (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === 'Default' && ((_a = outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.originalFormat) === null || _a === void 0 ? void 0 : _a.format) ? (_b = outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.originalFormat) === null || _b === void 0 ? void 0 : _b.format : outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format);
|
|
85
87
|
case 'NUMERIC': {
|
|
86
88
|
const parse = parseFloat(value);
|
|
87
89
|
const withLocale = outputFormat !== 'None' && (config === null || config === void 0 ? void 0 : config.lang);
|
|
@@ -24,9 +24,11 @@ export const formatWithLocale = (value, outputFormat, config = {}) => {
|
|
|
24
24
|
return formatLocaleNumber(value, outputFormat, config);
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
+
const DATE_FORMAT_CACHE = [];
|
|
27
28
|
function formatLocaleDate(value, outputFormat, config) {
|
|
28
29
|
const { lang = LANG_DEFAULT, options } = config;
|
|
29
|
-
const
|
|
30
|
+
const dateValue = value === null || value === void 0 ? void 0 : value.replace(/Z$/i, '');
|
|
31
|
+
const dateParam = new Date(dateValue);
|
|
30
32
|
let langOpts = options;
|
|
31
33
|
if (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.originalFormat) {
|
|
32
34
|
const { format } = outputFormat.originalFormat;
|
|
@@ -34,18 +36,31 @@ function formatLocaleDate(value, outputFormat, config) {
|
|
|
34
36
|
langOpts = DATETIME_OPTIONS;
|
|
35
37
|
}
|
|
36
38
|
try {
|
|
37
|
-
|
|
39
|
+
const key = lang + JSON.stringify(langOpts);
|
|
40
|
+
let formatter = DATE_FORMAT_CACHE[key];
|
|
41
|
+
if (!formatter) {
|
|
42
|
+
formatter = new Intl.DateTimeFormat([lang, LANG_DEFAULT], langOpts);
|
|
43
|
+
DATE_FORMAT_CACHE[key] = formatter;
|
|
44
|
+
}
|
|
45
|
+
return formatter.format(dateParam);
|
|
38
46
|
}
|
|
39
47
|
catch (error) {
|
|
40
48
|
return isEmpty(dateParam) ? value : new Intl.DateTimeFormat(LANG_DEFAULT, langOpts).format(dateParam);
|
|
41
49
|
}
|
|
42
50
|
}
|
|
51
|
+
const NUMBER_FORMAT_CACHE = [];
|
|
43
52
|
function formatLocaleNumber(value, outputFormat, config) {
|
|
44
53
|
const { lang = LANG_DEFAULT, options } = config;
|
|
45
54
|
const langOpts = options || getLocaleOptions(outputFormat);
|
|
46
55
|
const valueToFormat = (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Percentage" /* PERCENTAGE */ ? value / 100 : value;
|
|
47
56
|
try {
|
|
48
|
-
|
|
57
|
+
const key = lang + JSON.stringify(langOpts);
|
|
58
|
+
let formatter = NUMBER_FORMAT_CACHE[key];
|
|
59
|
+
if (!formatter) {
|
|
60
|
+
formatter = new Intl.NumberFormat([lang, LANG_DEFAULT], langOpts);
|
|
61
|
+
NUMBER_FORMAT_CACHE[key] = formatter;
|
|
62
|
+
}
|
|
63
|
+
return formatter.format(valueToFormat);
|
|
49
64
|
}
|
|
50
65
|
catch (e) {
|
|
51
66
|
return new Intl.NumberFormat(LANG_DEFAULT, langOpts).format(valueToFormat);
|
|
@@ -3,6 +3,7 @@ import { isNumericalColumn } from "../../columns/helpers/isNumericalColumn";
|
|
|
3
3
|
import { DATE_GROUPING_PROPERTY } from "../../dates/constants/DATE_GROUPING_PROPERTY";
|
|
4
4
|
import { DATE_GROUPING_TIME_PROPERTY } from "../../dates/constants/DATE_GROUPING_TIME_PROPERTY";
|
|
5
5
|
import { addFormat } from "../../format/format";
|
|
6
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
6
7
|
import { getI18nDateGroupLabel } from "../../globalization/helpers/getI18nDateGroupLabel";
|
|
7
8
|
import { getValueWithSuffixes } from "./getValueWithSuffixes";
|
|
8
9
|
/**
|
|
@@ -12,6 +13,8 @@ import { getValueWithSuffixes } from "./getValueWithSuffixes";
|
|
|
12
13
|
* @returns A transformed value
|
|
13
14
|
*/
|
|
14
15
|
export function transformValue(value, settings) {
|
|
16
|
+
if (isEmpty(value))
|
|
17
|
+
return value;
|
|
15
18
|
const valueWithI18n = getI18nDateGroupLabel(value, settings.property, settings.translate);
|
|
16
19
|
const valueWithLocalization = addFormat(valueWithI18n, getOutputFormat(settings), getFormatConfig(settings));
|
|
17
20
|
return getValueWithSuffixes(valueWithLocalization, { suffixTranslateLabel: settings.suffixTranslateLabel, translate: settings.translate });
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@ import { IFSValueRelativeDate } from "../interfaces/common/IFSValueRelativeDate"
|
|
|
15
15
|
* @returns A new value array with the filled properties.
|
|
16
16
|
*/
|
|
17
17
|
export function adaptFilterValues(filter: IFSFilter): IFValue[] {
|
|
18
|
-
const setValue = value => ({ ...value, enabled: isEmpty(value.enabled) ? true : value.enabled });
|
|
18
|
+
const setValue = value => ({ ...value, value: isEmpty(value.value) ? undefined : value.value, enabled: isEmpty(value.enabled) ? true : value.enabled });
|
|
19
19
|
|
|
20
20
|
if (filter.column.type === COLUMN.RANKING && isEmpty(filter.column.aggregate)) {
|
|
21
21
|
return (filter.values as IFSValueRanking[][]).map(rValues => rValues.map(setValue));
|
|
@@ -9,6 +9,7 @@ import { IFSData } from "../interfaces/common/IFSData";
|
|
|
9
9
|
import { IFSScope } from "../interfaces/common/IFSScope";
|
|
10
10
|
import { IFSFilter } from "../interfaces/common/IFSFilter";
|
|
11
11
|
import { IFSDataset } from "../interfaces/common/IFSDataset";
|
|
12
|
+
import { cloneDeep } from "../../general/object/cloneDeep";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Generates a filter data structure from the flatttened UI filters.
|
|
@@ -90,9 +91,13 @@ function buildDataset(uFilter: IFUFlattenedFilter): IFSDataset {
|
|
|
90
91
|
* @returns an filter structure
|
|
91
92
|
*/
|
|
92
93
|
function buildFilter(uFilter: IFUFlattenedFilter): IFSFilter {
|
|
94
|
+
uFilter = cloneDeep(uFilter);
|
|
95
|
+
|
|
93
96
|
const info = !isEmpty(uFilter.extras.info) ? { icon: uFilter.extras.info.icon, label: uFilter.extras.info.label } : undefined;
|
|
94
97
|
const property = adaptDateGroupingProperty(uFilter.property);
|
|
95
98
|
|
|
99
|
+
delete uFilter.extras.scopeInfo;
|
|
100
|
+
delete uFilter.extras.dataset;
|
|
96
101
|
return {
|
|
97
102
|
collapsed: uFilter.collapsed,
|
|
98
103
|
column: {
|
|
@@ -406,7 +406,7 @@ function getRankingValues(values: IFSValueRanking[][], rankingGroupIndex?: numbe
|
|
|
406
406
|
return values.map((value: IFSValue) => {
|
|
407
407
|
if (value.enabled) {
|
|
408
408
|
if (props.column.type === COLUMN.IMAGE) {
|
|
409
|
-
return value.valueid;
|
|
409
|
+
return value.valueid || value.imageUrl || value.value;
|
|
410
410
|
} else {
|
|
411
411
|
return value.value;
|
|
412
412
|
}
|
|
@@ -10,6 +10,7 @@ import { IFUFilter } from "../interfaces/ui/IFUFilter";
|
|
|
10
10
|
import { IFUDataset } from "../interfaces/ui/IFUDataset";
|
|
11
11
|
import { getLastIndexFromArray } from "../../general/array/getLastIndexFromArray";
|
|
12
12
|
import { isEmpty } from "../../general/mix/isEmpty";
|
|
13
|
+
import { cloneDeep } from "../../general/object/cloneDeep";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Generates a UI filter data structure from the flatttened UI filters.
|
|
@@ -96,9 +97,13 @@ function buildDataset(uFilter: IFUFlattenedFilter): IFUDataset {
|
|
|
96
97
|
* @returns an filter structure
|
|
97
98
|
*/
|
|
98
99
|
function buildFilter(uFilter: IFUFlattenedFilter): IFUFilter {
|
|
100
|
+
uFilter = cloneDeep(uFilter);
|
|
101
|
+
|
|
99
102
|
const info = !isEmpty(uFilter.extras.info) ? { icon: uFilter.extras.info.icon, label: uFilter.extras.info.label } : undefined;
|
|
100
103
|
const property = adaptDateGroupingProperty(uFilter.property);
|
|
101
104
|
|
|
105
|
+
delete uFilter.extras.scopeInfo;
|
|
106
|
+
delete uFilter.extras.dataset;
|
|
102
107
|
return {
|
|
103
108
|
collapsed: uFilter.collapsed,
|
|
104
109
|
column: {
|
|
@@ -3,6 +3,7 @@ import { COLUMN_PROPERTY } from "../../../columns/constants/COLUMN_PROPERTY";
|
|
|
3
3
|
import { isDateColumn } from "../../../columns/helpers/isDateColumn";
|
|
4
4
|
import { isEmpty } from "../../../general/mix/isEmpty";
|
|
5
5
|
import { IFSFilter } from "../../interfaces/common/IFSFilter";
|
|
6
|
+
import { IFSValue } from "../../interfaces/common/IFSValue";
|
|
6
7
|
import { IFProperty } from "../../interfaces/IFProperty";
|
|
7
8
|
import { isNullValidator } from "../common/isNullValidator";
|
|
8
9
|
|
|
@@ -20,7 +21,7 @@ export function getBackendProperty(filter: IFSFilter): IFProperty {
|
|
|
20
21
|
} else if (filter.column.type === COLUMN.LOOKUP && filter.property === COLUMN_PROPERTY.LOOKUP_DISPLAY && filter.lookupDisplayIndex != null) {
|
|
21
22
|
return filter.property.concat('_').concat(filter.lookupDisplayIndex.toString()) as any;
|
|
22
23
|
} else if (filter.column.type === COLUMN.IMAGE) {
|
|
23
|
-
return COLUMN_PROPERTY.IMAGE_ANSWER_ID;
|
|
24
|
+
return (filter.values as IFSValue[]).every(value => isEmpty(value.valueid)) ? undefined : COLUMN_PROPERTY.IMAGE_ANSWER_ID;
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
return filter.property;
|
|
@@ -81,7 +81,7 @@ function getResultValues(values: IFSValue[], filter: IFSFilter): IFBExpressionVa
|
|
|
81
81
|
return values.map((value: IFSValue) => {
|
|
82
82
|
if (value.enabled) {
|
|
83
83
|
if (filter.column.type === COLUMN.IMAGE) {
|
|
84
|
-
return value.valueid;
|
|
84
|
+
return value.valueid || value.imageUrl || value.value;
|
|
85
85
|
} else {
|
|
86
86
|
return value.value;
|
|
87
87
|
}
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
export interface IFSValue {
|
|
5
5
|
enabled?: boolean; // True: the value is enabled; False: the value is disabled
|
|
6
6
|
imageUrl?: string; // URL for a image. This is common for images column type.
|
|
7
|
-
value
|
|
7
|
+
value?: string; // The value to filter
|
|
8
8
|
valueid?: string; // Mostly for webform columns that need an ID. Alias for answerid in the model object.
|
|
9
9
|
}
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
export interface IFUValue {
|
|
5
5
|
enabled?: boolean; // Optional flag to enabled the value
|
|
6
6
|
imageUrl?: string; // URL from Image type
|
|
7
|
-
value
|
|
7
|
+
value?: string; // A string value
|
|
8
8
|
valueid?: string; // For values that need a value ID or answer ID
|
|
9
9
|
}
|
package/src/format/format.ts
CHANGED
|
@@ -23,7 +23,8 @@ function isValidDateString(dateString = '') {
|
|
|
23
23
|
export function formatDate(dateString, format) {
|
|
24
24
|
if (isEmpty(dateString) || !isNaN(dateString) || format === 'Default') return dateString;
|
|
25
25
|
if (!isValidDateString(dateString)) return dateString;
|
|
26
|
-
|
|
26
|
+
const dateValue = dateString?.replace(/Z$/i, '');
|
|
27
|
+
return dayjs(dateValue.split('.')[0]).format(format.replace('HH24:', 'HH:').replace('MI:SS', 'mm:ss').replace('MM:SS', 'mm:ss'));
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export function formatAbbreviated(num, decimals) {
|
|
@@ -89,7 +90,7 @@ export const addFormat = (value: any, outputFormat: any = 'None', config?: IForm
|
|
|
89
90
|
switch (outputFormat.type) {
|
|
90
91
|
case 'DATE':
|
|
91
92
|
case 'DATETIME':
|
|
92
|
-
return config?.lang && outputFormat.format === 'Default' ? formatWithLocale(value, outputFormat, config) : formatDate(value, outputFormat
|
|
93
|
+
return config?.lang && outputFormat.format === 'Default' ? formatWithLocale(value, outputFormat, config) : formatDate(value, outputFormat?.format === 'Default' && outputFormat?.originalFormat?.format ? outputFormat?.originalFormat?.format : outputFormat?.format);
|
|
93
94
|
case 'NUMERIC': {
|
|
94
95
|
const parse = parseFloat(value);
|
|
95
96
|
const withLocale = outputFormat !== 'None' && config?.lang;
|
|
@@ -27,27 +27,42 @@ export const formatWithLocale = (value: any, outputFormat: IFormatOutputFormat,
|
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
const DATE_FORMAT_CACHE = [];
|
|
30
31
|
function formatLocaleDate(value: any, outputFormat: IFormatOutputFormat, config: IFormatConfig) {
|
|
31
32
|
const { lang = LANG_DEFAULT, options } = config;
|
|
32
|
-
const
|
|
33
|
+
const dateValue = value?.replace(/Z$/i, '');
|
|
34
|
+
const dateParam = new Date(dateValue);
|
|
33
35
|
let langOpts = options;
|
|
34
36
|
if (outputFormat?.originalFormat) {
|
|
35
37
|
const { format } = outputFormat.originalFormat;
|
|
36
38
|
if (DATETIME_COLUMN_FORMAT.includes(format)) langOpts = DATETIME_OPTIONS;
|
|
37
39
|
}
|
|
38
40
|
try {
|
|
39
|
-
|
|
41
|
+
const key = lang + JSON.stringify(langOpts);
|
|
42
|
+
let formatter = DATE_FORMAT_CACHE[key];
|
|
43
|
+
if (!formatter) {
|
|
44
|
+
formatter = new Intl.DateTimeFormat([lang, LANG_DEFAULT], langOpts);
|
|
45
|
+
DATE_FORMAT_CACHE[key] = formatter;
|
|
46
|
+
}
|
|
47
|
+
return formatter.format(dateParam);
|
|
40
48
|
} catch (error) {
|
|
41
49
|
return isEmpty(dateParam) ? value : new Intl.DateTimeFormat(LANG_DEFAULT, langOpts).format(dateParam);
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
52
|
|
|
53
|
+
const NUMBER_FORMAT_CACHE = [];
|
|
45
54
|
function formatLocaleNumber(value: any, outputFormat: IFormatOutputFormat, config: IFormatConfig,) {
|
|
46
55
|
const { lang = LANG_DEFAULT, options } = config;
|
|
47
56
|
const langOpts = options || getLocaleOptions(outputFormat);
|
|
48
57
|
const valueToFormat = outputFormat?.format === LOCALE_FORMATS.PERCENTAGE ? value/100 : value;
|
|
49
58
|
try {
|
|
50
|
-
|
|
59
|
+
const key = lang + JSON.stringify(langOpts);
|
|
60
|
+
let formatter = NUMBER_FORMAT_CACHE[key];
|
|
61
|
+
if (!formatter) {
|
|
62
|
+
formatter = new Intl.NumberFormat([lang, LANG_DEFAULT], langOpts);
|
|
63
|
+
NUMBER_FORMAT_CACHE[key] = formatter;
|
|
64
|
+
}
|
|
65
|
+
return formatter.format(valueToFormat);
|
|
51
66
|
} catch (e) {
|
|
52
67
|
return new Intl.NumberFormat(LANG_DEFAULT, langOpts).format(valueToFormat);
|
|
53
68
|
}
|
|
@@ -4,6 +4,7 @@ import { IDateColumnPropertyType } from "../../columns/interfaces/IDateColumnPro
|
|
|
4
4
|
import { DATE_GROUPING_PROPERTY } from "../../dates/constants/DATE_GROUPING_PROPERTY";
|
|
5
5
|
import { DATE_GROUPING_TIME_PROPERTY } from "../../dates/constants/DATE_GROUPING_TIME_PROPERTY";
|
|
6
6
|
import { addFormat } from "../../format/format";
|
|
7
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
7
8
|
import { getI18nDateGroupLabel } from "../../globalization/helpers/getI18nDateGroupLabel";
|
|
8
9
|
import { ITransformValueSettings } from "../interfaces/ITransformValueSettings";
|
|
9
10
|
import { getValueWithSuffixes } from "./getValueWithSuffixes";
|
|
@@ -15,6 +16,8 @@ import { getValueWithSuffixes } from "./getValueWithSuffixes";
|
|
|
15
16
|
* @returns A transformed value
|
|
16
17
|
*/
|
|
17
18
|
export function transformValue(value: string, settings: ITransformValueSettings): string {
|
|
19
|
+
if (isEmpty(value)) return value;
|
|
20
|
+
|
|
18
21
|
const valueWithI18n = getI18nDateGroupLabel(value, settings.property as IDateColumnPropertyType, settings.translate);
|
|
19
22
|
|
|
20
23
|
const valueWithLocalization = addFormat(valueWithI18n, getOutputFormat(settings), getFormatConfig(settings));
|