[8.6] [DataViews] Fix data views sorting (#145873) (#146016)

# Backport

This will backport the following commits from `main` to `8.6`:
- [[DataViews] Fix data views sorting
(#145873)](https://github.com/elastic/kibana/pull/145873)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Julia
Rechkunova","email":"julia.rechkunova@elastic.co"},"sourceCommit":{"committedDate":"2022-11-22T16:09:30Z","message":"[DataViews]
Fix data views sorting (#145873)\n\nCloses
https://github.com/elastic/kibana/issues/143817\r\n\r\n##
Summary\r\n\r\nThis PR fixes default data views sorting by considering
also a custom\r\ndata view name.\r\n\r\n<img width=\"732\"
alt=\"Screenshot 2022-11-21 at 15 49
35\"\r\nsrc=\"https://user-images.githubusercontent.com/1415710/203086357-a3aec8a8-f20e-4529-8310-6f3c155bec1e.png\">","sha":"4f7d12c2c1e1186ac513ab9d18d264ba9f2fe304","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:DataDiscovery","backport:prev-minor","v8.7.0"],"number":145873,"url":"https://github.com/elastic/kibana/pull/145873","mergeCommit":{"message":"[DataViews]
Fix data views sorting (#145873)\n\nCloses
https://github.com/elastic/kibana/issues/143817\r\n\r\n##
Summary\r\n\r\nThis PR fixes default data views sorting by considering
also a custom\r\ndata view name.\r\n\r\n<img width=\"732\"
alt=\"Screenshot 2022-11-21 at 15 49
35\"\r\nsrc=\"https://user-images.githubusercontent.com/1415710/203086357-a3aec8a8-f20e-4529-8310-6f3c155bec1e.png\">","sha":"4f7d12c2c1e1186ac513ab9d18d264ba9f2fe304"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/145873","number":145873,"mergeCommit":{"message":"[DataViews]
Fix data views sorting (#145873)\n\nCloses
https://github.com/elastic/kibana/issues/143817\r\n\r\n##
Summary\r\n\r\nThis PR fixes default data views sorting by considering
also a custom\r\ndata view name.\r\n\r\n<img width=\"732\"
alt=\"Screenshot 2022-11-21 at 15 49
35\"\r\nsrc=\"https://user-images.githubusercontent.com/1415710/203086357-a3aec8a8-f20e-4529-8310-6f3c155bec1e.png\">","sha":"4f7d12c2c1e1186ac513ab9d18d264ba9f2fe304"}}]}]
BACKPORT-->

Co-authored-by: Julia Rechkunova <julia.rechkunova@elastic.co>
This commit is contained in:
Kibana Machine 2022-11-22 14:13:13 -05:00 committed by GitHub
parent 010bb24b87
commit e7c1a9b857
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -23,7 +23,7 @@ Array [
"id": "test1",
"name": "Test Name 1",
"namespaces": undefined,
"sort": "1test name 1",
"sort": "1Test Name 1",
"tags": Array [],
"title": "test name 1",
},

View file

@ -38,6 +38,7 @@ export async function getIndexPatterns(defaultIndex: string, dataViewsService: D
const { id, title, namespaces, name } = idxPattern;
const isDefault = defaultIndex === id;
const tags = getTags(idxPattern, isDefault);
const displayName = name ? name : title;
return {
id,
@ -48,9 +49,9 @@ export async function getIndexPatterns(defaultIndex: string, dataViewsService: D
tags,
// the prepending of 0 at the default pattern takes care of prioritization
// so the sorting will but the default index on top
// or on bottom of a the table
sort: `${isDefault ? '0' : '1'}${title}`,
getName: () => (name ? name : title),
// or on bottom of the table
sort: `${isDefault ? '0' : '1'}${displayName}`,
getName: () => displayName,
};
});