Skip to content

Commit

Permalink
[BUG] Updated cache for the sub tree in Workbench (#2351)
Browse files Browse the repository at this point in the history
* updated the flyout fix

Signed-off-by: sumukhswamy <[email protected]>

* updated the flyout fix

Signed-off-by: sumukhswamy <[email protected]>

* updated snapshots

Signed-off-by: sumukhswamy <[email protected]>

* Added test for accleration details flyout with MDSId

Signed-off-by: sumukhswamy <[email protected]>

---------

Signed-off-by: sumukhswamy <[email protected]>
  • Loading branch information
sumukhswamy authored Feb 20, 2025
1 parent 84fbc2f commit 535fa86
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 40 deletions.
1 change: 1 addition & 0 deletions common/types/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,5 @@ export interface DirectQueryRequest {
lang: string;
datasource: string;
sessionId?: string;
dataSourceMDSId?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<AccelerationDetailsFlyout
index="mockIndex"
acceleration={mockAcceleration}
dataSourceName="mockDataSource"
dataSourceMDSId="746ebe20-ee4a-11ef-823a-bd0a7d9fd697"
/>
);

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(
<AccelerationDetailsFlyout
index="mockIndex"
acceleration={mockAcceleration}
dataSourceName="mockDataSource"
/>
);
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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,25 @@ export interface AccelerationDetailsFlyoutProps {
dataSourceMDSId?: string;
}

const getMappings = (index: string): Promise<OpenSearchDashboardsResponse> | undefined => {
return coreRefs.dslService?.fetchFields(index);
const getMappings = (
index: string,
dataSourceMDSId?: string
): Promise<OpenSearchDashboardsResponse> | undefined => {
return coreRefs.dslService?.fetchFields(index, dataSourceMDSId);
};

const getSettings = (index: string): Promise<OpenSearchDashboardsResponse> | undefined => {
return coreRefs.dslService?.fetchSettings(index);
const getSettings = (
index: string,
dataSourceMDSId?: string
): Promise<OpenSearchDashboardsResponse> | undefined => {
return coreRefs.dslService?.fetchSettings(index, dataSourceMDSId);
};

const getIndexInfo = (index: string): Promise<OpenSearchDashboardsResponse> | undefined => {
return coreRefs.dslService?.fetchIndices(index);
const getIndexInfo = (
index: string,
dataSourceMDSId?: string
): Promise<OpenSearchDashboardsResponse> | undefined => {
return coreRefs.dslService?.fetchIndices(index, dataSourceMDSId);
};

const handleDetailsFetchingPromise = (
Expand All @@ -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 } = {
Expand Down Expand Up @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export const CreateAcceleration = ({
setAccelerationFormData={setAccelerationFormData}
resetFlyout={resetFlyout}
refreshHandler={refreshHandler}
dataSourceMDSId={dataSourceMDSId}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ interface CreateAccelerationButtonProps {
setAccelerationFormData: React.Dispatch<React.SetStateAction<CreateAccelerationForm>>;
resetFlyout: () => void;
refreshHandler?: () => void;
dataSourceMDSId?: string;
}

export const CreateAccelerationButton = ({
accelerationFormData,
setAccelerationFormData,
resetFlyout,
refreshHandler,
dataSourceMDSId,
}: CreateAccelerationButtonProps) => {
const { setToast } = useToast();
const { loadStatus: directqueryLoadStatus, startLoading: startDirectQuery } = useDirectQuery();
Expand All @@ -45,8 +47,7 @@ export const CreateAccelerationButton = ({
query: accelerationQueryBuilder(accelerationFormData).replaceAll(SANITIZE_QUERY_REGEX, ' '),
datasource: accelerationFormData.dataSource,
};

startDirectQuery(requestPayload);
startDirectQuery(requestPayload, dataSourceMDSId);
setIsLoading(true);
};

Expand Down
33 changes: 18 additions & 15 deletions public/framework/catalog_cache/cache_loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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 = (
Expand Down
10 changes: 6 additions & 4 deletions public/framework/catalog_cache/cache_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions public/services/requests/dsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
},
Expand Down

0 comments on commit 535fa86

Please sign in to comment.