Skip to content
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

[Dashboard] Retain maximized panel on link/unlink from library #150405

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,16 @@ export class AddToLibraryAction implements Action<AddToLibraryActionContext> {
type: embeddable.type,
explicitInput: { ...newInput },
};
dashboard.replacePanel(panelToReplace, newPanel, true);
const replacedPanelId = await dashboard.replacePanel(panelToReplace, newPanel, true);

const title = dashboardAddToLibraryActionStrings.getSuccessMessage(
embeddable.getTitle() ? `'${embeddable.getTitle()}'` : ''
);

if (dashboard.getExpandedPanelId() !== undefined) {
dashboard.setExpandedPanelId(undefined);
dashboard.setExpandedPanelId(replacedPanelId);
}

this.toastsService.addSuccess({
title,
'data-test-subj': 'addPanelToLibrarySuccess',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ export class UnlinkFromLibraryAction implements Action<UnlinkFromLibraryActionCo
type: embeddable.type,
explicitInput: { ...newInput, title: embeddable.getTitle() },
};
dashboard.replacePanel(panelToReplace, newPanel, true);
const replacedPanelId = await dashboard.replacePanel(panelToReplace, newPanel, true);

const title = dashboardUnlinkFromLibraryActionStrings.getSuccessMessage(
embeddable.getTitle() ? `'${embeddable.getTitle()}'` : ''
);

if (dashboard.getExpandedPanelId() !== undefined) {
dashboard.setExpandedPanelId(undefined);
dashboard.setExpandedPanelId(replacedPanelId);
}

this.toastsService.addSuccess({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,47 +46,52 @@ export async function replacePanel(
previousPanelState: DashboardPanelState<EmbeddableInput>,
newPanelState: Partial<PanelState>,
generateNewId?: boolean
) {
): Promise<string> {
let panels;
let panelId;

if (generateNewId) {
// replace panel can be called with generateNewId in order to totally destroy and recreate the embeddable
panelId = uuidv4();
panels = { ...this.input.panels };
delete panels[previousPanelState.explicitInput.id];
const newId = uuidv4();
panels[newId] = {
panels[panelId] = {
...previousPanelState,
...newPanelState,
gridData: {
...previousPanelState.gridData,
i: newId,
i: panelId,
},
explicitInput: {
...newPanelState.explicitInput,
id: newId,
id: panelId,
},
};
} else {
// Because the embeddable type can change, we have to operate at the container level here
panelId = previousPanelState.explicitInput.id;
panels = {
...this.input.panels,
[previousPanelState.explicitInput.id]: {
[panelId]: {
...previousPanelState,
...newPanelState,
gridData: {
...previousPanelState.gridData,
},
explicitInput: {
...newPanelState.explicitInput,
id: previousPanelState.explicitInput.id,
id: panelId,
},
},
};
}

return this.updateInput({
await this.updateInput({
panels,
lastReloadRequestTime: new Date().getTime(),
});

return panelId;
}

export function showPlaceholderUntil<TPlacementMethodArgs extends IPanelPlacementArgs>(
Expand Down