Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed May 22, 2023
1 parent 3d5b852 commit d585de9
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ export function useTextBasedQueryLanguage({
}
}
const indexPatternFromQuery = getIndexPatternFromSQLQuery(query.sql);
const internalState = stateContainer.sharedState.getState();
const dataViewList = [...internalState.savedDataViews, ...internalState.adHocDataViews];
const sharedState = stateContainer.sharedState.getState();
const dataViewList = [...sharedState.savedDataViews, ...sharedState.adHocDataViews];
let dataViewObj = dataViewList.find(({ title }) => title === indexPatternFromQuery);

// no dataview found but the index pattern is valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('buildStateSubscribe', () => {
appState: stateContainer.appState,
savedSearchState: stateContainer.savedSearchState,
dataState: stateContainer.dataState,
internalState: stateContainer.sharedState,
sharedState: stateContainer.sharedState,
services: discoverServiceMock,
setDataView: stateContainer.actions.setDataView,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ export const buildStateSubscribe =
({
appState,
dataState,
internalState,
sharedState,
savedSearchState,
services,
setDataView,
}: {
appState: DiscoverAppStateContainer;
dataState: DiscoverDataStateContainer;
internalState: DiscoverSharedStateContainer;
sharedState: DiscoverSharedStateContainer;
savedSearchState: DiscoverSavedSearchContainer;
services: DiscoverServices;
setDataView: DiscoverStateContainer['actions']['setDataView'];
Expand All @@ -62,7 +62,7 @@ export const buildStateSubscribe =
if (nextState.index && dataViewChanged) {
const { dataView: nextDataView, fallback } = await loadAndResolveDataView(
{ id: nextState.index, savedSearch },
{ internalStateContainer: internalState, services }
{ sharedStateContainer: sharedState, services }
);

// If the requested data view is not found, don't try to load it,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const setupTestParams = (dataView: DataView | undefined) => {
discoverState.sharedState.transitions.setDataView(savedSearch.searchSource.getField('index')!);
services.dataViews.get = jest.fn(() => Promise.resolve(dataView as DataView));
discoverState.appState.update = jest.fn();
return { services, appState: discoverState.appState, internalState: discoverState.sharedState };
return { services, appState: discoverState.appState, sharedState: discoverState.sharedState };
};

describe('changeDataView', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ export async function changeDataView(
id: string | DataView,
{
services,
internalState,
sharedState,
appState,
}: {
services: DiscoverServices;
internalState: DiscoverSharedStateContainer;
sharedState: DiscoverSharedStateContainer;
appState: DiscoverAppStateContainer;
}
) {
addLog('[ui] changeDataView', { id });
const { dataViews, uiSettings } = services;
const dataView = internalState.getState().dataView;
const dataView = sharedState.getState().dataView;
const state = appState.getState();
let nextDataView: DataView | null = null;

Expand All @@ -54,8 +54,8 @@ export async function changeDataView(
);

appState.update(nextAppState);
if (internalState.getState().expandedDoc) {
internalState.transitions.setExpandedDoc(undefined);
if (sharedState.getState().expandedDoc) {
sharedState.transitions.setExpandedDoc(undefined);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ describe('actions', () => {
);
});

test('loadSavedSearch with ad-hoc data view being added to internal state adHocDataViews', async () => {
test('loadSavedSearch with ad-hoc data view being added to shared state adHocDataViews', async () => {
const savedSearchAdHocCopy = copySavedSearch(savedSearchAdHoc);
const adHocDataViewId = savedSearchAdHoc.searchSource.getField('index')!.id;
const { state } = await getState('/', savedSearchAdHocCopy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export interface DiscoverStateContainer {
*/
initializeAndSync: () => () => void;
/**
* Load current list of data views, add them to internal state
* Load current list of data views, add them to shared state
*/
loadDataViewList: () => Promise<void>;
/**
Expand Down Expand Up @@ -223,9 +223,9 @@ export function getDiscoverStateContainer({
services,
});
/**
* Internal State Container, state that's not persisted and not part of the URL
* Shared State Container, state that's not persisted and not part of the URL
*/
const internalStateContainer = getSharedStateContainer();
const sharedStateContainer = getSharedStateContainer();

const dataStateContainer = getDataStateContainer({
services,
Expand All @@ -248,29 +248,29 @@ export function getDiscoverStateContainer({
};

const setDataView = (dataView: DataView) => {
internalStateContainer.transitions.setDataView(dataView);
sharedStateContainer.transitions.setDataView(dataView);
pauseAutoRefreshInterval(dataView);
savedSearchContainer.getState().searchSource.setField('index', dataView);
};

const loadDataViewList = async () => {
const dataViewList = await services.dataViews.getIdsWithTitle(true);
internalStateContainer.transitions.setSavedDataViews(dataViewList);
sharedStateContainer.transitions.setSavedDataViews(dataViewList);
};

/**
* When saving a saved search with an ad hoc data view, a new id needs to be generated for the data view
* This is to prevent duplicate ids messing with our system
*/
const updateAdHocDataViewId = async () => {
const prevDataView = internalStateContainer.getState().dataView;
const prevDataView = sharedStateContainer.getState().dataView;
if (!prevDataView || prevDataView.isPersisted()) return;
const newDataView = await services.dataViews.create({ ...prevDataView.toSpec(), id: uuidv4() });
services.dataViews.clearInstanceCache(prevDataView.id);

updateFiltersReferences(prevDataView, newDataView);

internalStateContainer.transitions.replaceAdHocDataViewWithId(prevDataView.id!, newDataView);
sharedStateContainer.transitions.replaceAdHocDataViewWithId(prevDataView.id!, newDataView);
await appStateContainer.replaceUrlState({ index: newDataView.id });
const trackingEnabled = Boolean(newDataView.isPersisted() || savedSearchContainer.getId());
getUrlTracker().setTrackingEnabled(trackingEnabled);
Expand All @@ -292,7 +292,7 @@ export function getDiscoverStateContainer({

const onDataViewCreated = async (nextDataView: DataView) => {
if (!nextDataView.isPersisted()) {
internalStateContainer.transitions.appendAdHocDataViews(nextDataView);
sharedStateContainer.transitions.appendAdHocDataViews(nextDataView);
} else {
await loadDataViewList();
}
Expand All @@ -318,7 +318,7 @@ export function getDiscoverStateContainer({
return loadSavedSearchFn(params ?? {}, {
appStateContainer,
dataStateContainer,
internalStateContainer,
sharedStateContainer,
savedSearchContainer,
services,
setDataView,
Expand All @@ -339,7 +339,7 @@ export function getDiscoverStateContainer({
appState: appStateContainer,
savedSearchState: savedSearchContainer,
dataState: dataStateContainer,
internalState: internalStateContainer,
sharedState: sharedStateContainer,
services,
setDataView,
})
Expand All @@ -353,7 +353,7 @@ export function getDiscoverStateContainer({
services.filterManager.getFetches$()
).subscribe(async () => {
await savedSearchContainer.update({
nextDataView: internalStateContainer.getState().dataView,
nextDataView: sharedStateContainer.getState().dataView,
nextState: appStateContainer.getState(),
useFilterAndQueryServices: true,
});
Expand All @@ -375,7 +375,7 @@ export function getDiscoverStateContainer({
if (newDataView.fields.getByName('@timestamp')?.type === 'date') {
newDataView.timeFieldName = '@timestamp';
}
internalStateContainer.transitions.appendAdHocDataViews(newDataView);
sharedStateContainer.transitions.appendAdHocDataViews(newDataView);

await onChangeDataView(newDataView);
};
Expand All @@ -399,7 +399,7 @@ export function getDiscoverStateContainer({
const onChangeDataView = async (id: string | DataView) => {
await changeDataView(id, {
services,
internalState: internalStateContainer,
sharedState: sharedStateContainer,
appState: appStateContainer,
});
};
Expand Down Expand Up @@ -427,7 +427,7 @@ export function getDiscoverStateContainer({

return {
appState: appStateContainer,
sharedState: internalStateContainer,
sharedState: sharedStateContainer,
dataState: dataStateContainer,
savedSearchState: savedSearchContainer,
searchSessionManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { DiscoverServices } from '../../../build_services';
interface LoadSavedSearchDeps {
appStateContainer: DiscoverAppStateContainer;
dataStateContainer: DiscoverDataStateContainer;
internalStateContainer: DiscoverSharedStateContainer;
sharedStateContainer: DiscoverSharedStateContainer;
savedSearchContainer: DiscoverSavedSearchContainer;
services: DiscoverServices;
setDataView: DiscoverStateContainer['actions']['setDataView'];
Expand All @@ -43,14 +43,14 @@ export const loadSavedSearch = async (
): Promise<SavedSearch> => {
addLog('[discoverState] loadSavedSearch');
const { savedSearchId, useAppState } = params ?? {};
const { appStateContainer, internalStateContainer, savedSearchContainer, services } = deps;
const { appStateContainer, sharedStateContainer, savedSearchContainer, services } = deps;
const appState = useAppState ? appStateContainer.getState() : undefined;

// Loading the saved search or creating a new one
let nextSavedSearch = savedSearchId
? await savedSearchContainer.load(savedSearchId)
: await savedSearchContainer.new(
await getStateDataView(params, { services, appState, internalStateContainer })
await getStateDataView(params, { services, appState, sharedStateContainer })
);

// Cleaning up the previous state
Expand All @@ -68,7 +68,7 @@ export const loadSavedSearch = async (
const stateDataView = await getStateDataView(params, {
services,
appState,
internalStateContainer,
sharedStateContainer,
savedSearch: nextSavedSearch,
});
const dataViewDifferentToAppState = stateDataView.id !== savedSearchDataViewId;
Expand Down Expand Up @@ -99,12 +99,12 @@ export const loadSavedSearch = async (
* @param deps
*/
function updateBySavedSearch(savedSearch: SavedSearch, deps: LoadSavedSearchDeps) {
const { dataStateContainer, internalStateContainer, services, setDataView } = deps;
const { dataStateContainer, sharedStateContainer, services, setDataView } = deps;
const savedSearchDataView = savedSearch.searchSource.getField('index')!;

setDataView(savedSearchDataView);
if (!savedSearchDataView.isPersisted()) {
internalStateContainer.transitions.appendAdHocDataViews(savedSearchDataView);
sharedStateContainer.transitions.appendAdHocDataViews(savedSearchDataView);
}

// Finally notify dataStateContainer, data.query and filterManager about new derived state
Expand Down Expand Up @@ -139,12 +139,12 @@ const getStateDataView = async (
savedSearch,
appState,
services,
internalStateContainer,
sharedStateContainer,
}: {
savedSearch?: SavedSearch;
appState?: DiscoverAppState;
services: DiscoverServices;
internalStateContainer: DiscoverSharedStateContainer;
sharedStateContainer: DiscoverSharedStateContainer;
}
) => {
const { dataView, dataViewSpec } = params ?? {};
Expand All @@ -159,7 +159,7 @@ const getStateDataView = async (
savedSearch,
isTextBasedQuery: isTextBasedQuery(appState?.query),
},
{ services, internalStateContainer }
{ services, sharedStateContainer }
);
return result.dataView;
};
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ export const loadAndResolveDataView = async (
isTextBasedQuery?: boolean;
},
{
internalStateContainer,
sharedStateContainer,
services,
}: { internalStateContainer: DiscoverSharedStateContainer; services: DiscoverServices }
}: { sharedStateContainer: DiscoverSharedStateContainer; services: DiscoverServices }
) => {
const { adHocDataViews, savedDataViews } = internalStateContainer.getState();
const { adHocDataViews, savedDataViews } = sharedStateContainer.getState();
const adHocDataView = adHocDataViews.find((dataView) => dataView.id === id);
if (adHocDataView) return { fallback: false, dataView: adHocDataView };

Expand Down

0 comments on commit d585de9

Please sign in to comment.