-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathapp.tsx
65 lines (57 loc) · 2.05 KB
/
app.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import './app.scss';
import React, { useEffect } from 'react';
import { Route, Switch, useLocation } from 'react-router-dom';
import { AppMountParameters } from 'kibana/public';
import { syncQueryStateWithUrl } from '../../../data/public';
import { useKibana } from '../../../kibana_react/public';
import { VisualizeServices } from './types';
import {
VisualizeEditor,
VisualizeListing,
VisualizeNoMatch,
VisualizeByValueEditor,
} from './components';
import { VisualizeConstants } from './visualize_constants';
export interface VisualizeAppProps {
onAppLeave: AppMountParameters['onAppLeave'];
}
export const VisualizeApp = ({ onAppLeave }: VisualizeAppProps) => {
const {
services: {
data: { query },
kbnUrlStateStorage,
},
} = useKibana<VisualizeServices>();
const { pathname } = useLocation();
useEffect(() => {
// syncs `_g` portion of url with query services
const { stop } = syncQueryStateWithUrl(query, kbnUrlStateStorage);
return () => stop();
// this effect should re-run when pathname is changed to preserve querystring part,
// so the global state is always preserved
}, [query, kbnUrlStateStorage, pathname]);
return (
<Switch>
<Route exact path={`${VisualizeConstants.EDIT_BY_VALUE_PATH}`}>
<VisualizeByValueEditor onAppLeave={onAppLeave} />
</Route>
<Route path={[VisualizeConstants.CREATE_PATH, `${VisualizeConstants.EDIT_PATH}/:id`]}>
<VisualizeEditor onAppLeave={onAppLeave} />
</Route>
<Route
exact
path={[VisualizeConstants.LANDING_PAGE_PATH, VisualizeConstants.WIZARD_STEP_1_PAGE_PATH]}
>
<VisualizeListing />
</Route>
<VisualizeNoMatch />
</Switch>
);
};