Skip to content

Commit

Permalink
addressing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed May 12, 2020
1 parent 16247f2 commit 010e52d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,15 @@ function getOptions(environments: string[]) {

export const EnvironmentFilter: React.FC = () => {
const location = useLocation();
const { uiFilters } = useUrlParams();
const { uiFilters, urlParams } = useUrlParams();

const { environment } = uiFilters;
const { environments, status = 'loading' } = useEnvironments();
const { serviceName, start, end } = urlParams;
const { environments, status = 'loading' } = useEnvironments({
serviceName,
start,
end
});

return (
<EuiSelect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ALERT_TYPES_CONFIG } from '../../../../common/alert_types';
import { ServiceAlertTrigger } from '../ServiceAlertTrigger';
import { PopoverExpression } from '../ServiceAlertTrigger/PopoverExpression';
import { useEnvironments, ALL_OPTION } from '../../../hooks/useEnvironments';
import { useUrlParams } from '../../../hooks/useUrlParams';

export interface ErrorRateAlertTriggerParams {
windowSize: number;
Expand All @@ -30,7 +31,9 @@ interface Props {
export function ErrorRateAlertTrigger(props: Props) {
const { setAlertParams, setAlertProperty, alertParams } = props;

const { environmentOptions } = useEnvironments();
const { urlParams } = useUrlParams();
const { serviceName, start, end } = urlParams;
const { environmentOptions } = useEnvironments({ serviceName, start, end });

const defaults = {
threshold: 25,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export function TransactionDurationAlertTrigger(props: Props) {
const { urlParams } = useUrlParams();

const transactionTypes = useServiceTransactionTypes(urlParams);
const { environmentOptions } = useEnvironments();

const { serviceName, start, end } = urlParams;
const { environmentOptions } = useEnvironments({ serviceName, start, end });

if (!transactionTypes.length) {
return null;
Expand Down
13 changes: 9 additions & 4 deletions x-pack/plugins/apm/public/hooks/useEnvironments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
ENVIRONMENT_NOT_DEFINED,
ENVIRONMENT_ALL
} from '../../common/environment_filter_values';
import { useUrlParams } from './useUrlParams';

export const ALL_OPTION = {
value: ENVIRONMENT_ALL,
Expand All @@ -31,9 +30,15 @@ function getEnvironmentOptions(environments: string[]) {
return [ALL_OPTION, ...environmentOptions];
}

export function useEnvironments() {
const { urlParams } = useUrlParams();
const { serviceName, start, end } = urlParams;
export function useEnvironments({
serviceName,
start,
end
}: {
serviceName?: string;
start?: string;
end?: string;
}) {
const { data: environments = [], status = 'loading' } = useFetcher(
callApmApi => {
if (start && end) {
Expand Down

0 comments on commit 010e52d

Please sign in to comment.