small tweaks
This commit is contained in:
@@ -62,22 +62,17 @@ function UnconfiguredPanelComp(props: PanelProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onUseSavedQuery = useCallback(async () => {
|
const onUseSavedQuery = useCallback(async () => {
|
||||||
if (!dashboard || !(dashboard instanceof DashboardScene)) {
|
|
||||||
throw new Error('DashboardScene not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!panel) {
|
|
||||||
throw new Error('Panel not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!queryLibraryEnabled) {
|
if (!queryLibraryEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!dashboard || !(dashboard instanceof DashboardScene) || !panel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
openQueryLibraryDrawer({
|
openQueryLibraryDrawer({
|
||||||
onSelectQuery: async (query: DataQuery) => {
|
onSelectQuery: async (query: DataQuery) => {
|
||||||
try {
|
try {
|
||||||
// Get or create the query runner for the panel BEFORE opening the editor
|
|
||||||
let queryRunner = getQueryRunnerFor(panel);
|
let queryRunner = getQueryRunnerFor(panel);
|
||||||
|
|
||||||
// If panel doesn't have a query runner yet, create one
|
// If panel doesn't have a query runner yet, create one
|
||||||
@@ -102,7 +97,6 @@ function UnconfiguredPanelComp(props: PanelProps) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure query has datasource set
|
|
||||||
const enrichedQuery = query.datasource
|
const enrichedQuery = query.datasource
|
||||||
? query
|
? query
|
||||||
: {
|
: {
|
||||||
@@ -110,8 +104,7 @@ function UnconfiguredPanelComp(props: PanelProps) {
|
|||||||
datasource: queryRunner.state.datasource || { uid: config.defaultDatasource },
|
datasource: queryRunner.state.datasource || { uid: config.defaultDatasource },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set the query in the panel BEFORE opening the editor
|
// Set the query in the panel
|
||||||
// The editor will pick up this query when it initializes
|
|
||||||
queryRunner.setState({ queries: [enrichedQuery] });
|
queryRunner.setState({ queries: [enrichedQuery] });
|
||||||
|
|
||||||
// Update datasource if needed
|
// Update datasource if needed
|
||||||
@@ -120,10 +113,8 @@ function UnconfiguredPanelComp(props: PanelProps) {
|
|||||||
queryRunner.setState({ datasource: { uid: dsSettings.uid, type: dsSettings.type } });
|
queryRunner.setState({ datasource: { uid: dsSettings.uid, type: dsSettings.type } });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now open the panel editor - it will pick up the query we just set
|
|
||||||
locationService.partial({ editPanel: props.id });
|
locationService.partial({ editPanel: props.id });
|
||||||
|
|
||||||
// Run the query after opening the editor
|
|
||||||
queryRunner.runQueries();
|
queryRunner.runQueries();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to set query from library:', error);
|
console.error('Failed to set query from library:', error);
|
||||||
@@ -154,18 +145,18 @@ function UnconfiguredPanelComp(props: PanelProps) {
|
|||||||
label={t('dashboard.new-panel.menu-open-panel-editor', 'Configure')}
|
label={t('dashboard.new-panel.menu-open-panel-editor', 'Configure')}
|
||||||
onClick={onConfigure}
|
onClick={onConfigure}
|
||||||
></Menu.Item>
|
></Menu.Item>
|
||||||
|
{queryLibraryEnabled && (
|
||||||
|
<Menu.Item
|
||||||
|
icon="book-open"
|
||||||
|
label={t('dashboard.new-panel.menu-use-saved-query', 'Use saved query')}
|
||||||
|
onClick={onUseSavedQuery}
|
||||||
|
></Menu.Item>
|
||||||
|
)}
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
icon="library-panel"
|
icon="library-panel"
|
||||||
label={t('dashboard.new-panel.menu-use-library-panel', 'Use library panel')}
|
label={t('dashboard.new-panel.menu-use-library-panel', 'Use library panel')}
|
||||||
onClick={onUseLibraryPanel}
|
onClick={onUseLibraryPanel}
|
||||||
></Menu.Item>
|
></Menu.Item>
|
||||||
{queryLibraryEnabled && (
|
|
||||||
<Menu.Item
|
|
||||||
icon="book-open"
|
|
||||||
label={t('dashboard.new-panel.use-saved-query', 'Use saved query')}
|
|
||||||
onClick={onUseSavedQuery}
|
|
||||||
></Menu.Item>
|
|
||||||
)}
|
|
||||||
</Menu>
|
</Menu>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user