Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
Signed-off-by: Qxisylolo <[email protected]>
  • Loading branch information
Qxisylolo committed Feb 8, 2025
1 parent 96d8589 commit 48d3b47
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions public/components/ui_action_context_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const ActionContextMenu = (props: Props) => {
const resultSummaryEnabled = useObservable(props.resultSummaryEnabled$, false);
const isQuerySummaryCollapsed = useObservable(props.isQuerySummaryCollapsed$, false);
const isSummaryAgentAvailable = useObservable(props.isSummaryAgentAvailable$, false);
const shouldShowSummarizationAction = resultSummaryEnabled && isSummaryAgentAvailable;

useEffect(() => {
props.isSummaryAgentAvailable$.next(false);
Expand Down Expand Up @@ -100,14 +101,13 @@ export const ActionContextMenu = (props: Props) => {
);

// The action button should be not displayed when there is no action and result summary disabled or there is no data2Summary agent
if ((!resultSummaryEnabled || !isSummaryAgentAvailable) && actionsRef.current.length === 0) {
if (!shouldShowSummarizationAction && actionsRef.current.length === 0) {
return null;
}

// The action button should be disabled when context menu has no item or result summary disabled or or no data2Summary agent is available
const actionDisabled =
(!resultSummaryEnabled || !isSummaryAgentAvailable) &&
(panels.value?.[0]?.items ?? []).length === 0;
!shouldShowSummarizationAction && (panels.value?.[0]?.items ?? []).length === 0;

return (
<EuiPopover
Expand Down Expand Up @@ -135,7 +135,7 @@ export const ActionContextMenu = (props: Props) => {
closePopover={() => setOpen(false)}
>
<EuiContextMenu size="s" initialPanelId={'mainMenu'} panels={panels.value} />
{resultSummaryEnabled && (
{shouldShowSummarizationAction && (
<EuiPopoverFooter paddingSize="s">
<EuiSwitch
label={i18n.translate('queryEnhancements.queryAssist.summary.switch.label', {
Expand Down

0 comments on commit 48d3b47

Please sign in to comment.