Skip to content

Commit

Permalink
Comments and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
davismcphee committed Nov 21, 2024
1 parent bef877d commit fe987ea
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ export function useEsqlMode({
return;
}

// We need to reset the default profile state on index pattern changes
// when loading starts to ensure the correct pre fetch state is available
// before data fetching is triggered
if (next.fetchStatus === FetchStatus.LOADING) {
// We have to grab the current query from appState
// here since nextQuery has not been updated yet
const appStateQuery = stateContainer.appState.getState().query;

if (isOfAggregateQueryType(appStateQuery)) {
Expand All @@ -86,6 +91,7 @@ export function useEsqlMode({
getIndexPatternFromESQLQuery(appStateQuery.esql) !==
getIndexPatternFromESQLQuery(prev.current.query);

// Reset all default profile state when index pattern changes
if (indexPatternChanged) {
stateContainer.internalState.transitions.setResetDefaultProfileState({
columns: true,
Expand All @@ -94,6 +100,8 @@ export function useEsqlMode({
});
}
}

return;
}

if (next.fetchStatus !== FetchStatus.PARTIAL) {
Expand Down Expand Up @@ -132,6 +140,8 @@ export function useEsqlMode({
const { viewMode } = stateContainer.appState.getState();
const changeViewMode = viewMode !== getValidViewMode({ viewMode, isEsqlMode: true });

// If the index pattern hasn't changed, but the available columns have changed
// due to transformational commands, reset the associated default profile state
if (!indexPatternChanged && allColumnsChanged) {
stateContainer.internalState.transitions.setResetDefaultProfileState({
columns: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ export function getDataStateContainer({
disableNextFetchOnStateChange$.next(false);
}

// Trigger chart fetching after the pre fetch state has been updated
// to ensure state values that would affect data fetching are set
fetchChart$.next();

abortController = new AbortController();
Expand All @@ -302,6 +304,8 @@ export function getDataStateContainer({
await appStateContainer.replaceUrlState(postFetchStateUpdate);
}

// Clear the default profile state flags after the data fetching
// is done so refetches don't reset the state again
internalStateContainer.transitions.setResetDefaultProfileState({
columns: false,
rowHeight: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const buildStateSubscribe =

if (dataState.disableNextFetchOnStateChange$.getValue()) {
addLog(
'[buildStateSubscribe] fetch disabled on state changes',
'[buildStateSubscribe] next fetch skipped on state change',
JSON.stringify(logData, null, 2)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export const getDefaultProfileState = ({
const defaultState = getDefaultState(profilesManager, dataView);

return {
/**
* Returns state that should be updated before data fetching occurs,
* for example state used as part of the data fetching process
* @returns The state to reset to before fetching data
*/
getPreFetchState: () => {
const stateUpdate: DiscoverAppState = {};

Expand All @@ -44,6 +49,12 @@ export const getDefaultProfileState = ({

return Object.keys(stateUpdate).length ? stateUpdate : undefined;
},

/**
* Returns state that should be updated after data fetching occurs,
* for example state used to modify the UI after receiving data
* @returns The state to reset to after fetching data
*/
getPostFetchState: ({
defaultColumns,
esqlQueryColumns,
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/unified_histogram/public/container/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export type UnifiedHistogramApi = {
export const UnifiedHistogramContainer = forwardRef<
UnifiedHistogramApi,
UnifiedHistogramContainerProps
>(({ onBreakdownFieldChange, onVisContextChanged, ...containerProps }, ref) => {
>(({ breakdownField, onBreakdownFieldChange, onVisContextChanged, ...containerProps }, ref) => {
const [layoutProps, setLayoutProps] = useState<LayoutProps>();
const [localStorageKeyPrefix, setLocalStorageKeyPrefix] = useState<string>();
const [stateService, setStateService] = useState<UnifiedHistogramStateService>();
Expand Down Expand Up @@ -158,8 +158,7 @@ export const UnifiedHistogramContainer = forwardRef<
searchSessionId,
requestAdapter,
columns,
breakdownField: initialBreakdownField,
...pick(containerProps, 'breakdownField'),
breakdownField: breakdownField ?? initialBreakdownField,
onBreakdownFieldChange,
});

Expand Down

0 comments on commit fe987ea

Please sign in to comment.