Skip to content

Commit 969d5e9

Browse files
[Enterprise Search] Migrate shared SourceConfigFields component
1 parent ae992ba commit 969d5e9

3 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export { SourceConfigFields } from './source_config_fields';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React from 'react';
8+
import { shallow } from 'enzyme';
9+
10+
import { ApiKey } from '../api_key';
11+
import { CredentialItem } from '../credential_item';
12+
13+
import { SourceConfigFields } from './';
14+
15+
describe('SourceConfigFields', () => {
16+
it('renders empty with no items', () => {
17+
const wrapper = shallow(<SourceConfigFields />);
18+
19+
expect(wrapper.find(ApiKey)).toHaveLength(0);
20+
expect(wrapper.find(CredentialItem)).toHaveLength(0);
21+
});
22+
23+
it('renders with all items, hiding API Keys', () => {
24+
const wrapper = shallow(
25+
<SourceConfigFields
26+
clientId="123"
27+
clientSecret="456"
28+
publicKey="abc"
29+
consumerKey="def"
30+
baseUrl="ghi"
31+
/>
32+
);
33+
34+
expect(wrapper.find(ApiKey)).toHaveLength(0);
35+
expect(wrapper.find(CredentialItem)).toHaveLength(3);
36+
});
37+
38+
it('shows API keys', () => {
39+
const wrapper = shallow(
40+
<SourceConfigFields clientSecret="456" publicKey="abc" consumerKey="def" baseUrl="ghi" />
41+
);
42+
43+
expect(wrapper.find(ApiKey)).toHaveLength(2);
44+
});
45+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React from 'react';
8+
9+
import { EuiSpacer } from '@elastic/eui';
10+
11+
import { ApiKey } from '../api_key';
12+
import { CredentialItem } from '../credential_item';
13+
14+
interface ISourceConfigFieldsProps {
15+
clientId?: string;
16+
clientSecret?: string;
17+
publicKey?: string;
18+
consumerKey?: string;
19+
baseUrl?: string;
20+
}
21+
22+
export const SourceConfigFields: React.FC<ISourceConfigFieldsProps> = ({
23+
clientId,
24+
clientSecret,
25+
publicKey,
26+
consumerKey,
27+
baseUrl,
28+
}) => {
29+
const showApiKey = (publicKey || consumerKey) && !clientId;
30+
31+
const credentialItem = (label: string, item?: string) =>
32+
item && <CredentialItem label={label} value={item} testSubj={label} hideCopy />;
33+
34+
const keyElement = (
35+
<>
36+
{publicKey && (
37+
<>
38+
<ApiKey label="Public Key" apiKey={publicKey} />
39+
<EuiSpacer />
40+
</>
41+
)}
42+
{consumerKey && (
43+
<>
44+
<ApiKey label="Consumer Key" apiKey={consumerKey} />
45+
<EuiSpacer />
46+
</>
47+
)}
48+
</>
49+
);
50+
51+
return (
52+
<>
53+
{showApiKey && keyElement}
54+
{credentialItem('Client id', clientId)}
55+
<EuiSpacer size="s" />
56+
{credentialItem('Client secret', clientSecret)}
57+
<EuiSpacer size="s" />
58+
{credentialItem('Base URL', baseUrl)}
59+
</>
60+
);
61+
};

0 commit comments

Comments
 (0)