[Dashboards] Add getSerializedState method to Dashboard API#204140
[Dashboards] Add getSerializedState method to Dashboard API#204140ThomThomson merged 10 commits intoelastic:mainfrom
Conversation
|
Pinging @elastic/kibana-presentation (Team:Presentation) |
| unifiedSearchManager.internalApi.controlGroupReload$, | ||
| unifiedSearchManager.internalApi.panelsReload$ | ||
| ).pipe(debounceTime(0)), | ||
| getSerializedState: async () => { |
There was a problem hiding this comment.
#203662 made getState sync so this method could now become sync as well.
There was a problem hiding this comment.
Oh good call! Updated in b58c33d.
Unfortunately, the getSerializedState method still needs to be async for now since the getDashboardState method on the CM service relies on a Promise to extract searchSource references. But this might change when we move reference handling to the server in #192758.
Unfortunately, the `getSerializedState` method still needs to be async since the `getDashboardState` method on the CM service is a promise. But this might change when we move reference handling to the server in elastic#192758.
| } | ||
| }; | ||
|
|
||
| export const getDashboardState = async ({ |
There was a problem hiding this comment.
Why is this part of content management service instead of just a function that can be imported where needed? Does it need to be part of content management service?
There was a problem hiding this comment.
It does not need to be on content management service. I moved the module into the dashboard_api directory in ed68550.
| ...(prefixedPanelReferences ?? []), | ||
| ...(controlGroupReferences ?? []), | ||
| ]; | ||
| const { attributes, references } = await getDashboardState({ |
There was a problem hiding this comment.
Should save methods be updated to just take output of getDashboardState instead of calling getDashboardState internally.
I think it would be better if getDashboardState lived in dashboard_api folder and any place that needed serialized state would just get passed { attributes: DashboardAttributes; references: SavedObjectReference[]; }
There was a problem hiding this comment.
I like this idea a lot, but I think I would like to scope that in a different PR. Making those changes in this PR would greatly increase the number of changes required for review.
| } | ||
| }; | ||
|
|
||
| export const getDashboardState = ({ |
There was a problem hiding this comment.
Can this be renamed to getSerializedState (and rename file to get_serialized_state)? That will avoid ambiguity of what state this is returning.
| panelReferences: [], | ||
| }); | ||
|
|
||
| expect(result.attributes.panels).toEqual([]); |
There was a problem hiding this comment.
How about asserting the entire result.attributes
| const dashboardState = { | ||
| ...getSampleDashboardState(), | ||
| panels: { oldPanelId: { type: 'visualization' } }, | ||
| } as unknown as DashboardState; |
There was a problem hiding this comment.
Can you move the cast from the entire dashboard state to just panel
const dashboardState = {
...getSampleDashboardState(),
panels: { oldPanelId: { type: 'visualization' } as DashboardPanelState },
};
| ], | ||
| }); | ||
|
|
||
| expect(result.attributes.panels).toEqual( |
There was a problem hiding this comment.
Why don't you mock v4 so you know the new id. Then you can assert attributes.panels has the right shape.
jest.mock('uuid', () => ({
v4: jest.fn().mockReturnValue('12345'),
}));
expect(result.attributes.panels).toEqual({ ...expectedValue});
| panelReferences, | ||
| saveOptions, | ||
| currentState: dashboardStateToSave, | ||
| dashboardState: dashboardStateToSave, |
There was a problem hiding this comment.
searchSourceReferences is not passed to saveDashboardState call
|
|
||
| it('should return the current state attributes and references', async () => { | ||
| const dashboardState = getSampleDashboardState(); | ||
| const result = await getSerializedState({ |
There was a problem hiding this comment.
Calls to getSerializedState should not be async. Also, all test cases do not need to be async
|
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Module Count
Public APIs missing comments
Async chunks
History
|
|
Starting backport for target branches: 8.x https://github.com/elastic/kibana/actions/runs/12420230354 |
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…04140) (#205010) # Backport This will backport the following commits from `main` to `8.x`: - [[Dashboards] Add getSerializedState method to Dashboard API (#204140)](#204140) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Nick Peihl","email":"nick.peihl@elastic.co"},"sourceCommit":{"committedDate":"2024-12-19T20:24:49Z","message":"[Dashboards] Add getSerializedState method to Dashboard API (#204140)\n\nAdds a `getSerializedState` method to the Dashboard API.","sha":"d7280a1380d66107a6818b1b84358c1762c20bb9","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Presentation","release_note:skip","v9.0.0","backport:prev-minor","v8.18.0"],"number":204140,"url":"https://github.com/elastic/kibana/pull/204140","mergeCommit":{"message":"[Dashboards] Add getSerializedState method to Dashboard API (#204140)\n\nAdds a `getSerializedState` method to the Dashboard API.","sha":"d7280a1380d66107a6818b1b84358c1762c20bb9"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204140","number":204140,"mergeCommit":{"message":"[Dashboards] Add getSerializedState method to Dashboard API (#204140)\n\nAdds a `getSerializedState` method to the Dashboard API.","sha":"d7280a1380d66107a6818b1b84358c1762c20bb9"}},{"branch":"8.x","label":"v8.18.0","labelRegex":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
…204140) Adds a `getSerializedState` method to the Dashboard API.
…204140) Adds a `getSerializedState` method to the Dashboard API.
…204140) Adds a `getSerializedState` method to the Dashboard API.
Summary
Adds a
getSerializedStatemethod to the Dashboard API.This can be used to retrieve a serialized form of the Dashboard that can be used with the Dashboard HTTP API. The "Export" flyout is a possible future consumer of this method.
Checklist
Check the PR satisfies following conditions.
Reviewers should verify this PR satisfies this list as well.
release_note:breakinglabel should be applied in these situations.release_note:*label is applied per the guidelinesIdentify risks
Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss.
Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging.