Skip to content
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
81 changes: 34 additions & 47 deletions src/sentry/static/sentry/app/views/eventsV2/eventView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import omit from 'lodash/omit';
import moment from 'moment';

import {DEFAULT_PER_PAGE} from 'app/constants';
import {SavedQuery as LegacySavedQuery} from 'app/views/discover/types';
import {SavedQuery, NewQuery} from 'app/types';
import {getParams} from 'app/components/organizations/globalSelectionHeader/getParams';

Expand Down Expand Up @@ -261,28 +260,10 @@ const decodeScalar = (
return isString(unwrapped) ? unwrapped : undefined;
};

function isLegacySavedQuery(
query: LegacySavedQuery | NewQuery
): query is LegacySavedQuery {
return (query as LegacySavedQuery).conditions !== undefined;
}

const queryStringFromSavedQuery = (saved: NewQuery | LegacySavedQuery): string => {
if (!isLegacySavedQuery(saved) && saved.query) {
const queryStringFromSavedQuery = (saved: NewQuery | SavedQuery): string => {
if (saved.query) {
return saved.query || '';
}
if (isLegacySavedQuery(saved) && saved.conditions) {
const conditions = saved.conditions.map(item => {
const [field, op, value] = item;
let operator = op;
// TODO handle all the other operator types
if (operator === '=') {
operator = '';
}
return field + ':' + operator + value;
});
return conditions.join(' ');
}
return '';
};

Expand Down Expand Up @@ -377,37 +358,43 @@ class EventView {
});
}

static fromSavedQueryWithLocation(
saved: NewQuery | LegacySavedQuery,
location: Location
): EventView {
static fromNewQueryWithLocation(newQuery: NewQuery, location: Location): EventView {
const query = location.query;

saved = {
...saved,
start: saved.start || decodeScalar(query.start),
end: saved.end || decodeScalar(query.end),
range: saved.range || decodeScalar(query.statsPeriod),
// apply global selection header values from location whenever possible

const environment: string[] =
Array.isArray(newQuery.environment) && newQuery.environment.length > 0
? newQuery.environment
: collectQueryStringByKey(location.query, 'environment');

const project: number[] =
Array.isArray(newQuery.projects) && newQuery.projects.length > 0
? newQuery.projects
: decodeProjects(location);

const saved: NewQuery = {
...newQuery,

environment,
projects: project,

// datetime selection

start: newQuery.start || decodeScalar(query.start),
end: newQuery.end || decodeScalar(query.end),
range: newQuery.range || decodeScalar(query.statsPeriod),
};

return EventView.fromSavedQuery(saved);
}

static fromSavedQuery(saved: NewQuery | LegacySavedQuery): EventView {
let fields, yAxis;
if (isLegacySavedQuery(saved)) {
fields = saved.fields.map(field => {
return {field, title: field};
});
yAxis = undefined;
} else {
fields = saved.fields.map((field, i) => {
const title =
saved.fieldnames && saved.fieldnames[i] ? saved.fieldnames[i] : field;
return {field, title};
});
yAxis = saved.yAxis;
}
static fromSavedQuery(saved: NewQuery | SavedQuery): EventView {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could remove the isLegacySavedQuery() conditions too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

const fields = saved.fields.map((field, i) => {
const title = saved.fieldnames && saved.fieldnames[i] ? saved.fieldnames[i] : field;
return {field, title};
});
const yAxis = saved.yAxis;

// normalize datetime selection
const {start, end, statsPeriod} = getParams({
Expand All @@ -428,13 +415,13 @@ class EventView {
sorts: fromSorts(saved.orderby),
tags: collectQueryStringByKey(
{
tags: (saved as SavedQuery).tags as string[],
tags: saved.tags as string[],
},
'tags'
),
environment: collectQueryStringByKey(
{
environment: (saved as SavedQuery).environment as string[],
environment: saved.environment as string[],
},
'environment'
),
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/static/sentry/app/views/eventsV2/landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class DiscoverLanding extends AsyncComponent<Props, State> {

const {location} = this.props;

const eventView = EventView.fromSavedQueryWithLocation(DEFAULT_EVENT_VIEW, location);
const eventView = EventView.fromNewQueryWithLocation(DEFAULT_EVENT_VIEW, location);

const to = {
pathname: location.pathname,
Expand Down
18 changes: 14 additions & 4 deletions src/sentry/static/sentry/app/views/eventsV2/miniGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,22 @@ class MiniGraph extends React.Component<Props> {
start,
end,
period,
project: eventView.project,
environment: eventView.environment,
};
}

render() {
const {eventView, api} = this.props;
const {query, start, end, period, organization} = this.getRefreshProps(this.props);
const {api} = this.props;
const {
query,
start,
end,
period,
organization,
project,
environment,
} = this.getRefreshProps(this.props);

return (
<EventsRequest
Expand All @@ -68,8 +78,8 @@ class MiniGraph extends React.Component<Props> {
end={end}
period={period}
interval={getInterval({start, end, period}, true)}
project={eventView.project as number[]}
environment={eventView.environment as string[]}
project={project as number[]}
environment={environment as string[]}
includePrevious={false}
>
{({loading, timeseriesData}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class QueryList extends React.Component<Props> {
const views = getPrebuiltQueries(organization);

const list = views.map((view, index) => {
const eventView = EventView.fromSavedQueryWithLocation(view, location);
const eventView = EventView.fromNewQueryWithLocation(view, location);
const recentTimeline = t('Last ') + eventView.statsPeriod;
const customTimeline =
moment(eventView.start).format('MMM D, YYYY h:mm A') +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Table extends React.PureComponent<TableProps, TableState> {
const {location, eventView} = this.props;

if (!eventView.isValid()) {
const nextEventView = EventView.fromSavedQueryWithLocation(
const nextEventView = EventView.fromNewQueryWithLocation(
DEFAULT_EVENT_VIEW,
location
);
Expand Down
Loading