@quillsql/react 2.12.28 → 2.12.29
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/cjs/Chart.d.ts.map +1 -1
- package/dist/cjs/Chart.js +10 -8
- package/dist/cjs/ChartBuilder.d.ts +35 -1
- package/dist/cjs/ChartBuilder.d.ts.map +1 -1
- package/dist/cjs/ChartBuilder.js +38 -4
- package/dist/cjs/Context.d.ts +1 -19
- package/dist/cjs/Context.d.ts.map +1 -1
- package/dist/cjs/Context.js +32 -83
- package/dist/cjs/Dashboard.d.ts.map +1 -1
- package/dist/cjs/Dashboard.js +76 -49
- package/dist/cjs/ReportBuilder.d.ts +9 -0
- package/dist/cjs/ReportBuilder.d.ts.map +1 -1
- package/dist/cjs/ReportBuilder.js +330 -100
- package/dist/cjs/SQLEditor.d.ts.map +1 -1
- package/dist/cjs/SQLEditor.js +98 -29
- package/dist/cjs/Table.d.ts.map +1 -1
- package/dist/cjs/Table.js +8 -8
- package/dist/cjs/components/Chart/ChartTooltip.d.ts.map +1 -1
- package/dist/cjs/components/Dashboard/DataLoader.d.ts.map +1 -1
- package/dist/cjs/components/Dashboard/DataLoader.js +20 -16
- package/dist/cjs/hooks/useDashboard.d.ts +1 -1
- package/dist/cjs/hooks/useDashboard.d.ts.map +1 -1
- package/dist/cjs/hooks/useDashboard.js +18 -4
- package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
- package/dist/cjs/internals/ReportBuilder/PivotModal.js +56 -57
- package/dist/cjs/utils/columnProcessing.d.ts +1 -0
- package/dist/cjs/utils/columnProcessing.d.ts.map +1 -1
- package/dist/cjs/utils/columnProcessing.js +8 -1
- package/dist/cjs/utils/dashboard.js +1 -1
- package/dist/cjs/utils/dataFetcher.d.ts +1 -1
- package/dist/cjs/utils/dataFetcher.d.ts.map +1 -1
- package/dist/cjs/utils/dataFetcher.js +9 -4
- package/dist/cjs/utils/dates.d.ts +1 -0
- package/dist/cjs/utils/dates.d.ts.map +1 -1
- package/dist/cjs/utils/dates.js +12 -3
- package/dist/cjs/utils/monacoAutocomplete.d.ts +20 -0
- package/dist/cjs/utils/monacoAutocomplete.d.ts.map +1 -0
- package/dist/cjs/utils/monacoAutocomplete.js +145 -0
- package/dist/cjs/utils/pivotConstructor.d.ts.map +1 -1
- package/dist/cjs/utils/pivotConstructor.js +58 -5
- package/dist/cjs/utils/queryConstructor.d.ts +4 -2
- package/dist/cjs/utils/queryConstructor.d.ts.map +1 -1
- package/dist/cjs/utils/queryConstructor.js +118 -57
- package/dist/cjs/utils/queryConstructor.uspec.d.ts +2 -0
- package/dist/cjs/utils/queryConstructor.uspec.d.ts.map +1 -0
- package/dist/cjs/utils/queryConstructor.uspec.js +225 -0
- package/dist/cjs/utils/tableProcessing.d.ts +1 -0
- package/dist/cjs/utils/tableProcessing.d.ts.map +1 -1
- package/dist/cjs/utils/tableProcessing.js +42 -5
- package/dist/esm/Chart.d.ts.map +1 -1
- package/dist/esm/Chart.js +10 -8
- package/dist/esm/ChartBuilder.d.ts +35 -1
- package/dist/esm/ChartBuilder.d.ts.map +1 -1
- package/dist/esm/ChartBuilder.js +36 -3
- package/dist/esm/Context.d.ts +1 -19
- package/dist/esm/Context.d.ts.map +1 -1
- package/dist/esm/Context.js +32 -82
- package/dist/esm/Dashboard.d.ts.map +1 -1
- package/dist/esm/Dashboard.js +77 -50
- package/dist/esm/ReportBuilder.d.ts +9 -0
- package/dist/esm/ReportBuilder.d.ts.map +1 -1
- package/dist/esm/ReportBuilder.js +333 -103
- package/dist/esm/SQLEditor.d.ts.map +1 -1
- package/dist/esm/SQLEditor.js +99 -30
- package/dist/esm/Table.d.ts.map +1 -1
- package/dist/esm/Table.js +8 -8
- package/dist/esm/components/Chart/ChartTooltip.d.ts.map +1 -1
- package/dist/esm/components/Dashboard/DataLoader.d.ts.map +1 -1
- package/dist/esm/components/Dashboard/DataLoader.js +20 -16
- package/dist/esm/hooks/useDashboard.d.ts +1 -1
- package/dist/esm/hooks/useDashboard.d.ts.map +1 -1
- package/dist/esm/hooks/useDashboard.js +19 -5
- package/dist/esm/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
- package/dist/esm/internals/ReportBuilder/PivotModal.js +57 -58
- package/dist/esm/utils/columnProcessing.d.ts +1 -0
- package/dist/esm/utils/columnProcessing.d.ts.map +1 -1
- package/dist/esm/utils/columnProcessing.js +6 -0
- package/dist/esm/utils/dashboard.js +1 -1
- package/dist/esm/utils/dataFetcher.d.ts +1 -1
- package/dist/esm/utils/dataFetcher.d.ts.map +1 -1
- package/dist/esm/utils/dataFetcher.js +9 -4
- package/dist/esm/utils/dates.d.ts +1 -0
- package/dist/esm/utils/dates.d.ts.map +1 -1
- package/dist/esm/utils/dates.js +10 -2
- package/dist/esm/utils/monacoAutocomplete.d.ts +20 -0
- package/dist/esm/utils/monacoAutocomplete.d.ts.map +1 -0
- package/dist/esm/utils/monacoAutocomplete.js +140 -0
- package/dist/esm/utils/pivotConstructor.d.ts.map +1 -1
- package/dist/esm/utils/pivotConstructor.js +58 -5
- package/dist/esm/utils/queryConstructor.d.ts +4 -2
- package/dist/esm/utils/queryConstructor.d.ts.map +1 -1
- package/dist/esm/utils/queryConstructor.js +115 -56
- package/dist/esm/utils/queryConstructor.uspec.d.ts +2 -0
- package/dist/esm/utils/queryConstructor.uspec.d.ts.map +1 -0
- package/dist/esm/utils/queryConstructor.uspec.js +223 -0
- package/dist/esm/utils/tableProcessing.d.ts +1 -0
- package/dist/esm/utils/tableProcessing.d.ts.map +1 -1
- package/dist/esm/utils/tableProcessing.js +41 -5
- package/package.json +1 -1
- package/dist/cjs/internals/ReportBuilder/PivotModal.spec.d.ts +0 -2
- package/dist/cjs/internals/ReportBuilder/PivotModal.spec.d.ts.map +0 -1
- package/dist/cjs/internals/ReportBuilder/PivotModal.spec.js +0 -213
- package/dist/esm/internals/ReportBuilder/PivotModal.spec.d.ts +0 -2
- package/dist/esm/internals/ReportBuilder/PivotModal.spec.d.ts.map +0 -1
- package/dist/esm/internals/ReportBuilder/PivotModal.spec.js +0 -211
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// @ts-nocheck
|
|
4
|
-
const chai_1 = require("chai");
|
|
5
|
-
const PivotModal_1 = require("./PivotModal");
|
|
6
|
-
const date_fns_1 = require("date-fns");
|
|
7
|
-
describe('PivotModal', function () {
|
|
8
|
-
describe('generatePivotTable', function () {
|
|
9
|
-
context('non date pivots', function () {
|
|
10
|
-
const rowPivot = {
|
|
11
|
-
rowField: 'merchant',
|
|
12
|
-
rowFieldType: 'varchar',
|
|
13
|
-
valueField: 'amount',
|
|
14
|
-
aggregationType: 'sum',
|
|
15
|
-
};
|
|
16
|
-
const rowColumnPivot = {
|
|
17
|
-
...rowPivot,
|
|
18
|
-
columnField: 'user_name',
|
|
19
|
-
columnFieldType: 'varchar',
|
|
20
|
-
};
|
|
21
|
-
const rows = [
|
|
22
|
-
{ merchant: 'm1', amount: 3, user_name: 'u1' },
|
|
23
|
-
{ merchant: 'm1', amount: 4, user_name: 'u2' },
|
|
24
|
-
{ merchant: 'm1', amount: 5, user_name: 'u1' },
|
|
25
|
-
{ merchant: 'm2', amount: 6, user_name: 'u1' },
|
|
26
|
-
{ merchant: 'm2', amount: 7, user_name: 'u2' },
|
|
27
|
-
{ merchant: 'm2', amount: 8, user_name: 'u2' },
|
|
28
|
-
];
|
|
29
|
-
it('should return empty table with no data', function () {
|
|
30
|
-
const table = (0, PivotModal_1.generatePivotTable)(rowPivot, [], [new Date(), (0, date_fns_1.subMonths)(new Date(), 3)]);
|
|
31
|
-
(0, chai_1.expect)(table.columns.length).to.equal(2);
|
|
32
|
-
(0, chai_1.expect)(table.rows.length).to.equal(0);
|
|
33
|
-
});
|
|
34
|
-
it('should combine values based on row pivot', function () {
|
|
35
|
-
const table = (0, PivotModal_1.generatePivotTable)(rowPivot, rows, [
|
|
36
|
-
new Date(),
|
|
37
|
-
(0, date_fns_1.subMonths)(new Date(), 3),
|
|
38
|
-
]);
|
|
39
|
-
(0, chai_1.expect)(table.columns.length).to.equal(2);
|
|
40
|
-
(0, chai_1.expect)(table.columns[0].field).to.equal('merchant');
|
|
41
|
-
(0, chai_1.expect)(table.columns[1].field).to.equal('amount');
|
|
42
|
-
(0, chai_1.expect)(table.rows.length).to.equal(2);
|
|
43
|
-
(0, chai_1.expect)(table.rows[0].amount).to.equal(12);
|
|
44
|
-
(0, chai_1.expect)(table.rows[1].amount).to.equal(21);
|
|
45
|
-
});
|
|
46
|
-
it('should combine values based on row and column pivots', function () {
|
|
47
|
-
const table = (0, PivotModal_1.generatePivotTable)(rowColumnPivot, rows, [
|
|
48
|
-
new Date(),
|
|
49
|
-
(0, date_fns_1.subMonths)(new Date(), 3),
|
|
50
|
-
]);
|
|
51
|
-
(0, chai_1.expect)(table.columns.length).to.equal(3);
|
|
52
|
-
(0, chai_1.expect)(table.columns[0].field).to.equal('merchant');
|
|
53
|
-
(0, chai_1.expect)(table.columns[1].field).to.equal('u1');
|
|
54
|
-
(0, chai_1.expect)(table.columns[2].field).to.equal('u2');
|
|
55
|
-
(0, chai_1.expect)(table.rows.length).to.equal(2);
|
|
56
|
-
(0, chai_1.expect)(table.rows[0].u1).to.equal(8);
|
|
57
|
-
(0, chai_1.expect)(table.rows[0].u2).to.equal(4);
|
|
58
|
-
(0, chai_1.expect)(table.rows[1].u1).to.equal(6);
|
|
59
|
-
(0, chai_1.expect)(table.rows[1].u2).to.equal(15);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
context('date pivots', function () {
|
|
63
|
-
const rows = [
|
|
64
|
-
{
|
|
65
|
-
merchant: 'm1',
|
|
66
|
-
amount: 3,
|
|
67
|
-
user_name: 'u1',
|
|
68
|
-
date: new Date('October 13, 2023 11:13:00'),
|
|
69
|
-
created_at: new Date('October 13, 2023 11:13:00'),
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
merchant: 'm1',
|
|
73
|
-
amount: 5,
|
|
74
|
-
user_name: 'u1',
|
|
75
|
-
date: new Date('October 14, 2023 11:13:00'),
|
|
76
|
-
created_at: new Date('October 14, 2023 11:13:00'),
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
merchant: 'm2',
|
|
80
|
-
amount: 6,
|
|
81
|
-
user_name: 'u1',
|
|
82
|
-
date: new Date('October 13, 2023 00:00:00'),
|
|
83
|
-
created_at: new Date('October 14, 2023 11:13:00'),
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
merchant: 'm2',
|
|
87
|
-
amount: 6,
|
|
88
|
-
user_name: 'u1',
|
|
89
|
-
date: new Date('October 14, 2023 23:13:00'),
|
|
90
|
-
created_at: new Date('October 13, 2023 11:13:00'),
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
merchant: 'm1',
|
|
94
|
-
amount: 6,
|
|
95
|
-
user_name: 'u2',
|
|
96
|
-
date: new Date('October 14, 2023 23:13:00'),
|
|
97
|
-
created_at: new Date('October 13, 2023 11:13:00'),
|
|
98
|
-
},
|
|
99
|
-
];
|
|
100
|
-
it('should handle a row date pivot', function () {
|
|
101
|
-
const pivot = {
|
|
102
|
-
rowField: 'date',
|
|
103
|
-
rowFieldType: 'date',
|
|
104
|
-
valueField: 'amount',
|
|
105
|
-
aggregationType: 'sum',
|
|
106
|
-
};
|
|
107
|
-
const table = (0, PivotModal_1.generatePivotTable)(pivot, rows, [
|
|
108
|
-
new Date('October 10, 2023 00:00:00'),
|
|
109
|
-
new Date('October 15, 2023 00:00:00'),
|
|
110
|
-
]);
|
|
111
|
-
(0, chai_1.expect)(table.columns.length).to.equal(2);
|
|
112
|
-
(0, chai_1.expect)(table.columns[0].field).to.equal('date');
|
|
113
|
-
(0, chai_1.expect)(table.columns[1].field).to.equal('amount');
|
|
114
|
-
(0, chai_1.expect)(table.rows.length).to.equal(6);
|
|
115
|
-
(0, chai_1.expect)(table.rows[3].amount).to.equal(9);
|
|
116
|
-
(0, chai_1.expect)(table.rows[4].amount).to.equal(17);
|
|
117
|
-
(0, chai_1.expect)(table.rows[5].amount).to.equal(0);
|
|
118
|
-
});
|
|
119
|
-
it('should handle a row timestamp pivot', function () {
|
|
120
|
-
const pivot = {
|
|
121
|
-
rowField: 'date',
|
|
122
|
-
rowFieldType: 'timestamp',
|
|
123
|
-
valueField: 'amount',
|
|
124
|
-
aggregationType: 'sum',
|
|
125
|
-
};
|
|
126
|
-
const table = (0, PivotModal_1.generatePivotTable)(pivot, rows, [
|
|
127
|
-
new Date('October 10, 2023 00:00:00').getTime(),
|
|
128
|
-
new Date('October 15, 2023 00:00:00').getTime(),
|
|
129
|
-
]);
|
|
130
|
-
(0, chai_1.expect)(table.columns.length).to.equal(2);
|
|
131
|
-
(0, chai_1.expect)(table.columns[0].field).to.equal('date');
|
|
132
|
-
(0, chai_1.expect)(table.columns[1].field).to.equal('amount');
|
|
133
|
-
(0, chai_1.expect)(table.rows.length).to.equal(6);
|
|
134
|
-
(0, chai_1.expect)(table.rows[3].amount).to.equal(9);
|
|
135
|
-
(0, chai_1.expect)(table.rows[4].amount).to.equal(17);
|
|
136
|
-
(0, chai_1.expect)(table.rows[5].amount).to.equal(0);
|
|
137
|
-
});
|
|
138
|
-
it('should handle a string row pivot with a date column pivot', function () {
|
|
139
|
-
const pivot = {
|
|
140
|
-
columnField: 'date',
|
|
141
|
-
columnFieldType: 'date',
|
|
142
|
-
valueField: 'amount',
|
|
143
|
-
aggregationType: 'sum',
|
|
144
|
-
rowField: 'user_name',
|
|
145
|
-
rowFieldType: 'varchar',
|
|
146
|
-
};
|
|
147
|
-
const table = (0, PivotModal_1.generatePivotTable)(pivot, rows, [
|
|
148
|
-
new Date('October 10, 2023 00:00:00'),
|
|
149
|
-
new Date('October 15, 2023 00:00:00'),
|
|
150
|
-
]);
|
|
151
|
-
(0, chai_1.expect)(table.columns.length).to.equal(7);
|
|
152
|
-
(0, chai_1.expect)(table.columns[0].field).to.equal('user_name');
|
|
153
|
-
(0, chai_1.expect)(table.rows.length).to.equal(2);
|
|
154
|
-
// u1
|
|
155
|
-
(0, chai_1.expect)(table.rows[0].user_name).to.equal('u1');
|
|
156
|
-
(0, chai_1.expect)(Object.values(table.rows[0])[4]).to.equal(9);
|
|
157
|
-
(0, chai_1.expect)(Object.values(table.rows[0])[5]).to.equal(11);
|
|
158
|
-
// u2
|
|
159
|
-
(0, chai_1.expect)(table.rows[1].user_name).to.equal('u2');
|
|
160
|
-
(0, chai_1.expect)(Object.values(table.rows[1])[5]).to.equal(6);
|
|
161
|
-
});
|
|
162
|
-
it('should handle a date row pivot with a string column pivot', function () {
|
|
163
|
-
const pivot = {
|
|
164
|
-
rowField: 'date',
|
|
165
|
-
rowFieldType: 'date',
|
|
166
|
-
valueField: 'amount',
|
|
167
|
-
aggregationType: 'sum',
|
|
168
|
-
columnField: 'user_name',
|
|
169
|
-
columnFieldType: 'varchar',
|
|
170
|
-
};
|
|
171
|
-
const table = (0, PivotModal_1.generatePivotTable)(pivot, rows, [
|
|
172
|
-
new Date('October 10, 2023 00:00:00'),
|
|
173
|
-
new Date('October 15, 2023 00:00:00'),
|
|
174
|
-
]);
|
|
175
|
-
(0, chai_1.expect)(table.columns.length).to.equal(3);
|
|
176
|
-
(0, chai_1.expect)(table.columns[0].field).to.equal('date');
|
|
177
|
-
(0, chai_1.expect)(table.columns[1].field).to.equal('u1');
|
|
178
|
-
(0, chai_1.expect)(table.columns[2].field).to.equal('u2');
|
|
179
|
-
(0, chai_1.expect)(table.rows.length).to.equal(6);
|
|
180
|
-
// day without transactions
|
|
181
|
-
(0, chai_1.expect)(table.rows[2].u1).to.equal(0);
|
|
182
|
-
(0, chai_1.expect)(table.rows[2].u2).to.equal(0);
|
|
183
|
-
// days with transactions
|
|
184
|
-
(0, chai_1.expect)(table.rows[3].u1).to.equal(9);
|
|
185
|
-
(0, chai_1.expect)(table.rows[3].u2).to.equal(0);
|
|
186
|
-
(0, chai_1.expect)(table.rows[4].u1).to.equal(11);
|
|
187
|
-
(0, chai_1.expect)(table.rows[4].u2).to.equal(6);
|
|
188
|
-
});
|
|
189
|
-
it('should handle a date row pivot with a date column pivot', function () {
|
|
190
|
-
const pivot = {
|
|
191
|
-
columnField: 'date',
|
|
192
|
-
columnFieldType: 'date',
|
|
193
|
-
valueField: 'amount',
|
|
194
|
-
aggregationType: 'count',
|
|
195
|
-
rowField: 'created_at',
|
|
196
|
-
rowFieldType: 'date',
|
|
197
|
-
};
|
|
198
|
-
const table = (0, PivotModal_1.generatePivotTable)(pivot, rows, [
|
|
199
|
-
new Date('October 10, 2023 00:00:00'),
|
|
200
|
-
new Date('October 15, 2023 00:00:00'),
|
|
201
|
-
]);
|
|
202
|
-
console.log(table);
|
|
203
|
-
(0, chai_1.expect)(table.columns.length).to.equal(7);
|
|
204
|
-
(0, chai_1.expect)(table.columns[0].field).to.equal('created_at');
|
|
205
|
-
(0, chai_1.expect)(table.rows.length).to.equal(6);
|
|
206
|
-
(0, chai_1.expect)(Object.values(table.rows[3])[4]).to.equal(1);
|
|
207
|
-
(0, chai_1.expect)(Object.values(table.rows[3])[5]).to.equal(2);
|
|
208
|
-
(0, chai_1.expect)(Object.values(table.rows[4])[4]).to.equal(1);
|
|
209
|
-
(0, chai_1.expect)(Object.values(table.rows[4])[5]).to.equal(1);
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PivotModal.spec.d.ts","sourceRoot":"","sources":["../../../../src/internals/ReportBuilder/PivotModal.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import { generatePivotTable } from './PivotModal';
|
|
4
|
-
import { subMonths } from 'date-fns';
|
|
5
|
-
describe('PivotModal', function () {
|
|
6
|
-
describe('generatePivotTable', function () {
|
|
7
|
-
context('non date pivots', function () {
|
|
8
|
-
const rowPivot = {
|
|
9
|
-
rowField: 'merchant',
|
|
10
|
-
rowFieldType: 'varchar',
|
|
11
|
-
valueField: 'amount',
|
|
12
|
-
aggregationType: 'sum',
|
|
13
|
-
};
|
|
14
|
-
const rowColumnPivot = {
|
|
15
|
-
...rowPivot,
|
|
16
|
-
columnField: 'user_name',
|
|
17
|
-
columnFieldType: 'varchar',
|
|
18
|
-
};
|
|
19
|
-
const rows = [
|
|
20
|
-
{ merchant: 'm1', amount: 3, user_name: 'u1' },
|
|
21
|
-
{ merchant: 'm1', amount: 4, user_name: 'u2' },
|
|
22
|
-
{ merchant: 'm1', amount: 5, user_name: 'u1' },
|
|
23
|
-
{ merchant: 'm2', amount: 6, user_name: 'u1' },
|
|
24
|
-
{ merchant: 'm2', amount: 7, user_name: 'u2' },
|
|
25
|
-
{ merchant: 'm2', amount: 8, user_name: 'u2' },
|
|
26
|
-
];
|
|
27
|
-
it('should return empty table with no data', function () {
|
|
28
|
-
const table = generatePivotTable(rowPivot, [], [new Date(), subMonths(new Date(), 3)]);
|
|
29
|
-
expect(table.columns.length).to.equal(2);
|
|
30
|
-
expect(table.rows.length).to.equal(0);
|
|
31
|
-
});
|
|
32
|
-
it('should combine values based on row pivot', function () {
|
|
33
|
-
const table = generatePivotTable(rowPivot, rows, [
|
|
34
|
-
new Date(),
|
|
35
|
-
subMonths(new Date(), 3),
|
|
36
|
-
]);
|
|
37
|
-
expect(table.columns.length).to.equal(2);
|
|
38
|
-
expect(table.columns[0].field).to.equal('merchant');
|
|
39
|
-
expect(table.columns[1].field).to.equal('amount');
|
|
40
|
-
expect(table.rows.length).to.equal(2);
|
|
41
|
-
expect(table.rows[0].amount).to.equal(12);
|
|
42
|
-
expect(table.rows[1].amount).to.equal(21);
|
|
43
|
-
});
|
|
44
|
-
it('should combine values based on row and column pivots', function () {
|
|
45
|
-
const table = generatePivotTable(rowColumnPivot, rows, [
|
|
46
|
-
new Date(),
|
|
47
|
-
subMonths(new Date(), 3),
|
|
48
|
-
]);
|
|
49
|
-
expect(table.columns.length).to.equal(3);
|
|
50
|
-
expect(table.columns[0].field).to.equal('merchant');
|
|
51
|
-
expect(table.columns[1].field).to.equal('u1');
|
|
52
|
-
expect(table.columns[2].field).to.equal('u2');
|
|
53
|
-
expect(table.rows.length).to.equal(2);
|
|
54
|
-
expect(table.rows[0].u1).to.equal(8);
|
|
55
|
-
expect(table.rows[0].u2).to.equal(4);
|
|
56
|
-
expect(table.rows[1].u1).to.equal(6);
|
|
57
|
-
expect(table.rows[1].u2).to.equal(15);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
context('date pivots', function () {
|
|
61
|
-
const rows = [
|
|
62
|
-
{
|
|
63
|
-
merchant: 'm1',
|
|
64
|
-
amount: 3,
|
|
65
|
-
user_name: 'u1',
|
|
66
|
-
date: new Date('October 13, 2023 11:13:00'),
|
|
67
|
-
created_at: new Date('October 13, 2023 11:13:00'),
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
merchant: 'm1',
|
|
71
|
-
amount: 5,
|
|
72
|
-
user_name: 'u1',
|
|
73
|
-
date: new Date('October 14, 2023 11:13:00'),
|
|
74
|
-
created_at: new Date('October 14, 2023 11:13:00'),
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
merchant: 'm2',
|
|
78
|
-
amount: 6,
|
|
79
|
-
user_name: 'u1',
|
|
80
|
-
date: new Date('October 13, 2023 00:00:00'),
|
|
81
|
-
created_at: new Date('October 14, 2023 11:13:00'),
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
merchant: 'm2',
|
|
85
|
-
amount: 6,
|
|
86
|
-
user_name: 'u1',
|
|
87
|
-
date: new Date('October 14, 2023 23:13:00'),
|
|
88
|
-
created_at: new Date('October 13, 2023 11:13:00'),
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
merchant: 'm1',
|
|
92
|
-
amount: 6,
|
|
93
|
-
user_name: 'u2',
|
|
94
|
-
date: new Date('October 14, 2023 23:13:00'),
|
|
95
|
-
created_at: new Date('October 13, 2023 11:13:00'),
|
|
96
|
-
},
|
|
97
|
-
];
|
|
98
|
-
it('should handle a row date pivot', function () {
|
|
99
|
-
const pivot = {
|
|
100
|
-
rowField: 'date',
|
|
101
|
-
rowFieldType: 'date',
|
|
102
|
-
valueField: 'amount',
|
|
103
|
-
aggregationType: 'sum',
|
|
104
|
-
};
|
|
105
|
-
const table = generatePivotTable(pivot, rows, [
|
|
106
|
-
new Date('October 10, 2023 00:00:00'),
|
|
107
|
-
new Date('October 15, 2023 00:00:00'),
|
|
108
|
-
]);
|
|
109
|
-
expect(table.columns.length).to.equal(2);
|
|
110
|
-
expect(table.columns[0].field).to.equal('date');
|
|
111
|
-
expect(table.columns[1].field).to.equal('amount');
|
|
112
|
-
expect(table.rows.length).to.equal(6);
|
|
113
|
-
expect(table.rows[3].amount).to.equal(9);
|
|
114
|
-
expect(table.rows[4].amount).to.equal(17);
|
|
115
|
-
expect(table.rows[5].amount).to.equal(0);
|
|
116
|
-
});
|
|
117
|
-
it('should handle a row timestamp pivot', function () {
|
|
118
|
-
const pivot = {
|
|
119
|
-
rowField: 'date',
|
|
120
|
-
rowFieldType: 'timestamp',
|
|
121
|
-
valueField: 'amount',
|
|
122
|
-
aggregationType: 'sum',
|
|
123
|
-
};
|
|
124
|
-
const table = generatePivotTable(pivot, rows, [
|
|
125
|
-
new Date('October 10, 2023 00:00:00').getTime(),
|
|
126
|
-
new Date('October 15, 2023 00:00:00').getTime(),
|
|
127
|
-
]);
|
|
128
|
-
expect(table.columns.length).to.equal(2);
|
|
129
|
-
expect(table.columns[0].field).to.equal('date');
|
|
130
|
-
expect(table.columns[1].field).to.equal('amount');
|
|
131
|
-
expect(table.rows.length).to.equal(6);
|
|
132
|
-
expect(table.rows[3].amount).to.equal(9);
|
|
133
|
-
expect(table.rows[4].amount).to.equal(17);
|
|
134
|
-
expect(table.rows[5].amount).to.equal(0);
|
|
135
|
-
});
|
|
136
|
-
it('should handle a string row pivot with a date column pivot', function () {
|
|
137
|
-
const pivot = {
|
|
138
|
-
columnField: 'date',
|
|
139
|
-
columnFieldType: 'date',
|
|
140
|
-
valueField: 'amount',
|
|
141
|
-
aggregationType: 'sum',
|
|
142
|
-
rowField: 'user_name',
|
|
143
|
-
rowFieldType: 'varchar',
|
|
144
|
-
};
|
|
145
|
-
const table = generatePivotTable(pivot, rows, [
|
|
146
|
-
new Date('October 10, 2023 00:00:00'),
|
|
147
|
-
new Date('October 15, 2023 00:00:00'),
|
|
148
|
-
]);
|
|
149
|
-
expect(table.columns.length).to.equal(7);
|
|
150
|
-
expect(table.columns[0].field).to.equal('user_name');
|
|
151
|
-
expect(table.rows.length).to.equal(2);
|
|
152
|
-
// u1
|
|
153
|
-
expect(table.rows[0].user_name).to.equal('u1');
|
|
154
|
-
expect(Object.values(table.rows[0])[4]).to.equal(9);
|
|
155
|
-
expect(Object.values(table.rows[0])[5]).to.equal(11);
|
|
156
|
-
// u2
|
|
157
|
-
expect(table.rows[1].user_name).to.equal('u2');
|
|
158
|
-
expect(Object.values(table.rows[1])[5]).to.equal(6);
|
|
159
|
-
});
|
|
160
|
-
it('should handle a date row pivot with a string column pivot', function () {
|
|
161
|
-
const pivot = {
|
|
162
|
-
rowField: 'date',
|
|
163
|
-
rowFieldType: 'date',
|
|
164
|
-
valueField: 'amount',
|
|
165
|
-
aggregationType: 'sum',
|
|
166
|
-
columnField: 'user_name',
|
|
167
|
-
columnFieldType: 'varchar',
|
|
168
|
-
};
|
|
169
|
-
const table = generatePivotTable(pivot, rows, [
|
|
170
|
-
new Date('October 10, 2023 00:00:00'),
|
|
171
|
-
new Date('October 15, 2023 00:00:00'),
|
|
172
|
-
]);
|
|
173
|
-
expect(table.columns.length).to.equal(3);
|
|
174
|
-
expect(table.columns[0].field).to.equal('date');
|
|
175
|
-
expect(table.columns[1].field).to.equal('u1');
|
|
176
|
-
expect(table.columns[2].field).to.equal('u2');
|
|
177
|
-
expect(table.rows.length).to.equal(6);
|
|
178
|
-
// day without transactions
|
|
179
|
-
expect(table.rows[2].u1).to.equal(0);
|
|
180
|
-
expect(table.rows[2].u2).to.equal(0);
|
|
181
|
-
// days with transactions
|
|
182
|
-
expect(table.rows[3].u1).to.equal(9);
|
|
183
|
-
expect(table.rows[3].u2).to.equal(0);
|
|
184
|
-
expect(table.rows[4].u1).to.equal(11);
|
|
185
|
-
expect(table.rows[4].u2).to.equal(6);
|
|
186
|
-
});
|
|
187
|
-
it('should handle a date row pivot with a date column pivot', function () {
|
|
188
|
-
const pivot = {
|
|
189
|
-
columnField: 'date',
|
|
190
|
-
columnFieldType: 'date',
|
|
191
|
-
valueField: 'amount',
|
|
192
|
-
aggregationType: 'count',
|
|
193
|
-
rowField: 'created_at',
|
|
194
|
-
rowFieldType: 'date',
|
|
195
|
-
};
|
|
196
|
-
const table = generatePivotTable(pivot, rows, [
|
|
197
|
-
new Date('October 10, 2023 00:00:00'),
|
|
198
|
-
new Date('October 15, 2023 00:00:00'),
|
|
199
|
-
]);
|
|
200
|
-
console.log(table);
|
|
201
|
-
expect(table.columns.length).to.equal(7);
|
|
202
|
-
expect(table.columns[0].field).to.equal('created_at');
|
|
203
|
-
expect(table.rows.length).to.equal(6);
|
|
204
|
-
expect(Object.values(table.rows[3])[4]).to.equal(1);
|
|
205
|
-
expect(Object.values(table.rows[3])[5]).to.equal(2);
|
|
206
|
-
expect(Object.values(table.rows[4])[4]).to.equal(1);
|
|
207
|
-
expect(Object.values(table.rows[4])[5]).to.equal(1);
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
});
|