Skip to content

Commit de4dffc

Browse files
Merge branch 'main' into InlineEdit/obs_cases
2 parents cec0c75 + 96e6eb9 commit de4dffc

40 files changed

Lines changed: 1022 additions & 426 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import { isValidVariableName } from './utils';
10+
11+
describe('utils', () => {
12+
describe('isValidVariableName', () => {
13+
it('returns `false` to `null`', () => {
14+
// @ts-ignore passing a wrong type intentionally
15+
expect(isValidVariableName(null)).toBe(false);
16+
});
17+
18+
it('returns `false` to empty string', () => {
19+
expect(isValidVariableName('')).toBe(false);
20+
});
21+
22+
it('returns `false` to space string', () => {
23+
expect(isValidVariableName(' ')).toBe(false);
24+
});
25+
26+
it('returns `false` to integer zero', () => {
27+
// @ts-ignore passing a wrong type intentionally
28+
expect(isValidVariableName(0)).toBe(false);
29+
});
30+
31+
it('returns `false` to float zero', () => {
32+
// @ts-ignore passing a wrong type intentionally
33+
expect(isValidVariableName(0.0)).toBe(false);
34+
});
35+
36+
it('returns `true` to string zero', () => {
37+
expect(isValidVariableName('0')).toBe(true);
38+
});
39+
40+
it('returns `true` to allowed styles', () => {
41+
for (const name of ['camelCase', 'snake_case', 'PascalCase', 'MACRO_CASE']) {
42+
expect(isValidVariableName(name)).toBe(true);
43+
}
44+
});
45+
46+
it('returns `false` to disallowed styles', () => {
47+
for (const name of ['kebab-case', 'COBOL-CASE', 'dot.notation', 'bracket[notation]']) {
48+
expect(isValidVariableName(name)).toBe(false);
49+
}
50+
});
51+
52+
it('returns `true` to underscores prefix & suffix', () => {
53+
expect(isValidVariableName('__name__')).toBe(true);
54+
});
55+
56+
it('returns `true` to numbers prefix & suffix', () => {
57+
expect(isValidVariableName('00name00')).toBe(true);
58+
});
59+
});
60+
});

src/plugins/console/public/application/components/variables/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ export const generateEmptyVariableField = (): DevToolsVariable => ({
3737
name: '',
3838
value: '',
3939
});
40+
41+
export const isValidVariableName = (name: string) => {
42+
/*
43+
* MUST avoid characters that get URL-encoded, because they'll result in unusable variable names.
44+
* Common variable names consist of letters, digits, and underscores and do not begin with a digit.
45+
* However, the ones beginning with a digit are still allowed here for backward compatibility.
46+
*/
47+
return typeof name === 'string' && name.match(/^[a-zA-Z0-9_]+$/g) !== null;
48+
};

src/plugins/console/public/application/components/variables/variables_flyout.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,14 @@ export const DevToolsVariablesFlyout = (props: DevToolsVariablesFlyoutProps) =>
8585
defaultMessage: 'Variable name',
8686
}),
8787
render: (name, { id }) => {
88-
// Avoid characters that get URL-encoded, because they'll result in unusable variable names.
89-
const isInvalid = name && !name.match(/^[a-zA-Z0-9]+$/g);
88+
const isInvalid = !utils.isValidVariableName(name);
9089
return (
9190
<EuiFormRow
9291
isInvalid={isInvalid}
9392
error={[
9493
<FormattedMessage
9594
id="console.variablesPage.variablesTable.variableInputError.validCharactersText"
96-
defaultMessage="Only letters and numbers are allowed"
95+
defaultMessage="Only letters, numbers and underscores are allowed"
9796
/>,
9897
]}
9998
fullWidth={true}

x-pack/packages/ml/data_frame_analytics_utils/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const JOB_MAP_NODE_TYPES = {
3939
TRANSFORM: 'transform',
4040
INDEX: 'index',
4141
TRAINED_MODEL: 'trainedModel',
42+
INGEST_PIPELINE: 'ingestPipeline',
4243
} as const;
4344

4445
/**

x-pack/packages/ml/data_frame_analytics_utils/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ export interface AnalyticsMapNodeElement {
378378
label: string;
379379
type: string;
380380
analysisType?: string;
381+
isRoot?: boolean;
381382
};
382383
}
383384

x-pack/plugins/enterprise_search/common/types/error_codes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export enum ErrorCode {
2222
SEARCH_APPLICATION_ALREADY_EXISTS = 'search_application_already_exists',
2323
SEARCH_APPLICATION_NAME_INVALID = 'search_application_name_invalid',
2424
SEARCH_APPLICATION_NOT_FOUND = 'search_application_not_found',
25+
SEARCH_APPLICATION_ALIAS_NOT_FOUND = 'search_application_alias_not_found',
2526
UNAUTHORIZED = 'unauthorized',
2627
UNCAUGHT_EXCEPTION = 'uncaught_exception',
2728
}

x-pack/plugins/enterprise_search/public/applications/applications/components/search_applications/search_applications_list.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ export const SearchApplicationsList: React.FC<ListProps> = ({
247247
{i18n.translate(
248248
'xpack.enterpriseSearch.searchApplications.list.searchBar.description',
249249
{
250-
defaultMessage:
251-
'Locate a search application via name or by its included indices.',
250+
defaultMessage: 'Locate a search application via name.',
252251
}
253252
)}
254253
</EuiText>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { IScopedClusterClient } from '@kbn/core-elasticsearch-server';
9+
10+
export const fetchAliasIndices = async (client: IScopedClusterClient, aliasName: string) => {
11+
const aliasIndices = await client.asCurrentUser.indices.getAlias({
12+
name: aliasName,
13+
});
14+
15+
return Object.keys(aliasIndices).sort();
16+
};

x-pack/plugins/enterprise_search/server/lib/search_applications/field_capabilities.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('search applications field_capabilities', () => {
2222
const mockClient = {
2323
asCurrentUser: {
2424
fieldCaps: jest.fn(),
25-
indices: { get: jest.fn() },
25+
indices: { get: jest.fn(), getAlias: jest.fn() },
2626
},
2727
asInternalUser: {},
2828
};
@@ -56,6 +56,11 @@ describe('search applications field_capabilities', () => {
5656
'index-001': { aliases: { unit_test_search_application: {} } },
5757
};
5858

59+
const getAliasIndicesResponse = {
60+
'index-001': { aliases: { unit_test_search_application: {} } },
61+
};
62+
63+
mockClient.asCurrentUser.indices.getAlias.mockResolvedValueOnce(getAliasIndicesResponse);
5964
mockClient.asCurrentUser.indices.get.mockResolvedValueOnce(getAllAvailableIndexResponse);
6065
mockClient.asCurrentUser.fieldCaps.mockResolvedValueOnce(fieldCapsResponse);
6166

x-pack/plugins/enterprise_search/server/lib/search_applications/field_capabilities.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ import {
1515
} from '../../../common/types/search_applications';
1616

1717
import { availableIndices } from './available_indices';
18+
import { fetchAliasIndices } from './fetch_alias_indices';
1819

1920
export const fetchSearchApplicationFieldCapabilities = async (
2021
client: IScopedClusterClient,
2122
searchApplication: EnterpriseSearchApplication
2223
): Promise<EnterpriseSearchApplicationFieldCapabilities> => {
23-
const { name, updated_at_millis, indices } = searchApplication;
24+
const { name, updated_at_millis } = searchApplication;
25+
26+
const indices = await fetchAliasIndices(client, name);
2427

2528
const availableIndicesList = await availableIndices(client, indices);
2629

0 commit comments

Comments
 (0)