-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
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.
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(), |
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.
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> => { |
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.
I know we talked about this a little earlier, but I wonder if this would help you prevent using the bang !
for searchSourceFields
below?
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.
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.
Oh except ISavedVis
has savedSearchRefName
, which is not returned by convertFrom SerializedVis
...
|
||
searchSource.setParent(savedSearch.searchSource); | ||
} | ||
searchSource!.setField('size', 0); |
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.
Is !
needed here? Because it doesn't appear to be needed in line 78.
interface PartialVisState extends Omit<SerializedVis, 'data'> { | ||
data: Partial<SerializedVisData>; | ||
} |
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.
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.
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.
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
if (state.params || typeChanged) { | ||
this.params = this.getParams(state.params); | ||
this.params = this.getParams(state.params!); |
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 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?
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; |
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.
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;
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.
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.
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.
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, |
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.
👍
a3ee243
to
cb5ed20
Compare
cb5ed20
to
af4f9ea
Compare
af4f9ea
to
19c1af9
Compare
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.
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
235b815
to
4b83ca8
Compare
4b83ca8
to
d5f52d5
Compare
# Conflicts: # src/plugins/data/public/public.api.md
retest |
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 changes here LGTM, pending a green build
@elasticmachine merge upstream |
ddaf007
to
34c826f
Compare
34c826f
to
284010f
Compare
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.
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', () => { |
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.
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
# Conflicts: # src/plugins/data/public/public.api.md
retest |
@elasticmachine merge upstream |
4ebe447
to
cbde348
Compare
💚 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.
Tested in Firefox and works as expected except for legacy import (separate issue created as it's probably not related)
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