Skip to content

Commit adacf9d

Browse files
committed
Add visualization (opensearch-project#4257)
Add and save visualization to dashboard Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
1 parent 75e307a commit adacf9d

10 files changed

+225
-111
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@
171171
"dns-sync": "^0.2.1",
172172
"elastic-apm-node": "^3.43.0",
173173
"elasticsearch": "^16.7.0",
174-
"http-aws-es": "npm:@zhongnansu/http-aws-es@6.0.1",
175174
"execa": "^4.0.2",
176175
"expiry-js": "0.1.7",
177176
"fast-deep-equal": "^3.1.1",
@@ -182,6 +181,7 @@
182181
"globby": "^11.1.0",
183182
"handlebars": "4.7.7",
184183
"hjson": "3.2.1",
184+
"http-aws-es": "npm:@zhongnansu/http-aws-es@6.0.1",
185185
"http-proxy-agent": "^2.1.0",
186186
"https-proxy-agent": "^5.0.0",
187187
"inline-style": "^2.0.0",
@@ -290,6 +290,7 @@
290290
"@types/has-ansi": "^3.0.0",
291291
"@types/history": "^4.7.3",
292292
"@types/hjson": "^2.4.2",
293+
"@types/http-aws-es": "6.0.2",
293294
"@types/jest": "^27.4.0",
294295
"@types/joi": "^13.4.2",
295296
"@types/jquery": "^3.3.31",
@@ -342,7 +343,6 @@
342343
"@types/zen-observable": "^0.8.0",
343344
"@typescript-eslint/eslint-plugin": "^3.10.0",
344345
"@typescript-eslint/parser": "^3.10.0",
345-
"@types/http-aws-es": "6.0.2",
346346
"angular-aria": "^1.8.0",
347347
"angular-mocks": "^1.8.2",
348348
"angular-recursion": "^1.0.5",

src/plugins/dashboard/public/application/components/dashboard_top_nav.tsx

+42-21
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import { uniqBy } from 'lodash';
67
import React, { memo, useState, useEffect } from 'react';
7-
import { Filter } from 'src/plugins/data/public';
8+
import { Filter, IndexPattern } from 'src/plugins/data/public';
89
import { useCallback } from 'react';
910
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
1011
import { getTopNavConfig } from '../top_nav/get_top_nav_config';
11-
import {
12-
DashboardAppStateContainer,
13-
DashboardAppState,
14-
DashboardServices,
15-
NavAction,
16-
} from '../../types';
12+
import { DashboardAppStateContainer, DashboardAppState, DashboardServices } from '../../types';
1713
import { getNavActions } from '../utils/get_nav_actions';
1814
import { DashboardContainer } from '../embeddable';
15+
import { isErrorEmbeddable } from '../../embeddable_plugin';
1916

2017
interface DashboardTopNavProps {
2118
isChromeVisible: boolean;
@@ -45,12 +42,22 @@ const TopNav = ({
4542
const [filters, setFilters] = useState<Filter[]>([]);
4643
const [topNavMenu, setTopNavMenu] = useState<any>();
4744
const [isFullScreenMode, setIsFullScreenMode] = useState<any>();
45+
const [indexPatterns, setIndexPatterns] = useState<IndexPattern[]>();
4846

4947
const { services } = useOpenSearchDashboards<DashboardServices>();
5048
const { TopNavMenu } = services.navigation.ui;
5149
const { data, dashboardConfig, setHeaderActionMenu } = services;
5250
const { query: queryService } = data;
5351

52+
const handleRefresh = useCallback(
53+
(_payload: any, isUpdate?: boolean) => {
54+
if (!isUpdate && dashboardContainer) {
55+
dashboardContainer.reload();
56+
}
57+
},
58+
[dashboardContainer]
59+
);
60+
5461
// TODO: this should base on URL
5562
const isEmbeddedExternally = false;
5663

@@ -97,6 +104,33 @@ const TopNav = ({
97104
setIsFullScreenMode(currentAppState?.fullScreenMode);
98105
}, [currentAppState, services]);
99106

107+
useEffect(() => {
108+
const asyncSetIndexPattern = async () => {
109+
if (dashboardContainer) {
110+
let panelIndexPatterns: IndexPattern[] = [];
111+
dashboardContainer.getChildIds().forEach((id) => {
112+
const embeddableInstance = dashboardContainer.getChild(id);
113+
if (isErrorEmbeddable(embeddableInstance)) return;
114+
const embeddableIndexPatterns = (embeddableInstance.getOutput() as any).indexPatterns;
115+
if (!embeddableIndexPatterns) return;
116+
panelIndexPatterns.push(...embeddableIndexPatterns);
117+
});
118+
panelIndexPatterns = uniqBy(panelIndexPatterns, 'id');
119+
120+
if (panelIndexPatterns.length > 0) {
121+
setIndexPatterns(panelIndexPatterns);
122+
} else {
123+
const defaultIndex = await services.data.indexPatterns.getDefault();
124+
if (defaultIndex) {
125+
setIndexPatterns([defaultIndex]);
126+
}
127+
}
128+
}
129+
};
130+
131+
asyncSetIndexPattern();
132+
}, [dashboardContainer, stateContainer, currentAppState, services.data.indexPatterns]);
133+
100134
const shouldShowFilterBar = (forceHide: boolean): boolean =>
101135
!forceHide && (filters!.length > 0 || !currentAppState?.fullScreenMode);
102136

@@ -111,19 +145,6 @@ const TopNav = ({
111145
const showFilterBar = shouldShowFilterBar(forceHideFilterBar);
112146
const showSearchBar = showQueryBar || showFilterBar;
113147

114-
// TODO: implement handleRefresh
115-
const handleRefresh = useCallback((_payload: any, isUpdate?: boolean) => {
116-
/* if (isUpdate === false) {
117-
// The user can still request a reload in the query bar, even if the
118-
// query is the same, and in that case, we have to explicitly ask for
119-
// a reload, since no state changes will cause it.
120-
lastReloadRequestTime = new Date().getTime();
121-
const changes = getChangesFromAppStateForContainerState();
122-
if (changes && dashboardContainer) {
123-
dashboardContainer.updateInput(changes);
124-
}*/
125-
}, []);
126-
127148
return isChromeVisible ? (
128149
<TopNavMenu
129150
appName={'dashboard'}
@@ -138,7 +159,7 @@ const TopNav = ({
138159
showDatePicker={showDatePicker}
139160
showFilterBar={showFilterBar}
140161
useDefaultBehaviors={true}
141-
indexPatterns={[]}
162+
indexPatterns={indexPatterns}
142163
showSaveQuery={services.dashboardCapabilities.saveQuery as boolean}
143164
savedQuery={undefined}
144165
onSavedQueryIdChange={() => {}}

src/plugins/dashboard/public/application/embeddable/dashboard_container.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export class DashboardContainer extends Container<InheritedChildInput, Dashboard
111111
public readonly type = DASHBOARD_CONTAINER_TYPE;
112112

113113
public renderEmpty?: undefined | (() => React.ReactNode);
114+
public getChangesFromAppStateForContainerState?: (containerInput: any) => any;
114115

115116
private embeddablePanel: EmbeddableStart['EmbeddablePanel'];
116117

src/plugins/dashboard/public/application/utils/dashboard_embeddable_editor.tsx

-44
This file was deleted.

src/plugins/dashboard/public/application/utils/get_nav_actions.tsx

-10
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,10 @@ export const getNavActions = (
7979
const appState = stateContainer.getState();
8080
navActions[TopNavIds.FULL_SCREEN] = () => {
8181
stateContainer.transitions.set('fullScreenMode', true);
82-
// updateNavBar();
8382
};
8483
navActions[TopNavIds.EXIT_EDIT_MODE] = () => onChangeViewMode(ViewMode.VIEW);
8584
navActions[TopNavIds.ENTER_EDIT_MODE] = () => onChangeViewMode(ViewMode.EDIT);
8685
navActions[TopNavIds.SAVE] = () => {
87-
console.log('inside save top nav!');
8886
const currentTitle = appState.title;
8987
const currentDescription = appState.description;
9088
const currentTimeRestore = appState.timeRestore;
@@ -362,12 +360,9 @@ export const getNavActions = (
362360
revertChangesAndExitEditMode();
363361
}
364362
});
365-
366-
// updateNavBar();
367363
}
368364

369365
async function save(saveOptions: SavedObjectSaveOpts) {
370-
console.log('in the save function!');
371366
const timefilter = queryService.timefilter.timefilter;
372367
try {
373368
const id = await saveDashboard(timefilter, stateContainer, savedDashboard, saveOptions);
@@ -381,11 +376,6 @@ export const getNavActions = (
381376
'data-test-subj': 'saveDashboardSuccess',
382377
});
383378

384-
const appPath = `${createDashboardEditUrl(id)}`;
385-
386-
// Manually insert a new url so the back button will open the saved visualization.
387-
history.replace(appPath);
388-
// setActiveUrl(appPath);
389379
chrome.docTitle.change(savedDashboard.lastSavedTitle);
390380
stateContainer.transitions.set('viewMode', ViewMode.VIEW);
391381
}

0 commit comments

Comments
 (0)