forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Search] Change endpoint to filter out already attached indices (elas…
…tic#178647) ## Summary https://github.com/elastic/kibana/assets/1410658/9ab9af95-09eb-4a82-980c-f6df1daa5105 Attach box fetch is moved to a simplified copy of the same endpoint for filtering out already attached indices. It helped also simplifying the FE code. ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [x] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [x] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
- Loading branch information
Showing
6 changed files
with
180 additions
and
42 deletions.
There are no files selected for viewing
31 changes: 0 additions & 31 deletions
31
...ch/public/applications/enterprise_search_content/api/index/fetch_all_indices_api_logic.ts
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
...lic/applications/enterprise_search_content/api/index/fetch_available_indices_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,43 @@ | ||
/* | ||
* 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 { Meta } from '../../../../../common/types/pagination'; | ||
|
||
import { Actions, createApiLogic } from '../../../shared/api_logic/create_api_logic'; | ||
import { INPUT_THROTTLE_DELAY_MS } from '../../../shared/constants/timers'; | ||
import { HttpLogic } from '../../../shared/http'; | ||
|
||
export interface FetchAvailabeIndicesApiParams { | ||
searchQuery?: string; | ||
} | ||
export interface FetchAvailableIndicesApiResponse { | ||
indexNames: string[]; | ||
meta: Meta; | ||
} | ||
|
||
export const fetchAvailableIndices = async ({ | ||
searchQuery, | ||
}: FetchAvailabeIndicesApiParams): Promise<FetchAvailableIndicesApiResponse> => { | ||
const { http } = HttpLogic.values; | ||
const route = '/internal/enterprise_search/connectors/available_indices'; | ||
const query = { search_query: searchQuery || null }; | ||
const response = await http.get<FetchAvailableIndicesApiResponse>(route, { query }); | ||
return response; | ||
}; | ||
|
||
export const FetchAvailableIndicesAPILogic = createApiLogic( | ||
['content', 'fetch_available_indices_api_logic'], | ||
fetchAvailableIndices, | ||
{ | ||
requestBreakpointMS: INPUT_THROTTLE_DELAY_MS, | ||
} | ||
); | ||
|
||
export type FetchAvailableIndicesApiActions = Actions< | ||
FetchAvailabeIndicesApiParams, | ||
FetchAvailableIndicesApiResponse | ||
>; |
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
50 changes: 50 additions & 0 deletions
50
x-pack/plugins/enterprise_search/server/lib/indices/fetch_unattached_indices.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,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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { IScopedClusterClient } from '@kbn/core/server'; | ||
import { fetchConnectors } from '@kbn/search-connectors'; | ||
|
||
import { isNotNullish } from '../../../common/utils/is_not_nullish'; | ||
import { fetchCrawlers } from '../crawler/fetch_crawlers'; | ||
|
||
import { getUnattachedIndexData } from './utils/get_index_data'; | ||
|
||
export const fetchUnattachedIndices = async ( | ||
client: IScopedClusterClient, | ||
searchQuery: string | undefined, | ||
from: number, | ||
size: number | ||
): Promise<{ | ||
indexNames: string[]; | ||
totalResults: number; | ||
}> => { | ||
const { indexNames } = await getUnattachedIndexData(client, searchQuery); | ||
const connectors = await fetchConnectors(client.asCurrentUser, indexNames); | ||
const crawlers = await fetchCrawlers(client, indexNames); | ||
|
||
const connectedIndexNames = [ | ||
...connectors.map((con) => con.index_name).filter(isNotNullish), | ||
...crawlers.map((crawler) => crawler.index_name).filter(isNotNullish), | ||
]; | ||
|
||
const indexNameSlice = indexNames | ||
.filter((indexName) => !connectedIndexNames.includes(indexName)) | ||
.filter(isNotNullish) | ||
.slice(from, from + size); | ||
|
||
if (indexNameSlice.length === 0) { | ||
return { | ||
indexNames: [], | ||
totalResults: indexNames.length, | ||
}; | ||
} | ||
|
||
return { | ||
indexNames: indexNameSlice, | ||
totalResults: indexNames.length, | ||
}; | ||
}; |
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