diff --git a/x-pack/platform/plugins/shared/index_management/public/application/components/no_match/no_match.tsx b/x-pack/platform/plugins/shared/index_management/public/application/components/no_match/no_match.tsx index 71673cdd24900..339e98aba640e 100644 --- a/x-pack/platform/plugins/shared/index_management/public/application/components/no_match/no_match.tsx +++ b/x-pack/platform/plugins/shared/index_management/public/application/components/no_match/no_match.tsx @@ -13,13 +13,11 @@ import { CreateIndexButton } from '../../sections/home/index_list/create_index/c import type { ExtensionsService } from '../../../services/extensions_service'; export const NoMatch = ({ - loadIndices, filter, resetFilter, extensionsService, share, }: { - loadIndices: () => void; filter: string; resetFilter: () => void; extensionsService: ExtensionsService; @@ -66,11 +64,7 @@ export const NoMatch = ({ if (extensionsService.emptyListContent) { return extensionsService.emptyListContent.renderContent({ createIndexButton: ( - + ), }); } @@ -94,13 +88,7 @@ export const NoMatch = ({ />

} - actions={ - - } + actions={} /> ); }; diff --git a/x-pack/platform/plugins/shared/index_management/public/application/index.tsx b/x-pack/platform/plugins/shared/index_management/public/application/index.tsx index 06893252e3acb..7ccde02f87f1c 100644 --- a/x-pack/platform/plugins/shared/index_management/public/application/index.tsx +++ b/x-pack/platform/plugins/shared/index_management/public/application/index.tsx @@ -20,12 +20,14 @@ import { useKibana as useKibanaReactPlugin, KibanaRenderContextProvider, } from '../shared_imports'; +import { loadIndices$ } from './services/api'; import type { AppDependencies } from './app_context'; import { AppContextProvider } from './app_context'; import { App } from './app'; import { indexManagementStore } from './store'; import { ComponentTemplatesProvider, MappingsEditorProvider } from './components'; +import { loadIndicesSuccess } from './store/actions/load_indices'; const { GlobalFlyoutProvider } = GlobalFlyout; @@ -80,11 +82,16 @@ export const IndexManagementAppContext: React.FC startServices, }; + const store = indexManagementStore(services); + loadIndices$.subscribe((indices) => { + store.dispatch(loadIndicesSuccess({ indices })); + }); + return ( - + diff --git a/x-pack/platform/plugins/shared/index_management/public/application/sections/home/index_list/create_index/create_index_button.tsx b/x-pack/platform/plugins/shared/index_management/public/application/sections/home/index_list/create_index/create_index_button.tsx index 99db6adcc1001..ff7e00443c89e 100644 --- a/x-pack/platform/plugins/shared/index_management/public/application/sections/home/index_list/create_index/create_index_button.tsx +++ b/x-pack/platform/plugins/shared/index_management/public/application/sections/home/index_list/create_index/create_index_button.tsx @@ -15,12 +15,11 @@ import { CreateIndexModal } from './create_index_modal'; import { useAppContext } from '../../../../app_context'; export interface CreateIndexButtonProps { - loadIndices: () => void; share?: SharePluginStart; dataTestSubj?: string; } -export const CreateIndexButton = ({ loadIndices, share, dataTestSubj }: CreateIndexButtonProps) => { +export const CreateIndexButton = ({ share, dataTestSubj }: CreateIndexButtonProps) => { const [createIndexModalOpen, setCreateIndexModalOpen] = useState(false); const createIndexUrl = share?.url.locators.get('SEARCH_CREATE_INDEX')?.useUrl({}); @@ -51,10 +50,7 @@ export const CreateIndexButton = ({ loadIndices, share, dataTestSubj }: CreateIn /> {createIndexModalOpen && ( - setCreateIndexModalOpen(false)} - loadIndices={loadIndices} - /> + setCreateIndexModalOpen(false)} /> )} ); diff --git a/x-pack/platform/plugins/shared/index_management/public/application/sections/home/index_list/create_index/create_index_modal.tsx b/x-pack/platform/plugins/shared/index_management/public/application/sections/home/index_list/create_index/create_index_modal.tsx index c9c9577274e75..7dec5ec5dca37 100644 --- a/x-pack/platform/plugins/shared/index_management/public/application/sections/home/index_list/create_index/create_index_modal.tsx +++ b/x-pack/platform/plugins/shared/index_management/public/application/sections/home/index_list/create_index/create_index_modal.tsx @@ -30,6 +30,7 @@ import { LOOKUP_INDEX_MODE, STANDARD_INDEX_MODE } from '../../../../../../common import { indexModeDescriptions, indexModeLabels } from '../../../../lib/index_mode_labels'; import { createIndex } from '../../../../services'; import { notificationService } from '../../../../services/notification'; +import { loadIndices } from '../../../../services/api'; import { isValidIndexName } from './utils'; @@ -40,10 +41,9 @@ const INVALID_INDEX_NAME_ERROR = i18n.translate( export interface CreateIndexModalProps { closeModal: () => void; - loadIndices: () => void; } -export const CreateIndexModal = ({ closeModal, loadIndices }: CreateIndexModalProps) => { +export const CreateIndexModal = ({ closeModal }: CreateIndexModalProps) => { const modalTitleId = useGeneratedHtmlId(); const [indexName, setIndexName] = useState(''); @@ -65,6 +65,7 @@ export const CreateIndexModal = ({ closeModal, loadIndices }: CreateIndexModalPr }) ); closeModal(); + loadIndices(); return; } @@ -73,7 +74,7 @@ export const CreateIndexModal = ({ closeModal, loadIndices }: CreateIndexModalPr setIsSaving(false); setCreateError(e.message); } - }, [closeModal, indexMode, indexName, loadIndices]); + }, [closeModal, indexMode, indexName]); const onSave = () => { if (isValidIndexName(indexName)) { diff --git a/x-pack/platform/plugins/shared/index_management/public/application/sections/home/index_list/index_table/index_table.container.js b/x-pack/platform/plugins/shared/index_management/public/application/sections/home/index_list/index_table/index_table.container.js index 66406576902c2..6250b8a907e2b 100644 --- a/x-pack/platform/plugins/shared/index_management/public/application/sections/home/index_list/index_table/index_table.container.js +++ b/x-pack/platform/plugins/shared/index_management/public/application/sections/home/index_list/index_table/index_table.container.js @@ -23,7 +23,6 @@ import { pageChanged, pageSizeChanged, sortChanged, - loadIndices, toggleChanged, performExtensionAction, } from '../../../../store/actions'; @@ -61,9 +60,6 @@ const mapDispatchToProps = (dispatch) => { toggleChanged: (toggleName, toggleValue) => { dispatch(toggleChanged({ toggleName, toggleValue })); }, - loadIndices: () => { - dispatch(loadIndices()); - }, performExtensionAction: (requestMethod, successMessage, indexNames) => { dispatch(performExtensionAction({ requestMethod, successMessage, indexNames })); }, diff --git a/x-pack/platform/plugins/shared/index_management/public/application/sections/home/index_list/index_table/index_table.js b/x-pack/platform/plugins/shared/index_management/public/application/sections/home/index_list/index_table/index_table.js index 37c257995f63c..e64c774ba56c2 100644 --- a/x-pack/platform/plugins/shared/index_management/public/application/sections/home/index_list/index_table/index_table.js +++ b/x-pack/platform/plugins/shared/index_management/public/application/sections/home/index_list/index_table/index_table.js @@ -51,6 +51,7 @@ import { CreateIndexButton } from '../create_index/create_index_button'; import { IndexTablePagination, PAGE_SIZE_OPTIONS } from './index_table_pagination'; import { DocCountCell } from './doc_count'; import { docCountApi } from './get_doc_count'; +import { loadIndices } from '../../../../services/api'; const getColumnConfigs = ({ showIndexStats, @@ -207,7 +208,7 @@ export class IndexTable extends Component { } componentDidMount() { - this.props.loadIndices(); + loadIndices(); const { filterChanged, pageSizeChanged, pageChanged, toggleNameToVisibleMap, toggleChanged } = this.props; diff --git a/x-pack/platform/plugins/shared/index_management/public/application/services/api.ts b/x-pack/platform/plugins/shared/index_management/public/application/services/api.ts index c33fcdd2d5a7e..fa757a2bbd660 100644 --- a/x-pack/platform/plugins/shared/index_management/public/application/services/api.ts +++ b/x-pack/platform/plugins/shared/index_management/public/application/services/api.ts @@ -11,6 +11,7 @@ import type { IndicesStatsResponse } from '@elastic/elasticsearch/lib/api/types' import type { InferenceAPIConfigResponse } from '@kbn/ml-trained-models-utils'; import type { MappingTypeMapping } from '@elastic/elasticsearch/lib/api/types'; import type { ReindexService } from '@kbn/reindex-service-plugin/public'; +import { from, Subject, mergeMap } from 'rxjs'; import { API_BASE_PATH, INTERNAL_API_BASE_PATH, @@ -142,9 +143,12 @@ export async function updateDSFailureStore( export async function loadIndices() { const response = await httpService.httpClient.get(`${API_BASE_PATH}/indices`); - return response.data ? response.data : response; + internalLoadIndicesSubject.next(response.data); } +const internalLoadIndicesSubject = new Subject<{}>(); +export const loadIndices$ = internalLoadIndicesSubject.asObservable(); + export async function reloadIndices( indexNames: string[], { asSystemRequest }: ReloadIndicesOptions = {} diff --git a/x-pack/platform/plugins/shared/index_management/public/application/store/actions/load_indices.js b/x-pack/platform/plugins/shared/index_management/public/application/store/actions/load_indices.js index f5a5679b02767..69f983a20574e 100644 --- a/x-pack/platform/plugins/shared/index_management/public/application/store/actions/load_indices.js +++ b/x-pack/platform/plugins/shared/index_management/public/application/store/actions/load_indices.js @@ -6,19 +6,7 @@ */ import { createAction } from 'redux-actions'; -import { loadIndices as request } from '../../services'; export const loadIndicesStart = createAction('INDEX_MANAGEMENT_LOAD_INDICES_START'); export const loadIndicesSuccess = createAction('INDEX_MANAGEMENT_LOAD_INDICES_SUCCESS'); export const loadIndicesError = createAction('INDEX_MANAGEMENT_LOAD_INDICES_ERROR'); - -export const loadIndices = () => async (dispatch) => { - dispatch(loadIndicesStart()); - let indices; - try { - indices = await request(); - } catch (error) { - return dispatch(loadIndicesError(error)); - } - dispatch(loadIndicesSuccess({ indices })); -}; diff --git a/x-pack/platform/plugins/shared/index_management/public/application/store/actions/reload_indices.js b/x-pack/platform/plugins/shared/index_management/public/application/store/actions/reload_indices.js index 99f6b92eb2c4f..421f139855b68 100644 --- a/x-pack/platform/plugins/shared/index_management/public/application/store/actions/reload_indices.js +++ b/x-pack/platform/plugins/shared/index_management/public/application/store/actions/reload_indices.js @@ -8,8 +8,8 @@ import { createAction } from 'redux-actions'; import { i18n } from '@kbn/i18n'; import { reloadIndices as request } from '../../services'; -import { loadIndices } from './load_indices'; import { notificationService } from '../../services/notification'; +import { loadIndices } from '../../services/api'; export const reloadIndicesSuccess = createAction('INDEX_MANAGEMENT_RELOAD_INDICES_SUCCESS'); export const reloadIndices = (indexNames, options) => async (dispatch) => { @@ -21,7 +21,7 @@ export const reloadIndices = (indexNames, options) => async (dispatch) => { // or the user does not have privileges for one of the indices on the current page, // reload the full list if (error.status === 404 || error.status === 403) { - return dispatch(loadIndices()); + loadIndices(); } return notificationService.showDangerToast(error.body.message); }