Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import React, { memo, useState, useMemo, useCallback } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import { EuiContextMenuItem, EuiPortal } from '@elastic/eui';

import type { AgentPolicy } from '../../../types';
Expand Down Expand Up @@ -88,6 +89,13 @@ export const AgentPolicyActionMenu = memo<{
}
}, [onCancelEnrollment, setIsEnrollmentFlyoutOpen]);

const actionsAriaLabel = fullButton
? undefined
: i18n.translate('xpack.fleet.agentPolicyActionMenu.actionsAriaLabel', {
defaultMessage: 'Actions for {policyName}',
values: { policyName: agentPolicy.name },
});

return (
<AgentPolicyCopyProvider>
{(copyAgentPolicyPrompt) => {
Expand Down Expand Up @@ -350,6 +358,7 @@ export const AgentPolicyActionMenu = memo<{
<ContextMenuActions
isOpen={isContextMenuOpen}
onChange={onContextMenuChange}
aria-label={actionsAriaLabel}
button={
fullButton
? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export const DataStreamRowActions = memo<{ datastream: DataStream }>(({ datastre
const { dashboards } = datastream;
const dashboardLocator = useDashboardLocator();

const actionsAriaLabel = i18n.translate('xpack.fleet.dataStreamList.rowActionsAriaLabel', {
defaultMessage: 'Actions for {dataset}',
values: { dataset: datastream.dataset },
});

const actionNameSingular = (
<FormattedMessage
id="xpack.fleet.dataStreamList.viewDashboardActionText"
Expand Down Expand Up @@ -58,7 +63,7 @@ export const DataStreamRowActions = memo<{ datastream: DataStream }>(({ datastre
],
},
];
return <ContextMenuActions panels={apmItem} />;
return <ContextMenuActions panels={apmItem} aria-label={actionsAriaLabel} />;
}

if (!dashboards || dashboards.length === 0) {
Expand All @@ -74,7 +79,7 @@ export const DataStreamRowActions = memo<{ datastream: DataStream }>(({ datastre
],
},
];
return <ContextMenuActions panels={disabledItems} />;
return <ContextMenuActions panels={disabledItems} aria-label={actionsAriaLabel} />;
}

if (dashboards.length === 1) {
Expand All @@ -91,7 +96,7 @@ export const DataStreamRowActions = memo<{ datastream: DataStream }>(({ datastre
],
},
];
return <ContextMenuActions panels={panelItems} />;
return <ContextMenuActions panels={panelItems} aria-label={actionsAriaLabel} />;
}

const panelItems = [
Expand Down Expand Up @@ -119,5 +124,5 @@ export const DataStreamRowActions = memo<{ datastream: DataStream }>(({ datastre
},
];

return <ContextMenuActions panels={panelItems} />;
return <ContextMenuActions panels={panelItems} aria-label={actionsAriaLabel} />;
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Props = {
isOpen?: boolean;
isManaged?: boolean;
onChange?: (isOpen: boolean) => void;
'aria-label'?: string;
} & (
| {
items: EuiContextMenuPanelProps['items'];
Expand All @@ -36,64 +37,69 @@ type Props = {
}
);

export const ContextMenuActions = React.memo<Props>(({ button, onChange, isOpen, ...props }) => {
const [isOpenState, setIsOpenState] = useState(false);
const handleCloseMenu = useCallback(() => {
if (onChange) {
onChange(false);
} else {
setIsOpenState(false);
}
}, [setIsOpenState, onChange]);
const handleToggleMenu = useCallback(() => {
if (onChange) {
onChange(!isOpen);
} else {
setIsOpenState(!isOpenState);
}
}, [isOpenState, onChange, isOpen]);
export const ContextMenuActions = React.memo<Props>(
({ button, onChange, isOpen, 'aria-label': ariaLabel, ...props }) => {
const [isOpenState, setIsOpenState] = useState(false);
const handleCloseMenu = useCallback(() => {
if (onChange) {
onChange(false);
} else {
setIsOpenState(false);
}
}, [setIsOpenState, onChange]);
const handleToggleMenu = useCallback(() => {
if (onChange) {
onChange(!isOpen);
} else {
setIsOpenState(!isOpenState);
}
}, [isOpenState, onChange, isOpen]);

const actionButton = button ? (
<EuiButton {...button.props} onClick={handleToggleMenu} isDisabled={props.isManaged}>
{button.children}
</EuiButton>
) : (
<EuiButtonIcon
isDisabled={props.isManaged}
iconType="boxesVertical"
onClick={handleToggleMenu}
aria-label={i18n.translate('xpack.fleet.genericActionsMenuText', {
defaultMessage: 'Open',
})}
data-test-subj="agentActionsBtn"
/>
);
const actionButton = button ? (
<EuiButton {...button.props} onClick={handleToggleMenu} isDisabled={props.isManaged}>
{button.children}
</EuiButton>
) : (
<EuiButtonIcon
isDisabled={props.isManaged}
iconType="boxesVertical"
onClick={handleToggleMenu}
aria-label={
ariaLabel ??
i18n.translate('xpack.fleet.genericActionsMenuText', {
defaultMessage: 'Actions',
})
}
data-test-subj="agentActionsBtn"
/>
);

return (
<EuiPopover
anchorPosition="downRight"
panelPaddingSize="none"
button={
props.isManaged ? (
<EuiToolTip
title={i18n.translate('xpack.fleet.externallyManagedLabel', {
defaultMessage: 'This is externally managed integration policy.',
})}
>
{actionButton}
</EuiToolTip>
return (
<EuiPopover
anchorPosition="downRight"
panelPaddingSize="none"
button={
props.isManaged ? (
<EuiToolTip
title={i18n.translate('xpack.fleet.externallyManagedLabel', {
defaultMessage: 'This is externally managed integration policy.',
})}
>
{actionButton}
</EuiToolTip>
) : (
actionButton
)
}
isOpen={isOpen === undefined ? isOpenState : isOpen}
closePopover={handleCloseMenu}
>
{'items' in props ? (
<EuiContextMenuPanel items={props.items} />
) : (
actionButton
)
}
isOpen={isOpen === undefined ? isOpenState : isOpen}
closePopover={handleCloseMenu}
>
{'items' in props ? (
<EuiContextMenuPanel items={props.items} />
) : (
<EuiContextMenu panels={props.panels} initialPanelId={0} />
)}
</EuiPopover>
);
});
<EuiContextMenu panels={props.panels} initialPanelId={0} />
)}
</EuiPopover>
);
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import React, { useMemo, useState } from 'react';
import { EuiContextMenuItem, EuiPortal } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';

import { EXCLUDED_FROM_PACKAGE_POLICY_COPY_PACKAGES } from '../../common/constants';
import type { AgentPolicy, InMemoryPackagePolicy } from '../types';
Expand Down Expand Up @@ -250,6 +251,10 @@ export const PackagePolicyActionsMenu: React.FunctionComponent<{
isOpen={isActionsMenuOpen}
items={menuItems}
onChange={(open) => setIsActionsMenuOpen(open)}
aria-label={i18n.translate('xpack.fleet.packagePolicyActionsMenu.actionsAriaLabel', {
defaultMessage: 'Actions for {policyName}',
values: { policyName: packagePolicy.name },
})}
/>
</>
);
Expand Down
Loading