Skip to content

Commit

Permalink
Fix snapshot and minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Sep 30, 2019
1 parent 7b04448 commit af55e78
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { transactionMaxSpansRt } from './index';
import { isRight } from 'fp-ts/lib/Either';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { EuiTitle, EuiSpacer, EuiFormRow } from '@elastic/eui';
import React from 'react';
import { i18n } from '@kbn/i18n';
import { SelectWithPlaceholder } from '../../../../shared/SelectWithPlaceholder';
import { FETCH_STATUS } from '../../../../../hooks/useFetcher';
import { useFetcher } from '../../../../../hooks/useFetcher';
import { ENVIRONMENT_NOT_DEFINED } from '../../../../../../common/environment_filter_values';
import { Config } from '../index';
import { callApmApi } from '../../../../../services/rest/callApmApi';
const t = (id: string, defaultMessage: string) =>
i18n.translate(`xpack.apm.settings.agentConf.flyOut.serviceSection.${id}`, {
defaultMessage
Expand All @@ -24,23 +25,39 @@ interface Props {
setEnvironment: (env: string) => void;
serviceName?: string;
setServiceName: (env: string) => void;
serviceNames: string[];
serviceNamesStatus?: FETCH_STATUS;
environments: Array<{ name: string; alreadyExists: boolean }>;
environmentStatus?: FETCH_STATUS;
}

export function FlyoutServiceSection({
export function ServiceSection({
selectedConfig,
environment,
setEnvironment,
serviceName,
setServiceName,
serviceNames,
serviceNamesStatus,
environments,
environmentStatus
setServiceName
}: Props) {
const { data: serviceNames = [], status: serviceNamesStatus } = useFetcher(
() => {
return callApmApi({
pathname: '/api/apm/settings/agent-configuration/services',
forceCache: true
});
},
[],
{ preservePreviousData: false }
);
const { data: environments = [], status: environmentStatus } = useFetcher(
() => {
if (serviceName) {
return callApmApi({
pathname:
'/api/apm/settings/agent-configuration/services/{serviceName}/environments',
params: { path: { serviceName } }
});
}
},
[serviceName],
{ preservePreviousData: false }
);

const environmentOptions = environments.map(({ name, alreadyExists }) => ({
disabled: alreadyExists,
text:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import { i18n } from '@kbn/i18n';
import { isEmpty } from 'lodash';
import { SelectWithPlaceholder } from '../../../../shared/SelectWithPlaceholder';
const t = (id: string, defaultMessage: string) =>
i18n.translate(
`xpack.apm.settings.agentConf.flyOut.ConfigurationSection.${id}`,
{ defaultMessage }
);
i18n.translate(`xpack.apm.settings.agentConf.flyOut.settingsSection.${id}`, {
defaultMessage
});

interface ConfigOption {
value: string;
Expand All @@ -33,15 +32,15 @@ interface Props {
transactionMaxSpans: ConfigOption;
}

export function FlyoutConfigurationSection({
export function SettingsSection({
sampleRate,
captureBody,
transactionMaxSpans
}: Props) {
return (
<>
<EuiTitle size="xs">
<h3>{t('title', 'Configuration')}</h3>
<h3>{t('title', 'Settings')}</h3>
</EuiTitle>

<EuiSpacer size="m" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ import { toastNotifications } from 'ui/notify';
import { i18n } from '@kbn/i18n';
import { isRight } from 'fp-ts/lib/Either';
import { transactionSampleRateRt } from '../../../../../../common/runtime_types/transaction_sample_rate_rt';
import { useFetcher } from '../../../../../hooks/useFetcher';
import { ENVIRONMENT_NOT_DEFINED } from '../../../../../../common/environment_filter_values';
import { callApmApi } from '../../../../../services/rest/callApmApi';
import { trackEvent } from '../../../../../../../infra/public/hooks/use_track_metric';
import { Config } from '../index';
import { FlyoutConfigurationSection } from './FlyoutConfigurationSection';
import { FlyoutServiceSection } from './FlyoutServiceSection';
import { SettingsSection } from './SettingsSection';
import { ServiceSection } from './ServiceSection';
import { DeleteSection } from './DeleteSection';
import { transactionMaxSpansRt } from '../../../../../../common/runtime_types/transaction_max_spans_rt';
const t = (id: string, defaultMessage: string, values?: Record<string, any>) =>
Expand All @@ -55,7 +54,7 @@ export function AddEditFlyout({
}: Props) {
const [isSaving, setIsSaving] = useState(false);

// config conditions
// config conditions (servie)
const [serviceName, setServiceName] = useState<string>(
selectedConfig ? selectedConfig.service.name : ''
);
Expand All @@ -80,30 +79,6 @@ export function AddEditFlyout({
).toString()
);

const { data: serviceNames = [], status: serviceNamesStatus } = useFetcher(
() => {
return callApmApi({
pathname: '/api/apm/settings/agent-configuration/services',
forceCache: true
});
},
[],
{ preservePreviousData: false }
);
const { data: environments = [], status: environmentStatus } = useFetcher(
() => {
if (serviceName) {
return callApmApi({
pathname:
'/api/apm/settings/agent-configuration/services/{serviceName}/environments',
params: { path: { serviceName } }
});
}
},
[serviceName],
{ preservePreviousData: false }
);

const isSampleRateValid = isRight(transactionSampleRateRt.decode(sampleRate));
const isTransactionMaxSpansValid = isRight(
transactionMaxSpansRt.decode(transactionMaxSpans)
Expand Down Expand Up @@ -170,21 +145,17 @@ export function AddEditFlyout({
}
}}
>
<FlyoutServiceSection
<ServiceSection
selectedConfig={selectedConfig}
environment={environment}
setEnvironment={setEnvironment}
serviceName={serviceName}
setServiceName={setServiceName}
serviceNames={serviceNames}
serviceNamesStatus={serviceNamesStatus}
environments={environments}
environmentStatus={environmentStatus}
/>

<EuiSpacer />

<FlyoutConfigurationSection
<SettingsSection
sampleRate={{
value: sampleRate,
set: setSampleRate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ export function AgentConfigurations() {

const hasConfigurations = !isEmpty(data);

const onClose = () => {
setSelectedConfig(null);
setIsFlyoutOpen(false);
};

return (
<>
{isFlyoutOpen && (
<AddEditFlyout
selectedConfig={selectedConfig}
onClose={() => {
setSelectedConfig(null);
setIsFlyoutOpen(false);
}}
onClose={onClose}
onSaved={() => {
setSelectedConfig(null);
setIsFlyoutOpen(false);
onClose();
refetch();
}}
onDeleted={() => {
setSelectedConfig(null);
setIsFlyoutOpen(false);
onClose();
refetch();
}}
/>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit af55e78

Please sign in to comment.