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

Field Formats namespace #56975

Merged

Conversation

lizozom
Copy link
Contributor

@lizozom lizozom commented Feb 6, 2020

Summary

Part of #56881

This PR demonstrates a proposed resolution for #52374, trying to balance code readability, API discoverability, DX and documentation generation using ApiExtractor.

The solution involves:

  • Exporting types directly from index.ts, with a prefix (consistent with core)
  • Exporting utility functions and constants using a "namespace" (A simple object).

In this PR I applied this approach to fieldFormats:

  • fieldFormats.FieldFormatIFieldFormat
  • fieldFormats.FieldFormatsRegistryFieldFormatsRegistry
  • fieldFormats.ContentTypeFieldFormatsContentType,
  • fieldFormats.GetConfigFnFieldFormatsGetConfigFn,
  • fieldFormats.IFieldFormatConfigFieldFormatConfig,
  • fieldFormats.IFieldFormatIdFieldFormatId

Other utilities are available, as before, on the fieldFormats namespace and documentation passes for this sub-service.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@lizozom lizozom added Feature:New Platform release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. v8.0.0 Team:AppArch v7.7.0 labels Feb 6, 2020
@lizozom lizozom requested a review from a team February 6, 2020 13:42
@lizozom lizozom requested a review from a team as a code owner February 6, 2020 13:42
@lizozom lizozom self-assigned this Feb 6, 2020
@elasticmachine
Copy link
Contributor

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

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.

Since we are composing the static utils namespaces as objects now, I wonder if the static.ts file convention is even useful anymore?

Plus, what if we have a situation where there are items that need to live in a namespace that don't live in a common directory? It's possible for other services we may have utils that, for example, rely on specific browser APIs that would only be exported under the namespace from public.

I think what I'd propose in this case is simply building the namespace from the public/index and server/index files. This has a few benefits:

  • Lets you combine utils from common and public/server, solving the issue described above
  • It's one less level of indirection
  • When you look at the index file you will immediately see everything that's publicly exported, less confusion over what is/isn't public.

Would look something like this:

// data/public/index.ts
import { FieldFormat, BytesFormat, ColorFormat, etc } from '../common';
import { BrowserThing } from './field_formats';

// types
export {
  FieldFormatsGetConfigFn,
  FieldFormatConfig,
  FieldFormatsRegistry,
  ...etc
} from '../common/types';

// utils
export const fieldFormats = {
  FieldFormat,
  BytesFormat,
  ColorFormat,
  BrowserThing,
  ...etc
};

Comment on lines -20 to -22
/**
* Everything the file exports is public
*/
Copy link
Member

Choose a reason for hiding this comment

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

Removing this implies that this file now exports some things that are internal - is that the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it exports just one thing, and we don't import * from it anymore.
So I found the comment irrelevant.

Copy link
Member

Choose a reason for hiding this comment

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

My overall vote would be to consider the direction I mentioned about composing these objects directly in the public/index and server/index files, in which case it doesn't matter.

That said, if we were to keep this implementation with static.ts I would think it would be important to identify somewhere in the file that this entire namespace is exported publicly, so you don't run the risk of someone adding something internal here accidentally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lukeelmers I update the PR to constructing the namespace in public\server index.ts.

src/plugins/data/public/index.ts Outdated Show resolved Hide resolved
Comment on lines 58 to 62
// fieldFormats
fieldFormats,
FieldFormatsGetConfigFn,
FieldFormatConfig,
FieldFormatsRegistry,
Copy link
Member

Choose a reason for hiding this comment

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

Currently (in both public/index and server/index) we have static exports separated from type exports. To avoid confusion maybe we should stick the namespace with the static exports for the time being?

Once we move everything over to this structure, it should be more intuitive whether something is static or a type, but in the interim it may help make things clearer.

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 transition shouldn't take more than a few days, so I don't think it's worth leaving it for later.
What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

If we're planning to make the transition right away, and you think it's only a couple days, then I have no concerns about keeping it as-is. I only brought it up in the event that the data plugin might sit like this for awhile before we come back to clean up the rest.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

History

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

@elastic elastic deleted a comment from kibanamachine Feb 6, 2020
@lizozom
Copy link
Contributor Author

lizozom commented Feb 10, 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

@lizozom lizozom added release_note:skip Skip the PR/issue when compiling release notes and removed release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. labels Feb 10, 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.

code LGTM

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

Changes in kibana-app owned files LGTM

@lizozom lizozom merged commit 09c6f25 into elastic:master Feb 10, 2020
lizozom pushed a commit to lizozom/kibana that referenced this pull request Feb 10, 2020
* Field Formats namespace

* Export IFieldFormatsRegistry and FieldFormatsRegistry separately.

* remove field_formats export from data plugin and adjust lens test

* Updated doc return types

* Cleanup fieldFormat namespace and define it index.ts

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
lizozom pushed a commit that referenced this pull request Feb 10, 2020
* Field Formats namespace

* Export IFieldFormatsRegistry and FieldFormatsRegistry separately.

* remove field_formats export from data plugin and adjust lens test

* Updated doc return types

* Cleanup fieldFormat namespace and define it index.ts

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
@lizozom lizozom mentioned this pull request Feb 12, 2020
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants