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

[Workspace] Fix non-workspace admin update observability:defaultDashboard #2223

Merged
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
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 @@
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 @@
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]);

Check warning on line 65 in public/components/overview/home.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useMemo has unnecessary dependencies: 'coreRefs.application.capabilities' and 'coreRefs.workspaces.currentWorkspace$'. Either exclude them or remove the dependency array. Outer scope values like 'coreRefs.workspaces.currentWorkspace$' aren't valid dependencies because mutating them doesn't re-render the component

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

const loadHomePage = () => {
Expand Down Expand Up @@ -95,14 +107,16 @@
});
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 @@ -132,7 +146,7 @@

fetchShowCards();
loadDashboardState();
}, []);

Check warning on line 149 in public/components/overview/home.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'loadDashboardState'. Either include it or remove the dependency array

const renderHeaderButton = () => {
if (showGetStarted === null) {
Expand Down Expand Up @@ -316,14 +330,16 @@
});
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 @@ -354,7 +370,7 @@
]
);
loadDashboardsState();
}, [isObservabilityUseCase]);

Check warning on line 373 in public/components/overview/home.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'loadDashboardsState'. Either include it or remove the dependency array

return (
<div>
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
Loading