-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Field Formats namespace #56975
Conversation
Pinging @elastic/kibana-app-arch (Team:AppArch) |
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.
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
};
/** | ||
* Everything the file exports is public | ||
*/ |
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.
Removing this implies that this file now exports some things that are internal - is that the case?
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.
Well, it exports just one thing, and we don't import * from it anymore.
So I found the comment irrelevant.
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.
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.
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.
@lukeelmers I update the PR to constructing the namespace in public\server index.ts.
src/plugins/data/server/index.ts
Outdated
// fieldFormats | ||
fieldFormats, | ||
FieldFormatsGetConfigFn, | ||
FieldFormatConfig, | ||
FieldFormatsRegistry, |
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.
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.
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.
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?
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.
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.
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
@elasticmachine merge upstream |
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
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.
code LGTM
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.
Changes in kibana-app owned files LGTM
* 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>
* 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>
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:
index.ts
, with a prefix (consistent withcore
)In this PR I applied this approach to fieldFormats:
fieldFormats.FieldFormat
⇒IFieldFormat
fieldFormats.FieldFormatsRegistry
⇒FieldFormatsRegistry
fieldFormats.ContentType
⇒FieldFormatsContentType
,fieldFormats.GetConfigFn
⇒FieldFormatsGetConfigFn
,fieldFormats.IFieldFormatConfig
⇒FieldFormatConfig
,fieldFormats.IFieldFormatId
⇒FieldFormatId
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