-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enterprise Search] Show error for crawlers without a connector docum…
…ent (#150928) ## Summary This shows an error for broken crawlers, where a connector document has been deleted. It offers users the choice to recreate the connector or delete their index. https://user-images.githubusercontent.com/94373878/221916920-f75299b4-f88d-4cba-89a2-92fe62366050.mov https://user-images.githubusercontent.com/94373878/221916935-b416a782-92b4-4795-a1af-73e97fa523c8.mov
- Loading branch information
Showing
18 changed files
with
757 additions
and
102 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...ations/enterprise_search_content/api/crawler/recreate_crawler_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,33 @@ | ||
/* | ||
* 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 { recreateCrawlerConnector } from './recreate_crawler_connector_api_logic'; | ||
|
||
describe('CreateCrawlerIndexApiLogic', () => { | ||
const { http } = mockHttpValues; | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
describe('createCrawlerIndex', () => { | ||
it('calls correct api', async () => { | ||
const indexName = 'elastic-co-crawler'; | ||
http.post.mockReturnValue(Promise.resolve({ connector_id: 'connectorId' })); | ||
|
||
const result = recreateCrawlerConnector({ indexName }); | ||
await nextTick(); | ||
|
||
expect(http.post).toHaveBeenCalledWith( | ||
'/internal/enterprise_search/indices/elastic-co-crawler/crawler/connector' | ||
); | ||
await expect(result).resolves.toEqual({ connector_id: 'connectorId' }); | ||
}); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
...pplications/enterprise_search_content/api/crawler/recreate_crawler_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,33 @@ | ||
/* | ||
* 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 { Actions, createApiLogic } from '../../../shared/api_logic/create_api_logic'; | ||
import { HttpLogic } from '../../../shared/http'; | ||
|
||
export interface RecreateCrawlerConnectorArgs { | ||
indexName: string; | ||
} | ||
|
||
export interface RecreateCrawlerConnectorResponse { | ||
created: string; // the name of the newly created index | ||
} | ||
|
||
export const recreateCrawlerConnector = async ({ indexName }: RecreateCrawlerConnectorArgs) => { | ||
const route = `/internal/enterprise_search/indices/${indexName}/crawler/connector`; | ||
|
||
return await HttpLogic.values.http.post<RecreateCrawlerConnectorResponse>(route); | ||
}; | ||
|
||
export const RecreateCrawlerConnectorApiLogic = createApiLogic( | ||
['recreate_crawler_connector_api_logic'], | ||
recreateCrawlerConnector | ||
); | ||
|
||
export type RecreateCrawlerConnectorActions = Actions< | ||
RecreateCrawlerConnectorArgs, | ||
RecreateCrawlerConnectorResponse | ||
>; |
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
94 changes: 94 additions & 0 deletions
94
...cations/enterprise_search_content/components/search_index/crawler/no_connector_record.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,94 @@ | ||
/* | ||
* 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 { EuiButton, EuiPageTemplate } from '@elastic/eui'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { Status } from '../../../../../../common/types/api'; | ||
|
||
import { RecreateCrawlerConnectorApiLogic } from '../../../api/crawler/recreate_crawler_connector_api_logic'; | ||
import { DeleteIndexModal } from '../../search_indices/delete_index_modal'; | ||
import { IndicesLogic } from '../../search_indices/indices_logic'; | ||
import { IndexViewLogic } from '../index_view_logic'; | ||
|
||
import { NoConnectorRecordLogic } from './no_connector_record_logic'; | ||
|
||
export const NoConnectorRecord: React.FC = () => { | ||
const { indexName } = useValues(IndexViewLogic); | ||
const { isDeleteLoading } = useValues(IndicesLogic); | ||
const { openDeleteModal } = useActions(IndicesLogic); | ||
const { makeRequest } = useActions(RecreateCrawlerConnectorApiLogic); | ||
const { status } = useValues(RecreateCrawlerConnectorApiLogic); | ||
NoConnectorRecordLogic.mount(); | ||
const buttonsDisabled = status === Status.LOADING || isDeleteLoading; | ||
|
||
return ( | ||
<> | ||
<DeleteIndexModal /> | ||
|
||
<EuiPageTemplate.EmptyPrompt | ||
iconType="alert" | ||
color="danger" | ||
title={ | ||
<h2> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.content.searchIndex.noCrawlerConnectorFound.title', | ||
{ | ||
defaultMessage: "This index's connector configuration has been removed", | ||
} | ||
)} | ||
</h2> | ||
} | ||
body={ | ||
<p> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.content.searchIndex.noCrawlerConnectorFound.description', | ||
{ | ||
defaultMessage: | ||
'We could not find a connector configuration for this crawler index. The record should be recreated, or the index should be deleted.', | ||
} | ||
)} | ||
</p> | ||
} | ||
actions={[ | ||
<EuiButton | ||
color="danger" | ||
disabled={buttonsDisabled} | ||
isLoading={status === Status.LOADING} | ||
onClick={() => makeRequest({ indexName })} | ||
> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.content.searchIndex.noCrawlerConnectorFound.recreateConnectorRecord', | ||
{ | ||
defaultMessage: 'Recreate connector record', | ||
} | ||
)} | ||
</EuiButton>, | ||
<EuiButton | ||
color="danger" | ||
disabled={buttonsDisabled} | ||
isLoading={isDeleteLoading} | ||
fill | ||
onClick={() => openDeleteModal(indexName)} | ||
> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.content.searchIndex.noCrawlerConnectorFound.deleteIndex', | ||
{ | ||
defaultMessage: 'Delete index', | ||
} | ||
)} | ||
</EuiButton>, | ||
]} | ||
/> | ||
</> | ||
); | ||
}; |
37 changes: 37 additions & 0 deletions
37
...terprise_search_content/components/search_index/crawler/no_connector_record_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,37 @@ | ||
/* | ||
* 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 { LogicMounter } from '../../../../__mocks__/kea_logic'; | ||
|
||
import { KibanaLogic } from '../../../../shared/kibana'; | ||
|
||
import { RecreateCrawlerConnectorApiLogic } from '../../../api/crawler/recreate_crawler_connector_api_logic'; | ||
import { DeleteIndexApiLogic } from '../../../api/index/delete_index_api_logic'; | ||
import { SEARCH_INDICES_PATH } from '../../../routes'; | ||
|
||
import { NoConnectorRecordLogic } from './no_connector_record_logic'; | ||
|
||
describe('NoConnectorRecordLogic', () => { | ||
const { mount: deleteMount } = new LogicMounter(DeleteIndexApiLogic); | ||
const { mount: recreateMount } = new LogicMounter(RecreateCrawlerConnectorApiLogic); | ||
const { mount } = new LogicMounter(NoConnectorRecordLogic); | ||
beforeEach(() => { | ||
deleteMount(); | ||
recreateMount(); | ||
mount(); | ||
}); | ||
it('should redirect to search indices on delete', () => { | ||
KibanaLogic.values.navigateToUrl = jest.fn(); | ||
DeleteIndexApiLogic.actions.apiSuccess({} as any); | ||
expect(KibanaLogic.values.navigateToUrl).toHaveBeenCalledWith(SEARCH_INDICES_PATH); | ||
}); | ||
it('should fetch index on recreate', () => { | ||
NoConnectorRecordLogic.actions.fetchIndex = jest.fn(); | ||
RecreateCrawlerConnectorApiLogic.actions.apiSuccess({} as any); | ||
expect(NoConnectorRecordLogic.actions.fetchIndex).toHaveBeenCalled(); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
...ns/enterprise_search_content/components/search_index/crawler/no_connector_record_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,48 @@ | ||
/* | ||
* 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 { KibanaLogic } from '../../../../shared/kibana'; | ||
|
||
import { | ||
RecreateCrawlerConnectorActions, | ||
RecreateCrawlerConnectorApiLogic, | ||
} from '../../../api/crawler/recreate_crawler_connector_api_logic'; | ||
import { | ||
DeleteIndexApiActions, | ||
DeleteIndexApiLogic, | ||
} from '../../../api/index/delete_index_api_logic'; | ||
import { SEARCH_INDICES_PATH } from '../../../routes'; | ||
import { IndexViewActions, IndexViewLogic } from '../index_view_logic'; | ||
|
||
type NoConnectorRecordActions = RecreateCrawlerConnectorActions['apiSuccess'] & { | ||
deleteSuccess: DeleteIndexApiActions['apiSuccess']; | ||
fetchIndex: IndexViewActions['fetchIndex']; | ||
}; | ||
|
||
export const NoConnectorRecordLogic = kea<MakeLogicType<{}, NoConnectorRecordActions>>({ | ||
connect: { | ||
actions: [ | ||
RecreateCrawlerConnectorApiLogic, | ||
['apiSuccess'], | ||
IndexViewLogic, | ||
['fetchIndex'], | ||
DeleteIndexApiLogic, | ||
['apiSuccess as deleteSuccess'], | ||
], | ||
}, | ||
listeners: ({ actions }) => ({ | ||
apiSuccess: () => { | ||
actions.fetchIndex(); | ||
}, | ||
deleteSuccess: () => { | ||
KibanaLogic.values.navigateToUrl(SEARCH_INDICES_PATH); | ||
}, | ||
}), | ||
path: ['enterprise_search', 'content', 'no_connector_record'], | ||
}); |
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
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
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.