-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into api/serverlessQA
- Loading branch information
Showing
71 changed files
with
1,563 additions
and
771 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/kbn-search-connectors/components/sync_jobs/sync_job_cancel_modal.test.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,50 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { CancelSyncJobModal } from './sync_job_cancel_modal'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import { I18nProvider } from '@kbn/i18n-react'; | ||
|
||
describe('CancelSyncJobModal', () => { | ||
const mockSyncJobId = '123'; | ||
const mockOnConfirmCb = jest.fn(); | ||
const mockOnCancel = jest.fn(); | ||
|
||
beforeEach(() => { | ||
render( | ||
<I18nProvider> | ||
<CancelSyncJobModal | ||
syncJobId={mockSyncJobId} | ||
onConfirmCb={mockOnConfirmCb} | ||
onCancel={mockOnCancel} | ||
isLoading={false} | ||
errorMessages={[]} | ||
/> | ||
</I18nProvider> | ||
); | ||
}); | ||
|
||
test('renders the sync job ID', () => { | ||
const syncJobIdElement = screen.getByTestId('confirmModalBodyText'); | ||
expect(syncJobIdElement).toHaveTextContent(`Sync job ID: ${mockSyncJobId}`); | ||
}); | ||
|
||
test('calls onConfirmCb when confirm button is clicked', () => { | ||
const confirmButton = screen.getByText('Confirm'); | ||
fireEvent.click(confirmButton); | ||
expect(mockOnConfirmCb).toHaveBeenCalledWith(mockSyncJobId); | ||
}); | ||
|
||
test('calls onCancel when cancel button is clicked', () => { | ||
const cancelButton = screen.getByTestId('confirmModalCancelButton'); | ||
fireEvent.click(cancelButton); | ||
expect(mockOnCancel).toHaveBeenCalled(); | ||
}); | ||
}); |
58 changes: 58 additions & 0 deletions
58
packages/kbn-search-connectors/components/sync_jobs/sync_job_cancel_modal.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,58 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { EuiConfirmModal, EuiText, EuiCode, EuiSpacer, EuiConfirmModalProps } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import React from 'react'; | ||
|
||
export type CancelSyncModalProps = Omit<EuiConfirmModalProps, 'onConfirm'> & { | ||
onConfirmCb: (syncJobId: string) => void; | ||
syncJobId: string; | ||
errorMessages?: string[]; | ||
}; | ||
|
||
export const CancelSyncJobModal: React.FC<CancelSyncModalProps> = ({ | ||
syncJobId, | ||
onCancel, | ||
onConfirmCb, | ||
isLoading, | ||
}) => { | ||
return ( | ||
<EuiConfirmModal | ||
title={i18n.translate('searchConnectors.syncJobs.cancelSyncModal.title', { | ||
defaultMessage: 'Cancel sync job', | ||
})} | ||
onCancel={onCancel} | ||
onConfirm={() => onConfirmCb(syncJobId)} | ||
cancelButtonText={i18n.translate('searchConnectors.syncJobs.cancelSyncModal.cancelButton', { | ||
defaultMessage: 'Cancel', | ||
})} | ||
confirmButtonText={i18n.translate('searchConnectors.syncJobs.cancelSyncModal.confirmButton', { | ||
defaultMessage: 'Confirm', | ||
})} | ||
buttonColor="danger" | ||
confirmButtonDisabled={isLoading} | ||
isLoading={isLoading} | ||
> | ||
<EuiText size="s"> | ||
<FormattedMessage | ||
id="searchConnectors.syncJobs.cancelSyncModal.description" | ||
defaultMessage="Are you sure you want to cancel this sync job?" | ||
/> | ||
<EuiSpacer size="m" /> | ||
<FormattedMessage | ||
id="searchConnectors.syncJobs.cancelSyncModal.syncJobId" | ||
defaultMessage="Sync job ID:" | ||
/> | ||
| ||
<EuiCode>{syncJobId}</EuiCode> | ||
</EuiText> | ||
</EuiConfirmModal> | ||
); | ||
}; |
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
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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; | ||
import { cancelSync } from './cancel_sync'; | ||
|
||
describe('cancelSync lib function', () => { | ||
const mockClient = { | ||
transport: { | ||
request: jest.fn(), | ||
}, | ||
}; | ||
|
||
it('should cancel a sync', async () => { | ||
mockClient.transport.request.mockImplementation(() => ({ | ||
success: true, | ||
})); | ||
|
||
await expect(cancelSync(mockClient as unknown as ElasticsearchClient, '1234')).resolves.toEqual( | ||
{ success: true } | ||
); | ||
expect(mockClient.transport.request).toHaveBeenCalledWith({ | ||
method: 'PUT', | ||
path: '/_connector/_sync_job/1234/_cancel', | ||
}); | ||
}); | ||
}); |
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,18 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; | ||
import { ConnectorAPICancelSyncResponse } from '../types'; | ||
|
||
export const cancelSync = async (client: ElasticsearchClient, syncJobId: string) => { | ||
const result = await client.transport.request<ConnectorAPICancelSyncResponse>({ | ||
method: 'PUT', | ||
path: `/_connector/_sync_job/${syncJobId}/_cancel`, | ||
}); | ||
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.