[Synthetics] Prevent imports from legacy_uptime (#134185)

* commit

* update usage

* update type
This commit is contained in:
Shahzad 2022-06-13 16:09:33 +02:00 committed by GitHub
parent 68e569bd7d
commit d32d9f571c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 37 deletions

View file

@ -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
*/

View file

@ -13,8 +13,6 @@ import styled from 'styled-components';
import { useBreadcrumbs } from '../../hooks';
import { getServiceLocations } from '../../state';
import { SimpleMonitorForm } from './simple_monitor_form';
import { MONITORING_OVERVIEW_LABEL } from '../../../../legacy_uptime/routes';
export const GettingStartedPage = () => {
const dispatch = useDispatch();
@ -95,3 +93,7 @@ const SELECT_DIFFERENT_MONITOR = i18n.translate(
const OR_LABEL = i18n.translate('xpack.synthetics.gettingStarted.orLabel', {
defaultMessage: 'Or',
});
const MONITORING_OVERVIEW_LABEL = i18n.translate('xpack.synthetics.overview.heading', {
defaultMessage: 'Monitors',
});

View file

@ -5,17 +5,14 @@
* 2.0.
*/
import { useCallback, useEffect } from 'react';
import { stringify } from 'query-string';
import { useCallback } from 'react';
import { parse, stringify } from 'query-string';
import { useLocation, useHistory } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import { SyntheticsUrlParams, getSupportedUrlParams } from '../utils/url_params';
// TODO: Create the following imports for new Synthetics App
import { selectedFiltersSelector } from '../../../legacy_uptime/state/selectors';
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';
function getParsedParams(search: string) {
return search ? parse(search[0] === '?' ? search.slice(1) : search, { sort: false }) : {};
}
export type GetUrlParams = () => SyntheticsUrlParams;
export type UpdateUrlParams = (updatedParams: {
@ -30,29 +27,9 @@ export const useGetUrlParams: GetUrlParams = () => {
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 = () => {
const { pathname, search } = useLocation();
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(
(updatedParams) => {
@ -69,6 +46,7 @@ export const useUrlParams: SyntheticsUrlParamsHook = () => {
if (value === undefined || value === '') {
return params;
}
return {
...params,
[key]: value,
@ -80,14 +58,8 @@ export const useUrlParams: SyntheticsUrlParamsHook = () => {
if (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];