-
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
[Dashboards] Add getSerializedState method to Dashboard API #204140
[Dashboards] Add getSerializedState method to Dashboard API #204140
Conversation
Pinging @elastic/kibana-presentation (Team:Presentation) |
@@ -171,6 +171,14 @@ export function getDashboardApi({ | |||
unifiedSearchManager.internalApi.controlGroupReload$, | |||
unifiedSearchManager.internalApi.panelsReload$ | |||
).pipe(debounceTime(0)), | |||
getSerializedState: async () => { |
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.
#203662 made getState sync so this method could now become sync as well.
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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});
@@ -102,7 +102,7 @@ export async function openSaveModal({ | |||
controlGroupReferences, | |||
panelReferences, | |||
saveOptions, | |||
currentState: dashboardStateToSave, | |||
dashboardState: dashboardStateToSave, |
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.
searchSourceReferences
is not passed to saveDashboardState
call
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
code review only
|
||
it('should return the current state attributes and references', async () => { | ||
const dashboardState = getSampleDashboardState(); | ||
const result = await getSerializedState({ |
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.
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":"[email protected]"},"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-->
Summary
Adds a
getSerializedState
method 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:breaking
label 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.