|
@@ -39,7 +39,7 @@ import {
|
|
|
DisplayModes,
|
|
|
TOP_N,
|
|
|
} from 'sentry/utils/discover/types';
|
|
|
-import {decodeList, decodeScalar} from 'sentry/utils/queryString';
|
|
|
+import {decodeList, decodeScalar, decodeSorts} from 'sentry/utils/queryString';
|
|
|
import toArray from 'sentry/utils/toArray';
|
|
|
import {normalizeUrl} from 'sentry/utils/withDomainRequired';
|
|
|
import type {TableColumn, TableColumnSort} from 'sentry/views/discover/table/types';
|
|
@@ -160,48 +160,6 @@ const decodeFields = (location: Location): Array<Field> => {
|
|
|
return parsed;
|
|
|
};
|
|
|
|
|
|
-const parseSort = (sort: string): Sort => {
|
|
|
- sort = sort.trim();
|
|
|
-
|
|
|
- if (sort.startsWith('-')) {
|
|
|
- return {
|
|
|
- kind: 'desc',
|
|
|
- field: sort.substring(1),
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- return {
|
|
|
- kind: 'asc',
|
|
|
- field: sort,
|
|
|
- };
|
|
|
-};
|
|
|
-
|
|
|
-export const fromSorts = (sorts: string | string[] | undefined): Array<Sort> => {
|
|
|
- if (sorts === undefined) {
|
|
|
- return [];
|
|
|
- }
|
|
|
-
|
|
|
- sorts = typeof sorts === 'string' ? [sorts] : sorts;
|
|
|
-
|
|
|
- // NOTE: sets are iterated in insertion order
|
|
|
- const uniqueSorts = [...new Set(sorts)];
|
|
|
-
|
|
|
- return uniqueSorts.reduce((acc: Array<Sort>, sort: string) => {
|
|
|
- acc.push(parseSort(sort));
|
|
|
- return acc;
|
|
|
- }, []);
|
|
|
-};
|
|
|
-
|
|
|
-export const decodeSorts = (location: Location): Array<Sort> => {
|
|
|
- const {query} = location;
|
|
|
-
|
|
|
- if (!query || !query.sort) {
|
|
|
- return [];
|
|
|
- }
|
|
|
- const sorts = decodeList(query.sort);
|
|
|
- return fromSorts(sorts);
|
|
|
-};
|
|
|
-
|
|
|
export const encodeSort = (sort: Sort): string => {
|
|
|
switch (sort.kind) {
|
|
|
case 'desc': {
|
|
@@ -385,7 +343,7 @@ class EventView {
|
|
|
id: decodeScalar(location.query.id),
|
|
|
name: decodeScalar(location.query.name),
|
|
|
fields: decodeFields(location),
|
|
|
- sorts: decodeSorts(location),
|
|
|
+ sorts: decodeSorts(location.query.sort),
|
|
|
query: decodeQuery(location),
|
|
|
team: decodeTeams(location),
|
|
|
project: decodeProjects(location),
|
|
@@ -473,7 +431,7 @@ class EventView {
|
|
|
end: decodeScalar(end),
|
|
|
statsPeriod: decodeScalar(statsPeriod),
|
|
|
utc,
|
|
|
- sorts: fromSorts(saved.orderby),
|
|
|
+ sorts: decodeSorts(saved.orderby),
|
|
|
environment: collectQueryStringByKey(
|
|
|
{
|
|
|
environment: saved.environment as string[],
|
|
@@ -502,7 +460,7 @@ class EventView {
|
|
|
const id = decodeScalar(location.query.id);
|
|
|
const teams = decodeTeams(location);
|
|
|
const projects = decodeProjects(location);
|
|
|
- const sorts = decodeSorts(location);
|
|
|
+ const sorts = decodeSorts(location.query.sort);
|
|
|
const environments = collectQueryStringByKey(location.query, 'environment');
|
|
|
|
|
|
if (saved) {
|
|
@@ -531,7 +489,7 @@ class EventView {
|
|
|
'query' in location.query
|
|
|
? decodeQuery(location)
|
|
|
: queryStringFromSavedQuery(saved),
|
|
|
- sorts: sorts.length === 0 ? fromSorts(saved.orderby) : sorts,
|
|
|
+ sorts: sorts.length === 0 ? decodeSorts(saved.orderby) : sorts,
|
|
|
yAxis:
|
|
|
decodeScalar(location.query.yAxis) ||
|
|
|
// Workaround to only use the first yAxis since eventView yAxis doesn't accept string[]
|