Skip to content

fix(release-health): Convert project IDs to slugs #93053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion static/app/components/modals/widgetViewerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import {
} from 'sentry/views/dashboards/widgetCard/dashboardsMEPContext';
import type {GenericWidgetQueriesChildrenProps} from 'sentry/views/dashboards/widgetCard/genericWidgetQueries';
import IssueWidgetQueries from 'sentry/views/dashboards/widgetCard/issueWidgetQueries';
import type {ReleaseWidgetQueriesProps} from 'sentry/views/dashboards/widgetCard/releaseWidgetQueries';
import ReleaseWidgetQueries from 'sentry/views/dashboards/widgetCard/releaseWidgetQueries';
import {WidgetCardChartContainer} from 'sentry/views/dashboards/widgetCard/widgetCardChartContainer';
import WidgetQueries from 'sentry/views/dashboards/widgetCard/widgetQueries';
Expand Down Expand Up @@ -627,7 +628,7 @@ function WidgetViewerModal(props: Props) {
);
};

const renderReleaseTable: ReleaseWidgetQueries['props']['children'] = ({
const renderReleaseTable: ReleaseWidgetQueriesProps['children'] = ({
tableResults,
loading,
pageLinks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export const FIELD_TO_METRICS_EXPRESSION = {
'crash_free_rate(user)': SessionMetric.USER_CRASH_FREE_RATE,
'crash_rate(session)': SessionMetric.SESSION_CRASH_RATE,
'crash_rate(user)': SessionMetric.USER_CRASH_RATE,
project: 'project_id',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was implicitly converting the project field to project_id in the response but it's not really necessary. Instead I just convert the ID to the correct project slug in the afterFetchData helper. Unfortunately, it is on the developer to know the endpoint only returns IDs.

It's possible we can map these back to slugs but I assume it's a limitation of the session data not being immediately join-able with the projects table to do the lookup.

};

export const METRICS_EXPRESSION_TO_FIELD = invert(FIELD_TO_METRICS_EXPRESSION);
Expand Down
24 changes: 18 additions & 6 deletions static/app/views/dashboards/widgetCard/releaseWidgetQueries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import {t} from 'sentry/locale';
import type {PageFilters} from 'sentry/types/core';
import type {Series} from 'sentry/types/echarts';
import type {Organization, SessionApiResponse} from 'sentry/types/organization';
import type {Project} from 'sentry/types/project';
import type {Release} from 'sentry/types/release';
import {defined, escapeDoubleQuotes} from 'sentry/utils';
import type {TableDataWithTitle} from 'sentry/utils/discover/discoverQuery';
import {stripDerivedMetricsPrefix} from 'sentry/utils/discover/fields';
import {TOP_N} from 'sentry/utils/discover/types';
import {TAG_VALUE_ESCAPE_PATTERN} from 'sentry/utils/queryString';
import withProjects from 'sentry/utils/withProjects';
import {ReleasesConfig} from 'sentry/views/dashboards/datasetConfig/releases';
import type {DashboardFilters, Widget, WidgetQuery} from 'sentry/views/dashboards/types';
import {DEFAULT_TABLE_LIMIT, DisplayType} from 'sentry/views/dashboards/types';
Expand All @@ -35,10 +37,11 @@ import type {
} from './genericWidgetQueries';
import GenericWidgetQueries from './genericWidgetQueries';

type Props = {
export interface ReleaseWidgetQueriesProps {
api: Client;
children: (props: GenericWidgetQueriesChildrenProps) => React.JSX.Element;
organization: Organization;
projects: Project[];
selection: PageFilters;
widget: Widget;
cursor?: string;
Expand All @@ -49,7 +52,7 @@ type Props = {
tableResults?: TableDataWithTitle[];
timeseriesResults?: Series[];
}) => void;
};
}

type State = {
loading: boolean;
Expand Down Expand Up @@ -142,7 +145,7 @@ export function requiresCustomReleaseSorting(query: WidgetQuery): boolean {
return useMetricsAPI && rawOrderby === 'release';
}

class ReleaseWidgetQueries extends Component<Props, State> {
class ReleaseWidgetQueries extends Component<ReleaseWidgetQueriesProps, State> {
state: State = {
loading: false,
errorMessage: undefined,
Expand All @@ -157,7 +160,7 @@ class ReleaseWidgetQueries extends Component<Props, State> {
}
}

componentDidUpdate(prevProps: Readonly<Props>): void {
componentDidUpdate(prevProps: Readonly<ReleaseWidgetQueriesProps>): void {
if (
!requiresCustomReleaseSorting(prevProps.widget.queries[0]!) &&
requiresCustomReleaseSorting(this.props.widget.queries[0]!) &&
Expand Down Expand Up @@ -317,7 +320,7 @@ class ReleaseWidgetQueries extends Component<Props, State> {
};

afterFetchData = (data: SessionApiResponse) => {
const {widget} = this.props;
const {widget, projects} = this.props;
const {releases} = this.state;

const isDescending = widget.queries[0]!.orderby.startsWith('-');
Expand Down Expand Up @@ -346,6 +349,15 @@ class ReleaseWidgetQueries extends Component<Props, State> {
});
data.groups = data.groups.slice(0, this.limit);
}

data.groups.forEach(group => {
// Convert the project ID in the grouping results to the project slug
// for a more human readable display
if (group.by.project) {
const project = projects.find(p => p.id === String(group.by.project));
group.by.project = project?.slug ?? group.by.project;
}
});
};

render() {
Expand Down Expand Up @@ -395,4 +407,4 @@ class ReleaseWidgetQueries extends Component<Props, State> {
}
}

export default ReleaseWidgetQueries;
export default withProjects(ReleaseWidgetQueries);
Loading