diff --git a/common/types/explorer.ts b/common/types/explorer.ts index 6a495218c6..98cd7f7cc2 100644 --- a/common/types/explorer.ts +++ b/common/types/explorer.ts @@ -438,4 +438,5 @@ export interface DirectQueryRequest { lang: string; datasource: string; sessionId?: string; + dataSourceMDSId?: string; } diff --git a/public/components/datasources/components/__tests__/acceleration_details_flyout.test.tsx b/public/components/datasources/components/__tests__/acceleration_details_flyout.test.tsx index 1ee87c474b..8f7fe27ebf 100644 --- a/public/components/datasources/components/__tests__/acceleration_details_flyout.test.tsx +++ b/public/components/datasources/components/__tests__/acceleration_details_flyout.test.tsx @@ -76,12 +76,63 @@ describe('AccelerationDetailsFlyout Component Tests', () => { index="mockIndex" acceleration={mockAcceleration} dataSourceName="mockDataSource" + dataSourceMDSId="" /> ); - expect(coreRefsModule.coreRefs.dslService!.fetchFields).toHaveBeenCalledWith('testIndex'); - expect(coreRefsModule.coreRefs.dslService!.fetchSettings).toHaveBeenCalledWith('testIndex'); - expect(coreRefsModule.coreRefs.dslService!.fetchIndices).toHaveBeenCalledWith('testIndex'); + expect(coreRefsModule.coreRefs.dslService!.fetchFields).toHaveBeenCalledWith('testIndex', ''); + expect(coreRefsModule.coreRefs.dslService!.fetchSettings).toHaveBeenCalledWith('testIndex', ''); + expect(coreRefsModule.coreRefs.dslService!.fetchIndices).toHaveBeenCalledWith('testIndex', ''); + }); + + it('fetches acceleration details with specific mdsId', async () => { + mount( + + ); + + expect(coreRefsModule.coreRefs.dslService!.fetchFields).toHaveBeenCalledWith( + 'testIndex', + '746ebe20-ee4a-11ef-823a-bd0a7d9fd697' + ); + expect(coreRefsModule.coreRefs.dslService!.fetchSettings).toHaveBeenCalledWith( + 'testIndex', + '746ebe20-ee4a-11ef-823a-bd0a7d9fd697' + ); + expect(coreRefsModule.coreRefs.dslService!.fetchIndices).toHaveBeenCalledWith( + 'testIndex', + '746ebe20-ee4a-11ef-823a-bd0a7d9fd697' + ); + }); + + it('renders the correct tab content on tab switch', async () => { + const wrapper = mount( + + ); + await new Promise(setImmediate); + wrapper.update(); + + const detailsTab = wrapper.find('EuiTab').filterWhere((node) => node.text() === 'Details'); + detailsTab.simulate('click'); + await new Promise(setImmediate); + wrapper.update(); + + expect(wrapper.find('AccelerationDetailsTab').exists()).toBe(true); + + const schemaTab = wrapper.find('EuiTab').filterWhere((node) => node.text() === 'Schema'); + schemaTab.simulate('click'); + await new Promise(setImmediate); + wrapper.update(); + + expect(wrapper.find('AccelerationSchemaTab').exists()).toBe(true); }); it('switches tabs correctly', async () => { diff --git a/public/components/datasources/components/manage/accelerations/acceleration_details_flyout.tsx b/public/components/datasources/components/manage/accelerations/acceleration_details_flyout.tsx index 8c64efa15a..c2b3293833 100644 --- a/public/components/datasources/components/manage/accelerations/acceleration_details_flyout.tsx +++ b/public/components/datasources/components/manage/accelerations/acceleration_details_flyout.tsx @@ -37,16 +37,25 @@ export interface AccelerationDetailsFlyoutProps { dataSourceMDSId?: string; } -const getMappings = (index: string): Promise | undefined => { - return coreRefs.dslService?.fetchFields(index); +const getMappings = ( + index: string, + dataSourceMDSId?: string +): Promise | undefined => { + return coreRefs.dslService?.fetchFields(index, dataSourceMDSId); }; -const getSettings = (index: string): Promise | undefined => { - return coreRefs.dslService?.fetchSettings(index); +const getSettings = ( + index: string, + dataSourceMDSId?: string +): Promise | undefined => { + return coreRefs.dslService?.fetchSettings(index, dataSourceMDSId); }; -const getIndexInfo = (index: string): Promise | undefined => { - return coreRefs.dslService?.fetchIndices(index); +const getIndexInfo = ( + index: string, + dataSourceMDSId?: string +): Promise | undefined => { + return coreRefs.dslService?.fetchIndices(index, dataSourceMDSId); }; const handleDetailsFetchingPromise = ( @@ -59,7 +68,7 @@ const handleDetailsFetchingPromise = ( }; export const AccelerationDetailsFlyout = (props: AccelerationDetailsFlyoutProps) => { - const { dataSourceName, acceleration, resetFlyout, handleRefresh } = props; + const { dataSourceName, acceleration, resetFlyout, handleRefresh, dataSourceMDSId } = props; const { flintIndexName } = acceleration; const [selectedTab, setSelectedTab] = useState('details'); const tabsMap: { [key: string]: any } = { @@ -113,9 +122,9 @@ export const AccelerationDetailsFlyout = (props: AccelerationDetailsFlyoutProps) const getAccDetail = (selectedIndex: string) => { Promise.all([ - handleDetailsFetchingPromise(getMappings(selectedIndex), 'getMappings'), - handleDetailsFetchingPromise(getSettings(selectedIndex), 'getSettings'), - handleDetailsFetchingPromise(getIndexInfo(selectedIndex), 'getIndexInfo'), + handleDetailsFetchingPromise(getMappings(selectedIndex, dataSourceMDSId), 'getMappings'), + handleDetailsFetchingPromise(getSettings(selectedIndex, dataSourceMDSId), 'getSettings'), + handleDetailsFetchingPromise(getIndexInfo(selectedIndex, dataSourceMDSId), 'getIndexInfo'), ]) .then((results) => { updateMapping(results[0]); diff --git a/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration.tsx b/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration.tsx index e5fc9a7156..43df19719d 100644 --- a/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration.tsx +++ b/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration.tsx @@ -277,6 +277,7 @@ export const CreateAcceleration = ({ setAccelerationFormData={setAccelerationFormData} resetFlyout={resetFlyout} refreshHandler={refreshHandler} + dataSourceMDSId={dataSourceMDSId} /> diff --git a/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration_button.tsx b/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration_button.tsx index ac6123edc3..ba5e3e5c92 100644 --- a/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration_button.tsx +++ b/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration_button.tsx @@ -21,6 +21,7 @@ interface CreateAccelerationButtonProps { setAccelerationFormData: React.Dispatch>; resetFlyout: () => void; refreshHandler?: () => void; + dataSourceMDSId?: string; } export const CreateAccelerationButton = ({ @@ -28,6 +29,7 @@ export const CreateAccelerationButton = ({ setAccelerationFormData, resetFlyout, refreshHandler, + dataSourceMDSId, }: CreateAccelerationButtonProps) => { const { setToast } = useToast(); const { loadStatus: directqueryLoadStatus, startLoading: startDirectQuery } = useDirectQuery(); @@ -45,8 +47,7 @@ export const CreateAccelerationButton = ({ query: accelerationQueryBuilder(accelerationFormData).replaceAll(SANITIZE_QUERY_REGEX, ' '), datasource: accelerationFormData.dataSource, }; - - startDirectQuery(requestPayload); + startDirectQuery(requestPayload, dataSourceMDSId); setIsLoading(true); }; diff --git a/public/framework/catalog_cache/cache_loader.tsx b/public/framework/catalog_cache/cache_loader.tsx index 294346c441..3f46014456 100644 --- a/public/framework/catalog_cache/cache_loader.tsx +++ b/public/framework/catalog_cache/cache_loader.tsx @@ -134,13 +134,15 @@ export const updateAccelerationsToCache = ( const currentTime = new Date().toUTCString(); if (!pollingResult) { - CatalogCacheManager.addOrUpdateAccelerationsByDataSource({ - name: dataSourceName, - accelerations: [], - lastUpdated: currentTime, - status: CachedDataSourceStatus.Failed, - ...(dataSourceMDSId && { dataSourceMDSId }), - }); + CatalogCacheManager.addOrUpdateAccelerationsByDataSource( + { + name: dataSourceName, + accelerations: [], + lastUpdated: currentTime, + status: CachedDataSourceStatus.Failed, + }, + dataSourceMDSId + ); return; } @@ -155,14 +157,15 @@ export const updateAccelerationsToCache = ( autoRefresh: row.auto_refresh, status: row.status, })); - - CatalogCacheManager.addOrUpdateAccelerationsByDataSource({ - name: dataSourceName, - accelerations: newAccelerations, - lastUpdated: currentTime, - status: CachedDataSourceStatus.Updated, - ...(dataSourceMDSId && { dataSourceMDSId }), - }); + CatalogCacheManager.addOrUpdateAccelerationsByDataSource( + { + name: dataSourceName, + accelerations: newAccelerations, + lastUpdated: currentTime, + status: CachedDataSourceStatus.Updated, + }, + dataSourceMDSId + ); }; export const updateTableColumnsToCache = ( diff --git a/public/framework/catalog_cache/cache_manager.ts b/public/framework/catalog_cache/cache_manager.ts index bcd0dedbf8..10143961e0 100644 --- a/public/framework/catalog_cache/cache_manager.ts +++ b/public/framework/catalog_cache/cache_manager.ts @@ -100,12 +100,11 @@ export class CatalogCacheManager { ); } else { index = accCacheData.dataSources.findIndex( - (ds: CachedAccelerationByDataSource) => - ds.name === dataSource.name && ds.dataSourceMDSId === dataSourceMDSId + (ds: CachedAccelerationByDataSource) => ds.name === dataSource.name ); } if (index !== -1) { - accCacheData.dataSources[index] = dataSource; + accCacheData.dataSources[index] = { ...dataSource, dataSourceMDSId }; } else { accCacheData.dataSources.push(dataSource); } @@ -161,8 +160,11 @@ export class CatalogCacheManager { (ds: CachedDataSource) => ds.name === dataSource.name && ds.dataSourceMDSId === dataSourceMDSId ); + } else { + index = cacheData.dataSources.findIndex( + (ds: CachedDataSource) => ds.name === dataSource.name + ); } - index = cacheData.dataSources.findIndex((ds: CachedDataSource) => ds.name === dataSource.name); if (index !== -1) { cacheData.dataSources[index] = dataSource; } else { diff --git a/public/services/requests/dsl.ts b/public/services/requests/dsl.ts index f1050fddf6..b7ca9849b0 100644 --- a/public/services/requests/dsl.ts +++ b/public/services/requests/dsl.ts @@ -28,9 +28,9 @@ export default class DSLService { .catch((error) => console.error(error)); }; - fetchIndices = async (index: string = '') => { + fetchIndices = async (index: string = '', dataSourceMDSId?: string) => { return this.http - .get(`${DSL_BASE}${DSL_CAT}`, { + .get(`${DSL_BASE}${DSL_CAT}/dataSourceMDSId=${dataSourceMDSId}`, { query: { format: 'json', index, @@ -39,16 +39,16 @@ export default class DSLService { .catch((error) => console.error(error)); }; - fetchFields = async (index: string) => { - return this.http.get(`${DSL_BASE}${DSL_MAPPING}`, { + fetchFields = async (index: string, dataSourceMDSId?: string) => { + return this.http.get(`${DSL_BASE}${DSL_MAPPING}/dataSourceMDSId=${dataSourceMDSId}`, { query: { index, }, }); }; - fetchSettings = async (index: string) => { - return this.http.get(`${DSL_BASE}${DSL_SETTINGS}`, { + fetchSettings = async (index: string, dataSourceMDSId?: string) => { + return this.http.get(`${DSL_BASE}${DSL_SETTINGS}/dataSourceMDSId=${dataSourceMDSId}`, { query: { index, },