The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/features/explore/ExploreToolbar.tsx

363 lines
13 KiB

import { css, cx } from '@emotion/css';
import { pick } from 'lodash';
import React, { RefObject, useMemo } from 'react';
import { shallowEqual } from 'react-redux';
import { DataSourceInstanceSettings, RawTimeRange, GrafanaTheme2 } from '@grafana/data';
Explore: Content Outline (#74536) * Add images * Basic button functionality; TODO placeholders for dispatching contentOutlineToggle and rendering content outline component * Basic content outline container * Content outline toggles * Remove icon files from explore * Scroll into view v1 * outline that reflect's explore's order of vizs * Update icon name * Add scrollId to PanelChrome; scrolling enabled for Table * Add queries icon * Improve scroll behavior in split view * Add wrapper so the sticky navigation doesn't scroll when on the bottom of the window * Fix the issue with logs gap; center icons * Memoize register and unregister functions; adjust content height * Make displayOrderId optional * Use Node API for finding position of panels in content outline; add tooltip * Dock content outline in expanded mode; at tooltip to toggle button * Handle content outline visibility from Explore and not redux; pass outlineItems as a prop * Fix ContentOutline test * Add interaction tracking * Add padding to fix test * Replace string literals with objects for styles * Update event reporting payloads * Custom content outline button; content outline container improvements * Add aria-expanded to content outline button in ExploreToolbar * Fix vertical and horizontal scrolling * Add aria-controls * Remove unneccessary css since ExploreToolbar is sticky * Update feature toggles; Fix typos * Make content outline button more prominent in split mode; add padding to content outline items; * Diego's UX updates * WIP: some scroll fixes * Fix test and type error * Add id to ContentOutline to differentiate in split mode * No default exports --------- Co-authored-by: Giordano Ricci <me@giordanoricci.com>
2 years ago
import { reportInteraction, config } from '@grafana/runtime';
import {
defaultIntervals,
PageToolbar,
RefreshPicker,
SetInterval,
ToolbarButton,
ButtonGroup,
useStyles2,
} from '@grafana/ui';
import { AppChromeUpdate } from 'app/core/components/AppChrome/AppChromeUpdate';
import { t, Trans } from 'app/core/internationalization';
import { createAndCopyShortLink } from 'app/core/utils/shortLinks';
import { DataSourcePicker } from 'app/features/datasources/components/picker/DataSourcePicker';
Correlations: Add an editor in Explore (#73315) * 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>
2 years ago
import { CORRELATION_EDITOR_POST_CONFIRM_ACTION } from 'app/types/explore';
import { StoreState, useDispatch, useSelector } from 'app/types/store';
import { contextSrv } from '../../core/core';
import { DashNavButton } from '../dashboard/components/DashNav/DashNavButton';
import { updateFiscalYearStartMonthForSession, updateTimeZoneForSession } from '../profile/state/reducers';
import { getFiscalYearStartMonth, getTimeZone } from '../profile/state/selectors';
import { ExploreTimeControls } from './ExploreTimeControls';
import { LiveTailButton } from './LiveTailButton';
import { ToolbarExtensionPoint } from './extensions/ToolbarExtensionPoint';
import { changeDatasource } from './state/datasource';
Correlations: Add an editor in Explore (#73315) * 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>
2 years ago
import { changeCorrelationHelperData } from './state/explorePane';
import {
splitClose,
splitOpen,
maximizePaneAction,
evenPaneResizeAction,
changeCorrelationEditorDetails,
} from './state/main';
import { cancelQueries, runQueries, selectIsWaitingForData } from './state/query';
Correlations: Add an editor in Explore (#73315) * 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>
2 years ago
import { isLeftPaneSelector, isSplit, selectCorrelationDetails, selectPanesEntries } from './state/selectors';
import { syncTimes, changeRefreshInterval } from './state/time';
import { LiveTailControls } from './useLiveTailControls';
Explore: Content Outline (#74536) * Add images * Basic button functionality; TODO placeholders for dispatching contentOutlineToggle and rendering content outline component * Basic content outline container * Content outline toggles * Remove icon files from explore * Scroll into view v1 * outline that reflect's explore's order of vizs * Update icon name * Add scrollId to PanelChrome; scrolling enabled for Table * Add queries icon * Improve scroll behavior in split view * Add wrapper so the sticky navigation doesn't scroll when on the bottom of the window * Fix the issue with logs gap; center icons * Memoize register and unregister functions; adjust content height * Make displayOrderId optional * Use Node API for finding position of panels in content outline; add tooltip * Dock content outline in expanded mode; at tooltip to toggle button * Handle content outline visibility from Explore and not redux; pass outlineItems as a prop * Fix ContentOutline test * Add interaction tracking * Add padding to fix test * Replace string literals with objects for styles * Update event reporting payloads * Custom content outline button; content outline container improvements * Add aria-expanded to content outline button in ExploreToolbar * Fix vertical and horizontal scrolling * Add aria-controls * Remove unneccessary css since ExploreToolbar is sticky * Update feature toggles; Fix typos * Make content outline button more prominent in split mode; add padding to content outline items; * Diego's UX updates * WIP: some scroll fixes * Fix test and type error * Add id to ContentOutline to differentiate in split mode * No default exports --------- Co-authored-by: Giordano Ricci <me@giordanoricci.com>
2 years ago
const getStyles = (theme: GrafanaTheme2, splitted: Boolean) => ({
rotateIcon: css({
'> div > svg': {
transform: 'rotate(180deg)',
},
}),
Explore: Content Outline (#74536) * Add images * Basic button functionality; TODO placeholders for dispatching contentOutlineToggle and rendering content outline component * Basic content outline container * Content outline toggles * Remove icon files from explore * Scroll into view v1 * outline that reflect's explore's order of vizs * Update icon name * Add scrollId to PanelChrome; scrolling enabled for Table * Add queries icon * Improve scroll behavior in split view * Add wrapper so the sticky navigation doesn't scroll when on the bottom of the window * Fix the issue with logs gap; center icons * Memoize register and unregister functions; adjust content height * Make displayOrderId optional * Use Node API for finding position of panels in content outline; add tooltip * Dock content outline in expanded mode; at tooltip to toggle button * Handle content outline visibility from Explore and not redux; pass outlineItems as a prop * Fix ContentOutline test * Add interaction tracking * Add padding to fix test * Replace string literals with objects for styles * Update event reporting payloads * Custom content outline button; content outline container improvements * Add aria-expanded to content outline button in ExploreToolbar * Fix vertical and horizontal scrolling * Add aria-controls * Remove unneccessary css since ExploreToolbar is sticky * Update feature toggles; Fix typos * Make content outline button more prominent in split mode; add padding to content outline items; * Diego's UX updates * WIP: some scroll fixes * Fix test and type error * Add id to ContentOutline to differentiate in split mode * No default exports --------- Co-authored-by: Giordano Ricci <me@giordanoricci.com>
2 years ago
toolbarButton: css({
display: 'flex',
justifyContent: 'center',
marginRight: theme.spacing(0.5),
width: splitted && theme.spacing(6),
}),
});
interface Props {
exploreId: string;
onChangeTime: (range: RawTimeRange, changedByScanner?: boolean) => void;
Explore: Content Outline (#74536) * Add images * Basic button functionality; TODO placeholders for dispatching contentOutlineToggle and rendering content outline component * Basic content outline container * Content outline toggles * Remove icon files from explore * Scroll into view v1 * outline that reflect's explore's order of vizs * Update icon name * Add scrollId to PanelChrome; scrolling enabled for Table * Add queries icon * Improve scroll behavior in split view * Add wrapper so the sticky navigation doesn't scroll when on the bottom of the window * Fix the issue with logs gap; center icons * Memoize register and unregister functions; adjust content height * Make displayOrderId optional * Use Node API for finding position of panels in content outline; add tooltip * Dock content outline in expanded mode; at tooltip to toggle button * Handle content outline visibility from Explore and not redux; pass outlineItems as a prop * Fix ContentOutline test * Add interaction tracking * Add padding to fix test * Replace string literals with objects for styles * Update event reporting payloads * Custom content outline button; content outline container improvements * Add aria-expanded to content outline button in ExploreToolbar * Fix vertical and horizontal scrolling * Add aria-controls * Remove unneccessary css since ExploreToolbar is sticky * Update feature toggles; Fix typos * Make content outline button more prominent in split mode; add padding to content outline items; * Diego's UX updates * WIP: some scroll fixes * Fix test and type error * Add id to ContentOutline to differentiate in split mode * No default exports --------- Co-authored-by: Giordano Ricci <me@giordanoricci.com>
2 years ago
onContentOutlineToogle: () => void;
isContentOutlineOpen: boolean;
topOfViewRef?: RefObject<HTMLDivElement>;
}
Explore: Content Outline (#74536) * Add images * Basic button functionality; TODO placeholders for dispatching contentOutlineToggle and rendering content outline component * Basic content outline container * Content outline toggles * Remove icon files from explore * Scroll into view v1 * outline that reflect's explore's order of vizs * Update icon name * Add scrollId to PanelChrome; scrolling enabled for Table * Add queries icon * Improve scroll behavior in split view * Add wrapper so the sticky navigation doesn't scroll when on the bottom of the window * Fix the issue with logs gap; center icons * Memoize register and unregister functions; adjust content height * Make displayOrderId optional * Use Node API for finding position of panels in content outline; add tooltip * Dock content outline in expanded mode; at tooltip to toggle button * Handle content outline visibility from Explore and not redux; pass outlineItems as a prop * Fix ContentOutline test * Add interaction tracking * Add padding to fix test * Replace string literals with objects for styles * Update event reporting payloads * Custom content outline button; content outline container improvements * Add aria-expanded to content outline button in ExploreToolbar * Fix vertical and horizontal scrolling * Add aria-controls * Remove unneccessary css since ExploreToolbar is sticky * Update feature toggles; Fix typos * Make content outline button more prominent in split mode; add padding to content outline items; * Diego's UX updates * WIP: some scroll fixes * Fix test and type error * Add id to ContentOutline to differentiate in split mode * No default exports --------- Co-authored-by: Giordano Ricci <me@giordanoricci.com>
2 years ago
export function ExploreToolbar({
exploreId,
topOfViewRef,
onChangeTime,
onContentOutlineToogle,
isContentOutlineOpen,
}: Props) {
const dispatch = useDispatch();
const splitted = useSelector(isSplit);
Explore: Content Outline (#74536) * Add images * Basic button functionality; TODO placeholders for dispatching contentOutlineToggle and rendering content outline component * Basic content outline container * Content outline toggles * Remove icon files from explore * Scroll into view v1 * outline that reflect's explore's order of vizs * Update icon name * Add scrollId to PanelChrome; scrolling enabled for Table * Add queries icon * Improve scroll behavior in split view * Add wrapper so the sticky navigation doesn't scroll when on the bottom of the window * Fix the issue with logs gap; center icons * Memoize register and unregister functions; adjust content height * Make displayOrderId optional * Use Node API for finding position of panels in content outline; add tooltip * Dock content outline in expanded mode; at tooltip to toggle button * Handle content outline visibility from Explore and not redux; pass outlineItems as a prop * Fix ContentOutline test * Add interaction tracking * Add padding to fix test * Replace string literals with objects for styles * Update event reporting payloads * Custom content outline button; content outline container improvements * Add aria-expanded to content outline button in ExploreToolbar * Fix vertical and horizontal scrolling * Add aria-controls * Remove unneccessary css since ExploreToolbar is sticky * Update feature toggles; Fix typos * Make content outline button more prominent in split mode; add padding to content outline items; * Diego's UX updates * WIP: some scroll fixes * Fix test and type error * Add id to ContentOutline to differentiate in split mode * No default exports --------- Co-authored-by: Giordano Ricci <me@giordanoricci.com>
2 years ago
const styles = useStyles2(getStyles, splitted);
const timeZone = useSelector((state: StoreState) => getTimeZone(state.user));
const fiscalYearStartMonth = useSelector((state: StoreState) => getFiscalYearStartMonth(state.user));
const { refreshInterval, datasourceInstance, range, isLive, isPaused, syncedTimes } = useSelector(
(state: StoreState) => ({
...pick(state.explore.panes[exploreId]!, 'refreshInterval', 'datasourceInstance', 'range', 'isLive', 'isPaused'),
syncedTimes: state.explore.syncedTimes,
}),
shallowEqual
);
const loading = useSelector(selectIsWaitingForData(exploreId));
const isLargerPane = useSelector((state: StoreState) => state.explore.largerExploreId === exploreId);
const showSmallTimePicker = useSelector((state) => splitted || state.explore.panes[exploreId]!.containerWidth < 1210);
const showSmallDataSourcePicker = useSelector(
(state) => state.explore.panes[exploreId]!.containerWidth < (splitted ? 700 : 800)
);
const panes = useSelector(selectPanesEntries);
Correlations: Add an editor in Explore (#73315) * 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>
2 years ago
const correlationDetails = useSelector(selectCorrelationDetails);
const isCorrelationsEditorMode = correlationDetails?.editorMode || false;
const isLeftPane = useSelector(isLeftPaneSelector(exploreId));
const shouldRotateSplitIcon = useMemo(
Correlations: Add an editor in Explore (#73315) * 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>
2 years ago
() => (isLeftPane && isLargerPane) || (!isLeftPane && !isLargerPane),
[isLeftPane, isLargerPane]
);
const refreshPickerLabel = loading
? t('explore.toolbar.refresh-picker-cancel', 'Cancel')
: t('explore.toolbar.refresh-picker-run', 'Run query');
const onCopyShortLink = () => {
createAndCopyShortLink(global.location.href);
reportInteraction('grafana_explore_shortened_link_clicked');
};
const onChangeDatasource = async (dsSettings: DataSourceInstanceSettings) => {
Correlations: Add an editor in Explore (#73315) * 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>
2 years ago
if (!isCorrelationsEditorMode) {
dispatch(changeDatasource(exploreId, dsSettings.uid, { importQueries: true }));
} else {
if (correlationDetails?.dirty) {
// prompt will handle datasource change if needed
dispatch(
changeCorrelationEditorDetails({
isExiting: true,
postConfirmAction: {
exploreId: exploreId,
action: CORRELATION_EDITOR_POST_CONFIRM_ACTION.CHANGE_DATASOURCE,
changeDatasourceUid: dsSettings.uid,
},
})
);
} else {
// if the left pane is changing, clear helper data for right pane
if (isLeftPane) {
panes.forEach((pane) => {
dispatch(
changeCorrelationHelperData({
exploreId: pane[0],
correlationEditorHelperData: undefined,
})
);
});
}
dispatch(changeDatasource(exploreId, dsSettings.uid, { importQueries: true }));
}
}
};
const onRunQuery = (loading = false) => {
if (loading) {
return dispatch(cancelQueries(exploreId));
} else {
return dispatch(runQueries({ exploreId }));
}
};
const onChangeTimeZone = (timezone: string) => dispatch(updateTimeZoneForSession(timezone));
const onOpenSplitView = () => {
dispatch(splitOpen());
reportInteraction('grafana_explore_split_view_opened', { origin: 'menu' });
};
const onCloseSplitView = () => {
Correlations: Add an editor in Explore (#73315) * 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>
2 years ago
if (isCorrelationsEditorMode) {
if (correlationDetails?.dirty) {
// if dirty, prompt
dispatch(
changeCorrelationEditorDetails({
isExiting: true,
postConfirmAction: {
exploreId: exploreId,
action: CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_PANE,
},
})
);
} else {
// otherwise, clear helper data and close
panes.forEach((pane) => {
dispatch(
changeCorrelationHelperData({
exploreId: pane[0],
correlationEditorHelperData: undefined,
})
);
});
dispatch(splitClose(exploreId));
reportInteraction('grafana_explore_split_view_closed');
}
} else {
dispatch(splitClose(exploreId));
reportInteraction('grafana_explore_split_view_closed');
}
};
const onClickResize = () => {
if (isLargerPane) {
dispatch(evenPaneResizeAction());
} else {
dispatch(maximizePaneAction({ exploreId }));
}
};
const onChangeTimeSync = () => {
dispatch(syncTimes(exploreId));
};
const onChangeFiscalYearStartMonth = (fiscalyearStartMonth: number) =>
dispatch(updateFiscalYearStartMonthForSession(fiscalyearStartMonth));
const onChangeRefreshInterval = (refreshInterval: string) => {
dispatch(changeRefreshInterval({ exploreId, refreshInterval }));
};
Correlations: Add an editor in Explore (#73315) * 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>
2 years ago
const navBarActions = [
<DashNavButton
key="share"
tooltip={t('explore.toolbar.copy-shortened-link', 'Copy shortened link')}
icon="share-alt"
onClick={onCopyShortLink}
aria-label={t('explore.toolbar.copy-shortened-link', 'Copy shortened link')}
/>,
<div style={{ flex: 1 }} key="spacer0" />,
];
return (
<div ref={topOfViewRef}>
{refreshInterval && <SetInterval func={onRunQuery} interval={refreshInterval} loading={loading} />}
<div ref={topOfViewRef}>
Correlations: Add an editor in Explore (#73315) * 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>
2 years ago
<AppChromeUpdate actions={navBarActions} />
</div>
<PageToolbar
aria-label={t('explore.toolbar.aria-label', 'Explore toolbar')}
leftItems={[
Explore: Content Outline (#74536) * Add images * Basic button functionality; TODO placeholders for dispatching contentOutlineToggle and rendering content outline component * Basic content outline container * Content outline toggles * Remove icon files from explore * Scroll into view v1 * outline that reflect's explore's order of vizs * Update icon name * Add scrollId to PanelChrome; scrolling enabled for Table * Add queries icon * Improve scroll behavior in split view * Add wrapper so the sticky navigation doesn't scroll when on the bottom of the window * Fix the issue with logs gap; center icons * Memoize register and unregister functions; adjust content height * Make displayOrderId optional * Use Node API for finding position of panels in content outline; add tooltip * Dock content outline in expanded mode; at tooltip to toggle button * Handle content outline visibility from Explore and not redux; pass outlineItems as a prop * Fix ContentOutline test * Add interaction tracking * Add padding to fix test * Replace string literals with objects for styles * Update event reporting payloads * Custom content outline button; content outline container improvements * Add aria-expanded to content outline button in ExploreToolbar * Fix vertical and horizontal scrolling * Add aria-controls * Remove unneccessary css since ExploreToolbar is sticky * Update feature toggles; Fix typos * Make content outline button more prominent in split mode; add padding to content outline items; * Diego's UX updates * WIP: some scroll fixes * Fix test and type error * Add id to ContentOutline to differentiate in split mode * No default exports --------- Co-authored-by: Giordano Ricci <me@giordanoricci.com>
2 years ago
config.featureToggles.exploreContentOutline && (
<ToolbarButton
key="content-outline"
variant="canvas"
tooltip="Content outline"
icon="list-ui-alt"
iconOnly={splitted}
onClick={onContentOutlineToogle}
aria-expanded={isContentOutlineOpen}
aria-controls={isContentOutlineOpen ? 'content-outline-container' : undefined}
className={styles.toolbarButton}
>
Outline
</ToolbarButton>
),
<DataSourcePicker
key={`${exploreId}-ds-picker`}
Correlations: Add an editor in Explore (#73315) * 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>
2 years ago
mixed={!isCorrelationsEditorMode}
onChange={onChangeDatasource}
current={datasourceInstance?.getRef()}
hideTextValue={showSmallDataSourcePicker}
width={showSmallDataSourcePicker ? 8 : undefined}
/>,
Explore: Content Outline (#74536) * Add images * Basic button functionality; TODO placeholders for dispatching contentOutlineToggle and rendering content outline component * Basic content outline container * Content outline toggles * Remove icon files from explore * Scroll into view v1 * outline that reflect's explore's order of vizs * Update icon name * Add scrollId to PanelChrome; scrolling enabled for Table * Add queries icon * Improve scroll behavior in split view * Add wrapper so the sticky navigation doesn't scroll when on the bottom of the window * Fix the issue with logs gap; center icons * Memoize register and unregister functions; adjust content height * Make displayOrderId optional * Use Node API for finding position of panels in content outline; add tooltip * Dock content outline in expanded mode; at tooltip to toggle button * Handle content outline visibility from Explore and not redux; pass outlineItems as a prop * Fix ContentOutline test * Add interaction tracking * Add padding to fix test * Replace string literals with objects for styles * Update event reporting payloads * Custom content outline button; content outline container improvements * Add aria-expanded to content outline button in ExploreToolbar * Fix vertical and horizontal scrolling * Add aria-controls * Remove unneccessary css since ExploreToolbar is sticky * Update feature toggles; Fix typos * Make content outline button more prominent in split mode; add padding to content outline items; * Diego's UX updates * WIP: some scroll fixes * Fix test and type error * Add id to ContentOutline to differentiate in split mode * No default exports --------- Co-authored-by: Giordano Ricci <me@giordanoricci.com>
2 years ago
].filter(Boolean)}
forceShowLeftItems
>
{[
!splitted ? (
<ToolbarButton
variant="canvas"
key="split"
tooltip={t('explore.toolbar.split-tooltip', 'Split the pane')}
onClick={onOpenSplitView}
icon="columns"
disabled={isLive}
>
<Trans i18nKey="explore.toolbar.split-title">Split</Trans>
</ToolbarButton>
) : (
<ButtonGroup key="split-controls">
<ToolbarButton
variant="canvas"
tooltip={
isLargerPane
? t('explore.toolbar.split-narrow', 'Narrow pane')
: t('explore.toolbar.split-widen', 'Widen pane')
}
onClick={onClickResize}
icon={isLargerPane ? 'gf-movepane-left' : 'gf-movepane-right'}
iconOnly={true}
className={cx(shouldRotateSplitIcon && styles.rotateIcon)}
/>
<ToolbarButton
tooltip={t('explore.toolbar.split-close-tooltip', 'Close split pane')}
onClick={onCloseSplitView}
icon="times"
variant="canvas"
>
<Trans i18nKey="explore.toolbar.split-close"> Close </Trans>
</ToolbarButton>
</ButtonGroup>
),
<ToolbarExtensionPoint
splitted={splitted}
key="toolbar-extension-point"
exploreId={exploreId}
timeZone={timeZone}
/>,
!isLive && (
<ExploreTimeControls
key="timeControls"
exploreId={exploreId}
range={range}
timeZone={timeZone}
fiscalYearStartMonth={fiscalYearStartMonth}
onChangeTime={onChangeTime}
splitted={splitted}
syncedTimes={syncedTimes}
onChangeTimeSync={onChangeTimeSync}
hideText={showSmallTimePicker}
onChangeTimeZone={onChangeTimeZone}
onChangeFiscalYearStartMonth={onChangeFiscalYearStartMonth}
/>
),
<RefreshPicker
key="refreshPicker"
onIntervalChanged={onChangeRefreshInterval}
value={refreshInterval}
isLoading={loading}
text={showSmallTimePicker ? undefined : refreshPickerLabel}
tooltip={showSmallTimePicker ? refreshPickerLabel : undefined}
intervals={contextSrv.getValidIntervals(defaultIntervals)}
isLive={isLive}
onRefresh={() => onRunQuery(loading)}
noIntervalPicker={isLive}
primary={true}
width={(showSmallTimePicker ? 35 : 108) + 'px'}
/>,
datasourceInstance?.meta.streaming && (
<LiveTailControls key="liveControls" exploreId={exploreId}>
{(c) => {
const controls = {
...c,
start: () => {
reportInteraction('grafana_explore_logs_live_tailing_clicked', {
datasourceType: datasourceInstance?.type,
});
c.start();
},
};
return (
<LiveTailButton
splitted={splitted}
isLive={isLive}
isPaused={isPaused}
start={controls.start}
pause={controls.pause}
resume={controls.resume}
stop={controls.stop}
/>
);
}}
</LiveTailControls>
),
].filter(Boolean)}
</PageToolbar>
</div>
);
}