-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '8.8' into backport/8.8/pr-155795
- Loading branch information
Showing
25 changed files
with
9,252 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
.../applications/enterprise_search_content/api/connector/convert_connector_api_logic.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { mockHttpValues } from '../../../__mocks__/kea_logic'; | ||
|
||
import { nextTick } from '@kbn/test-jest-helpers'; | ||
|
||
import { convertConnector } from './convert_connector_api_logic'; | ||
|
||
describe('ConvertConnectorApilogic', () => { | ||
const { http } = mockHttpValues; | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
describe('convertConnector', () => { | ||
it('calls correct api', async () => { | ||
const promise = Promise.resolve('result'); | ||
http.put.mockReturnValue(promise); | ||
const result = convertConnector({ connectorId: 'connectorId1' }); | ||
await nextTick(); | ||
expect(http.put).toHaveBeenCalledWith( | ||
'/internal/enterprise_search/connectors/connectorId1/native', | ||
{ body: JSON.stringify({ is_native: false }) } | ||
); | ||
await expect(result).resolves.toEqual('result'); | ||
}); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
...ublic/applications/enterprise_search_content/api/connector/convert_connector_api_logic.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { createApiLogic } from '../../../shared/api_logic/create_api_logic'; | ||
import { HttpLogic } from '../../../shared/http'; | ||
|
||
export interface ConvertConnectorApiLogicArgs { | ||
connectorId: string; | ||
} | ||
|
||
export interface ConvertConnectorApiLogicResponse { | ||
updated: boolean; | ||
} | ||
|
||
export const convertConnector = async ({ | ||
connectorId, | ||
}: ConvertConnectorApiLogicArgs): Promise<ConvertConnectorApiLogicResponse> => { | ||
const route = `/internal/enterprise_search/connectors/${connectorId}/native`; | ||
|
||
return await HttpLogic.values.http.put<{ updated: boolean }>(route, { | ||
body: JSON.stringify({ is_native: false }), | ||
}); | ||
}; | ||
|
||
export const ConvertConnectorApiLogic = createApiLogic( | ||
['convert_connector_api_logic'], | ||
convertConnector | ||
); |
115 changes: 115 additions & 0 deletions
115
...nt/components/search_index/connector/native_connector_configuration/convert_connector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { useActions, useValues } from 'kea'; | ||
|
||
import { | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiIcon, | ||
EuiTitle, | ||
EuiSpacer, | ||
EuiText, | ||
EuiLink, | ||
EuiButton, | ||
EuiConfirmModal, | ||
} from '@elastic/eui'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
|
||
import { CANCEL_BUTTON_LABEL } from '../../../../../shared/constants'; | ||
|
||
import { docLinks } from '../../../../../shared/doc_links'; | ||
|
||
import { ConvertConnectorLogic } from './convert_connector_logic'; | ||
|
||
export const ConvertConnector: React.FC = () => { | ||
const { convertConnector, hideModal, showModal } = useActions(ConvertConnectorLogic); | ||
const { isLoading, isModalVisible } = useValues(ConvertConnectorLogic); | ||
|
||
return ( | ||
<> | ||
{isModalVisible && ( | ||
<EuiConfirmModal | ||
onCancel={() => hideModal()} | ||
onConfirm={() => convertConnector()} | ||
title={i18n.translate( | ||
'xpack.enterpriseSearch.content.engine.indices.convertInfexConfirm.title', | ||
{ defaultMessage: 'Sure you want to convert your connector?' } | ||
)} | ||
buttonColor="danger" | ||
cancelButtonText={CANCEL_BUTTON_LABEL} | ||
confirmButtonText={i18n.translate( | ||
'xpack.enterpriseSearch.content.engine.indices.convertIndexConfirm.text', | ||
{ | ||
defaultMessage: 'Yes', | ||
} | ||
)} | ||
isLoading={isLoading} | ||
defaultFocusedButton="confirm" | ||
maxWidth | ||
> | ||
<EuiText> | ||
<p> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.content.engine.indices.convertIndexConfirm.description', | ||
{ | ||
defaultMessage: | ||
"Once you convert a native connector to a self-managed connector client this can't be undone.", | ||
} | ||
)} | ||
</p> | ||
</EuiText> | ||
</EuiConfirmModal> | ||
)} | ||
<EuiFlexGroup direction="row" alignItems="center" gutterSize="xs"> | ||
<EuiFlexItem grow={false}> | ||
<EuiIcon type="wrench" /> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiTitle size="xxs"> | ||
<h4> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.content.indices.configurationConnector.nativeConnector.convertConnector.title', | ||
{ | ||
defaultMessage: 'Customize your connector', | ||
} | ||
)} | ||
</h4> | ||
</EuiTitle> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
<EuiSpacer size="s" /> | ||
<EuiText size="s"> | ||
<FormattedMessage | ||
id="xpack.enterpriseSearch.content.indices.configurationConnector.nativeConnector.convertConnector.description" | ||
defaultMessage="Want to customize this native connector? Convert it to a {link}, to be self-managed on your own infrastructure." | ||
values={{ | ||
link: ( | ||
<EuiLink href={docLinks.buildConnector} target="_blank"> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.content.indices.configurationConnector.nativeConnector.convertConnector.linkTitle', | ||
{ defaultMessage: 'connector client' } | ||
)} | ||
</EuiLink> | ||
), | ||
}} | ||
/> | ||
<EuiSpacer size="s" /> | ||
<EuiButton onClick={() => showModal()}> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.content.indices.configurationConnector.nativeConnector.convertConnector.buttonTitle', | ||
{ defaultMessage: 'Convert connector' } | ||
)} | ||
</EuiButton> | ||
</EuiText> | ||
</> | ||
); | ||
}; |
82 changes: 82 additions & 0 deletions
82
...ponents/search_index/connector/native_connector_configuration/convert_connector_logic.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { kea, MakeLogicType } from 'kea'; | ||
|
||
import { Status } from '../../../../../../../common/types/api'; | ||
import { Actions } from '../../../../../shared/api_logic/create_api_logic'; | ||
import { | ||
ConvertConnectorApiLogic, | ||
ConvertConnectorApiLogicArgs, | ||
ConvertConnectorApiLogicResponse, | ||
} from '../../../../api/connector/convert_connector_api_logic'; | ||
import { IndexViewActions, IndexViewLogic } from '../../index_view_logic'; | ||
|
||
interface ConvertConnectorValues { | ||
connectorId: typeof IndexViewLogic.values.connectorId; | ||
isLoading: boolean; | ||
isModalVisible: boolean; | ||
status: Status; | ||
} | ||
|
||
type ConvertConnectorActions = Pick< | ||
Actions<ConvertConnectorApiLogicArgs, ConvertConnectorApiLogicResponse>, | ||
'apiError' | 'apiSuccess' | 'makeRequest' | ||
> & { | ||
convertConnector(): void; | ||
fetchIndex(): IndexViewActions['fetchIndex']; | ||
hideModal(): void; | ||
showModal(): void; | ||
}; | ||
|
||
export const ConvertConnectorLogic = kea< | ||
MakeLogicType<ConvertConnectorValues, ConvertConnectorActions> | ||
>({ | ||
actions: { | ||
convertConnector: () => true, | ||
deleteDomain: () => true, | ||
hideModal: () => true, | ||
showModal: () => true, | ||
}, | ||
connect: { | ||
actions: [ | ||
ConvertConnectorApiLogic, | ||
['apiError', 'apiSuccess', 'makeRequest'], | ||
IndexViewLogic, | ||
['fetchIndex'], | ||
], | ||
values: [ConvertConnectorApiLogic, ['status'], IndexViewLogic, ['connectorId']], | ||
}, | ||
listeners: ({ actions, values }) => ({ | ||
convertConnector: () => { | ||
if (values.connectorId) { | ||
actions.makeRequest({ connectorId: values.connectorId }); | ||
} | ||
}, | ||
}), | ||
path: ['enterprise_search', 'convert_connector_modal'], | ||
reducers: { | ||
isModalVisible: [ | ||
false, | ||
{ | ||
apiError: () => false, | ||
apiSuccess: () => false, | ||
hideModal: () => false, | ||
showModal: () => true, | ||
}, | ||
], | ||
}, | ||
selectors: ({ selectors }) => ({ | ||
isLoading: [() => [selectors.status], (status: Status) => status === Status.LOADING], | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
x-pack/plugins/enterprise_search/server/lib/connectors/put_update_native.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { IScopedClusterClient } from '@kbn/core-elasticsearch-server'; | ||
|
||
import { CONNECTORS_INDEX } from '../..'; | ||
import { Connector } from '../../../common/types/connectors'; | ||
|
||
export const putUpdateNative = async ( | ||
client: IScopedClusterClient, | ||
connectorId: string, | ||
isNative: boolean | ||
) => { | ||
const result = await client.asCurrentUser.update<Connector>({ | ||
doc: { | ||
is_native: isNative, | ||
}, | ||
id: connectorId, | ||
index: CONNECTORS_INDEX, | ||
}); | ||
|
||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.