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 De-Angular] Add new/existing visualizations to dashboard #4257

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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@
"dns-sync": "^0.2.1",
"elastic-apm-node": "^3.43.0",
"elasticsearch": "^16.7.0",
"http-aws-es": "npm:@zhongnansu/[email protected]",
"execa": "^4.0.2",
"expiry-js": "0.1.7",
"fast-deep-equal": "^3.1.1",
Expand All @@ -181,6 +180,7 @@
"globby": "^11.1.0",
"handlebars": "4.7.7",
"hjson": "3.2.1",
"http-aws-es": "npm:@zhongnansu/[email protected]",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^5.0.0",
"inline-style": "^2.0.0",
Expand Down Expand Up @@ -287,6 +287,7 @@
"@types/has-ansi": "^3.0.0",
"@types/history": "^4.7.3",
"@types/hjson": "^2.4.2",
"@types/http-aws-es": "6.0.2",
"@types/jest": "^27.4.0",
"@types/joi": "^13.4.2",
"@types/jquery": "^3.3.31",
Expand Down Expand Up @@ -339,7 +340,6 @@
"@types/zen-observable": "^0.8.0",
"@typescript-eslint/eslint-plugin": "^3.10.0",
"@typescript-eslint/parser": "^3.10.0",
"@types/http-aws-es": "6.0.2",
"angular-aria": "^1.8.0",
"angular-mocks": "^1.8.2",
"angular-recursion": "^1.0.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { uniqBy } from 'lodash';
import React, { memo, useState, useEffect } from 'react';
import { Filter } from 'src/plugins/data/public';
import { Filter, IndexPattern } from 'src/plugins/data/public';
import { useCallback } from 'react';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
import { getTopNavConfig } from '../top_nav/get_top_nav_config';
import {
DashboardAppStateContainer,
DashboardAppState,
DashboardServices,
NavAction,
} from '../../types';
import { DashboardAppStateContainer, DashboardAppState, DashboardServices } from '../../types';
import { getNavActions } from '../utils/get_nav_actions';
import { DashboardContainer } from '../embeddable';
import { isErrorEmbeddable } from '../../embeddable_plugin';

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

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

const handleRefresh = useCallback(
(_payload: any, isUpdate?: boolean) => {
if (!isUpdate && dashboardContainer) {
dashboardContainer.reload();
}
},
[dashboardContainer]
);

// TODO: this should base on URL
const isEmbeddedExternally = false;

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

useEffect(() => {
const asyncSetIndexPattern = async () => {
if (dashboardContainer) {
let panelIndexPatterns: IndexPattern[] = [];
dashboardContainer.getChildIds().forEach((id) => {
const embeddableInstance = dashboardContainer.getChild(id);
if (isErrorEmbeddable(embeddableInstance)) return;
const embeddableIndexPatterns = (embeddableInstance.getOutput() as any).indexPatterns;
if (!embeddableIndexPatterns) return;
panelIndexPatterns.push(...embeddableIndexPatterns);
});
panelIndexPatterns = uniqBy(panelIndexPatterns, 'id');

if (panelIndexPatterns.length > 0) {
setIndexPatterns(panelIndexPatterns);
} else {
const defaultIndex = await services.data.indexPatterns.getDefault();
if (defaultIndex) {
setIndexPatterns([defaultIndex]);
}
}
}
};

asyncSetIndexPattern();
}, [dashboardContainer, stateContainer, currentAppState, services.data.indexPatterns]);

const shouldShowFilterBar = (forceHide: boolean): boolean =>
!forceHide && (filters!.length > 0 || !currentAppState?.fullScreenMode);

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

// TODO: implement handleRefresh
const handleRefresh = useCallback((_payload: any, isUpdate?: boolean) => {
/* if (isUpdate === false) {
// The user can still request a reload in the query bar, even if the
// query is the same, and in that case, we have to explicitly ask for
// a reload, since no state changes will cause it.
lastReloadRequestTime = new Date().getTime();
const changes = getChangesFromAppStateForContainerState();
if (changes && dashboardContainer) {
dashboardContainer.updateInput(changes);
}*/
}, []);

return isChromeVisible ? (
<TopNavMenu
appName={'dashboard'}
Expand All @@ -138,7 +159,7 @@ const TopNav = ({
showDatePicker={showDatePicker}
showFilterBar={showFilterBar}
useDefaultBehaviors={true}
indexPatterns={[]}
indexPatterns={indexPatterns}
showSaveQuery={services.dashboardCapabilities.saveQuery as boolean}
savedQuery={undefined}
onSavedQueryIdChange={() => {}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class DashboardContainer extends Container<InheritedChildInput, Dashboard
public readonly type = DASHBOARD_CONTAINER_TYPE;

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

private embeddablePanel: EmbeddableStart['EmbeddablePanel'];

Expand Down

This file was deleted.

10 changes: 0 additions & 10 deletions src/plugins/dashboard/public/application/utils/get_nav_actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,10 @@ export const getNavActions = (
const appState = stateContainer.getState();
navActions[TopNavIds.FULL_SCREEN] = () => {
stateContainer.transitions.set('fullScreenMode', true);
// updateNavBar();
};
navActions[TopNavIds.EXIT_EDIT_MODE] = () => onChangeViewMode(ViewMode.VIEW);
navActions[TopNavIds.ENTER_EDIT_MODE] = () => onChangeViewMode(ViewMode.EDIT);
navActions[TopNavIds.SAVE] = () => {
console.log('inside save top nav!');
const currentTitle = appState.title;
const currentDescription = appState.description;
const currentTimeRestore = appState.timeRestore;
Expand Down Expand Up @@ -362,12 +360,9 @@ export const getNavActions = (
revertChangesAndExitEditMode();
}
});

// updateNavBar();
}

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

const appPath = `${createDashboardEditUrl(id)}`;

// Manually insert a new url so the back button will open the saved visualization.
history.replace(appPath);
// setActiveUrl(appPath);
Comment on lines -384 to -388
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this behavior moved elsewhere? This is a vital piece of user experience.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea this is added under the TODO list that is part of URL navigations.

chrome.docTitle.change(savedDashboard.lastSavedTitle);
stateContainer.transitions.set('viewMode', ViewMode.VIEW);
}
Expand Down
Loading