Skip to content

Commit

Permalink
Attempt to fix onDataViewEdited flakiness by resetting dataStateConta…
Browse files Browse the repository at this point in the history
…iner
  • Loading branch information
kertal committed Nov 13, 2024
1 parent 7fa9e84 commit bdba505
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export interface DiscoverStateContainer {
* 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
*/
updateAdHocDataViewId: () => Promise<DataView | undefined>;
updateAdHocDataViewId: (cleanCache?: boolean) => Promise<DataView | undefined>;
/**
* Updates the ES|QL query string
*/
Expand Down Expand Up @@ -324,16 +324,17 @@ export function getDiscoverStateContainer({
* 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 updateAdHocDataViewId = async (cleanCache = true) => {
const prevDataView = internalStateContainer.getState().dataView;
if (!prevDataView || prevDataView.isPersisted()) return;

const nextDataView = await services.dataViews.create({
...prevDataView.toSpec(),
id: uuidv4(),
});

services.dataViews.clearInstanceCache(prevDataView.id);
if (cleanCache) {
services.dataViews.clearInstanceCache(prevDataView.id);
}

updateFiltersReferences({
prevDataView,
Expand Down Expand Up @@ -413,6 +414,7 @@ export function getDiscoverStateContainer({
};

const onDataViewEdited = async (editedDataView: DataView) => {
dataStateContainer.reset();
if (editedDataView.isPersisted()) {
// Clear the current data view from the cache and create a new instance
// of it, ensuring we have a new object reference to trigger a re-render
Expand All @@ -421,7 +423,7 @@ export function getDiscoverStateContainer({
} else {
await updateAdHocDataViewId();
}
loadDataViewList();
await loadDataViewList();
addLog('[getDiscoverStateContainer] onDataViewEdited triggers data fetching');
fetchData();
};
Expand Down

0 comments on commit bdba505

Please sign in to comment.