Skip to content
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

Index pattern public api => common #68289

Merged
merged 33 commits into from
Jun 10, 2020

Conversation

mattkime
Copy link
Contributor

@mattkime mattkime commented Jun 4, 2020

Summary

This pr moves the index pattern api into a common directory and factors out client side code. The next pr will expose index pattern api via server.

Part of moving the index pattern api to a common (client and server) api - #68003

  • Replace core.notifications.toast with onNotification and onError callback functions
  • Replace FieldFormatsStart usage with FieldFormatsStartCommon
  • Move kibana_utils/public/{errors, field_mapping} => kibana_utils/common/{errors, field_mapping}
  • Move Index Pattern API code to common directory

@mattkime mattkime changed the title index pattern server api Index pattern public api => common Jun 5, 2020
This reverts commit ebc56d8.
@mattkime mattkime marked this pull request as ready for review June 6, 2020 00:06
@mattkime mattkime requested a review from a team as a code owner June 6, 2020 00:06
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

@mattkime mattkime added Feature:Data Views Data Views code and UI - index patterns before 8.0 v8.0.0 v7.9.0 release_note:skip Skip the PR/issue when compiling release notes labels Jun 6, 2020
@mattkime mattkime mentioned this pull request Jun 6, 2020
8 tasks
@elastic elastic deleted a comment from kibanamachine Jun 6, 2020
Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some initial comments

title,
text,
});
onNotification({ title, text, color: 'danger', iconType: 'alert' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we throw here and let the caller handle the exception. instead of passing onNotification in they can wrap code in try/cache

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good idea but I'd prefer to address it in another ticket as this PR aims to be a minimal set of changes required to provide a common api. I think I'd need to examine all places where index patterns are used to ensure errors are being caught. I've added a ticket to #67920

specs?: FieldSpec[],
shortDotsEnable?: boolean
) => IIndexPatternFieldList;

export const getIndexPatternFieldListCreator = ({
fieldFormats,
toastNotifications,
onNotification,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on this level we can then remove onNotification and leave catching the exception to the caller.

return [];
}

toasts.addError(err, {
this.onError(err, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets throw here as well and leave it up to the caller to decide what kind of notification they want to show ?

defaultId = patterns[0];
core.uiSettings.set('defaultIndex', defaultId);
} else {
return onRedirectNoIndexPattern();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets have this method always return and the caller decide what to do (no need to pass in callbacks)

export type EnsureDefaultIndexPattern = () => Promise<unknown> | undefined;

export const createEnsureDefaultIndexPattern = (
core: CoreStart,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets not pass in whole core but just uiSettingsClient

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason this is wrapped in a function ? why not just export ensureDefaultIndexPattern ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd prefer to leave further refactoring of this code to future PRs. I'm drawing a rather arbitrary line since I need to do things backwards - provide the service and then clean up the code.

@mattkime
Copy link
Contributor Author

mattkime commented Jun 8, 2020

@elasticmachine merge upstream

Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall makes sense, my main questions were around keeping some of the old directories in public which are only re-exporting common items & could probably be removed.

Also I agree with @ppisljar's idea on getting rid of the callbacks & instead just throwing and relying on the caller to handle things appropriately. But no strong feelings as to whether that's addressed here or as a follow-up.

@@ -17,5 +17,4 @@
* under the License.
*/

export * from './field_list';
export * from './field';
export * from '../../../common/index_patterns/fields';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than re-exporting here, should we just remove the public/index_patterns/fields directory entirely and import items from common/index_patterns/fields wherever they are needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These haven't been removed yet because I ran into errors when I did them all at once. There's an undesirable import somewhere. Just a matter of chasing it down now or later.

export * from './index_patterns';
export * from './index_patterns_api_client';
export * from './types';
export * from '../../../common/index_patterns/index_patterns';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question, should we re-export from here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed other instances but this one is giving me trouble.

src/plugins/data/public/index_patterns/lib/index.ts Outdated Show resolved Hide resolved
src/plugins/kibana_utils/common/index.ts Outdated Show resolved Hide resolved
@mattkime
Copy link
Contributor Author

mattkime commented Jun 9, 2020

But no strong feelings as to whether that's addressed here or as a follow-up.

No strong opinions here either. Drew the line here because the PR was still relatively easy to understand. Perhaps we should determine where to draw the line by when works starts on the index pattern expression function. I was under the impression that the answer was 'as soon as possible'

@mattkime
Copy link
Contributor Author

mattkime commented Jun 9, 2020

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code LGTM

Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM -- I'm cool with addressing the items discussed in a followup PR.

Tested Chrome (macOS) and everything seemed to work as expected 👍

I was able to reproduce the "missing indices" error message using the onNotification callback, though I did not test every notification or error scenario.

@mattkime mattkime merged commit 40d2cfc into elastic:master Jun 10, 2020
mattkime added a commit to mattkime/kibana that referenced this pull request Jun 11, 2020
Refactor index pattern api so it can be used by public and server services
# Conflicts:
#	src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts
#	src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts
#	src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jun 11, 2020
* master: (38 commits)
  Support migrating from reserved feature privileges (elastic#68504)
  add `preference` field to SavedObjectsFindOptions (elastic#68620)
  [ILM] Add "wait for snapshot" policy field to Delete phase (elastic#68505)
  Cleanup old license overwrites (elastic#68744)
  Bump TypeScript to v3.9 (elastic#67666)
  [APM] Service maps - adds new storybook stories to test out various data sets (elastic#68727)
  Fix vega specification parsing (elastic#67963)
  docs: add more api information (elastic#68717)
  [APM] Don't show annotations on charts with no data (elastic#68829)
  [Metrics UI] Fix Inventory View sorting by handling null values (elastic#67889)
  skip flaky suite (elastic#68836)
  [SIEM][Detections Engine] - Fix reference rule url overflow (elastic#68640)
  Index pattern public api => common (elastic#68289)
  [APM] Lazy-load alert triggers (elastic#68806)
  [DOCS] Fix table formatting in ingest manager settings (elastic#68824)
  [Endpoint] Functional Tests cleanup (elastic#68756)
  revert previous commit which was unintentional
  Use Github token instead for project assignments
  [SIEM][Exceptions] - ExceptionsViewer cleanup (elastic#68739)
  move @kbn/storybook to devDeps (elastic#68791)
  ...
mattkime added a commit that referenced this pull request Jun 11, 2020
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jun 12, 2020
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 68289 or prevent reminders by adding the backport:skip label.

@mattkime mattkime added backport:skip This commit does not require backporting and removed backport missing Added to PRs automatically when the are determined to be missing a backport. labels Jun 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Data Views Data Views code and UI - index patterns before 8.0 release_note:skip Skip the PR/issue when compiling release notes v7.9.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants