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)

* Fix non-workspace admin update observability:defaultDashboard

Signed-off-by: yubonluo <yubonluo@amazon.com>

* optimize the code

Signed-off-by: yubonluo <yubonluo@amazon.com>

* optimize the code

Signed-off-by: yubonluo <yubonluo@amazon.com>

* optimize the code

Signed-off-by: yubonluo <yubonluo@amazon.com>

---------

Signed-off-by: yubonluo <yubonluo@amazon.com>
  • Loading branch information
yubonluo authored Oct 22, 2024
1 parent 46ec7f2 commit f631248
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 { DataSourcePluginStart } from '../../../../src/plugins/data_source/public';
Expand All @@ -38,6 +39,7 @@ class CoreRefs {
public dataSource?: DataSourcePluginStart;
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 f631248

Please sign in to comment.