import {useMemo} from 'react';
import styled from '@emotion/styled';
import Tag from 'sentry/components/badge/tag';
import Panel from 'sentry/components/panels/panel';
import {ALL_ACCESS_PROJECTS} from 'sentry/constants/pageFilters';
import {
backend,
frontend,
mobile,
PlatformCategory,
serverless,
} from 'sentry/data/platformCategories';
import {IconClose} from 'sentry/icons/iconClose';
import {t} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import type {PageFilters} from 'sentry/types/core';
import type {Project} from 'sentry/types/project';
import {defined} from 'sentry/utils';
import useDismissAlert from 'sentry/utils/useDismissAlert';
import {useLocation} from 'sentry/utils/useLocation';
import useOrganization from 'sentry/utils/useOrganization';
import usePageFilters from 'sentry/utils/usePageFilters';
import useProjects from 'sentry/utils/useProjects';
import {
newExploreTarget,
type SuggestedQuery,
} from 'sentry/views/explore/contexts/pageParamsContext';
import {Mode} from 'sentry/views/explore/contexts/pageParamsContext/mode';
import {ChartType} from 'sentry/views/insights/common/components/chart';
import {ToolbarHeader, ToolbarHeaderButton, ToolbarLabel, ToolbarSection} from './styles';
interface ToolbarSuggestedQueriesProps {}
export function ToolbarSuggestedQueries(props: ToolbarSuggestedQueriesProps) {
const organization = useOrganization();
const {dismiss, isDismissed} = useDismissAlert({
key: `${organization.id}:metrics-empty-state-dismissed`,
expirationDays: 30,
});
if (isDismissed) {
return null;
}
return ;
}
interface ToolbarSuggestedQueriesInnerProps extends ToolbarSuggestedQueriesProps {
dismiss: () => void;
}
function ToolbarSuggestedQueriesInner({dismiss}: ToolbarSuggestedQueriesInnerProps) {
const {selection} = usePageFilters();
const {projects} = useProjects();
const suggestedQueries: SuggestedQuery[] = useMemo(() => {
const counters = {
[PlatformCategory.FRONTEND]: 0,
[PlatformCategory.MOBILE]: 0,
[PlatformCategory.BACKEND]: 0,
};
for (const project of getSelectedProjectsList(selection.projects, projects)) {
if (!defined(project.platform)) {
continue;
}
if (frontend.includes(project.platform)) {
counters[PlatformCategory.FRONTEND] += 1;
} else if (mobile.includes(project.platform)) {
counters[PlatformCategory.MOBILE] += 1;
} else if (backend.includes(project.platform)) {
counters[PlatformCategory.BACKEND] += 1;
} else if (serverless.includes(project.platform)) {
// consider serverless as a type of backend platform
counters[PlatformCategory.BACKEND] += 1;
}
}
const platforms = [
PlatformCategory.FRONTEND,
PlatformCategory.MOBILE,
PlatformCategory.BACKEND,
]
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
.filter(k => counters[k] > 0)
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
.sort((a, b) => counters[b] - counters[a]);
return getSuggestedQueries(platforms);
}, [selection, projects]);
return (
{t('Suggested Queries')}}
/>
{t("Feeling like a newb? Been there, done that. Here's a few to get you goin.")}