Skip to content

Commit

Permalink
show loading state for ppl generation
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <[email protected]>
  • Loading branch information
joshuali925 committed Mar 14, 2024
1 parent 1d35ae2 commit dcb9247
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
11 changes: 10 additions & 1 deletion public/components/event_analytics/explorer/no_results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
EuiEmptyPrompt,
EuiFlexGroup,
EuiFlexItem,
EuiLoadingSpinner,
EuiPage,
EuiSpacer,
EuiText,
Expand All @@ -16,18 +17,26 @@ import { FormattedMessage } from '@osd/i18n/react';
import React from 'react';
import { useSelector } from 'react-redux';
import { coreRefs } from '../../../framework/core_refs';
import { selectQueryAssistantSummarization } from '../redux/slices/query_assistant_summarization_slice';
import { selectQueries } from '../redux/slices/query_slice';

export const NoResults = ({ tabId }: any) => {
// get the queries isLoaded, if it exists AND is true = show no res
const queryInfo = useSelector(selectQueries)[tabId];
const summaryData = useSelector(selectQueryAssistantSummarization)[tabId];
const queryAssistLoading = summaryData.loading;

return (
<EuiPage paddingSize="s">
{coreRefs.queryAssistEnabled ? (
<>
{/* check to see if the rawQuery is empty or not */}
{queryInfo?.rawQuery ? (
{queryAssistLoading ? (
<EuiEmptyPrompt

Check warning on line 35 in public/components/event_analytics/explorer/no_results.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/event_analytics/explorer/no_results.tsx#L35

Added line #L35 was not covered by tests
title={<EuiLoadingSpinner size="xl" />}
body={<p>Loading results...</p>}
/>
) : queryInfo?.rawQuery ? (
<EuiFlexGroup justifyContent="center" direction="column">
<EuiFlexItem grow={false}>
<EuiCallOut
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
changeSummary,
resetSummary,
selectQueryAssistantSummarization,
setLoading,
setResponseForSummaryStatus,
} from '../../redux/slices/query_assistant_summarization_slice';
import { reset, selectQueryResult } from '../../redux/slices/query_result_slice';
Expand Down Expand Up @@ -115,6 +116,7 @@ export const QueryAssistInput: React.FC<React.PropsWithChildren<Props>> = (props
const explorerData = useSelector(selectQueryResult)[props.tabId];
// @ts-ignore
const summaryData = useSelector(selectQueryAssistantSummarization)[props.tabId];
const loading = summaryData.loading;
const inputRef = useRef<HTMLInputElement>(null);

useEffect(() => {
Expand All @@ -141,7 +143,6 @@ export const QueryAssistInput: React.FC<React.PropsWithChildren<Props>> = (props
const dispatch = useDispatch();

const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const [loading, setLoading] = useState(false);
// below is only used for url redirection
const [autoRun, setAutoRun] = useState(false);
const [callOut, setCallOut] = useState<React.ReactNode>(null);
Expand Down Expand Up @@ -203,7 +204,7 @@ export const QueryAssistInput: React.FC<React.PropsWithChildren<Props>> = (props
return;

Check warning on line 204 in public/components/event_analytics/explorer/query_assist/input.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/event_analytics/explorer/query_assist/input.tsx#L203-L204

Added lines #L203 - L204 were not covered by tests
}
try {
setLoading(true);
dispatch(setLoading({ tabId: props.tabId, loading: true }));
setCallOut(null);
await request();
} catch (err) {
Expand All @@ -214,7 +215,7 @@ export const QueryAssistInput: React.FC<React.PropsWithChildren<Props>> = (props
}
coreRefs.toasts?.addError(error, { title: 'Failed to generate results' });
} finally {
setLoading(false);
dispatch(setLoading({ tabId: props.tabId, loading: false }));
}
};
const generateSummary = async (context?: Partial<SummarizationContext>) => {
Expand Down Expand Up @@ -294,7 +295,7 @@ export const QueryAssistInput: React.FC<React.PropsWithChildren<Props>> = (props
return;

Check warning on line 295 in public/components/event_analytics/explorer/query_assist/input.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/event_analytics/explorer/query_assist/input.tsx#L294-L295

Added lines #L294 - L295 were not covered by tests
}
try {
setLoading(true);
dispatch(setLoading({ tabId: props.tabId, loading: true }));
setCallOut(null);
await request();
await props.handleTimePickerChange([QUERY_ASSIST_START_TIME, 'now']);
Expand All @@ -311,7 +312,7 @@ export const QueryAssistInput: React.FC<React.PropsWithChildren<Props>> = (props
coreRefs.toasts?.addError(error, { title: 'Failed to generate results' });
}
} finally {
setLoading(false);
dispatch(setLoading({ tabId: props.tabId, loading: false }));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { initialTabId } from '../../../../framework/redux/store/shared_state';

const initialState = {
[initialTabId]: {
loading: false,
responseForSummaryStatus: 'false' as 'false' | 'success' | 'failure',
},
};
Expand All @@ -30,16 +31,24 @@ export const summarizationSlice = createSlice({
},
resetSummary: (state, { payload }) => {
state[payload.tabId] = {
loading: false,
responseForSummaryStatus: initialState[initialTabId].responseForSummaryStatus,
};
},
setLoading: (state, { payload }) => {
state[payload.tabId] = {
...state[payload.tabId],
loading: payload.loading,
};
},
},
});

export const {
setResponseForSummaryStatus,
changeSummary,
resetSummary,
setLoading,
} = summarizationSlice.actions;

export const selectQueryAssistantSummarization = createSelector(
Expand Down

0 comments on commit dcb9247

Please sign in to comment.