-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Discover] Remove error when a user without default index patterns accesses #47705
Closed
kertal
wants to merge
12
commits into
elastic:master
from
kertal:kertal-pr-2019-10-09-discover-readonly-error
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6e45a31
Refactor defaultIndex logic
kertal 431b2bd
Take care of case when no index patterns are available
kertal 47854b9
Merge remote-tracking branch 'upstream/master' into kertal-pr-2019-10…
kertal af36902
Improve logic
kertal 60e3557
Merge branch 'master' into kertal-pr-2019-10-09-discover-readonly-error
elasticmachine aff471d
Consider condition when the configured defaultIndex is wrong
kertal c926c7e
Merge branch 'master' into kertal-pr-2019-10-09-discover-readonly-error
elasticmachine 941b970
Refactor functionionality to seperate file
kertal cf181f7
Merge branch 'kertal-pr-2019-10-09-discover-readonly-error' of github…
kertal b04b503
Merge remote-tracking branch 'upstream/master' into kertal-pr-2019-10…
kertal b446b92
Fix naming indexpatterns collision
kertal d740444
Fix types
kertal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
60 changes: 60 additions & 0 deletions
60
src/legacy/core_plugins/kibana/public/discover/helpers/get_index_pattern_id.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,60 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { IndexPattern } from '../../../../data/public/index_patterns'; | ||
|
||
export function findIndexPatternById( | ||
indexPatterns: IndexPattern[], | ||
id: string | ||
): IndexPattern | undefined { | ||
if (!Array.isArray(indexPatterns) || !id) { | ||
return; | ||
} | ||
return indexPatterns.find(o => o.id === id); | ||
} | ||
|
||
/** | ||
* Checks if the given defaultIndex exists and returns | ||
* the first available index pattern id if not | ||
*/ | ||
export function getFallbackIndexPatternId( | ||
indexPatterns: IndexPattern[], | ||
defaultIndex: string = '' | ||
): string { | ||
if (defaultIndex && findIndexPatternById(indexPatterns, defaultIndex)) { | ||
return defaultIndex; | ||
} | ||
return !indexPatterns || !indexPatterns.length || !indexPatterns[0].id ? '' : indexPatterns[0].id; | ||
} | ||
|
||
/** | ||
* A given index pattern id is checked for existence and a fallback is provided if it doesn't exist | ||
* The provided defaultIndex is usually configured in Advanced Setting, if it's also invalid | ||
* the first entry of the given list of Indexpatterns is used | ||
*/ | ||
export function getIndexPatternId( | ||
id: string = '', | ||
indexPatterns: IndexPattern[], | ||
defaultIndex: string = '' | ||
): string { | ||
if (!id || !findIndexPatternById(indexPatterns, id)) { | ||
return getFallbackIndexPatternId(indexPatterns, defaultIndex); | ||
} | ||
return id; | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When setting this to false, kibana no longer is trying to persist the
defaultIndex
when none is setkibana/src/legacy/core_plugins/kibana/public/management/route_setup/load_default.js
Line 89 in fcc4c48