Skip to content

Commit 3d74bac

Browse files
authored
Support duplicate visualization in dashboard (opensearch-project#400)
Signed-off-by: Joshua Li <joshuali925@gmail.com>
1 parent 78347d9 commit 3d74bac

File tree

1 file changed

+22
-46
lines changed

1 file changed

+22
-46
lines changed

public/components/custom_panels/custom_panel_view_so.tsx

+22-46
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
/* // eslint-disable no-console */
66
/* eslint-disable react-hooks/exhaustive-deps */
77

8-
import { useCallback } from 'react';
98
import {
109
EuiBreadcrumb,
1110
EuiButton,
@@ -27,60 +26,34 @@ import {
2726
OnTimeChangeProps,
2827
ShortDate,
2928
} from '@elastic/eui';
30-
import { last } from 'lodash';
31-
import React, { useEffect, useState } from 'react';
3229
import { DurationRange } from '@elastic/eui/src/components/date_picker/types';
30+
import { last } from 'lodash';
3331
import moment from 'moment';
34-
import _ from 'lodash';
32+
import React, { useCallback, useEffect, useState } from 'react';
3533
import { useDispatch, useSelector } from 'react-redux';
36-
import { useRef } from 'react';
37-
import DSLService from '../../services/requests/dsl';
38-
import { CoreStart, SimpleSavedObject } from '../../../../../src/core/public';
39-
import { EmptyPanelView } from './panel_modules/empty_panel';
40-
import {
41-
CREATE_PANEL_MESSAGE,
42-
CUSTOM_PANELS_API_PREFIX,
43-
CUSTOM_PANELS_SAVED_OBJECT_TYPE,
44-
} from '../../../common/constants/custom_panels';
45-
import { CustomPanelType, PanelType } from '../../../common/types/custom_panels';
46-
import { PanelGridSO } from './panel_modules/panel_grid/panel_grid_so';
47-
34+
import { CoreStart } from '../../../../../src/core/public';
35+
import { CREATE_PANEL_MESSAGE } from '../../../common/constants/custom_panels';
36+
import { UI_DATE_FORMAT } from '../../../common/constants/shared';
37+
import { CustomPanelType } from '../../../common/types/custom_panels';
38+
import { uiSettingsService } from '../../../common/utils';
39+
import { coreRefs } from '../../framework/core_refs';
40+
import { PPLReferenceFlyout } from '../common/helpers';
41+
import { DeleteModal } from '../common/helpers/delete_modal';
42+
import { Autocomplete } from '../common/search/autocomplete';
43+
import { onItemSelect, parseGetSuggestions } from '../common/search/autocomplete_logic';
44+
import { addVisualizationPanel } from './helpers/add_visualization_helper';
45+
import { AddVisualizationPopover } from './helpers/add_visualization_popover';
4846
import { getCustomModal } from './helpers/modal_containers';
49-
import PPLService from '../../services/requests/ppl';
5047
import {
51-
isDateValid,
5248
convertDateTime,
49+
isDateValid,
5350
isPPLFilterValid,
54-
isNameValid,
5551
prependRecentlyUsedRange,
5652
} from './helpers/utils';
57-
import { UI_DATE_FORMAT } from '../../../common/constants/shared';
58-
import { VisaulizationFlyout } from './panel_modules/visualization_flyout';
59-
import { uiSettingsService } from '../../../common/utils';
60-
import { PPLReferenceFlyout } from '../common/helpers';
61-
import { Autocomplete } from '../common/search/autocomplete';
62-
import {
63-
parseGetSuggestions,
64-
onItemSelect,
65-
parseForIndices,
66-
} from '../common/search/autocomplete_logic';
67-
import { AddVisualizationPopover } from './helpers/add_visualization_popover';
68-
import { DeleteModal } from '../common/helpers/delete_modal';
53+
import { EmptyPanelView } from './panel_modules/empty_panel';
54+
import { PanelGridSO } from './panel_modules/panel_grid/panel_grid_so';
6955
import { VisaulizationFlyoutSO } from './panel_modules/visualization_flyout/visualization_flyout_so';
70-
import { addVisualizationPanel } from './helpers/add_visualization_helper';
71-
import {
72-
clonePanel,
73-
createPanel,
74-
fetchPanel,
75-
newPanelTemplate,
76-
selectPanel,
77-
setPanel,
78-
setPanelEt,
79-
setPanelId,
80-
setPanelSt,
81-
updatePanel,
82-
} from './redux/panel_slice';
83-
import { coreRefs } from '../../framework/core_refs';
56+
import { clonePanel, fetchPanel, selectPanel, setPanel, updatePanel } from './redux/panel_slice';
8457

8558
/*
8659
* "CustomPanelsView" module used to render an Observability Dashboard
@@ -377,6 +350,7 @@ export const CustomPanelViewSO = (props: CustomPanelViewProps) => {
377350
};
378351

379352
const cloneVisualization = (visualzationTitle: string, savedVisualizationId: string) => {
353+
addVisualizationToCurrentPanel({ savedVisualizationId });
380354
// http
381355
// .post(`${CUSTOM_PANELS_API_PREFIX}/visualizations`, {
382356
// body: JSON.stringify({
@@ -550,7 +524,9 @@ export const CustomPanelViewSO = (props: CustomPanelViewProps) => {
550524
// Toggle input type (disabled or not disabled)
551525
// Disabled when there no visualizations in panels or when the panel is in edit mode
552526
useEffect(() => {
553-
!loading && checkDisabledInputs();
527+
if (!loading) {
528+
checkDisabledInputs();
529+
}
554530
}, [isEditing, loading]);
555531

556532
// Build base query with all of the indices included in the current visualizations

0 commit comments

Comments
 (0)