Skip to content

Commit

Permalink
Only show "Not defined" in environment selector if there are actually
Browse files Browse the repository at this point in the history
documents without service.environment set
  • Loading branch information
ogupte committed Jul 6, 2020
1 parent 69bcc2c commit 2dca952
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ export const AddEnvironments = ({
{ preservePreviousData: false }
);

const environments = [...data, ENVIRONMENT_NOT_DEFINED];
const environmentOptions = environments.map((env) => ({
const environmentOptions = data.map((env) => ({
label: env === ENVIRONMENT_NOT_DEFINED ? NOT_DEFINED_OPTION_LABEL : env,
value: env,
disabled: currentEnvironments.includes(env),
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,16 @@ describe('getAllEnvironments', () => {

expect(mock.params).toMatchSnapshot();
});

it('fetches all environments with includeMissing', async () => {
mock = await inspectSearchParams((setup) =>
getAllEnvironments({
serviceName: 'test',
setup,
includeMissing: true,
})
);

expect(mock.params).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import {
SERVICE_NAME,
SERVICE_ENVIRONMENT,
} from '../../../common/elasticsearch_fieldnames';
import { ENVIRONMENT_NOT_DEFINED } from '../../../common/environment_filter_values';

export async function getAllEnvironments({
serviceName,
setup,
includeMissing = false,
}: {
serviceName?: string;
setup: Setup;
includeMissing?: boolean;
}) {
const { client, indices } = setup;

Expand Down Expand Up @@ -48,6 +51,7 @@ export async function getAllEnvironments({
terms: {
field: SERVICE_ENVIRONMENT,
size: 100,
missing: includeMissing ? ENVIRONMENT_NOT_DEFINED : undefined,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ export const anomalyDetectionEnvironmentsRoute = createRoute(() => ({
path: '/api/apm/settings/anomaly-detection/environments',
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
return await getAllEnvironments({ setup });
return await getAllEnvironments({ setup, includeMissing: true });
},
}));

0 comments on commit 2dca952

Please sign in to comment.