make empty dashboard experience a bit better
CodeQL checks / Detect whether code changed (push) Has been cancelled Details
CodeQL checks / Analyze (actions) (push) Has been cancelled Details
CodeQL checks / Analyze (go) (push) Has been cancelled Details
CodeQL checks / Analyze (javascript) (push) Has been cancelled Details

This commit is contained in:
oscarkilhed 2025-10-03 09:29:16 +02:00
parent 411b218f68
commit 3b8f221f23
2 changed files with 20 additions and 4 deletions

View File

@ -97,9 +97,15 @@ export function DashboardAddPanelPane({ editPane }: Props) {
},
]);
// This defaults to open, but should probably not be open if there is a current datasource.
// FIXME [HACK] it was set as false for fast development purposes
const [isDsPickerOpen, setIsDsPickerOpen] = useState(false);
// Open datasource picker if no datasource is selected
const [isDsPickerOpen, setIsDsPickerOpen] = useState(!currentDatasource);
// Update datasource picker state when currentDatasource changes
useEffect(() => {
if (!currentDatasource && !isDsPickerOpen) {
setIsDsPickerOpen(true);
}
}, [currentDatasource, isDsPickerOpen]);
const styles = useStyles2(getStyles);
const clearButton = useStyles2(clearButtonStyles);

View File

@ -1,5 +1,5 @@
import { css } from '@emotion/css';
import type { DragEvent as ReactDragEvent } from 'react';
import { useEffect, type DragEvent as ReactDragEvent } from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { selectors } from '@grafana/e2e-selectors';
@ -63,6 +63,16 @@ const DashboardEmpty = ({ dashboard, canCreate }: Props) => {
const isProvisioned = dashboard instanceof DashboardScene && dashboard.isManagedRepository();
// Automatically open the add panel pane when DashboardEmpty is rendered for DashboardScene
useEffect(() => {
if (dashboard instanceof DashboardScene && canCreate && !isReadOnlyRepo) {
// Only open if not already adding and dashboard is editable
if (!dashboard.state.editPane.state.isAdding && dashboard.state.editable) {
dashboard.state.editPane.setState({ isAdding: true });
}
}
}, [dashboard, canCreate, isReadOnlyRepo]);
const onDragOver = (e: ReactDragEvent<HTMLDivElement>) => {
if (!(dashboard instanceof DashboardScene)) {
return;