From d8eca7240aae4f03cefb0e85839c0292424112b8 Mon Sep 17 00:00:00 2001 From: Nar Saynorath Date: Wed, 20 Nov 2024 14:59:45 -0500 Subject: [PATCH 01/11] ref(dashboards): Move widget type to param This modal is coupled strongly with discover saved queries. Moving this up to a param so I could integrate it properly with Explore --- static/app/views/discover/queryList.tsx | 17 ++++++++++++++++- .../app/views/discover/savedQuery/index.tsx | 11 ++++++++++- static/app/views/discover/utils.tsx | 19 ++++++++----------- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/static/app/views/discover/queryList.tsx b/static/app/views/discover/queryList.tsx index 591e7f0a0feff9..1e82240a4038d8 100644 --- a/static/app/views/discover/queryList.tsx +++ b/static/app/views/discover/queryList.tsx @@ -26,6 +26,7 @@ import withApi from 'sentry/utils/withApi'; import {hasDatasetSelector} from 'sentry/views/dashboards/utils'; import { + getSavedQueryDataset, getSavedQueryWithDataset, handleCreateQuery, handleDeleteQuery, @@ -33,7 +34,11 @@ import { } from './savedQuery/utils'; import MiniGraph from './miniGraph'; import QueryCard from './querycard'; -import {getPrebuiltQueries, handleAddQueryToDashboard} from './utils'; +import { + getPrebuiltQueries, + handleAddQueryToDashboard, + SAVED_QUERY_DATASET_TO_WIDGET_TYPE, +} from './utils'; type Props = { api: Client; @@ -185,6 +190,11 @@ class QueryList extends Component { organization, yAxis: view?.yAxis, router, + widgetType: hasDatasetSelector(organization) + ? SAVED_QUERY_DATASET_TO_WIDGET_TYPE[ + getSavedQueryDataset(organization, location, newQuery) + ] + : undefined, }), }, { @@ -275,6 +285,11 @@ class QueryList extends Component { organization, yAxis: savedQuery?.yAxis ?? eventView.yAxis, router, + widgetType: hasDatasetSelector(organization) + ? SAVED_QUERY_DATASET_TO_WIDGET_TYPE[ + getSavedQueryDataset(organization, location, savedQuery) + ] + : undefined, }), }, ] diff --git a/static/app/views/discover/savedQuery/index.tsx b/static/app/views/discover/savedQuery/index.tsx index 405baa87747c86..abefd491ea00a0 100644 --- a/static/app/views/discover/savedQuery/index.tsx +++ b/static/app/views/discover/savedQuery/index.tsx @@ -36,12 +36,16 @@ import useOverlay from 'sentry/utils/useOverlay'; import withApi from 'sentry/utils/withApi'; import withProjects from 'sentry/utils/withProjects'; import {hasDatasetSelector} from 'sentry/views/dashboards/utils'; -import {handleAddQueryToDashboard} from 'sentry/views/discover/utils'; +import { + handleAddQueryToDashboard, + SAVED_QUERY_DATASET_TO_WIDGET_TYPE, +} from 'sentry/views/discover/utils'; import {DEFAULT_EVENT_VIEW} from '../data'; import { getDatasetFromLocationOrSavedQueryDataset, + getSavedQueryDataset, handleCreateQuery, handleDeleteQuery, handleResetHomepageQuery, @@ -449,6 +453,11 @@ class SavedQueryButtonGroup extends PureComponent { query: savedQuery, yAxis, router, + widgetType: hasDatasetSelector(organization) + ? SAVED_QUERY_DATASET_TO_WIDGET_TYPE[ + getSavedQueryDataset(organization, location, savedQuery) + ] + : undefined, }) } > diff --git a/static/app/views/discover/utils.tsx b/static/app/views/discover/utils.tsx index 98bad6311316b5..8fe153c9e615da 100644 --- a/static/app/views/discover/utils.tsx +++ b/static/app/views/discover/utils.tsx @@ -48,7 +48,6 @@ import {getTitle} from 'sentry/utils/events'; import {DISCOVER_FIELDS, FieldValueType, getFieldDefinition} from 'sentry/utils/fields'; import localStorage from 'sentry/utils/localStorage'; import {MutableSearch} from 'sentry/utils/tokenizeSearch'; -import {hasDatasetSelector} from 'sentry/views/dashboards/utils'; import { DashboardWidgetSource, @@ -58,7 +57,7 @@ import { } from '../dashboards/types'; import {transactionSummaryRouteWithQuery} from '../performance/transactionSummary/utils'; -import {displayModeToDisplayType, getSavedQueryDataset} from './savedQuery/utils'; +import {displayModeToDisplayType} from './savedQuery/utils'; import type {FieldValue, TableColumn} from './table/types'; import {FieldValueKind} from './table/types'; import {getAllViews, getTransactionViews, getWebVitalsViews} from './data'; @@ -688,12 +687,14 @@ export function handleAddQueryToDashboard({ organization, router, yAxis, + widgetType, }: { eventView: EventView; location: Location; organization: Organization; router: InjectedRouter; query?: NewQuery; + widgetType?: WidgetType; yAxis?: string | string[]; }) { const displayType = displayModeToDisplayType(eventView.display as DisplayModes); @@ -703,14 +704,13 @@ export function handleAddQueryToDashboard({ yAxis, }); - const dataset = getSavedQueryDataset(organization, location, query); - const {query: widgetAsQueryParams} = constructAddQueryToDashboardLink({ eventView, query, organization, yAxis, location, + widgetType, }); openAddToDashboardModal({ organization, @@ -738,9 +738,7 @@ export function handleAddQueryToDashboard({ displayType === DisplayType.TOP_N ? Number(eventView.topEvents) || TOP_N : undefined, - widgetType: hasDatasetSelector(organization) - ? SAVED_QUERY_DATASET_TO_WIDGET_TYPE[dataset] - : undefined, + widgetType, }, router, widgetAsQueryParams, @@ -792,11 +790,13 @@ export function constructAddQueryToDashboardLink({ organization, yAxis, location, + widgetType, }: { eventView: EventView; organization: Organization; location?: Location; query?: NewQuery; + widgetType?: WidgetType; yAxis?: string | string[]; }) { const displayType = displayModeToDisplayType(eventView.display as DisplayModes); @@ -806,7 +806,6 @@ export function constructAddQueryToDashboardLink({ displayType, yAxis, }); - const dataset = getSavedQueryDataset(organization, location, query); const defaultTitle = query?.name ?? (eventView.name !== 'All Events' ? eventView.name : undefined); @@ -823,9 +822,7 @@ export function constructAddQueryToDashboardLink({ defaultTableColumns: defaultTableFields, defaultTitle, displayType: displayType === DisplayType.TOP_N ? DisplayType.AREA : displayType, - dataset: hasDatasetSelector(organization) - ? SAVED_QUERY_DATASET_TO_WIDGET_TYPE[dataset] - : undefined, + dataset: widgetType, limit: displayType === DisplayType.TOP_N ? Number(eventView.topEvents) || TOP_N From 43fc9fd2d49cef0de237d13113125c93983eefdc Mon Sep 17 00:00:00 2001 From: Nar Saynorath Date: Wed, 20 Nov 2024 15:17:39 -0500 Subject: [PATCH 02/11] Fix missing call site --- static/app/views/discover/savedQuery/index.tsx | 5 +++++ static/app/views/discover/utils.tsx | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/static/app/views/discover/savedQuery/index.tsx b/static/app/views/discover/savedQuery/index.tsx index abefd491ea00a0..015477a301b5a1 100644 --- a/static/app/views/discover/savedQuery/index.tsx +++ b/static/app/views/discover/savedQuery/index.tsx @@ -577,6 +577,11 @@ class SavedQueryButtonGroup extends PureComponent { query: savedQuery, yAxis, router, + widgetType: hasDatasetSelector(organization) + ? SAVED_QUERY_DATASET_TO_WIDGET_TYPE[ + getSavedQueryDataset(organization, location, savedQuery) + ] + : undefined, }); }, }); diff --git a/static/app/views/discover/utils.tsx b/static/app/views/discover/utils.tsx index 8fe153c9e615da..76cdf83d1f93a5 100644 --- a/static/app/views/discover/utils.tsx +++ b/static/app/views/discover/utils.tsx @@ -693,8 +693,8 @@ export function handleAddQueryToDashboard({ location: Location; organization: Organization; router: InjectedRouter; + widgetType: WidgetType | undefined; query?: NewQuery; - widgetType?: WidgetType; yAxis?: string | string[]; }) { const displayType = displayModeToDisplayType(eventView.display as DisplayModes); From 372aa2c924917f6b588d20afda33db21668db613 Mon Sep 17 00:00:00 2001 From: Nar Saynorath Date: Wed, 20 Nov 2024 14:23:27 -0500 Subject: [PATCH 03/11] wip --- .../views/dashboards/datasetConfig/base.tsx | 1 + .../views/dashboards/datasetConfig/errors.tsx | 2 + .../dashboards/utils/getWidgetExploreUrl.tsx | 8 +- .../dashboards/widgetCard/widgetQueries.tsx | 1 + .../app/views/discover/savedQuery/index.tsx | 2 + static/app/views/explore/charts/index.tsx | 4 + .../components/addToDashboardButton.tsx | 82 +++++++++++++++++++ 7 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 static/app/views/explore/components/addToDashboardButton.tsx diff --git a/static/app/views/dashboards/datasetConfig/base.tsx b/static/app/views/dashboards/datasetConfig/base.tsx index 7d9f136cbaae86..3143170f1c2cc5 100644 --- a/static/app/views/dashboards/datasetConfig/base.tsx +++ b/static/app/views/dashboards/datasetConfig/base.tsx @@ -236,6 +236,7 @@ export function getDatasetConfig( | typeof ErrorsAndTransactionsConfig | typeof ErrorsConfig | typeof TransactionsConfig { + console.log('getDatasetConfig', widgetType); switch (widgetType) { case WidgetType.ISSUE: return IssuesConfig; diff --git a/static/app/views/dashboards/datasetConfig/errors.tsx b/static/app/views/dashboards/datasetConfig/errors.tsx index de9240da1ef9e6..bb256b5c23cb0e 100644 --- a/static/app/views/dashboards/datasetConfig/errors.tsx +++ b/static/app/views/dashboards/datasetConfig/errors.tsx @@ -200,6 +200,7 @@ function getErrorsSeriesRequest( referrer?: string, _mepSetting?: MEPState | null ) { + console.log('errors dataset', widget); const requestData = getSeriesRequestData( widget, queryIndex, @@ -208,5 +209,6 @@ function getErrorsSeriesRequest( DiscoverDatasets.ERRORS, referrer ); + console.log('request data', requestData); return doEventsRequest(api, requestData); } diff --git a/static/app/views/dashboards/utils/getWidgetExploreUrl.tsx b/static/app/views/dashboards/utils/getWidgetExploreUrl.tsx index bca2e043bddf6f..7430b332c21eaa 100644 --- a/static/app/views/dashboards/utils/getWidgetExploreUrl.tsx +++ b/static/app/views/dashboards/utils/getWidgetExploreUrl.tsx @@ -4,10 +4,7 @@ import * as qs from 'query-string'; import type {PageFilters} from 'sentry/types/core'; import type {Organization} from 'sentry/types/organization'; import {defined} from 'sentry/utils'; -import { - getAggregateAlias, - isAggregateFieldOrEquation, -} from 'sentry/utils/discover/fields'; +import {getAggregateAlias} from 'sentry/utils/discover/fields'; import {DisplayType, type Widget} from 'sentry/views/dashboards/types'; import { eventViewFromWidget, @@ -91,7 +88,8 @@ export function getWidgetExploreUrl( mode: exploreMode, visualize: JSON.stringify(pick(locationQueryParams, ['yAxes', 'chartType'])), - groupBy: fields?.filter(field => !isAggregateFieldOrEquation(field)), + // TODO(nar): Support passing along groupBy + // groupBy: fields?.filter(field => !isAggregateFieldOrEquation(field)), field: locationQueryParams.field, query: locationQueryParams.query, sort: diff --git a/static/app/views/dashboards/widgetCard/widgetQueries.tsx b/static/app/views/dashboards/widgetCard/widgetQueries.tsx index 8348c90df0947c..f40d47e66226fa 100644 --- a/static/app/views/dashboards/widgetCard/widgetQueries.tsx +++ b/static/app/views/dashboards/widgetCard/widgetQueries.tsx @@ -237,6 +237,7 @@ function WidgetQueries({ } }; + console.log('widget queries', widget); return ( {OnDemandControlContext => ( diff --git a/static/app/views/discover/savedQuery/index.tsx b/static/app/views/discover/savedQuery/index.tsx index 015477a301b5a1..fed0e49aa092dd 100644 --- a/static/app/views/discover/savedQuery/index.tsx +++ b/static/app/views/discover/savedQuery/index.tsx @@ -440,6 +440,7 @@ class SavedQueryButtonGroup extends PureComponent { renderButtonAddToDashboard() { const {organization, eventView, savedQuery, yAxis, router, location} = this.props; + console.log(eventView); return (