@qrvey/utils 1.6.0-7 → 1.7.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/charts/adapters/RequestAdapterMetric.d.ts +7 -0
- package/dist/charts/adapters/RequestAdapterMetric.js +120 -0
- package/dist/charts/adapters/index.d.ts +1 -0
- package/dist/charts/adapters/index.js +1 -0
- package/dist/charts/constants/REQUEST_ADAPTER.d.ts +91 -0
- package/dist/charts/constants/REQUEST_ADAPTER.js +93 -0
- package/dist/charts/constants/index.d.ts +1 -0
- package/dist/charts/constants/index.js +1 -0
- package/dist/charts/interfaces/IRequestAdapterMetric.d.ts +124 -0
- package/dist/charts/interfaces/IRequestAdapterMetric.js +1 -0
- package/dist/charts/interfaces/index.d.ts +1 -0
- package/dist/charts/interfaces/index.js +1 -0
- package/dist/cjs/charts/adapters/RequestAdapterMetric.d.ts +7 -0
- package/dist/cjs/charts/adapters/RequestAdapterMetric.js +124 -0
- package/dist/cjs/charts/adapters/index.d.ts +1 -0
- package/dist/cjs/charts/adapters/index.js +1 -0
- package/dist/cjs/charts/constants/REQUEST_ADAPTER.d.ts +91 -0
- package/dist/cjs/charts/constants/REQUEST_ADAPTER.js +96 -0
- package/dist/cjs/charts/constants/index.d.ts +1 -0
- package/dist/cjs/charts/constants/index.js +1 -0
- package/dist/cjs/charts/interfaces/IRequestAdapterMetric.d.ts +124 -0
- package/dist/cjs/charts/interfaces/IRequestAdapterMetric.js +2 -0
- package/dist/cjs/charts/interfaces/index.d.ts +1 -0
- package/dist/cjs/charts/interfaces/index.js +1 -0
- package/dist/cjs/columns/constants/COLUMN_PROPERTIES.d.ts +1 -1
- package/dist/cjs/dates/constants/DATE_GROUPING_ALL_PROPERTIES.d.ts +1 -1
- package/dist/cjs/filters/adapters/adaptFilterValues.js +4 -1
- package/dist/cjs/format/helpers/isDateTimeFormat.js +2 -0
- package/dist/cjs/globalization/interfaces/II18nServiceTranslateOption.d.ts +1 -1
- package/dist/cjs/globalization/interfaces/chart_builder/II18nChartBuilderStyleOptions.d.ts +2 -0
- package/dist/cjs/globalization/interfaces/cross_tabs/II18nCrossTabs.d.ts +5 -5
- package/dist/cjs/globalization/interfaces/cross_tabs/II18nCrossTabsSorting.d.ts +3 -3
- package/dist/cjs/globalization/interfaces/filters/II18nFilter.d.ts +0 -2
- package/dist/cjs/globalization/interfaces/filters/II18nTokenBox.d.ts +5 -5
- package/dist/cjs/globalization/interfaces/panel/II18nPanelSummaryViews.d.ts +1 -1
- package/dist/cjs/globalization/labels/chart_builder/I18N_CHART_BUILDER_STYLE_OPTIONS.js +2 -0
- package/dist/cjs/globalization/labels/common/I18N_COMMON.js +4 -1
- package/dist/cjs/globalization/labels/filters/I18N_FILTER.js +0 -6
- package/dist/cjs/globalization/labels/panel/I18N_PANEL.js +1 -1
- package/dist/cjs/interfaces/IChartBuilder.Interface.d.ts +26 -0
- package/dist/cjs/interfaces/IChartBuilder.Interface.js +28 -0
- package/dist/columns/constants/COLUMN_PROPERTIES.d.ts +1 -1
- package/dist/dates/constants/DATE_GROUPING_ALL_PROPERTIES.d.ts +1 -1
- package/dist/filters/adapters/adaptFilterValues.js +4 -1
- package/dist/format/helpers/isDateTimeFormat.js +2 -0
- package/dist/globalization/interfaces/II18nServiceTranslateOption.d.ts +1 -1
- package/dist/globalization/interfaces/chart_builder/II18nChartBuilderStyleOptions.d.ts +2 -0
- package/dist/globalization/interfaces/cross_tabs/II18nCrossTabs.d.ts +5 -5
- package/dist/globalization/interfaces/cross_tabs/II18nCrossTabsSorting.d.ts +3 -3
- package/dist/globalization/interfaces/filters/II18nFilter.d.ts +0 -2
- package/dist/globalization/interfaces/filters/II18nTokenBox.d.ts +5 -5
- package/dist/globalization/interfaces/panel/II18nPanelSummaryViews.d.ts +1 -1
- package/dist/globalization/labels/chart_builder/I18N_CHART_BUILDER_STYLE_OPTIONS.js +2 -0
- package/dist/globalization/labels/common/I18N_COMMON.js +4 -1
- package/dist/globalization/labels/filters/I18N_FILTER.js +0 -6
- package/dist/globalization/labels/panel/I18N_PANEL.js +1 -1
- package/dist/interfaces/IChartBuilder.Interface.d.ts +26 -0
- package/dist/interfaces/IChartBuilder.Interface.js +27 -1
- package/package.json +9 -9
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MetricConfig, MetricRequestPayload } from "../interfaces/IRequestAdapterMetric";
|
|
2
|
+
/**
|
|
3
|
+
* It takes a metric object and returns a metric request object
|
|
4
|
+
* @param {MetricConfig} metricObj - MetricConfigData
|
|
5
|
+
* @returns A function that takes in a metricObj and returns a partial metricRequest
|
|
6
|
+
*/
|
|
7
|
+
export declare const makeBodyRequestMetrics: (metricObj: MetricConfig) => Partial<MetricRequestPayload>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { isEmpty } from "../../general";
|
|
2
|
+
import { TIME_PERIOD, TP_CUSTOM_RANGE } from "../../interfaces";
|
|
3
|
+
import { RELATIVE_OBJECT_BY_TIME_LABEL } from "../constants/REQUEST_ADAPTER";
|
|
4
|
+
/**
|
|
5
|
+
* It takes a metric object and returns a metric request object
|
|
6
|
+
* @param {MetricConfig} metricObj - MetricConfigData
|
|
7
|
+
* @returns A function that takes in a metricObj and returns a partial metricRequest
|
|
8
|
+
*/
|
|
9
|
+
export const makeBodyRequestMetrics = (metricObj) => {
|
|
10
|
+
const body = {};
|
|
11
|
+
const data = metricObj.data;
|
|
12
|
+
body.logic = getFilterLogic(metricObj);
|
|
13
|
+
body.value = metricMakeValue(data);
|
|
14
|
+
/* Checking if the data object has a dateColumn property. If it does, it will add a period and
|
|
15
|
+
comparison property to the body object. */
|
|
16
|
+
if (isComparison(data)) {
|
|
17
|
+
body.period = metricMakeTimeData(data.dateColumn, data.timePeriod, getRangeDataPeriod(data));
|
|
18
|
+
body.comparison = metricMakeTimeData(data.dateColumn, data.comparison, getRangeDataComparison(data));
|
|
19
|
+
}
|
|
20
|
+
return body;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* If data is truthy, return data.logic, otherwise return an empty array.
|
|
24
|
+
* @param filters - The data object that is passed to the component.
|
|
25
|
+
*/
|
|
26
|
+
const getFilterLogic = (filters) => (filters === null || filters === void 0 ? void 0 : filters.logic) || [];
|
|
27
|
+
/**
|
|
28
|
+
* It takes a data object and returns a MetricValue object
|
|
29
|
+
* @param data - The data object that is passed to the component.
|
|
30
|
+
* @returns A metric value object
|
|
31
|
+
*/
|
|
32
|
+
const metricMakeValue = (data) => {
|
|
33
|
+
var _a, _b, _c;
|
|
34
|
+
return {
|
|
35
|
+
questionid: (_a = data === null || data === void 0 ? void 0 : data.value) === null || _a === void 0 ? void 0 : _a.id,
|
|
36
|
+
aggregate: (_b = data === null || data === void 0 ? void 0 : data.valueAggregate) === null || _b === void 0 ? void 0 : _b.label,
|
|
37
|
+
property: ((_c = data === null || data === void 0 ? void 0 : data.value) === null || _c === void 0 ? void 0 : _c.property) || null,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* If data is truthy and data.dateColumn is truthy, return true, otherwise return false.
|
|
42
|
+
* @param data - The data object that is passed to the component.
|
|
43
|
+
*/
|
|
44
|
+
const isComparison = (data) => Boolean(data === null || data === void 0 ? void 0 : data.dateColumn);
|
|
45
|
+
/**
|
|
46
|
+
* It takes a date column, time data, and a custom range config and returns a metric period or metric
|
|
47
|
+
* custom range
|
|
48
|
+
* @param dateColumn - The column that contains the date data.
|
|
49
|
+
* @param timeData - {
|
|
50
|
+
* @param {CustomRangeConfig} range - CustomRangeConfig
|
|
51
|
+
* @returns An object with the following properties:
|
|
52
|
+
* - label
|
|
53
|
+
* - value
|
|
54
|
+
* - questionid
|
|
55
|
+
*/
|
|
56
|
+
const metricMakeTimeData = (dateColumn, timeData, range) => {
|
|
57
|
+
const relativObject = getConfigRelativeObjectBytimeLabel(timeData.label, range);
|
|
58
|
+
if (!isEmpty(relativObject))
|
|
59
|
+
return Object.assign(Object.assign({}, relativObject), { questionid: dateColumn.id });
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Given a time label and a custom range, return a relative date config or a metric custom range.
|
|
63
|
+
* @param {TIME_PERIOD} timeLabel - TIME_PERIOD.CUSTOM_RANGE
|
|
64
|
+
* @param {CustomRangeConfig} range - CustomRangeConfig
|
|
65
|
+
* @returns A relative date config or a metric custom range
|
|
66
|
+
*/
|
|
67
|
+
const getConfigRelativeObjectBytimeLabel = (timeLabel, range) => {
|
|
68
|
+
if (timeLabel === TIME_PERIOD.CUSTOM_RANGE) {
|
|
69
|
+
const rangeResults = makeCustomRangeConfig(range);
|
|
70
|
+
if (!isEmpty(rangeResults))
|
|
71
|
+
return { customRange: rangeResults };
|
|
72
|
+
}
|
|
73
|
+
return RELATIVE_OBJECT_BY_TIME_LABEL[timeLabel];
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* It takes in a custom range config object and returns a custom range object
|
|
77
|
+
* @param {CustomRangeConfig} customRangeData - CustomRangeConfig
|
|
78
|
+
* @returns A function that takes in a customRangeData object and returns a customRange object.
|
|
79
|
+
*/
|
|
80
|
+
const makeCustomRangeConfig = (customRangeData) => {
|
|
81
|
+
const { endDate, startingDate, label } = customRangeData;
|
|
82
|
+
if (label === TP_CUSTOM_RANGE.AFTER && !isEmpty(startingDate))
|
|
83
|
+
return { gte: startingDate };
|
|
84
|
+
if (label === TP_CUSTOM_RANGE.BEFORE && !isEmpty(startingDate))
|
|
85
|
+
return { lte: startingDate };
|
|
86
|
+
if (!isEmpty(startingDate) && !isEmpty(endDate))
|
|
87
|
+
return { gte: startingDate, lte: endDate };
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* It takes in a metricData object and returns a CustomRangeConfig object
|
|
91
|
+
* @param metricData - The metric data object that is returned from the API.
|
|
92
|
+
* @returns An object with the following properties:
|
|
93
|
+
* startingDate: metricData?.timePeriodDate,
|
|
94
|
+
* endDate: metricData?.timePeriodEndDate,
|
|
95
|
+
* label: metricData?.timePeriodCustomRange?.label,
|
|
96
|
+
*/
|
|
97
|
+
const getRangeDataPeriod = (metricData) => {
|
|
98
|
+
var _a;
|
|
99
|
+
return {
|
|
100
|
+
startingDate: metricData === null || metricData === void 0 ? void 0 : metricData.timePeriodDate,
|
|
101
|
+
endDate: metricData === null || metricData === void 0 ? void 0 : metricData.timePeriodEndDate,
|
|
102
|
+
label: (_a = metricData === null || metricData === void 0 ? void 0 : metricData.timePeriodCustomRange) === null || _a === void 0 ? void 0 : _a.label,
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* It takes in a metricData object and returns a CustomRangeConfig object
|
|
107
|
+
* @param metricData - The metric data object that is returned from the API.
|
|
108
|
+
* @returns An object with the following properties:
|
|
109
|
+
* startingDate: metricData?.comparisonDate,
|
|
110
|
+
* endDate: metricData?.comparisonEndDate,
|
|
111
|
+
* label: metricData?.comparisonCustomRange?.label,
|
|
112
|
+
*/
|
|
113
|
+
const getRangeDataComparison = (metricData) => {
|
|
114
|
+
var _a;
|
|
115
|
+
return {
|
|
116
|
+
startingDate: metricData === null || metricData === void 0 ? void 0 : metricData.comparisonDate,
|
|
117
|
+
endDate: metricData === null || metricData === void 0 ? void 0 : metricData.comparisonEndDate,
|
|
118
|
+
label: (_a = metricData === null || metricData === void 0 ? void 0 : metricData.comparisonCustomRange) === null || _a === void 0 ? void 0 : _a.label,
|
|
119
|
+
};
|
|
120
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { DATE_GROUPING_PROPERTY, DATE_GROUPING_TIME_PROPERTY, RELATIVE_CURSOR } from "../../dates";
|
|
2
|
+
export declare const RELATIVE_OBJECT_BY_TIME_LABEL: {
|
|
3
|
+
THIS_SECOND: {
|
|
4
|
+
cursor: RELATIVE_CURSOR;
|
|
5
|
+
unit: DATE_GROUPING_TIME_PROPERTY;
|
|
6
|
+
};
|
|
7
|
+
LAST_SECOND: {
|
|
8
|
+
cursor: RELATIVE_CURSOR;
|
|
9
|
+
unit: DATE_GROUPING_TIME_PROPERTY;
|
|
10
|
+
number: number;
|
|
11
|
+
includeCurrent: boolean;
|
|
12
|
+
isCalendarDate: boolean;
|
|
13
|
+
};
|
|
14
|
+
THIS_MINUTE: {
|
|
15
|
+
cursor: RELATIVE_CURSOR;
|
|
16
|
+
unit: DATE_GROUPING_TIME_PROPERTY;
|
|
17
|
+
};
|
|
18
|
+
LAST_MINUTE: {
|
|
19
|
+
cursor: RELATIVE_CURSOR;
|
|
20
|
+
unit: DATE_GROUPING_TIME_PROPERTY;
|
|
21
|
+
number: number;
|
|
22
|
+
includeCurrent: boolean;
|
|
23
|
+
isCalendarDate: boolean;
|
|
24
|
+
};
|
|
25
|
+
THIS_HOUR: {
|
|
26
|
+
cursor: RELATIVE_CURSOR;
|
|
27
|
+
unit: DATE_GROUPING_TIME_PROPERTY;
|
|
28
|
+
};
|
|
29
|
+
LAST_HOUR: {
|
|
30
|
+
cursor: RELATIVE_CURSOR;
|
|
31
|
+
number: number;
|
|
32
|
+
unit: DATE_GROUPING_TIME_PROPERTY;
|
|
33
|
+
includeCurrent: boolean;
|
|
34
|
+
isCalendarDate: boolean;
|
|
35
|
+
};
|
|
36
|
+
TODAY: {
|
|
37
|
+
cursor: RELATIVE_CURSOR;
|
|
38
|
+
unit: DATE_GROUPING_PROPERTY;
|
|
39
|
+
};
|
|
40
|
+
YESTERDAY: {
|
|
41
|
+
cursor: RELATIVE_CURSOR;
|
|
42
|
+
number: number;
|
|
43
|
+
unit: DATE_GROUPING_PROPERTY;
|
|
44
|
+
includeCurrent: boolean;
|
|
45
|
+
isCalendarDate: boolean;
|
|
46
|
+
};
|
|
47
|
+
THIS_WEEK: {
|
|
48
|
+
cursor: RELATIVE_CURSOR;
|
|
49
|
+
unit: DATE_GROUPING_PROPERTY;
|
|
50
|
+
};
|
|
51
|
+
LAST_WEEK: {
|
|
52
|
+
cursor: RELATIVE_CURSOR;
|
|
53
|
+
number: number;
|
|
54
|
+
unit: DATE_GROUPING_PROPERTY;
|
|
55
|
+
includeCurrent: boolean;
|
|
56
|
+
isCalendarDate: boolean;
|
|
57
|
+
};
|
|
58
|
+
THIS_MONTH: {
|
|
59
|
+
cursor: RELATIVE_CURSOR;
|
|
60
|
+
unit: DATE_GROUPING_PROPERTY;
|
|
61
|
+
};
|
|
62
|
+
LAST_MONTH: {
|
|
63
|
+
cursor: RELATIVE_CURSOR;
|
|
64
|
+
number: number;
|
|
65
|
+
unit: DATE_GROUPING_PROPERTY;
|
|
66
|
+
includeCurrent: boolean;
|
|
67
|
+
isCalendarDate: boolean;
|
|
68
|
+
};
|
|
69
|
+
THIS_QUARTER: {
|
|
70
|
+
cursor: RELATIVE_CURSOR;
|
|
71
|
+
unit: DATE_GROUPING_PROPERTY;
|
|
72
|
+
};
|
|
73
|
+
LAST_QUARTER: {
|
|
74
|
+
cursor: RELATIVE_CURSOR;
|
|
75
|
+
number: number;
|
|
76
|
+
unit: DATE_GROUPING_PROPERTY;
|
|
77
|
+
includeCurrent: boolean;
|
|
78
|
+
isCalendarDate: boolean;
|
|
79
|
+
};
|
|
80
|
+
THIS_YEAR: {
|
|
81
|
+
cursor: RELATIVE_CURSOR;
|
|
82
|
+
unit: DATE_GROUPING_PROPERTY;
|
|
83
|
+
};
|
|
84
|
+
LAST_YEAR: {
|
|
85
|
+
cursor: RELATIVE_CURSOR;
|
|
86
|
+
number: number;
|
|
87
|
+
unit: DATE_GROUPING_PROPERTY;
|
|
88
|
+
includeCurrent: boolean;
|
|
89
|
+
isCalendarDate: boolean;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { DATE_GROUPING_PROPERTY, DATE_GROUPING_TIME_PROPERTY, RELATIVE_CURSOR, } from "../../dates";
|
|
2
|
+
import { TIME_PERIOD } from "../../interfaces";
|
|
3
|
+
/* A constant that is used to define the time period for the metric chart. */
|
|
4
|
+
export const RELATIVE_OBJECT_BY_TIME_LABEL = {
|
|
5
|
+
[TIME_PERIOD.THIS_SECOND]: {
|
|
6
|
+
cursor: RELATIVE_CURSOR.THIS,
|
|
7
|
+
unit: DATE_GROUPING_TIME_PROPERTY.SECOND,
|
|
8
|
+
},
|
|
9
|
+
[TIME_PERIOD.LAST_SECOND]: {
|
|
10
|
+
cursor: RELATIVE_CURSOR.LAST,
|
|
11
|
+
unit: DATE_GROUPING_TIME_PROPERTY.SECOND,
|
|
12
|
+
number: 1,
|
|
13
|
+
includeCurrent: false,
|
|
14
|
+
isCalendarDate: true,
|
|
15
|
+
},
|
|
16
|
+
[TIME_PERIOD.THIS_MINUTE]: {
|
|
17
|
+
cursor: RELATIVE_CURSOR.THIS,
|
|
18
|
+
unit: DATE_GROUPING_TIME_PROPERTY.MINUTE,
|
|
19
|
+
},
|
|
20
|
+
[TIME_PERIOD.LAST_MINUTE]: {
|
|
21
|
+
cursor: RELATIVE_CURSOR.LAST,
|
|
22
|
+
unit: DATE_GROUPING_TIME_PROPERTY.MINUTE,
|
|
23
|
+
number: 1,
|
|
24
|
+
includeCurrent: false,
|
|
25
|
+
isCalendarDate: true,
|
|
26
|
+
},
|
|
27
|
+
[TIME_PERIOD.THIS_HOUR]: {
|
|
28
|
+
cursor: RELATIVE_CURSOR.THIS,
|
|
29
|
+
unit: DATE_GROUPING_TIME_PROPERTY.HOUR,
|
|
30
|
+
},
|
|
31
|
+
[TIME_PERIOD.LAST_HOUR]: {
|
|
32
|
+
cursor: RELATIVE_CURSOR.LAST,
|
|
33
|
+
number: 1,
|
|
34
|
+
unit: DATE_GROUPING_TIME_PROPERTY.HOUR,
|
|
35
|
+
includeCurrent: false,
|
|
36
|
+
isCalendarDate: true,
|
|
37
|
+
},
|
|
38
|
+
[TIME_PERIOD.TODAY]: {
|
|
39
|
+
cursor: RELATIVE_CURSOR.THIS,
|
|
40
|
+
unit: DATE_GROUPING_PROPERTY.DAY,
|
|
41
|
+
},
|
|
42
|
+
[TIME_PERIOD.YESTERDAY]: {
|
|
43
|
+
cursor: RELATIVE_CURSOR.LAST,
|
|
44
|
+
number: 1,
|
|
45
|
+
unit: DATE_GROUPING_PROPERTY.DAY,
|
|
46
|
+
includeCurrent: false,
|
|
47
|
+
isCalendarDate: true,
|
|
48
|
+
},
|
|
49
|
+
[TIME_PERIOD.THIS_WEEK]: {
|
|
50
|
+
cursor: RELATIVE_CURSOR.THIS,
|
|
51
|
+
unit: DATE_GROUPING_PROPERTY.WEEK,
|
|
52
|
+
},
|
|
53
|
+
[TIME_PERIOD.LAST_WEEK]: {
|
|
54
|
+
cursor: RELATIVE_CURSOR.LAST,
|
|
55
|
+
number: 1,
|
|
56
|
+
unit: DATE_GROUPING_PROPERTY.WEEK,
|
|
57
|
+
includeCurrent: false,
|
|
58
|
+
isCalendarDate: true,
|
|
59
|
+
},
|
|
60
|
+
[TIME_PERIOD.THIS_MONTH]: {
|
|
61
|
+
cursor: RELATIVE_CURSOR.THIS,
|
|
62
|
+
unit: DATE_GROUPING_PROPERTY.MONTH,
|
|
63
|
+
},
|
|
64
|
+
[TIME_PERIOD.LAST_MONTH]: {
|
|
65
|
+
cursor: RELATIVE_CURSOR.LAST,
|
|
66
|
+
number: 1,
|
|
67
|
+
unit: DATE_GROUPING_PROPERTY.MONTH,
|
|
68
|
+
includeCurrent: false,
|
|
69
|
+
isCalendarDate: true,
|
|
70
|
+
},
|
|
71
|
+
[TIME_PERIOD.THIS_QUARTER]: {
|
|
72
|
+
cursor: RELATIVE_CURSOR.THIS,
|
|
73
|
+
unit: DATE_GROUPING_PROPERTY.QUARTER,
|
|
74
|
+
},
|
|
75
|
+
[TIME_PERIOD.LAST_QUARTER]: {
|
|
76
|
+
cursor: RELATIVE_CURSOR.LAST,
|
|
77
|
+
number: 1,
|
|
78
|
+
unit: DATE_GROUPING_PROPERTY.QUARTER,
|
|
79
|
+
includeCurrent: false,
|
|
80
|
+
isCalendarDate: true,
|
|
81
|
+
},
|
|
82
|
+
[TIME_PERIOD.THIS_YEAR]: {
|
|
83
|
+
cursor: RELATIVE_CURSOR.THIS,
|
|
84
|
+
unit: DATE_GROUPING_PROPERTY.YEAR,
|
|
85
|
+
},
|
|
86
|
+
[TIME_PERIOD.LAST_YEAR]: {
|
|
87
|
+
cursor: RELATIVE_CURSOR.LAST,
|
|
88
|
+
number: 1,
|
|
89
|
+
unit: DATE_GROUPING_PROPERTY.YEAR,
|
|
90
|
+
includeCurrent: false,
|
|
91
|
+
isCalendarDate: true,
|
|
92
|
+
},
|
|
93
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { IBColumn } from "../../columns";
|
|
2
|
+
import { IDateGroupingProperty, RelativeCursor } from "../../dates";
|
|
3
|
+
import { IFBLogic } from "../../filters";
|
|
4
|
+
import { TimePeriod, TP_CUSTOM_RANGE } from "../../interfaces";
|
|
5
|
+
import { AGGREGATE_LABEL } from "../constants";
|
|
6
|
+
export interface MetricRequestPayload {
|
|
7
|
+
logic: IFBLogic[];
|
|
8
|
+
value: MetricValue;
|
|
9
|
+
period?: MetricPeriod | MetricCustomRange;
|
|
10
|
+
comparison?: MetricComparison | MetricCustomRange;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A metric value is an object with an aggregate label, a question id, and an optional property.
|
|
14
|
+
* @property {AGGREGATE_LABEL} aggregate - The aggregate label to use.
|
|
15
|
+
* @property {string} questionid - The question ID of the question you want to get the metric for.
|
|
16
|
+
* @property {string | null} property - The property of the question that you want to aggregate. For
|
|
17
|
+
* example, if you want to aggregate the number of times a question was answered, you would use the
|
|
18
|
+
* property "answered".
|
|
19
|
+
*/
|
|
20
|
+
export declare type MetricValue = {
|
|
21
|
+
aggregate: AGGREGATE_LABEL;
|
|
22
|
+
questionid: string;
|
|
23
|
+
property?: string | null;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A `RelativeDateConfig` is an object with a `questionid` property, a `cursor` property, an optional
|
|
27
|
+
* `number` property, a `unit` property, an optional `includeCurrent` property, and an optional
|
|
28
|
+
* `isCalendarDate` property.
|
|
29
|
+
* @property {string} questionid - The question id of the question that you want to filter on.
|
|
30
|
+
* @property {RelativeCursor} cursor - The cursor is the date that the relative date is based on. It
|
|
31
|
+
* can be one of the following:
|
|
32
|
+
* @property {number} number - The number of units to go back.
|
|
33
|
+
* @property {IDateGroupingProperty} unit - The unit of time to use for the relative date. This can be
|
|
34
|
+
* one of the following:
|
|
35
|
+
* @property {boolean} includeCurrent - If true, the current date is included in the range.
|
|
36
|
+
* @property {boolean} isCalendarDate - If true, the date is a calendar date, otherwise it's a relative
|
|
37
|
+
* date.
|
|
38
|
+
*/
|
|
39
|
+
export declare type RelativeDateConfig = {
|
|
40
|
+
questionid: string;
|
|
41
|
+
cursor: RelativeCursor;
|
|
42
|
+
number?: number;
|
|
43
|
+
unit: IDateGroupingProperty;
|
|
44
|
+
includeCurrent?: boolean;
|
|
45
|
+
isCalendarDate?: boolean;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* `MetricCustomRange` is a type that has a property called `customRange` that is of type
|
|
49
|
+
* `CustomRange`.
|
|
50
|
+
* @property {CustomRange} customRange - The custom range to use for the metric.
|
|
51
|
+
*/
|
|
52
|
+
export declare type MetricCustomRange = {
|
|
53
|
+
customRange: CustomRange;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* `CustomRangeConfig` is an object with optional properties `startingDate`, `endDate`, and `label`.
|
|
57
|
+
* @property {string} startingDate - The starting date of the custom range.
|
|
58
|
+
* @property {string} endDate - The end date of the custom range.
|
|
59
|
+
* @property {TP_CUSTOM_RANGE} label - The label for the custom range.
|
|
60
|
+
*/
|
|
61
|
+
export declare type CustomRangeConfig = {
|
|
62
|
+
startingDate?: string;
|
|
63
|
+
endDate?: string;
|
|
64
|
+
label?: TP_CUSTOM_RANGE;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* CustomRange is an object with optional gte and lte properties, both of which are strings.
|
|
68
|
+
* @property {string} gte - Greater than or equal to
|
|
69
|
+
* @property {string} lte - Less than or equal to
|
|
70
|
+
*/
|
|
71
|
+
export declare type CustomRange = {
|
|
72
|
+
gte?: string;
|
|
73
|
+
lte?: string;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* `MetricRequestResponse` is an object with four properties: `value`, `min`, `max`, and `comparison`.
|
|
77
|
+
*
|
|
78
|
+
* The `value` property is a number. The `min` and `max` properties are also numbers. The `comparison`
|
|
79
|
+
* property is a number.
|
|
80
|
+
* @property {number} value - The value of the metric
|
|
81
|
+
* @property {number} min - The minimum value of the metric
|
|
82
|
+
* @property {number} max - The maximum value of the metric
|
|
83
|
+
* @property {number} comparison - The value of the metric for the previous period.
|
|
84
|
+
*/
|
|
85
|
+
export declare type MetricRequestResponse = {
|
|
86
|
+
value: number;
|
|
87
|
+
min: number;
|
|
88
|
+
max: number;
|
|
89
|
+
comparison: number;
|
|
90
|
+
};
|
|
91
|
+
export declare type MetricPeriod = RelativeDateConfig;
|
|
92
|
+
export declare type MetricComparison = RelativeDateConfig;
|
|
93
|
+
export declare type MetricConfig = {
|
|
94
|
+
logic: IFBLogic[];
|
|
95
|
+
data: MetricConfigData;
|
|
96
|
+
};
|
|
97
|
+
export declare type MetricConfigData = {
|
|
98
|
+
dateColumn: IBColumn;
|
|
99
|
+
timePeriod: MetricTimeInfo;
|
|
100
|
+
timePeriodCustomRange: MetricTimeCustomRange;
|
|
101
|
+
timePeriodDate: string;
|
|
102
|
+
timePeriodEndDate: string;
|
|
103
|
+
comparison: MetricTimeInfo;
|
|
104
|
+
comparisonCustomRange: MetricTimeCustomRange;
|
|
105
|
+
comparisonDate: string;
|
|
106
|
+
comparisonEndDate: string;
|
|
107
|
+
value: {
|
|
108
|
+
id: string;
|
|
109
|
+
property: string;
|
|
110
|
+
};
|
|
111
|
+
valueAggregate: {
|
|
112
|
+
label: AGGREGATE_LABEL;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
export declare type MetricTimeCustomRange = {
|
|
116
|
+
key: string;
|
|
117
|
+
label: TP_CUSTOM_RANGE;
|
|
118
|
+
text: string;
|
|
119
|
+
};
|
|
120
|
+
export declare type MetricTimeInfo = {
|
|
121
|
+
key: string;
|
|
122
|
+
label: TimePeriod;
|
|
123
|
+
text: string;
|
|
124
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MetricConfig, MetricRequestPayload } from "../interfaces/IRequestAdapterMetric";
|
|
2
|
+
/**
|
|
3
|
+
* It takes a metric object and returns a metric request object
|
|
4
|
+
* @param {MetricConfig} metricObj - MetricConfigData
|
|
5
|
+
* @returns A function that takes in a metricObj and returns a partial metricRequest
|
|
6
|
+
*/
|
|
7
|
+
export declare const makeBodyRequestMetrics: (metricObj: MetricConfig) => Partial<MetricRequestPayload>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeBodyRequestMetrics = void 0;
|
|
4
|
+
const general_1 = require("../../general");
|
|
5
|
+
const interfaces_1 = require("../../interfaces");
|
|
6
|
+
const REQUEST_ADAPTER_1 = require("../constants/REQUEST_ADAPTER");
|
|
7
|
+
/**
|
|
8
|
+
* It takes a metric object and returns a metric request object
|
|
9
|
+
* @param {MetricConfig} metricObj - MetricConfigData
|
|
10
|
+
* @returns A function that takes in a metricObj and returns a partial metricRequest
|
|
11
|
+
*/
|
|
12
|
+
const makeBodyRequestMetrics = (metricObj) => {
|
|
13
|
+
const body = {};
|
|
14
|
+
const data = metricObj.data;
|
|
15
|
+
body.logic = getFilterLogic(metricObj);
|
|
16
|
+
body.value = metricMakeValue(data);
|
|
17
|
+
/* Checking if the data object has a dateColumn property. If it does, it will add a period and
|
|
18
|
+
comparison property to the body object. */
|
|
19
|
+
if (isComparison(data)) {
|
|
20
|
+
body.period = metricMakeTimeData(data.dateColumn, data.timePeriod, getRangeDataPeriod(data));
|
|
21
|
+
body.comparison = metricMakeTimeData(data.dateColumn, data.comparison, getRangeDataComparison(data));
|
|
22
|
+
}
|
|
23
|
+
return body;
|
|
24
|
+
};
|
|
25
|
+
exports.makeBodyRequestMetrics = makeBodyRequestMetrics;
|
|
26
|
+
/**
|
|
27
|
+
* If data is truthy, return data.logic, otherwise return an empty array.
|
|
28
|
+
* @param filters - The data object that is passed to the component.
|
|
29
|
+
*/
|
|
30
|
+
const getFilterLogic = (filters) => (filters === null || filters === void 0 ? void 0 : filters.logic) || [];
|
|
31
|
+
/**
|
|
32
|
+
* It takes a data object and returns a MetricValue object
|
|
33
|
+
* @param data - The data object that is passed to the component.
|
|
34
|
+
* @returns A metric value object
|
|
35
|
+
*/
|
|
36
|
+
const metricMakeValue = (data) => {
|
|
37
|
+
var _a, _b, _c;
|
|
38
|
+
return {
|
|
39
|
+
questionid: (_a = data === null || data === void 0 ? void 0 : data.value) === null || _a === void 0 ? void 0 : _a.id,
|
|
40
|
+
aggregate: (_b = data === null || data === void 0 ? void 0 : data.valueAggregate) === null || _b === void 0 ? void 0 : _b.label,
|
|
41
|
+
property: ((_c = data === null || data === void 0 ? void 0 : data.value) === null || _c === void 0 ? void 0 : _c.property) || null,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* If data is truthy and data.dateColumn is truthy, return true, otherwise return false.
|
|
46
|
+
* @param data - The data object that is passed to the component.
|
|
47
|
+
*/
|
|
48
|
+
const isComparison = (data) => Boolean(data === null || data === void 0 ? void 0 : data.dateColumn);
|
|
49
|
+
/**
|
|
50
|
+
* It takes a date column, time data, and a custom range config and returns a metric period or metric
|
|
51
|
+
* custom range
|
|
52
|
+
* @param dateColumn - The column that contains the date data.
|
|
53
|
+
* @param timeData - {
|
|
54
|
+
* @param {CustomRangeConfig} range - CustomRangeConfig
|
|
55
|
+
* @returns An object with the following properties:
|
|
56
|
+
* - label
|
|
57
|
+
* - value
|
|
58
|
+
* - questionid
|
|
59
|
+
*/
|
|
60
|
+
const metricMakeTimeData = (dateColumn, timeData, range) => {
|
|
61
|
+
const relativObject = getConfigRelativeObjectBytimeLabel(timeData.label, range);
|
|
62
|
+
if (!(0, general_1.isEmpty)(relativObject))
|
|
63
|
+
return Object.assign(Object.assign({}, relativObject), { questionid: dateColumn.id });
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Given a time label and a custom range, return a relative date config or a metric custom range.
|
|
67
|
+
* @param {TIME_PERIOD} timeLabel - TIME_PERIOD.CUSTOM_RANGE
|
|
68
|
+
* @param {CustomRangeConfig} range - CustomRangeConfig
|
|
69
|
+
* @returns A relative date config or a metric custom range
|
|
70
|
+
*/
|
|
71
|
+
const getConfigRelativeObjectBytimeLabel = (timeLabel, range) => {
|
|
72
|
+
if (timeLabel === interfaces_1.TIME_PERIOD.CUSTOM_RANGE) {
|
|
73
|
+
const rangeResults = makeCustomRangeConfig(range);
|
|
74
|
+
if (!(0, general_1.isEmpty)(rangeResults))
|
|
75
|
+
return { customRange: rangeResults };
|
|
76
|
+
}
|
|
77
|
+
return REQUEST_ADAPTER_1.RELATIVE_OBJECT_BY_TIME_LABEL[timeLabel];
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* It takes in a custom range config object and returns a custom range object
|
|
81
|
+
* @param {CustomRangeConfig} customRangeData - CustomRangeConfig
|
|
82
|
+
* @returns A function that takes in a customRangeData object and returns a customRange object.
|
|
83
|
+
*/
|
|
84
|
+
const makeCustomRangeConfig = (customRangeData) => {
|
|
85
|
+
const { endDate, startingDate, label } = customRangeData;
|
|
86
|
+
if (label === interfaces_1.TP_CUSTOM_RANGE.AFTER && !(0, general_1.isEmpty)(startingDate))
|
|
87
|
+
return { gte: startingDate };
|
|
88
|
+
if (label === interfaces_1.TP_CUSTOM_RANGE.BEFORE && !(0, general_1.isEmpty)(startingDate))
|
|
89
|
+
return { lte: startingDate };
|
|
90
|
+
if (!(0, general_1.isEmpty)(startingDate) && !(0, general_1.isEmpty)(endDate))
|
|
91
|
+
return { gte: startingDate, lte: endDate };
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* It takes in a metricData object and returns a CustomRangeConfig object
|
|
95
|
+
* @param metricData - The metric data object that is returned from the API.
|
|
96
|
+
* @returns An object with the following properties:
|
|
97
|
+
* startingDate: metricData?.timePeriodDate,
|
|
98
|
+
* endDate: metricData?.timePeriodEndDate,
|
|
99
|
+
* label: metricData?.timePeriodCustomRange?.label,
|
|
100
|
+
*/
|
|
101
|
+
const getRangeDataPeriod = (metricData) => {
|
|
102
|
+
var _a;
|
|
103
|
+
return {
|
|
104
|
+
startingDate: metricData === null || metricData === void 0 ? void 0 : metricData.timePeriodDate,
|
|
105
|
+
endDate: metricData === null || metricData === void 0 ? void 0 : metricData.timePeriodEndDate,
|
|
106
|
+
label: (_a = metricData === null || metricData === void 0 ? void 0 : metricData.timePeriodCustomRange) === null || _a === void 0 ? void 0 : _a.label,
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* It takes in a metricData object and returns a CustomRangeConfig object
|
|
111
|
+
* @param metricData - The metric data object that is returned from the API.
|
|
112
|
+
* @returns An object with the following properties:
|
|
113
|
+
* startingDate: metricData?.comparisonDate,
|
|
114
|
+
* endDate: metricData?.comparisonEndDate,
|
|
115
|
+
* label: metricData?.comparisonCustomRange?.label,
|
|
116
|
+
*/
|
|
117
|
+
const getRangeDataComparison = (metricData) => {
|
|
118
|
+
var _a;
|
|
119
|
+
return {
|
|
120
|
+
startingDate: metricData === null || metricData === void 0 ? void 0 : metricData.comparisonDate,
|
|
121
|
+
endDate: metricData === null || metricData === void 0 ? void 0 : metricData.comparisonEndDate,
|
|
122
|
+
label: (_a = metricData === null || metricData === void 0 ? void 0 : metricData.comparisonCustomRange) === null || _a === void 0 ? void 0 : _a.label,
|
|
123
|
+
};
|
|
124
|
+
};
|
|
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./endpointDataValidators"), exports);
|
|
18
18
|
__exportStar(require("./endpointDataGet"), exports);
|
|
19
19
|
__exportStar(require("./endpointData"), exports);
|
|
20
|
+
__exportStar(require("./RequestAdapterMetric"), exports);
|