Skip to content

[Mappings editor] Add json editor to edit field settings#47674

Merged
sebelga merged 4 commits intoelastic:feature/mappings-editorfrom
sebelga:feature/mappings-editor-ui
Oct 9, 2019
Merged

[Mappings editor] Add json editor to edit field settings#47674
sebelga merged 4 commits intoelastic:feature/mappings-editorfrom
sebelga:feature/mappings-editor-ui

Conversation

@sebelga
Copy link
Copy Markdown
Contributor

@sebelga sebelga commented Oct 9, 2019

This PR adds a JSON editor to edit a field setting in the flyout.

Screen Shot 2019-10-09 at 11 29 27

@sebelga sebelga requested a review from jloleysens October 9, 2019 10:32
@sebelga sebelga added Feature:Index Management Index and index templates UI Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more t// v7.5.0 v8.0.0 labels Oct 9, 2019
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/es-ui (Team:Elasticsearch UI)


export type OnUpdateHandler<T = { [key: string]: any }> = (arg: {
getData(): T;
data: {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jloleysens I slightly changed the contract to get the json data in order to align with the contract of the form hook update.

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Copy link
Copy Markdown
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

Did not test this locally, but overall this looks good!

I left some comments you can choose to address or not.

export const MappingsEditor = React.memo(({ onUpdate, defaultValue }: Props) => {
const configurationDefaultValue = useMemo(
() =>
defaultValue === undefined
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, I think this filter + reduce pattern can be made slightly less verbose:

// something like
useMemo(() => _.pick(defaultValue === undefined ? {} : defaultValue, CONFIGURATION_FIELDS), [defaultValue]);

Did not test, may need to jam a Types['MappingsConfiguration'] in somewhere 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great idea, I haven't used pick in the past but indeed it makes it much easier to read. I'll merge the PR and update that part of the code. 👍

...acc,
[key]: value,
}),
{} as Types['MappingsConfiguration']
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm also wondering if this namespacing of interfaces under Types helps. As a reader I find this quite a verbose way of specifying the interface we're targeting. If we want namespacing I'd prefer this pattern (using file as a namespace provider):

import * as types from './my_types'
...
const a: types.MappingsConfiguration = {};

Just my 2 cents :)

Copy link
Copy Markdown
Contributor Author

@sebelga sebelga Oct 9, 2019

Choose a reason for hiding this comment

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

I take note and will look how the exported types could be exported differently. It's mainly to avoid name conflict exporting interfaces and components from the same index.ts file.

But I am not sure that types.MappingsConfiguration is much less verbose than Types['MappingsConfiguration']. 😊

@sebelga
Copy link
Copy Markdown
Contributor Author

sebelga commented Oct 9, 2019

Thanks for the review @jloleysens ! I'll update using _.pick as suggested on my current branch.

@sebelga sebelga merged commit 183ed1e into elastic:feature/mappings-editor Oct 9, 2019
@sebelga sebelga deleted the feature/mappings-editor-ui branch October 9, 2019 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Index Management Index and index templates UI Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more t// v7.5.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants