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

making vis (completely) serializable #64207

Merged
merged 11 commits into from
May 12, 2020

Conversation

ppisljar
Copy link
Member

@ppisljar ppisljar commented Apr 22, 2020

Summary

Summarize your PR. If it involves visual changes include a screenshot or gif.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@elasticmachine
Copy link
Contributor

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

@ppisljar ppisljar requested a review from lukeelmers April 22, 2020 15:52
@ppisljar ppisljar added the release_note:skip Skip the PR/issue when compiling release notes label Apr 22, 2020
@ppisljar ppisljar requested a review from flash1293 April 22, 2020 15:53
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.

Couple of questions, otherwise this makes sense to me so far

@@ -48,6 +49,7 @@ export const pluginsMock = {
visualizations: visualizationsPluginMock.createSetupContract(),
kibanaLegacy: kibanaLegacyPluginMock.createSetupContract(),
savedObjectsManagement: savedObjectsManagementPluginMock.createSetupContract(),
discover: discoverPluginMock.createSetupContract(),
Copy link
Member

Choose a reason for hiding this comment

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

You will likely need to add mocks to the karma mocks file as well, since it calls setSetupServices and setStartService expecting the same arguments. This is probably contributing to some of the build failures.

import { ISavedVis, SerializedVis } from '../types';
import { createSavedSearchesLoader } from '../../../../plugins/discover/public';
import { getChrome, getOverlays, getIndexPatterns, getSavedObjects, getSearch } from '../services';

export const convertToSerializedVis = async (savedVis: ISavedVis): Promise<SerializedVis> => {
Copy link
Member

Choose a reason for hiding this comment

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

I know we talked about this a little earlier, but I wonder if this would help you prevent using the bang ! for searchSourceFields below?

Suggested change
export const convertToSerializedVis = async (savedVis: ISavedVis): Promise<SerializedVis> => {
export const convertToSerializedVis = async (savedVis: Required<ISavedVis>): Promise<SerializedVis> => {

Because really the value taken in to convertToSerializedVis isn't ISavedVis, it is the return type of convertFromSerializedVis, in which all the fields should be present.

Copy link
Member

Choose a reason for hiding this comment

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

Oh except ISavedVis has savedSearchRefName, which is not returned by convertFrom SerializedVis...


searchSource.setParent(savedSearch.searchSource);
}
searchSource!.setField('size', 0);
Copy link
Member

Choose a reason for hiding this comment

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

Is ! needed here? Because it doesn't appear to be needed in line 78.

interface PartialVisState extends Omit<SerializedVis, 'data'> {
data: Partial<SerializedVisData>;
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: This could be simplified with the Assign utility, and you wouldn't have to do the weird extends Omit<...> thing:

import { Assign } from '@kbn/utility-types';

type PartialVisState = Assign<SerializedVis, { data: Partial<SerializedVisData> }>;

It's basically Object.assign() for types.

Copy link
Member

Choose a reason for hiding this comment

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

Also, are you sure data shouldn't be optional here? It appears we set a default (lines 96-98). And from what I understand data won't really ever be "populated" with info until setState is called

Comment on lines 134 to 133
if (state.params || typeChanged) {
this.params = this.getParams(state.params);
this.params = this.getParams(state.params!);
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 are saying we know for sure that params exists (by asserting state.params!), then why do we have a conditional at all on line 134?

If state.params is always truthy, then typeChanged will never be evaluated, and the block will always execute.

So at that point what is typeChanged actually doing?

Comment on lines 168 to 173
const { data, ...restOfSerialized } = this.serialize();
const vis = new Vis(this.type.name, restOfSerialized as any);
vis.setState(restOfSerialized as any);
const aggs = this.data.indexPattern
? getAggs().createAggConfigs(this.data.indexPattern, data.aggs)
: undefined;
vis.data = {
...this.data,
aggs,
};
return vis;
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if this could be simplified. Since you are relying on mutating vis.data after the fact anyway, why do you need to separate it from restOfSerialized?

Would this do the same thing?

    const serializedVis = this.serialize();
    const vis = new Vis(this.type.name, serializedVis);
    vis.setState(serializedVis);
    vis.data.aggs = this.data.indexPattern
      ? getAggs().createAggConfigs(this.data.indexPattern, serializedVis.data.aggs)
      : undefined;
    return vis;

Copy link
Member Author

@ppisljar ppisljar Apr 30, 2020

Choose a reason for hiding this comment

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

no, to keep clone method sync we must not call setState without data property set.
we work around loading index pattern and linked search by keeping the same references.

Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

LGTM for SOM plugin changes

service: discover.savedSearches.createLoader({
savedObjectsClient: coreStart.savedObjects.client,
indexPatterns: data.indexPatterns,
search: data.search,
chrome: coreStart.chrome,
overlays: coreStart.overlays,
}),
service: discover.savedSearchLoader,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@ppisljar ppisljar force-pushed the searchSource/serialize branch 2 times, most recently from a3ee243 to cb5ed20 Compare April 23, 2020 13:44
@ppisljar ppisljar force-pushed the searchSource/serialize branch from cb5ed20 to af4f9ea Compare April 30, 2020 05:21
@ppisljar ppisljar force-pushed the searchSource/serialize branch from af4f9ea to 19c1af9 Compare April 30, 2020 11:39
@ppisljar ppisljar requested a review from a team as a code owner April 30, 2020 11:39
Copy link
Contributor

@kindsun kindsun left a comment

Choose a reason for hiding this comment

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

Nice! Maps changes lgtm

# Conflicts:
#	src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/context.ts
#	src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/query/actions.js
#	src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js
#	src/plugins/data/public/public.api.md
#	src/plugins/data/public/search/types.ts
#	src/plugins/discover/kibana.json
#	src/plugins/discover/public/mocks.ts
#	src/plugins/discover/public/plugin.ts
#	src/plugins/visualize/public/application/legacy_app.js
#	test/functional/config.js
@ppisljar ppisljar force-pushed the searchSource/serialize branch 2 times, most recently from 235b815 to 4b83ca8 Compare May 6, 2020 08:40
@ppisljar ppisljar force-pushed the searchSource/serialize branch from 4b83ca8 to d5f52d5 Compare May 6, 2020 10:50
ppisljar added 2 commits May 6, 2020 04:01
# Conflicts:
#	src/plugins/data/public/public.api.md
@ppisljar
Copy link
Member Author

ppisljar commented May 6, 2020

retest

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 changes here LGTM, pending a green build

@ppisljar
Copy link
Member Author

ppisljar commented May 7, 2020

@elasticmachine merge upstream

@ppisljar ppisljar force-pushed the searchSource/serialize branch from ddaf007 to 34c826f Compare May 7, 2020 13:28
@ppisljar ppisljar force-pushed the searchSource/serialize branch from 34c826f to 284010f Compare May 7, 2020 15:02
Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

I found an error which is likely related to this change (couldn't make the connection yet). When importing a legacy JSON file via management that contains a broken index pattern reference, selecting a resolution and confirming raises an exception "Cannot read property 'save' of undefined".

You can verify with https://gist.github.com/flash1293/55a6dac0d1e833d9c0a77baf11c78682 - the index pattern reference of the last visualization is the malformed one.

});

test('should fail if JSON is invalid', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big deal but seems like this test got lost - looks like it should become a unit test of https://github.com/elastic/kibana/pull/64207/files#diff-0138b68230bd9fd9e68b55fe4e8868b1

@ppisljar
Copy link
Member Author

retest

@ppisljar
Copy link
Member Author

@elasticmachine merge upstream

@ppisljar ppisljar force-pushed the searchSource/serialize branch from 4ebe447 to cbde348 Compare May 12, 2020 08:13
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Tested in Firefox and works as expected except for legacy import (separate issue created as it's probably not related)

@ppisljar ppisljar merged commit 15c0644 into elastic:master May 12, 2020
ppisljar added a commit to ppisljar/kibana that referenced this pull request May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes review v7.8.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants