forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use saved object references for dashboard drilldowns (elastic#82602) (e…
- Loading branch information
Showing
58 changed files
with
1,122 additions
and
301 deletions.
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.