mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Start adding correlations editor mode * Add selector for merge conflict resolution * Enable saving * Build out new corelation helper component * flesh out save with label/description, change color * Have breadcrumb exit correlation editor mode * Add extension property to show/hide, use it for correlations * Bring in feature toggle * Remove unnecessary param * Cleanup * Parse logs json * Work on correlation edit mode bar * Tinker with a top element for the editor mode * Handle various explore state changes with correlations editor mode * WIP - add unsaved changes modal * Have correlation bar always rendered, sometimes hidden * Add various prompt modals * Clear correlations data on mode bar unmount, only use not left pane changes to count as dirty * Move special logic to explore * Remove all shouldShow logic from plugin extensions * remove grafana data changes * WIP - clean up correlations state * Interpolate data before sending to onclick * Override outline button coloring to account for dark background * More cleanup, more color tweaking * Prettier formatting, change state to refer to editor * Fix tests * More state change tweaks * ensure correlation save ability, change correlation editor state vars * fix import * Remove independent selector for editorMode, work close pane into editor exit flow * Add change datasource post action * Clean up based on PR feedback, handle closing left panel with helper better * Remove breadcrumb additions, add section and better ID to cmd palette action * Interpolate query results if it is ran with a helper with vars * Pass the datasource query along with the correlate link to ensure the datasource unique ID requirement passes * Use different onmount function to capture state of panes at time of close instead of time of mount * Fix node graph’s datalink not working * Actually commit the fix to saving * Fix saving correlations with mixed datasource to use the first query correlation UID * Add tracking * Use query datasources in mixed scenario, move exit tracking to click handler * Add correlations to a place where both can be used in the correlations editor * Be more selective on when we await the datasource get * Fix CSS to use objects * Update betterer * Add test around new decorator functionality * Add tests for decorate with correlations * Some reorganization and a few tweaks based on feedback * Move dirty state change to state function and out of component * Change the verbiage around a little * Various suggestions from Gio Co-authored-by: Giordano Ricci <me@giordanoricci.com> * More small Gio-related tweaks * Tie helper data to datasource - clear it out when the datasource changes * Missed another Gio tweak * Fix linter error * Only clear helper data on left pane changes * Add height offset for correlation editor bar so it doesn’t scroll off page --------- Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com> Co-authored-by: Giordano Ricci <me@giordanoricci.com>
116 lines
3.6 KiB
TypeScript
116 lines
3.6 KiB
TypeScript
import { useRegisterActions, useKBar, Action, Priority } from 'kbar';
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import { config } from '@grafana/runtime';
|
|
import { contextSrv } from 'app/core/services/context_srv';
|
|
import { MIXED_DATASOURCE_NAME } from 'app/plugins/datasource/mixed/MixedDataSource';
|
|
import { AccessControlAction, useDispatch, useSelector } from 'app/types';
|
|
|
|
import { splitOpen, splitClose, changeCorrelationEditorDetails } from './state/main';
|
|
import { runQueries } from './state/query';
|
|
import { isSplit, selectPanes } from './state/selectors';
|
|
|
|
// FIXME: this should use the new IDs
|
|
export const ExploreActions = () => {
|
|
const [actions, setActions] = useState<Action[]>([]);
|
|
const { query } = useKBar();
|
|
const dispatch = useDispatch();
|
|
const panes = useSelector(selectPanes);
|
|
const splitted = useSelector(isSplit);
|
|
|
|
const canWriteCorrelations = contextSrv.hasPermission(AccessControlAction.DataSourcesWrite);
|
|
|
|
useEffect(() => {
|
|
const keys = Object.keys(panes);
|
|
const exploreSection = {
|
|
name: 'Explore',
|
|
priority: Priority.HIGH + 1,
|
|
};
|
|
|
|
const actionsArr: Action[] = [];
|
|
|
|
if (splitted) {
|
|
actionsArr.push({
|
|
id: 'explore/run-query-left',
|
|
name: 'Run query (left)',
|
|
keywords: 'query left',
|
|
perform: () => {
|
|
dispatch(runQueries({ exploreId: keys[0] }));
|
|
},
|
|
section: exploreSection,
|
|
});
|
|
if ([panes[1]]) {
|
|
// we should always have the right exploreId if split
|
|
actionsArr.push({
|
|
id: 'explore/run-query-right',
|
|
name: 'Run query (right)',
|
|
keywords: 'query right',
|
|
perform: () => {
|
|
dispatch(runQueries({ exploreId: keys[1] }));
|
|
},
|
|
section: exploreSection,
|
|
});
|
|
actionsArr.push({
|
|
id: 'explore/split-view-close-left',
|
|
name: 'Close split view left',
|
|
keywords: 'split',
|
|
perform: () => {
|
|
dispatch(splitClose(keys[0]));
|
|
},
|
|
section: exploreSection,
|
|
});
|
|
actionsArr.push({
|
|
id: 'explore/split-view-close-right',
|
|
name: 'Close split view right',
|
|
keywords: 'split',
|
|
perform: () => {
|
|
dispatch(splitClose(keys[1]));
|
|
},
|
|
section: exploreSection,
|
|
});
|
|
}
|
|
} else {
|
|
// command palette doesn't know what pane we're in, only show option if not split and no datasource is mixed
|
|
const hasMixed = Object.values(panes).some((pane) => {
|
|
return pane?.datasourceInstance?.uid === MIXED_DATASOURCE_NAME;
|
|
});
|
|
|
|
if (config.featureToggles.correlations && canWriteCorrelations && !hasMixed) {
|
|
actionsArr.push({
|
|
id: 'explore/correlations-editor',
|
|
name: 'Correlations editor',
|
|
perform: () => {
|
|
dispatch(changeCorrelationEditorDetails({ editorMode: true }));
|
|
dispatch(runQueries({ exploreId: keys[0] }));
|
|
},
|
|
section: exploreSection,
|
|
});
|
|
}
|
|
|
|
actionsArr.push({
|
|
id: 'explore/run-query',
|
|
name: 'Run query',
|
|
keywords: 'query',
|
|
perform: () => {
|
|
dispatch(runQueries({ exploreId: keys[0] }));
|
|
},
|
|
section: exploreSection,
|
|
});
|
|
actionsArr.push({
|
|
id: 'explore/split-view-open',
|
|
name: 'Open split view',
|
|
keywords: 'split',
|
|
perform: () => {
|
|
dispatch(splitOpen());
|
|
},
|
|
section: exploreSection,
|
|
});
|
|
}
|
|
setActions(actionsArr);
|
|
}, [panes, splitted, query, dispatch, canWriteCorrelations]);
|
|
|
|
useRegisterActions(!query ? [] : actions, [actions, query]);
|
|
|
|
return null;
|
|
};
|