Skip to content

Commit

Permalink
Saved object datasource backward compatibility fixes (#1208)
Browse files Browse the repository at this point in the history
* remove unused files

Signed-off-by: Eric Wei <menwe@amazon.com>

* missing snapshots

Signed-off-by: Eric Wei <menwe@amazon.com>

* remove unused files

Signed-off-by: Eric Wei <menwe@amazon.com>

* move dispatch to within batch

Signed-off-by: Eric <menwe@amazon.com>

* backward compatibility for existing saved object

Signed-off-by: Eric <menwe@amazon.com>

* update snapshots

Signed-off-by: Eric <menwe@amazon.com>

---------

Signed-off-by: Eric Wei <menwe@amazon.com>
Signed-off-by: Eric <menwe@amazon.com>
  • Loading branch information
mengweieric committed Oct 30, 2023
1 parent 667bbb7 commit eb2721f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion public/components/common/search/sql_search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ export const DirectSearch = (props: any) => {
dispatch(
changeQuery({ tabId, query: { [RAW_QUERY]: tempQuery.replaceAll(PPL_NEWLINE_REGEX, '') } })
);
dispatch(updateSearchMetaData({ tabId, data: { isPolling: true, lang } }));
});
dispatch(updateSearchMetaData({ tabId, data: { isPolling: true, lang } }));
const sessionId = getAsyncSessionId();
const requestPayload = {
lang: lang.toLowerCase(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ import { coreRefs } from '../../../framework/core_refs';
import { UsePolling } from '../../../components/hooks/use_polling';
import { getAsyncSessionId, setAsyncSessionId } from '../../../../common/utils/query_session_utils';
import { get as getObjValue } from '../../../../common/utils/shared';
import { ASYNC_POLLING_INTERVAL } from '../../../../common/constants/data_sources';
import {
ASYNC_POLLING_INTERVAL,
DEFAULT_DATA_SOURCE_NAME,
DEFAULT_DATA_SOURCE_TYPE,
} from '../../../../common/constants/data_sources';

enum DIRECT_DATA_SOURCE_TYPES {
DEFAULT_INDEX_PATTERNS = 'DEFAULT_INDEX_PATTERNS',
Expand Down Expand Up @@ -318,6 +322,31 @@ export class ExplorerSavedObjectLoader extends SavedObjectLoaderBase implements
return true;
};

loadWODataSource = ({ tabId }: { tabId: string }) => {
const { dispatch, batch } = this.dispatchers;
const { fetchData } = this.loadContext;

// default datasource
batch(() => {
dispatch(
updateSearchMetaData({
tabId,
data: {
datasources: [
{
name: DEFAULT_DATA_SOURCE_NAME,
type: DEFAULT_DATA_SOURCE_TYPE,
label: DEFAULT_DATA_SOURCE_NAME,
value: DEFAULT_DATA_SOURCE_NAME,
},
],
},
})
);
fetchData();
});
};

loadDefaultIndexPattern = () => {
const { fetchData } = this.loadContext;
fetchData();
Expand Down Expand Up @@ -380,7 +409,15 @@ export class ExplorerSavedObjectLoader extends SavedObjectLoaderBase implements

async loadDataFromSavedObject(objectData, tabId: string) {
const dataSources = parseStringDataSource(objectData.data_sources, this.notifications);
if (dataSources.length > 0 && dataSources[0].type) {

// backward compatibility for saved object that doesn't contain datasource
if (dataSources.length === 0) {
this.loadWODataSource({ tabId });
return;
}

// saved object contains data source information
if (dataSources[0].type) {
switch (dataSources[0].type) {
case DIRECT_DATA_SOURCE_TYPES.DEFAULT_INDEX_PATTERNS:
this.loadDefaultIndexPattern();
Expand Down

0 comments on commit eb2721f

Please sign in to comment.