소스 검색

Merge pull request #12630 from grafana/davkal/explore-empty-error

Dont parse empty explore state from url
David 7 년 전
부모
커밋
5c6adbbada
1개의 변경된 파일13개의 추가작업 그리고 11개의 파일을 삭제
  1. 13 11
      public/app/containers/Explore/Explore.tsx

+ 13 - 11
public/app/containers/Explore/Explore.tsx

@@ -33,18 +33,20 @@ function makeTimeSeriesList(dataList, options) {
   });
 }
 
-function parseInitialState(initial) {
-  try {
-    const parsed = JSON.parse(decodePathComponent(initial));
-    return {
-      datasource: parsed.datasource,
-      queries: parsed.queries.map(q => q.query),
-      range: parsed.range,
-    };
-  } catch (e) {
-    console.error(e);
-    return { queries: [], range: DEFAULT_RANGE };
+function parseInitialState(initial: string | undefined) {
+  if (initial) {
+    try {
+      const parsed = JSON.parse(decodePathComponent(initial));
+      return {
+        datasource: parsed.datasource,
+        queries: parsed.queries.map(q => q.query),
+        range: parsed.range,
+      };
+    } catch (e) {
+      console.error(e);
+    }
   }
+  return { datasource: null, queries: [], range: DEFAULT_RANGE };
 }
 
 interface IExploreState {