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

Use NP registry instead of ui/registry/field_formats #48108

Merged
merged 83 commits into from
Nov 20, 2019
Merged

Use NP registry instead of ui/registry/field_formats #48108

merged 83 commits into from
Nov 20, 2019

Conversation

gospodarsky
Copy link
Contributor

@gospodarsky gospodarsky commented Oct 14, 2019

Summary

A part of #43443

  • Get rid of uiExports/fieldFormats;
  • Remove field_formats.js;
  • Create FieldFormatRegisty and replace old field_formats.js dependencies by the new one;
  • Add the FieldFormatRegisty to plugins/data;

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

Dev Docs

The FieldFormats service has been moved to the data plugin in the New Platform. If your plugin has any imports from ui/registry/field_formats, you'll need to update your imports as follows:

Use it in your New Platform plugin:

class MyPlugin {
  setup (core, { data }) {
    data.fieldFormats.register(myFieldFormat);
    // ...
  }
  start (core, { data }) {
    data.fieldFormats.getType(myFieldFormatId);
    // ...
  }
}

Or, in your legacy platform plugin, consume it through the ui/new_platform module:

import { npSetup, npStart } from 'ui/new_platform';

npSetup.plugins.data.fieldFormats.register(myFieldFormat);
npStart.plugins.data.fieldFormats.getType(myFieldFormatId);
// ...

@gospodarsky gospodarsky self-assigned this Oct 14, 2019
@gospodarsky gospodarsky changed the title Create Field Format Provider Use NP registry instead of ui/registry/field_formats Oct 14, 2019
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@gospodarsky gospodarsky merged commit 3a915b2 into elastic:master Nov 20, 2019
kibana-app-arch automation moved this from Review in progress to Done in 7.6 Nov 20, 2019
@gospodarsky
Copy link
Contributor Author

l_f25b4d05 (1)

lizozom pushed a commit to lizozom/kibana that referenced this pull request Nov 20, 2019
* Create Field Format Provider

* Pass Field Format as a start dependency

* Register utils in the new field formats

* Fix types issue

* Make FieldFormats instance as a service

* Exclude importing of register.js

* Remove uiExports/fieldFormats imports

* Migrate some dependencies to new Field Format

* Migrate field format to new instance

* Fix type errors

* Fix Jest tests

* Move from getFieldFormat to npSetup

* Fix types errors

* Fix reviews

* Fix types errors

* Fix types

* fix CI

* Bind getConfig to FieldFormatRegisty

* Mock FieldFormat in FieldItem

* Fix DataPanel tests

* Fix DataPanel tests

* Fix Jest tests

* Create a fieldFormats mock for mocha tests

* fix CI

* fix CI

* Mock fieldFormatsRegistry in all visualizations

* Fix 'should create scripted field' functional test

* Change FieldFormat.from return type

* Fix reviews

* Fix mocha test

* Fix mocha tests

* Encapsulate FieldFormatRegistry

* Pretty field_item.tsx

* Fix reviews

* Fix PR comments

* Fix CI

* Replace any by a specific type

* Fix mocha tests

* Remove config from url converter

* Expand Field Format ID type for creating custom converters

* Fix a jest test

* Update migration doc

* Add quote and semicolon

* Fix types errors which doesn't relate to the aim of PR
lizozom pushed a commit that referenced this pull request Nov 20, 2019
* Create Field Format Provider

* Pass Field Format as a start dependency

* Register utils in the new field formats

* Fix types issue

* Make FieldFormats instance as a service

* Exclude importing of register.js

* Remove uiExports/fieldFormats imports

* Migrate some dependencies to new Field Format

* Migrate field format to new instance

* Fix type errors

* Fix Jest tests

* Move from getFieldFormat to npSetup

* Fix types errors

* Fix reviews

* Fix types errors

* Fix types

* fix CI

* Bind getConfig to FieldFormatRegisty

* Mock FieldFormat in FieldItem

* Fix DataPanel tests

* Fix DataPanel tests

* Fix Jest tests

* Create a fieldFormats mock for mocha tests

* fix CI

* fix CI

* Mock fieldFormatsRegistry in all visualizations

* Fix 'should create scripted field' functional test

