Skip to content

Commit 30f430c

Browse files
authored
[backport v2.12.3] Table Sort Improvements (#15508)
* Sort Improvements + Fix Events SSP sort - Apply SSP sort order with generic `:desc` notation, - Allow headers to provide default sort order - Ensure SSP first seen and last seen column sorts behave the same * fix l10n --------- Co-authored-by: Richard Cox <[email protected]>
2 parents ecbfe13 + 7ae8aee commit 30f430c

File tree

10 files changed

+51
-16
lines changed

10 files changed

+51
-16
lines changed

shell/assets/translations/en-us.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6484,6 +6484,7 @@ tableHeaders:
64846484
endpoints: Endpoints
64856485
expires: Expires
64866486
firstSeen: First Seen
6487+
firstSeenTooltip: The time at which the event was first recorded
64876488
flow: Flow
64886489
fingerprint: Fingerprint
64896490
gitRepos: Git Repos

shell/components/SortableTable/sorting.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export default {
6868

6969
data() {
7070
let sortBy = null;
71+
let descending = false;
7172

7273
this._defaultSortBy = this.defaultSortBy;
7374

@@ -78,6 +79,7 @@ export default {
7879

7980
if ( markedColumn ) {
8081
this._defaultSortBy = markedColumn.name;
82+
descending = markedColumn.defaultSortDescending;
8183
} else if ( nameColumn ) {
8284
// Use the name column if there is one
8385
this._defaultSortBy = nameColumn.name;
@@ -101,7 +103,7 @@ export default {
101103

102104
return {
103105
sortBy,
104-
descending: false,
106+
descending,
105107
cachedRows: null,
106108
cacheKey: null,
107109
};

shell/components/form/ResourceTabs/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import RelatedResources from '@shell/components/RelatedResources';
1414
import { isConditionReadyAndWaiting } from '@shell/plugins/dashboard-store/resource-class';
1515
import { PaginationParamFilter } from '@shell/types/store/pagination.types';
1616
import { MESSAGE, REASON } from '@shell/config/table-headers';
17-
import { STEVE_EVENT_LAST_SEEN, STEVE_EVENT_TYPE, STEVE_NAME_COL } from '@shell/config/pagination-table-headers';
17+
import { STEVE_EVENT_FIRST_SEEN, STEVE_EVENT_LAST_SEEN, STEVE_EVENT_TYPE, STEVE_NAME_COL } from '@shell/config/pagination-table-headers';
1818
import { headerFromSchemaColString } from '@shell/store/type-map.utils';
1919
2020
export default {
@@ -86,7 +86,7 @@ export default {
8686
headerFromSchemaColString('Subobject', eventSchema, this.$store.getters, true),
8787
headerFromSchemaColString('Source', eventSchema, this.$store.getters, true),
8888
MESSAGE,
89-
headerFromSchemaColString('First Seen', eventSchema, this.$store.getters, true),
89+
STEVE_EVENT_FIRST_SEEN,
9090
headerFromSchemaColString('Count', eventSchema, this.$store.getters, true),
9191
STEVE_NAME_COL,
9292
] : [];

shell/config/pagination-table-headers.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
STATE, NAME as NAME_COL, NAMESPACE as NAMESPACE_COL, AGE, OBJECT,
44
EVENT_LAST_SEEN_TIME,
55
EVENT_TYPE,
6-
SECRET_CLONE
6+
SECRET_CLONE,
7+
EVENT_FIRST_SEEN_TIME
78
} from '@shell/config/table-headers';
89

910
// This file contains table headers
@@ -56,10 +57,17 @@ export const STEVE_EVENT_OBJECT = {
5657
search: 'involvedObject.kind',
5758
};
5859

60+
export const STEVE_EVENT_FIRST_SEEN = {
61+
...EVENT_FIRST_SEEN_TIME,
62+
63+
value: 'metadata.fields.7',
64+
sort: 'metadata.fields.7:desc',
65+
};
66+
5967
export const STEVE_EVENT_LAST_SEEN = {
6068
...EVENT_LAST_SEEN_TIME,
6169
value: 'metadata.fields.0',
62-
sort: 'metadata.fields.0',
70+
sort: 'metadata.fields.0:desc',
6371
};
6472

6573
export const STEVE_EVENT_TYPE = {

shell/config/product/explorer.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ import {
2222
ACCESS_KEY, DESCRIPTION, EXPIRES, EXPIRY_STATE, LAST_USED, SUB_TYPE, AGE_NORMAN, SCOPE_NORMAN, PERSISTENT_VOLUME_CLAIM, RECLAIM_POLICY, PV_REASON, WORKLOAD_HEALTH_SCALE, POD_RESTARTS,
2323
DURATION, MESSAGE, REASON, EVENT_TYPE, OBJECT, ROLE, ROLES, VERSION, INTERNAL_EXTERNAL_IP, KUBE_NODE_OS, CPU, RAM, SECRET_DATA,
2424
EVENT_LAST_SEEN_TIME,
25+
EVENT_FIRST_SEEN_TIME,
2526
} from '@shell/config/table-headers';
2627

2728
import { DSL } from '@shell/store/type-map';
2829
import {
29-
STEVE_AGE_COL, STEVE_EVENT_LAST_SEEN, STEVE_EVENT_OBJECT, STEVE_EVENT_TYPE, STEVE_LIST_GROUPS, STEVE_NAMESPACE_COL, STEVE_NAME_COL, STEVE_STATE_COL
30+
STEVE_AGE_COL, STEVE_EVENT_FIRST_SEEN, STEVE_EVENT_LAST_SEEN, STEVE_EVENT_OBJECT, STEVE_EVENT_TYPE, STEVE_LIST_GROUPS, STEVE_NAMESPACE_COL, STEVE_NAME_COL, STEVE_STATE_COL
3031
} from '@shell/config/pagination-table-headers';
3132

3233
import { COLUMN_BREAKPOINTS } from '@shell/types/store/type-map';
@@ -337,7 +338,7 @@ export function init(store) {
337338
);
338339

339340
headers(EVENT,
340-
[STATE, EVENT_LAST_SEEN_TIME, EVENT_TYPE, REASON, OBJECT, 'Subobject', 'Source', MESSAGE, 'First Seen', 'Count', NAME_COL, NAMESPACE_COL],
341+
[STATE, EVENT_LAST_SEEN_TIME, EVENT_TYPE, REASON, OBJECT, 'Subobject', 'Source', MESSAGE, EVENT_FIRST_SEEN_TIME, 'Count', NAME_COL, NAMESPACE_COL],
341342
[
342343
STEVE_STATE_COL,
343344
STEVE_EVENT_LAST_SEEN,
@@ -347,7 +348,7 @@ export function init(store) {
347348
'Subobject',
348349
'Source',
349350
MESSAGE,
350-
'First Seen',
351+
STEVE_EVENT_FIRST_SEEN,
351352
'Count',
352353
STEVE_NAME_COL,
353354
STEVE_NAMESPACE_COL,

shell/config/table-headers.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,15 @@ export const LAST_SEEN_TIME = {
541541
tooltip: 'tableHeaders.lastSeenTooltip'
542542
};
543543

544+
export const EVENT_FIRST_SEEN_TIME = {
545+
name: 'firstSeen',
546+
labelKey: 'tableHeaders.firstSeen',
547+
tooltip: 'tableHeaders.firstSeenTooltip',
548+
549+
value: 'firstSeen',
550+
sort: 'firstSeen:desc',
551+
};
552+
544553
export const EVENT_LAST_SEEN_TIME = {
545554
...LAST_SEEN_TIME,
546555
defaultSort: true,

shell/models/event.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ export default class K8sEvent extends SteveModel {
2525
return this._type;
2626
}
2727

28+
get firstSeen() {
29+
const schema = this.$getters['schemaFor'](this.type);
30+
const rowValueGetter = this.$rootGetters['type-map/rowValueGetter'];
31+
32+
return schema && rowValueGetter ? rowValueGetter(schema, 'First Seen')(this) : null;
33+
}
34+
2835
get lastSeen() {
2936
const schema = this.$getters['schemaFor'](this.type);
3037
const rowValueGetter = this.$rootGetters['type-map/rowValueGetter'];

shell/pages/c/_cluster/explorer/EventsTable.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { MESSAGE, NAME, OBJECT, REASON } from '@shell/config/table-headers';
44
import { EVENT } from '@shell/config/types';
55
import PaginatedResourceTable from '@shell/components/PaginatedResourceTable';
6-
import { STEVE_EVENT_OBJECT, STEVE_NAME_COL } from '@shell/config/pagination-table-headers';
6+
import { STEVE_EVENT_FIRST_SEEN, STEVE_EVENT_LAST_SEEN, STEVE_EVENT_OBJECT, STEVE_NAME_COL } from '@shell/config/pagination-table-headers';
77
import { headerFromSchemaColString } from '@shell/store/type-map.utils';
88
import { NAME as EXPLORER } from '@shell/config/product/explorer';
99
@@ -59,11 +59,8 @@ export default {
5959
...STEVE_NAME_COL,
6060
defaultSort: false,
6161
},
62-
headerFromSchemaColString('First Seen', schema, this.$store.getters, true),
63-
{
64-
...headerFromSchemaColString('Last Seen', schema, this.$store.getters, true),
65-
defaultSort: true,
66-
},
62+
STEVE_EVENT_FIRST_SEEN,
63+
STEVE_EVENT_LAST_SEEN,
6764
headerFromSchemaColString('Count', schema, this.$store.getters, true),
6865
] : [];
6966

shell/plugins/steve/steve-pagination-utils.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { Schema } from '@shell/plugins/steve/schema';
2222
import { PaginationSettingsStore } from '@shell/types/resources/settings';
2323
import paginationUtils from '@shell/utils/pagination-utils';
2424
import { KubeLabelSelector, KubeLabelSelectorExpression } from '@shell/types/kube/kube-api';
25+
import { parseField } from '@shell/utils/sort';
2526

2627
/**
2728
* This is a workaround for a ts build issue found in check-plugins-build.
@@ -409,9 +410,13 @@ class StevePaginationUtils extends NamespaceProjectFilters {
409410

410411
const joined = opt.pagination.sort
411412
.map((s) => {
412-
this.validateField(validateFields, schema, s.field);
413+
// Use the same mechanism as local sorting to flip logic for asc/des
414+
const { field, reverse } = parseField(s.field);
415+
const asc = reverse ? !s.asc : s.asc;
413416

414-
return `${ s.asc ? '' : '-' }${ this.convertArrayPath(s.field) }`;
417+
this.validateField(validateFields, schema, field);
418+
419+
return `${ asc ? '' : '-' }${ this.convertArrayPath(field) }`;
415420
})
416421
.join(',');
417422

shell/utils/sort.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ export function compare(a, b) {
169169
return 0;
170170
}
171171

172+
/**
173+
* Should the logic of this sort field be flipped?
174+
*
175+
* For instance show descending but sort by ascending
176+
*/
172177
export function parseField(str) {
173178
const parts = str.split(/:/);
174179

0 commit comments

Comments
 (0)