-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(explore): Convert buttons into context menu
- Loading branch information
1 parent
4e8a6ba
commit 0abd945
Showing
6 changed files
with
238 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 0 additions & 97 deletions
97
static/app/views/explore/components/addToDashboardButton.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import {DropdownMenu} from 'sentry/components/dropdownMenu'; | ||
import {IconEllipsis} from 'sentry/icons'; | ||
import {t} from 'sentry/locale'; | ||
import useOrganization from 'sentry/utils/useOrganization'; | ||
import usePageFilters from 'sentry/utils/usePageFilters'; | ||
import useProjects from 'sentry/utils/useProjects'; | ||
import {Dataset} from 'sentry/views/alerts/rules/metric/types'; | ||
import {useAddToDashboard} from 'sentry/views/explore/hooks/useAddToDashboard'; | ||
import {getAlertsUrl} from 'sentry/views/insights/common/utils/getAlertsUrl'; | ||
|
||
function ChartContextMenu({ | ||
visualizeIndex, | ||
visualizeYAxes, | ||
query, | ||
interval, | ||
}: { | ||
interval: string; | ||
query: string; | ||
visualizeIndex: number; | ||
visualizeYAxes: string[]; | ||
}) { | ||
const {addToDashboard} = useAddToDashboard(); | ||
const organization = useOrganization(); | ||
|
||
const {projects} = useProjects(); | ||
const pageFilters = usePageFilters(); | ||
|
||
const project = | ||
projects.length === 1 | ||
? projects[0] | ||
: projects.find(p => p.id === `${pageFilters.selection.projects[0]}`); | ||
const singleProject = | ||
(pageFilters.selection.projects.length === 1 || projects.length === 1) && project; | ||
|
||
const alertsUrls = singleProject | ||
? visualizeYAxes.map(yAxis => ({ | ||
key: yAxis, | ||
label: yAxis, | ||
to: getAlertsUrl({ | ||
project, | ||
query, | ||
pageFilters: pageFilters.selection, | ||
aggregate: yAxis, | ||
orgSlug: organization.slug, | ||
dataset: Dataset.EVENTS_ANALYTICS_PLATFORM, | ||
interval, | ||
}), | ||
})) | ||
: undefined; | ||
|
||
if ( | ||
!organization.features.includes('alerts-eap') && | ||
!organization.features.includes('dashboards-eap') | ||
) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<DropdownMenu | ||
triggerProps={{ | ||
size: 'sm', | ||
borderless: true, | ||
showChevron: false, | ||
icon: <IconEllipsis />, | ||
}} | ||
position="bottom-end" | ||
items={[ | ||
...(organization.features.includes('alerts-eap') | ||
? [ | ||
{ | ||
key: 'create-alert', | ||
label: t('Create an alert for'), | ||
children: alertsUrls ?? [], | ||
tooltip: !singleProject | ||
? t('Cannot create an alert when multiple projects are selected') | ||
: undefined, | ||
disabled: !alertsUrls || alertsUrls.length === 0 || !singleProject, | ||
isSubmenu: true, | ||
}, | ||
] | ||
: []), | ||
...(organization.features.includes('dashboards-eap') | ||
? [ | ||
{ | ||
key: 'add-to-dashboard', | ||
label: t('Add to Dashboard'), | ||
onAction: () => addToDashboard(visualizeIndex), | ||
}, | ||
] | ||
: []), | ||
]} | ||
/> | ||
); | ||
} | ||
|
||
export default ChartContextMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.