grafana/public/app/features/explore/AddToDashboard/index.tsx
Torkel Ödegaard 7181efd1cf
Explore: Allow users to save Explore queries to dashboards (#47083)
* Select: Expose AsyncSelectProps interface

* DashboardPicker: Add a generic DashboardPicker component

* Dashboard Service: improve types

* Explore: allow saving explore state in a new panel in an existing dashboard

* Handle saving provisioned dashboards error

* Improve test coverage

* simplify test setup

* Strip base path from url when redirecting to a dashboard

* Keep existing variables when saving to an existing dashboard

* group assertions in test

* SearchCard: handle undefined in meta.updated

* Change required error message

* Add to dashboard alternative

* Add to existing is working

* Add to dashboard form

* remove default add-panel when creating a dashboard from explore

* types cleanup

* remove unneeded BE change

* simplify selector

* Add explore2Dashboard feature toggle

* add tests

* Small refactor & add tests

* small DashboardPicker improvements

* use partial from lodash

* Better error handling

* improve tests & disable button when there are no queries

* rename addPanelToDashboard function

* remove localStorage item if opening tab fails

* UI touchups & tracking

* Fix tests & remove close reporting

* remove echologger debug

* fix adding a panel to an existing dashboard

* Enable explore2Dashboard by default and add docs

* Ensure each panel in dashboards has a valid ID

* force CI restart

Co-authored-by: Elfo404 <me@giordanoricci.com>
2022-04-12 13:26:07 +02:00

32 lines
937 B
TypeScript

import React, { useState } from 'react';
import { ExploreId } from 'app/types';
import { AddToDashboardModal } from './AddToDashboardModal';
import { ToolbarButton } from '@grafana/ui';
import { useSelector } from 'react-redux';
import { getExploreItemSelector } from '../state/selectors';
interface Props {
exploreId: ExploreId;
}
export const AddToDashboard = ({ exploreId }: Props) => {
const [isOpen, setIsOpen] = useState(false);
const selectExploreItem = getExploreItemSelector(exploreId);
const explorePaneHasQueries = !!useSelector(selectExploreItem)?.queries?.length;
return (
<>
<ToolbarButton
icon="apps"
onClick={() => setIsOpen(true)}
aria-label="Add to dashboard"
disabled={!explorePaneHasQueries}
>
Add to dashboard
</ToolbarButton>
{isOpen && <AddToDashboardModal onClose={() => setIsOpen(false)} exploreId={exploreId} />}
</>
);
};