[APM] Use default service environment for service groups (#129457)

This commit is contained in:
Dario Gieselaar 2022-04-07 07:27:31 +02:00 committed by GitHub
parent 55c3353afd
commit 3d182b965e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 12 deletions

View file

@ -12,7 +12,7 @@ import { ServiceGroupsCard } from './service_group_card';
import { SERVICE_GROUP_COLOR_DEFAULT } from '../../../../../common/service_groups';
import { useApmRouter } from '../../../../hooks/use_apm_router';
import { useApmParams } from '../../../../hooks/use_apm_params';
import { ENVIRONMENT_ALL } from '../../../../../common/environment_filter_values';
import { useDefaultEnvironment } from '../../../../hooks/use_default_environment';
interface Props {
items: SavedServiceGroup[];
@ -22,6 +22,9 @@ interface Props {
export function ServiceGroupsListItems({ items }: Props) {
const router = useApmRouter();
const { query } = useApmParams('/service-groups');
const environment = useDefaultEnvironment();
return (
<EuiFlexGrid gutterSize="m">
{items.map((item) => (
@ -31,7 +34,7 @@ export function ServiceGroupsListItems({ items }: Props) {
query: {
...query,
serviceGroup: item.id,
environment: ENVIRONMENT_ALL.value,
environment,
kuery: '',
},
})}
@ -57,7 +60,7 @@ export function ServiceGroupsListItems({ items }: Props) {
query: {
...query,
serviceGroup: '',
environment: ENVIRONMENT_ALL.value,
environment,
kuery: '',
},
})}

View file

@ -8,29 +8,25 @@
import { useLocation, Redirect } from 'react-router-dom';
import qs from 'query-string';
import React from 'react';
import { defaultApmServiceEnvironment } from '../../../../../observability/common';
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_context';
import { useDefaultEnvironment } from '../../../hooks/use_default_environment';
export function RedirectWithDefaultEnvironment({
children,
}: {
children: React.ReactElement;
}) {
const { core } = useApmPluginContext();
const location = useLocation();
const query = qs.parse(location.search);
const defaultServiceEnvironment = useDefaultEnvironment();
if ('environment' in query) {
return children;
}
if (location.pathname === '/services' || location.pathname === '/services/') {
const defaultServiceEnvironment =
core.uiSettings.get<string>(defaultApmServiceEnvironment) ||
ENVIRONMENT_ALL.value;
const normalizedPathname = location.pathname.replace(/\/$/, '');
if (normalizedPathname === '/services') {
return (
<Redirect
to={qs.stringifyUrl({

View file

@ -0,0 +1,21 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { defaultApmServiceEnvironment } from '../../../observability/common';
import { ENVIRONMENT_ALL } from '../../common/environment_filter_values';
import { Environment } from '../../common/environment_rt';
import { useApmPluginContext } from '../context/apm_plugin/use_apm_plugin_context';
export function useDefaultEnvironment() {
const { core } = useApmPluginContext();
const defaultServiceEnvironment =
core.uiSettings.get<Environment>(defaultApmServiceEnvironment) ||
ENVIRONMENT_ALL.value;
return defaultServiceEnvironment;
}