Skip to content

Commit

Permalink
[Workspace] Fix non-workspace admin update observability:defaultDashb…
Browse files Browse the repository at this point in the history
…oard (#2223) (#2224)

* Fix non-workspace admin update observability:defaultDashboard



* optimize the code



* optimize the code



* optimize the code



---------


(cherry picked from commit f631248)

Signed-off-by: yubonluo <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent c04db60 commit e3f33ec
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
50 changes: 33 additions & 17 deletions public/components/overview/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
EuiButtonEmpty,
EuiToolTip,
} from '@elastic/eui';
import React, { ReactNode, useEffect, useState } from 'react';
import React, { ReactNode, useEffect, useMemo, useState } from 'react';
import { HashRouter, Route, Switch } from 'react-router-dom';
import { useObservable } from 'react-use';
import { EMPTY } from 'rxjs';
Expand Down Expand Up @@ -52,6 +52,18 @@ export const Home = () => {
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const [showGetStarted, setShowGetStarted] = useState<boolean | null>(null); // Initial null state

const canUpdateUiSetting = useMemo(() => {
const capabilities = coreRefs.application?.capabilities;

// When workspace enabled, only workspace owner/OSD admin can update observability:defaultDashboard.
if (capabilities?.workspaces?.enabled) {
const isCurrentWorkspaceOwner = coreRefs.workspaces?.currentWorkspace$.getValue()?.owner;
const isDashboardAdmin = capabilities?.dashboards?.isDashboardAdmin !== false;
return isCurrentWorkspaceOwner || isDashboardAdmin;
}
return true;
}, [coreRefs.workspaces?.currentWorkspace$, coreRefs.application?.capabilities]);

ObsDashboardStateManager.showFlyout$.next(() => () => setIsFlyoutVisible(true));

const loadHomePage = () => {
Expand Down Expand Up @@ -95,14 +107,16 @@ export const Home = () => {
});
ObsDashboardStateManager.isDashboardSelected$.next(true);
} else {
setObservabilityDashboardsId(null);
ObsDashboardStateManager.dashboardState$.next({
startDate: '',
endDate: '',
dashboardTitle: '',
dashboardId: '',
});
ObsDashboardStateManager.isDashboardSelected$.next(false);
if (canUpdateUiSetting) {
setObservabilityDashboardsId(null);
ObsDashboardStateManager.dashboardState$.next({
startDate: '',
endDate: '',
dashboardTitle: '',
dashboardId: '',
});
ObsDashboardStateManager.isDashboardSelected$.next(false);
}
}
})
.catch((error) => {
Expand Down Expand Up @@ -316,14 +330,16 @@ export const Home = () => {
});
ObsDashboardStateManager.isDashboardSelected$.next(true);
} else {
setObservabilityDashboardsId(null);
ObsDashboardStateManager.dashboardState$.next({
startDate: '',
endDate: '',
dashboardTitle: '',
dashboardId: '',
});
ObsDashboardStateManager.isDashboardSelected$.next(false);
if (canUpdateUiSetting) {
setObservabilityDashboardsId(null);
ObsDashboardStateManager.dashboardState$.next({
startDate: '',
endDate: '',
dashboardTitle: '',
dashboardId: '',
});
ObsDashboardStateManager.isDashboardSelected$.next(false);
}
}
})
.catch((error) => {
Expand Down
2 changes: 2 additions & 0 deletions public/framework/core_refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
IToasts,
OverlayStart,
SavedObjectsClientContract,
WorkspacesStart,
} from '../../../../src/core/public';
import { DashboardStart } from '../../../../src/plugins/dashboard/public';
import { DataSourceStart } from '../../../../src/plugins/data/public/data_sources/datasource_services/types';
Expand Down Expand Up @@ -40,6 +41,7 @@ class CoreRefs {
public dataSources?: DataSourceStart;
public navigation?: NavigationPublicPluginStart;
public contentManagement?: ContentManagementPluginStart;
public workspaces?: WorkspacesStart;
private constructor() {
// ...
}
Expand Down
1 change: 1 addition & 0 deletions public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ export class ObservabilityPlugin
coreRefs.dataSource = startDeps.dataSource;
coreRefs.navigation = startDeps.navigation;
coreRefs.contentManagement = startDeps.contentManagement;
coreRefs.workspaces = core.workspaces;

// redirect trace URL based on new navigation
if (window.location.pathname.includes(observabilityTracesID)) {
Expand Down

0 comments on commit e3f33ec

Please sign in to comment.