Skip to content

Commit

Permalink
Set expanded panel to new ID on link/unlink
Browse files Browse the repository at this point in the history
  • Loading branch information
cqliu1 committed Feb 7, 2023
1 parent 705ba7b commit 122fa13
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
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

0 comments on commit 122fa13

Please sign in to comment.