-
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
Use saved object references for dashboard drilldowns #82602
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d67b343
Use saved object references for dashboard drilldowns
Dosant 3eb2c39
Merge branch 'master' of github.com:elastic/kibana into dev/dashboard…
Dosant 4441cc1
fix corrupted dashboard object
Dosant e1aef10
Merge branch 'master' of github.com:elastic/kibana into dev/dashboard…
Dosant 57ea0d9
Merge branch 'master' of github.com:elastic/kibana into dev/dashboard…
Dosant 8cddea3
Merge branch 'master' into dev/dashboard-drilldown-so-2
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 0 additions & 11 deletions
11
.../kibana-plugin-plugins-embeddable-server.embeddablesetup.getattributeservice.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/plugins/dashboard/common/embeddable/embeddable_references.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { | ||
ExtractDeps, | ||
extractPanelsReferences, | ||
InjectDeps, | ||
injectPanelsReferences, | ||
} from './embeddable_references'; | ||
import { createEmbeddablePersistableStateServiceMock } from '../../../embeddable/common/mocks'; | ||
import { SavedDashboardPanel } from '../types'; | ||
import { EmbeddableStateWithType } from '../../../embeddable/common'; | ||
|
||
const embeddablePersistableStateService = createEmbeddablePersistableStateServiceMock(); | ||
const deps: InjectDeps & ExtractDeps = { | ||
embeddablePersistableStateService, | ||
}; | ||
|
||
test('inject/extract panel references', () => { | ||
embeddablePersistableStateService.extract.mockImplementationOnce((state) => { | ||
const { HARDCODED_ID, ...restOfState } = (state as unknown) as Record<string, unknown>; | ||
return { | ||
state: restOfState as EmbeddableStateWithType, | ||
references: [{ id: HARDCODED_ID as string, name: 'refName', type: 'type' }], | ||
}; | ||
}); | ||
|
||
embeddablePersistableStateService.inject.mockImplementationOnce((state, references) => { | ||
const ref = references.find((r) => r.name === 'refName'); | ||
return { | ||
...state, | ||
HARDCODED_ID: ref!.id, | ||
}; | ||
}); | ||
|
||
const savedDashboardPanel: SavedDashboardPanel = { | ||
type: 'search', | ||
embeddableConfig: { | ||
HARDCODED_ID: 'IMPORTANT_HARDCODED_ID', | ||
}, | ||
id: 'savedObjectId', | ||
panelIndex: '123', | ||
gridData: { | ||
x: 0, | ||
y: 0, | ||
h: 15, | ||
w: 15, | ||
i: '123', | ||
}, | ||
version: '7.0.0', | ||
}; | ||
|
||
const [{ panel: extractedPanel, references }] = extractPanelsReferences( | ||
[savedDashboardPanel], | ||
deps | ||
); | ||
expect(extractedPanel.embeddableConfig).toEqual({}); | ||
expect(references).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"id": "IMPORTANT_HARDCODED_ID", | ||
"name": "refName", | ||
"type": "type", | ||
}, | ||
] | ||
`); | ||
|
||
const [injectedPanel] = injectPanelsReferences([extractedPanel], references, deps); | ||
|
||
expect(injectedPanel).toEqual(savedDashboardPanel); | ||
}); |
82 changes: 82 additions & 0 deletions
82
src/plugins/dashboard/common/embeddable/embeddable_references.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { omit } from 'lodash'; | ||
import { | ||
convertSavedDashboardPanelToPanelState, | ||
convertPanelStateToSavedDashboardPanel, | ||
} from './embeddable_saved_object_converters'; | ||
import { SavedDashboardPanel } from '../types'; | ||
import { SavedObjectReference } from '../../../../core/types'; | ||
import { EmbeddablePersistableStateService } from '../../../embeddable/common/types'; | ||
|
||
export interface InjectDeps { | ||
embeddablePersistableStateService: EmbeddablePersistableStateService; | ||
} | ||
|
||
export function injectPanelsReferences( | ||
panels: SavedDashboardPanel[], | ||
references: SavedObjectReference[], | ||
deps: InjectDeps | ||
): SavedDashboardPanel[] { | ||
const result: SavedDashboardPanel[] = []; | ||
for (const panel of panels) { | ||
const embeddableState = convertSavedDashboardPanelToPanelState(panel); | ||
embeddableState.explicitInput = omit( | ||
deps.embeddablePersistableStateService.inject( | ||
{ ...embeddableState.explicitInput, type: panel.type }, | ||
references | ||
), | ||
'type' | ||
); | ||
result.push(convertPanelStateToSavedDashboardPanel(embeddableState, panel.version)); | ||
} | ||
return result; | ||
} | ||
|
||
export interface ExtractDeps { | ||
embeddablePersistableStateService: EmbeddablePersistableStateService; | ||
} | ||
|
||
export function extractPanelsReferences( | ||
panels: SavedDashboardPanel[], | ||
deps: ExtractDeps | ||
): Array<{ panel: SavedDashboardPanel; references: SavedObjectReference[] }> { | ||
const result: Array<{ panel: SavedDashboardPanel; references: SavedObjectReference[] }> = []; | ||
|
||
for (const panel of panels) { | ||
const embeddable = convertSavedDashboardPanelToPanelState(panel); | ||
const { | ||
state: embeddableInputWithExtractedReferences, | ||
references, | ||
} = deps.embeddablePersistableStateService.extract({ | ||
...embeddable.explicitInput, | ||
type: embeddable.type, | ||
}); | ||
embeddable.explicitInput = omit(embeddableInputWithExtractedReferences, 'type'); | ||
|
||
const newPanel = convertPanelStateToSavedDashboardPanel(embeddable, panel.version); | ||
result.push({ | ||
panel: newPanel, | ||
references, | ||
}); | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
I noticed that
title
was not omitted even though it is copied on a root level of the object.This is causing duplicate title in each panel of dashboard SO which caught my eye in new unit tests.