mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[Synthetics] Prevent imports from legacy_uptime (#134185)
* commit * update usage * update type
This commit is contained in:
parent
68e569bd7d
commit
d32d9f571c
3 changed files with 24 additions and 37 deletions
13
.eslintrc.js
13
.eslintrc.js
|
@ -958,6 +958,19 @@ module.exports = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// disable imports from legacy uptime plugin
|
||||||
|
files: ['x-pack/plugins/synthetics/public/apps/synthetics/**/*.{js,mjs,ts,tsx}'],
|
||||||
|
rules: {
|
||||||
|
'no-restricted-imports': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
patterns: ['**/legacy_uptime/*'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fleet overrides
|
* Fleet overrides
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -13,8 +13,6 @@ import styled from 'styled-components';
|
||||||
import { useBreadcrumbs } from '../../hooks';
|
import { useBreadcrumbs } from '../../hooks';
|
||||||
import { getServiceLocations } from '../../state';
|
import { getServiceLocations } from '../../state';
|
||||||
import { SimpleMonitorForm } from './simple_monitor_form';
|
import { SimpleMonitorForm } from './simple_monitor_form';
|
||||||
import { MONITORING_OVERVIEW_LABEL } from '../../../../legacy_uptime/routes';
|
|
||||||
|
|
||||||
export const GettingStartedPage = () => {
|
export const GettingStartedPage = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
@ -95,3 +93,7 @@ const SELECT_DIFFERENT_MONITOR = i18n.translate(
|
||||||
const OR_LABEL = i18n.translate('xpack.synthetics.gettingStarted.orLabel', {
|
const OR_LABEL = i18n.translate('xpack.synthetics.gettingStarted.orLabel', {
|
||||||
defaultMessage: 'Or',
|
defaultMessage: 'Or',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const MONITORING_OVERVIEW_LABEL = i18n.translate('xpack.synthetics.overview.heading', {
|
||||||
|
defaultMessage: 'Monitors',
|
||||||
|
});
|
||||||
|
|
|
@ -5,17 +5,14 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useCallback, useEffect } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { stringify } from 'query-string';
|
import { parse, stringify } from 'query-string';
|
||||||
import { useLocation, useHistory } from 'react-router-dom';
|
import { useLocation, useHistory } from 'react-router-dom';
|
||||||
import { useDispatch, useSelector } from 'react-redux';
|
|
||||||
import { SyntheticsUrlParams, getSupportedUrlParams } from '../utils/url_params';
|
import { SyntheticsUrlParams, getSupportedUrlParams } from '../utils/url_params';
|
||||||
|
|
||||||
// TODO: Create the following imports for new Synthetics App
|
function getParsedParams(search: string) {
|
||||||
import { selectedFiltersSelector } from '../../../legacy_uptime/state/selectors';
|
return search ? parse(search[0] === '?' ? search.slice(1) : search, { sort: false }) : {};
|
||||||
import { setSelectedFilters } from '../../../legacy_uptime/state/actions/selected_filters';
|
}
|
||||||
import { getFiltersFromMap } from '../../../legacy_uptime/hooks/use_selected_filters';
|
|
||||||
import { getParsedParams } from '../../../legacy_uptime/lib/helper/parse_search';
|
|
||||||
|
|
||||||
export type GetUrlParams = () => SyntheticsUrlParams;
|
export type GetUrlParams = () => SyntheticsUrlParams;
|
||||||
export type UpdateUrlParams = (updatedParams: {
|
export type UpdateUrlParams = (updatedParams: {
|
||||||
|
@ -30,29 +27,9 @@ export const useGetUrlParams: GetUrlParams = () => {
|
||||||
return getSupportedUrlParams(getParsedParams(search));
|
return getSupportedUrlParams(getParsedParams(search));
|
||||||
};
|
};
|
||||||
|
|
||||||
const getMapFromFilters = (value: any): Map<string, any> | undefined => {
|
|
||||||
try {
|
|
||||||
return new Map(JSON.parse(value));
|
|
||||||
} catch {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useUrlParams: SyntheticsUrlParamsHook = () => {
|
export const useUrlParams: SyntheticsUrlParamsHook = () => {
|
||||||
const { pathname, search } = useLocation();
|
const { pathname, search } = useLocation();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const dispatch = useDispatch();
|
|
||||||
const selectedFilters = useSelector(selectedFiltersSelector);
|
|
||||||
const { filters } = useGetUrlParams();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (selectedFilters === null) {
|
|
||||||
const filterMap = getMapFromFilters(filters);
|
|
||||||
if (filterMap) {
|
|
||||||
dispatch(setSelectedFilters(getFiltersFromMap(filterMap)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [dispatch, filters, selectedFilters]);
|
|
||||||
|
|
||||||
const updateUrlParams: UpdateUrlParams = useCallback(
|
const updateUrlParams: UpdateUrlParams = useCallback(
|
||||||
(updatedParams) => {
|
(updatedParams) => {
|
||||||
|
@ -69,6 +46,7 @@ export const useUrlParams: SyntheticsUrlParamsHook = () => {
|
||||||
if (value === undefined || value === '') {
|
if (value === undefined || value === '') {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...params,
|
...params,
|
||||||
[key]: value,
|
[key]: value,
|
||||||
|
@ -80,14 +58,8 @@ export const useUrlParams: SyntheticsUrlParamsHook = () => {
|
||||||
if (search !== updatedSearch) {
|
if (search !== updatedSearch) {
|
||||||
history.push({ pathname, search: updatedSearch });
|
history.push({ pathname, search: updatedSearch });
|
||||||
}
|
}
|
||||||
const filterMap = getMapFromFilters(mergedParams.filters);
|
|
||||||
if (!filterMap) {
|
|
||||||
dispatch(setSelectedFilters(null));
|
|
||||||
} else {
|
|
||||||
dispatch(setSelectedFilters(getFiltersFromMap(filterMap)));
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[dispatch, history, pathname, search]
|
[history, pathname, search]
|
||||||
);
|
);
|
||||||
|
|
||||||
return [useGetUrlParams, updateUrlParams];
|
return [useGetUrlParams, updateUrlParams];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue