-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Move ensureDefaultIndexPattern into data plugin #63100
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
Merged
sulemanof
merged 14 commits into
elastic:master
from
sulemanof:np/move_ensure_index_pattern
Apr 24, 2020
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2716e33
Move ensure_default_index_pattern into data plugin
sulemanof 6d0a4e0
Update docs to include ensureDefaultIndexPattern
sulemanof 3bfa875
Fix translations
sulemanof 9519da7
Merge branch 'master' into np/move_ensure_index_pattern
elasticmachine 78f4c97
Merge remote-tracking branch 'upstream/master' into np/move_ensure_in…
sulemanof d0532d7
Move helper into index_patterns service
sulemanof 1df31de
Update docs
sulemanof e1a0cf7
Merge branch 'np/move_ensure_index_pattern' of github.com:sulemanof/k…
sulemanof 64ba52f
Remove mock
sulemanof 162d8d7
Merge branch 'master' into np/move_ensure_index_pattern
elasticmachine 095edcf
Merge remote-tracking branch 'upstream/master' into np/move_ensure_in…
sulemanof a7d2a20
Merge branch 'np/move_ensure_index_pattern' of github.com:sulemanof/k…
sulemanof 16ad08a
Add mock
sulemanof 14cb75a
Merge remote-tracking branch 'upstream/master' into np/move_ensure_in…
sulemanof 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
98 changes: 98 additions & 0 deletions
98
src/plugins/data/public/index_patterns/index_patterns/ensure_default_index_pattern.tsx
This file contains hidden or 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,98 @@ | ||
| /* | ||
| * 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 { contains } from 'lodash'; | ||
| import React from 'react'; | ||
| import { History } from 'history'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { EuiCallOut } from '@elastic/eui'; | ||
| import { CoreStart } from 'kibana/public'; | ||
| import { toMountPoint } from '../../../../kibana_react/public'; | ||
| import { IndexPatternsContract } from './index_patterns'; | ||
|
|
||
| export type EnsureDefaultIndexPattern = (history: History) => Promise<unknown> | undefined; | ||
|
|
||
| export const createEnsureDefaultIndexPattern = (core: CoreStart) => { | ||
| let bannerId: string; | ||
| let timeoutId: NodeJS.Timeout | undefined; | ||
|
|
||
| /** | ||
| * Checks whether a default index pattern is set and exists and defines | ||
| * one otherwise. | ||
| * | ||
| * If there are no index patterns, redirect to management page and show | ||
| * banner. In this case the promise returned from this function will never | ||
| * resolve to wait for the URL change to happen. | ||
| */ | ||
| return async function ensureDefaultIndexPattern(this: IndexPatternsContract, history: History) { | ||
| const patterns = await this.getIds(); | ||
| let defaultId = core.uiSettings.get('defaultIndex'); | ||
| let defined = !!defaultId; | ||
| const exists = contains(patterns, defaultId); | ||
|
|
||
| if (defined && !exists) { | ||
| core.uiSettings.remove('defaultIndex'); | ||
| defaultId = defined = false; | ||
| } | ||
|
|
||
| if (defined) { | ||
| return; | ||
| } | ||
|
|
||
| // If there is any index pattern created, set the first as default | ||
| if (patterns.length >= 1) { | ||
| defaultId = patterns[0]; | ||
| core.uiSettings.set('defaultIndex', defaultId); | ||
| } else { | ||
| const canManageIndexPatterns = core.application.capabilities.management.kibana.index_patterns; | ||
| const redirectTarget = canManageIndexPatterns ? '/management/kibana/index_pattern' : '/home'; | ||
|
|
||
| if (timeoutId) { | ||
| clearTimeout(timeoutId); | ||
| } | ||
|
|
||
| // Avoid being hostile to new users who don't have an index pattern setup yet | ||
| // give them a friendly info message instead of a terse error message | ||
| bannerId = core.overlays.banners.replace( | ||
| bannerId, | ||
| toMountPoint( | ||
| <EuiCallOut | ||
| color="warning" | ||
| iconType="iInCircle" | ||
| title={i18n.translate('data.indexPatterns.ensureDefaultIndexPattern.bannerLabel', { | ||
| defaultMessage: | ||
| "In order to visualize and explore data in Kibana, you'll need to create an index pattern to retrieve data from Elasticsearch.", | ||
| })} | ||
| /> | ||
| ) | ||
| ); | ||
|
|
||
| // hide the message after the user has had a chance to acknowledge it -- so it doesn't permanently stick around | ||
| timeoutId = setTimeout(() => { | ||
| core.overlays.banners.remove(bannerId); | ||
| timeoutId = undefined; | ||
| }, 15000); | ||
|
|
||
| history.push(redirectTarget); | ||
|
|
||
| // return never-resolving promise to stop resolving and wait for the url change | ||
| return new Promise(() => {}); | ||
| } | ||
| }; | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
98 changes: 0 additions & 98 deletions
98
src/plugins/kibana_utils/public/history/ensure_default_index_pattern.tsx
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Where is this change coming from?
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.
Seems all of the docs changes were not directly related to changes in this PR,
because after the last merge with the master, all of them are just gone (means the same changes have been already merged -> https://github.com/elastic/kibana/blob/master/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.search.md#search-variable)
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.
Weird, I thought we had a check for that in the build.
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.
CI checks that the latest
api.jsonfile is up to date and committed but doesn't verify that docs (based on this file) are up to date. so if you--acceptapi changes but don't commit the new docs this could happen.