* Change FieldFormat.from return type

* Fix reviews

* Fix mocha test

* Fix mocha tests

* Encapsulate FieldFormatRegistry

* Pretty field_item.tsx

* Fix reviews

* Fix PR comments

* Fix CI

* Replace any by a specific type

* Fix mocha tests

* Remove config from url converter

* Expand Field Format ID type for creating custom converters

* Fix a jest test

* Update migration doc

* Add quote and semicolon

* Fix types errors which doesn't relate to the aim of PR
alexwizp added a commit to alexwizp/kibana that referenced this pull request Nov 22, 2019
alexwizp added a commit that referenced this pull request Nov 22, 2019
alexwizp added a commit to alexwizp/kibana that referenced this pull request Nov 22, 2019
alexwizp added a commit that referenced this pull request Nov 22, 2019
@pgege
Copy link

pgege commented Apr 17, 2020

Hi, I attempted to register my plugin using this:
image

Here is how I used it:
image

But I get this error:
image

I changed the code to this (passing an array with my field formatter):
image

However the page to edit field types comes up blank on kibana
image

Can someone provide some insight as to what I can do to register my field formatter plugin?

@alexwizp
Copy link
Contributor

@paulyg321 Looks like you did everything right. At the setup stage, you must execute the fieldFormats.register method and pass an array of your custom field formats.

Keep in mind that you can add custom field formats only at the setup stage
But I'm a little worried why you see a blank page. Could you confirm that DictionaryLookupProvider is a class inherited from FieldFormat

@mattkime
Copy link
Contributor

@paulyg321 Is there a way for you to share your code? Perhaps point me to a PR on your own repo.

@pgege
Copy link

pgege commented Apr 17, 2020

@mattkime @alexwizp Here's a link to the Github repo with the code i'm working on. https://github.com/paulyg321/kibana-field-formatters/blob/master/public/dictionary-lookup.js

@mattkime
Copy link
Contributor

mattkime commented Apr 18, 2020

@paulyg321 I think it would be helpful to try to use the kibana platform (aka the new platform) to create this plugin. It will be a little bit more work but it will help preserve future compatibility. Here's how I recommend we accomplish that -

Clone the kibana repo, run yarn run kbn bootstrap and then run node scripts/generate_plugin - you can try adding your field formatting code there or just push the result as a PR and we can continue the discussion there.

You can also reach me on the elastic community slack - https://www.elastic.co/blog/join-our-elastic-stack-workspace-on-slack

Anyway, I know I'm pointing you in a different direction but I hope you find it helpful.


Oh, do you see any console errors with your current code? There might be a simple fix.

@cliffplaysdrums
Copy link

cliffplaysdrums commented May 27, 2020

Hello, I've been encountering the same issues as the previous poster. My code is very similar to what they linked on GitHub, but I'll also try to make mine publicly available shortly.

The current issue only appears after clicking "edit" on a field within an index pattern (management tab). When the new page loads that would normally allow the selection of a field formatter, I see a console error "format.fieldType is undefined." It is however defined as such

class ScteFormat extends FieldFormat {
    static id = 'scte';
    static title = 'SCTE';
    static fieldType = ['string']; // src/plugins/data/common/kbn_field_types/types.ts

    constructor(params) {
      super(params);
    }
  }

Edit: plugin code is available here https://github.com/cliffplaysdrums/kibana-plugins/tree/master/cliff_test_plugin

@cliffplaysdrums
Copy link

@mattkime @alexwizp just checking if this commit is still being watched, or if I should be asking for help elsewhere.
Thanks!

@alexwizp
Copy link
Contributor

alexwizp commented Jun 2, 2020

Hi @cliffplaysdrums. I looked at your code and found that you are still using an outdated approach that has already been removed. Please see our migration documentation:

Also I can show you an example of how to register a custom format in a new platform:
alexwizp@4246029

Please let me know if something is unclear.

You can use the following command to generate new plugin:
node scripts/generate_plugin plugin_name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:FieldFormatters Feature:NP Migration release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. review v7.6.0 v8.0.0
Projects
kibana-app-arch
  
Done in previous release
Development

Successfully merging this pull request may close these issues.

None yet