only allow sorting by date and number fields (#128111)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Andrew Tate 2022-03-21 08:10:51 -05:00 committed by GitHub
parent de02c2da65
commit ee4f521b43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 2 deletions

View file

@ -474,7 +474,28 @@ describe('isSortableByColumn()', () => {
).toBeFalsy();
});
it('SHOULD be sortable when NOT using top-hit agg', () => {
it('should NOT be sortable when NOT using date or number source field', () => {
expect(
isSortableByColumn(
getLayer(getStringBasedOperationColumn(), [
{
label: 'Last Value',
dataType: 'string',
isBucketed: false,
sourceField: 'some_string_field',
operationType: 'last_value',
params: {
sortField: 'time',
showArrayValues: false,
},
} as GenericIndexPatternColumn,
]),
'col2'
)
).toBeFalsy();
});
it('SHOULD be sortable when NOT using top-hit agg and source field is date or number', () => {
expect(
isSortableByColumn(
getLayer(getStringBasedOperationColumn(), [
@ -493,6 +514,25 @@ describe('isSortableByColumn()', () => {
'col2'
)
).toBeTruthy();
expect(
isSortableByColumn(
getLayer(getStringBasedOperationColumn(), [
{
label: 'Last Value',
dataType: 'date',
isBucketed: false,
sourceField: 'order_date',
operationType: 'last_value',
params: {
sortField: 'time',
showArrayValues: false,
},
} as GenericIndexPatternColumn,
]),
'col2'
)
).toBeTruthy();
});
});
});

View file

@ -208,7 +208,8 @@ export function getDisallowedTermsMessage(
function checkLastValue(column: GenericIndexPatternColumn) {
return (
column.operationType !== 'last_value' ||
!(column as LastValueIndexPatternColumn).params.showArrayValues
(['number', 'date'].includes(column.dataType) &&
!(column as LastValueIndexPatternColumn).params.showArrayValues)
);
}