Skip to content

Commit

Permalink
Recover Panel View Legacy - Duplicate Action (#366)
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Fitzgibbons <[email protected]>
Co-authored-by: Peter Fitzgibbons <[email protected]>
  • Loading branch information
pjfitzgibbons and Peter Fitzgibbons authored Apr 17, 2023
1 parent 5034f44 commit 17b3f71
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions public/components/custom_panels/custom_panel_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ import { EmptyPanelView } from './panel_modules/empty_panel';
import {
CREATE_PANEL_MESSAGE,
CUSTOM_PANELS_API_PREFIX,
CUSTOM_PANELS_SAVED_OBJECT_TYPE,
} from '../../../common/constants/custom_panels';
import {
PanelType,
SavedVisualizationType,
VisualizationType,
VizContainerError,
Expand All @@ -64,6 +66,7 @@ import {
} from '../common/search/autocomplete_logic';
import { AddVisualizationPopover } from './helpers/add_visualization_popover';
import { DeleteModal } from '../common/helpers/delete_modal';
import { coreRefs } from '../../framework/core_refs';

/*
* "CustomPanelsView" module used to render an Operational Panel
Expand Down Expand Up @@ -142,6 +145,7 @@ export const CustomPanelView = (props: CustomPanelViewProps) => {
onAddClick,
} = props;

const [panel, setPanel] = useState();
const [openPanelName, setOpenPanelName] = useState('');
const [panelCreatedTime, setPanelCreatedTime] = useState('');
const [pplFilterValue, setPPLFilterValue] = useState('');
Expand Down Expand Up @@ -183,6 +187,7 @@ export const CustomPanelView = (props: CustomPanelViewProps) => {
return http
.get(`${CUSTOM_PANELS_API_PREFIX}/panels/${panelId}`)
.then((res) => {
setPanel(res.operationalPanel);
setOpenPanelName(res.operationalPanel.name);
setPanelCreatedTime(res.createdTimeMs);
setPPLFilterValue(res.operationalPanel.queryFilter.query);
Expand Down Expand Up @@ -269,9 +274,18 @@ export const CustomPanelView = (props: CustomPanelViewProps) => {
};

const onClone = async (newCustomPanelName: string) => {
cloneCustomPanel(newCustomPanelName, panelId).then((id: string) => {
window.location.assign(`${last(parentBreadcrumbs)!.href}${id}`);
});
const newPanel = {
...panel,
title: newCustomPanelName,
dateCreated: new Date().getTime(),
dateModified: new Date().getTime(),
} as PanelType;
const newSOPanel = await coreRefs.savedObjectsClient!.create(
CUSTOM_PANELS_SAVED_OBJECT_TYPE,
newPanel
);

window.location.assign(`${last(parentBreadcrumbs)!.href}${newSOPanel.id}`);
closeModal();
};

Expand Down

0 comments on commit 17b3f71

Please sign in to comment.