-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Anomaly swim lane: Fix disappearing rows per page button (#194531)
## Summary Fix for: [#194027](#194027). Fixed issue with disappearing `rows per page` button. Enhanced the logic to display only relevant pagination options, showing the first larger option, which works like 'show all'. * For example, if there are 23 results, the available `rows per page` options will be: `5,10,20,50`. https://github.com/user-attachments/assets/29c3f0db-84b8-4a0c-b4b5-a722cfc490c4
- Loading branch information
Showing
4 changed files
with
77 additions
and
24 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
x-pack/plugins/ml/public/application/explorer/calculate_row_options.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { calculateRowOptions } from './calculate_row_options'; | ||
|
||
describe('calculateRowOptions', () => { | ||
it('should return all options when cardinality is greater than all row options', () => { | ||
const rowOptions = [5, 10, 20, 50, 100]; | ||
const cardinality = 150; | ||
expect(calculateRowOptions(rowOptions, cardinality)).toEqual([5, 10, 20, 50, 100]); | ||
}); | ||
|
||
it('should return options up to and including cardinality', () => { | ||
const rowOptions = [5, 10, 20, 50, 100]; | ||
const cardinality = 30; | ||
expect(calculateRowOptions(rowOptions, cardinality)).toEqual([5, 10, 20, 50]); | ||
}); | ||
|
||
it('should return at least one option even if cardinality is less than all options', () => { | ||
const rowOptions = [5, 10, 20, 50, 100]; | ||
const cardinality = 3; | ||
expect(calculateRowOptions(rowOptions, cardinality)).toEqual([5]); | ||
}); | ||
|
||
it('should handle cardinality of zero', () => { | ||
const rowOptions = [5, 10, 20, 50, 100]; | ||
const cardinality = 0; | ||
expect(calculateRowOptions(rowOptions, cardinality)).toEqual([5]); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
x-pack/plugins/ml/public/application/explorer/calculate_row_options.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export const calculateRowOptions = (rowOptions: number[], cardinality: number): number[] => { | ||
return rowOptions.reduce((acc, v) => { | ||
if (v <= cardinality) { | ||
acc.push(v); | ||
} else if (acc.length === 0 || acc[acc.length - 1] < cardinality) { | ||
acc.push(v); | ||
} | ||
return acc; | ||
}, [] as number[]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters