mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-03-16 21:43:34 +00:00
Fix earliest and latest date aggregations
This commit is contained in:
parent
8219a4a641
commit
508ac133b0
4 changed files with 202 additions and 11 deletions
|
@ -340,6 +340,7 @@
|
|||
* Book Catalog
|
||||
* Applicant Tracker
|
||||
* Project Tracker
|
||||
* Fixed earliest and latest date aggregations
|
||||
|
||||
## Released (2021-07-16)
|
||||
|
||||
|
|
|
@ -89,10 +89,6 @@ export default {
|
|||
if (this.fieldAggregationData[this.field.id] !== undefined) {
|
||||
const { value } = this.fieldAggregationData[this.field.id]
|
||||
|
||||
if (isNaN(value)) {
|
||||
return null
|
||||
}
|
||||
|
||||
return this.viewAggregationType.getValue(value, {
|
||||
rowCount: this.rowCount,
|
||||
field: this.field,
|
||||
|
|
|
@ -84,6 +84,9 @@ export class ViewAggregationType extends Registerable {
|
|||
* @returns the final aggregation value for this type.
|
||||
*/
|
||||
getValue(value, context) {
|
||||
if (isNaN(value)) {
|
||||
return null
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
|
@ -230,7 +233,7 @@ export class CheckedCountViewAggregationType extends ViewAggregationType {
|
|||
}
|
||||
|
||||
getValue(value, { rowCount }) {
|
||||
if (rowCount === 0) {
|
||||
if (rowCount === 0 || isNaN(value)) {
|
||||
return null
|
||||
}
|
||||
return rowCount - value
|
||||
|
@ -285,7 +288,7 @@ export class EmptyPercentageViewAggregationType extends ViewAggregationType {
|
|||
}
|
||||
|
||||
getValue(value, { rowCount }) {
|
||||
if (rowCount === 0) {
|
||||
if (rowCount === 0 || isNaN(value)) {
|
||||
return null
|
||||
}
|
||||
return `${Math.round((value / rowCount) * 100)}%`
|
||||
|
@ -340,7 +343,7 @@ export class NotEmptyPercentageViewAggregationType extends ViewAggregationType {
|
|||
}
|
||||
|
||||
getValue(value, { rowCount }) {
|
||||
if (rowCount === 0) {
|
||||
if (rowCount === 0 || isNaN(value)) {
|
||||
return null
|
||||
}
|
||||
return `${Math.round(((rowCount - value) / rowCount) * 100)}%`
|
||||
|
@ -375,7 +378,7 @@ export class NotCheckedPercentageViewAggregationType extends ViewAggregationType
|
|||
}
|
||||
|
||||
getValue(value, { rowCount }) {
|
||||
if (rowCount === 0) {
|
||||
if (rowCount === 0 || isNaN(value)) {
|
||||
return null
|
||||
}
|
||||
return `${Math.round((value / rowCount) * 100)}%`
|
||||
|
@ -410,7 +413,7 @@ export class CheckedPercentageViewAggregationType extends ViewAggregationType {
|
|||
}
|
||||
|
||||
getValue(value, { rowCount }) {
|
||||
if (rowCount === 0) {
|
||||
if (rowCount === 0 || isNaN(value)) {
|
||||
return null
|
||||
}
|
||||
return `${Math.round(((rowCount - value) / rowCount) * 100)}%`
|
||||
|
@ -530,6 +533,9 @@ export class EarliestDateViewAggregationType extends ViewAggregationType {
|
|||
}
|
||||
|
||||
getValue(value, { field, fieldType }) {
|
||||
if (!(typeof value === 'string')) {
|
||||
return null
|
||||
}
|
||||
return fieldType.toHumanReadableString(field, value)
|
||||
}
|
||||
|
||||
|
@ -567,6 +573,9 @@ export class LatestDateViewAggregationType extends ViewAggregationType {
|
|||
}
|
||||
|
||||
getValue(value, { field, fieldType }) {
|
||||
if (!(typeof value === 'string')) {
|
||||
return null
|
||||
}
|
||||
return fieldType.toHumanReadableString(field, value)
|
||||
}
|
||||
|
||||
|
@ -616,6 +625,9 @@ export class AverageViewAggregationType extends ViewAggregationType {
|
|||
}
|
||||
|
||||
getValue(value, { field, fieldType }) {
|
||||
if (isNaN(value)) {
|
||||
return null
|
||||
}
|
||||
if (fieldType.getType() === 'number') {
|
||||
return NumberFieldType.formatNumber(field, value)
|
||||
} else {
|
||||
|
@ -652,6 +664,9 @@ export class StdDevViewAggregationType extends ViewAggregationType {
|
|||
}
|
||||
|
||||
getValue(value, { field, fieldType }) {
|
||||
if (isNaN(value)) {
|
||||
return null
|
||||
}
|
||||
if (fieldType.getType() === 'number') {
|
||||
return NumberFieldType.formatNumber(field, value)
|
||||
} else {
|
||||
|
@ -683,6 +698,9 @@ export class VarianceViewAggregationType extends ViewAggregationType {
|
|||
}
|
||||
|
||||
getValue(value, { field, fieldType }) {
|
||||
if (isNaN(value)) {
|
||||
return null
|
||||
}
|
||||
if (fieldType.getType() === 'number') {
|
||||
return NumberFieldType.formatNumber(field, value)
|
||||
} else {
|
||||
|
|
|
@ -57,7 +57,7 @@ const testData = {
|
|||
context: { rowCount: 100 },
|
||||
},
|
||||
max_date: {
|
||||
inputValue: new Date(2018, 11, 24, 10, 33, 30, 0),
|
||||
inputValue: new Date(2018, 11, 24, 10, 33, 30, 0).toISOString(),
|
||||
expectedResult: '24/12/2018',
|
||||
context: {
|
||||
rowCount: 100,
|
||||
|
@ -70,7 +70,7 @@ const testData = {
|
|||
},
|
||||
},
|
||||
min_date: {
|
||||
inputValue: new Date(2018, 11, 24, 10, 33, 30, 0),
|
||||
inputValue: new Date(2018, 11, 24, 10, 33, 30, 0).toISOString(),
|
||||
expectedResult: '24/12/2018',
|
||||
context: {
|
||||
rowCount: 100,
|
||||
|
@ -193,6 +193,164 @@ const testData = {
|
|||
],
|
||||
}
|
||||
|
||||
const testDataError = {
|
||||
empty_count: {
|
||||
inputValue: 'test',
|
||||
expectedResult: null,
|
||||
context: {},
|
||||
},
|
||||
checked_count: {
|
||||
inputValue: undefined,
|
||||
expectedResult: null,
|
||||
context: { rowCount: 100 },
|
||||
},
|
||||
min: {
|
||||
inputValue: null,
|
||||
expectedResult: null,
|
||||
context: { rowCount: 100 },
|
||||
},
|
||||
max: {
|
||||
inputValue: null,
|
||||
expectedResult: null,
|
||||
context: { rowCount: 100 },
|
||||
},
|
||||
max_date: {
|
||||
inputValue: 0,
|
||||
expectedResult: null,
|
||||
context: {
|
||||
rowCount: 100,
|
||||
field: {
|
||||
timezone: 'Europe/London',
|
||||
date_format: 'EU',
|
||||
date_include_time: false,
|
||||
},
|
||||
fieldType: new DateFieldType(),
|
||||
},
|
||||
},
|
||||
min_date: {
|
||||
inputValue: 0,
|
||||
expectedResult: null,
|
||||
context: {
|
||||
rowCount: 100,
|
||||
field: {
|
||||
timezone: 'Europe/London',
|
||||
date_format: 'EU',
|
||||
date_include_time: false,
|
||||
},
|
||||
fieldType: new DateFieldType(),
|
||||
},
|
||||
},
|
||||
sum: {
|
||||
inputValue: null,
|
||||
expectedResult: null,
|
||||
context: { rowCount: 100 },
|
||||
},
|
||||
average: [
|
||||
{
|
||||
inputValue: null,
|
||||
expectedResult: null,
|
||||
context: {
|
||||
rowCount: 100,
|
||||
field: {
|
||||
type: 'number',
|
||||
number_type: 'DECIMAL',
|
||||
number_decimal_places: 3,
|
||||
},
|
||||
fieldType: new NumberFieldType(),
|
||||
},
|
||||
},
|
||||
{
|
||||
inputValue: null,
|
||||
expectedResult: null,
|
||||
context: {
|
||||
rowCount: 100,
|
||||
field: {
|
||||
type: 'rating',
|
||||
},
|
||||
fieldType: new RatingFieldType(),
|
||||
},
|
||||
},
|
||||
],
|
||||
std_dev: [
|
||||
{
|
||||
inputValue: null,
|
||||
expectedResult: null,
|
||||
context: {
|
||||
rowCount: 100,
|
||||
field: {
|
||||
type: 'number',
|
||||
number_type: 'DECIMAL',
|
||||
number_decimal_places: 3,
|
||||
},
|
||||
fieldType: new NumberFieldType(),
|
||||
},
|
||||
},
|
||||
{
|
||||
inputValue: null,
|
||||
expectedResult: null,
|
||||
context: {
|
||||
rowCount: 100,
|
||||
field: {
|
||||
type: 'rating',
|
||||
},
|
||||
fieldType: new RatingFieldType(),
|
||||
},
|
||||
},
|
||||
],
|
||||
variance: [
|
||||
{
|
||||
inputValue: null,
|
||||
expectedResult: null,
|
||||
context: {
|
||||
rowCount: 100,
|
||||
field: {
|
||||
type: 'number',
|
||||
number_type: 'DECIMAL',
|
||||
number_decimal_places: 3,
|
||||
},
|
||||
fieldType: new NumberFieldType(),
|
||||
},
|
||||
},
|
||||
{
|
||||
inputValue: null,
|
||||
expectedResult: null,
|
||||
context: {
|
||||
rowCount: 100,
|
||||
field: {
|
||||
type: 'rating',
|
||||
},
|
||||
fieldType: new RatingFieldType(),
|
||||
},
|
||||
},
|
||||
],
|
||||
unique: [
|
||||
{
|
||||
inputValue: null,
|
||||
expectedResult: null,
|
||||
context: {
|
||||
rowCount: 100,
|
||||
field: {
|
||||
type: 'number',
|
||||
number_type: 'DECIMAL',
|
||||
number_decimal_places: 3,
|
||||
},
|
||||
fieldType: new NumberFieldType(),
|
||||
},
|
||||
},
|
||||
{
|
||||
inputValue: null,
|
||||
expectedResult: null,
|
||||
context: {
|
||||
rowCount: 100,
|
||||
field: {
|
||||
type: 'rating',
|
||||
},
|
||||
fieldType: new RatingFieldType(),
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
describe('View Aggregation Tests', () => {
|
||||
let testApp = null
|
||||
let store = null
|
||||
|
@ -223,4 +381,22 @@ describe('View Aggregation Tests', () => {
|
|||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('Test field empty value', () => {
|
||||
store.$registry
|
||||
.getOrderedList('viewAggregation')
|
||||
.forEach((aggregationType) => {
|
||||
// Get test data for this aggregation type
|
||||
let dataset = testDataError[aggregationType.getType()]
|
||||
if (dataset) {
|
||||
if (!Array.isArray(dataset)) {
|
||||
dataset = [dataset]
|
||||
}
|
||||
dataset.forEach(({ inputValue, expectedResult, context }) => {
|
||||
const actualResult = aggregationType.getValue(inputValue, context)
|
||||
expect(actualResult).toEqual(expectedResult)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue