Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Add a is_managed field to package policy #136183

Merged
merged 18 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/models/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface AgentPolicy extends Omit<NewAgentPolicy, 'id'> {
updated_at: string;
updated_by: string;
revision: number;
agents?: number;
shahzad31 marked this conversation as resolved.
Show resolved Hide resolved
}

export type AgentPolicySOAttributes = Omit<AgentPolicy, 'id'>;
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/models/package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface NewPackagePolicy {
description?: string;
namespace: string;
enabled: boolean;
is_externally_managed?: boolean;
policy_id: string;
output_id: string;
package?: PackagePolicyPackage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ export const StepDefinePackagePolicy: React.FunctionComponent<{
isLoadingPackagePolicies,
]);

const isReadonly = packagePolicy.is_externally_managed;

return validationResults ? (
<FormGroupResponsiveFields
title={
Expand Down Expand Up @@ -190,6 +192,7 @@ export const StepDefinePackagePolicy: React.FunctionComponent<{
}
>
<EuiFieldText
readOnly={isReadonly}
value={packagePolicy.name}
onChange={(e) =>
updatePackagePolicy({
Expand Down Expand Up @@ -222,6 +225,7 @@ export const StepDefinePackagePolicy: React.FunctionComponent<{
error={validationResults.description}
>
<EuiFieldText
readOnly={isReadonly}
value={packagePolicy.description}
onChange={(e) =>
updatePackagePolicy({
Expand Down Expand Up @@ -263,7 +267,7 @@ export const StepDefinePackagePolicy: React.FunctionComponent<{
})}

{/* Advanced options toggle */}
{!noAdvancedToggle && (
{!noAdvancedToggle && !isReadonly && (
<EuiFlexItem>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem grow={false}>
Expand Down
39 changes: 27 additions & 12 deletions x-pack/plugins/fleet/public/components/context_menu_actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
EuiContextMenuPanel,
EuiPopover,
EuiButton,
EuiToolTip,
} from '@elastic/eui';
import type { EuiButtonProps } from '@elastic/eui/src/components/button/button';
import type { EuiContextMenuProps } from '@elastic/eui/src/components/context_menu/context_menu';
Expand All @@ -24,6 +25,7 @@ type Props = {
children: JSX.Element;
};
isOpen?: boolean;
isExternallyManaged?: boolean;
onChange?: (isOpen: boolean) => void;
} & (
| {
Expand Down Expand Up @@ -51,24 +53,37 @@ export const ContextMenuActions = React.memo<Props>(({ button, onChange, isOpen,
}
}, [isOpenState, onChange, isOpen]);

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

return (
<EuiPopover
anchorPosition="downRight"
panelPaddingSize="none"
button={
button ? (
<EuiButton {...button.props} onClick={handleToggleMenu}>
{button.children}
</EuiButton>
) : (
<EuiButtonIcon
iconType="boxesHorizontal"
onClick={handleToggleMenu}
aria-label={i18n.translate('xpack.fleet.genericActionsMenuText', {
defaultMessage: 'Open',
props.isExternallyManaged ? (
<EuiToolTip
title={i18n.translate('xpack.fleet.externallyManagedLabel', {
defaultMessage: 'This is externally managed integration policy.',
Copy link
Contributor

@hbharding hbharding Jul 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message should go in the content prop. Only use the title prop if content is being used. The title prop adds a horizontal divider, and looks bad when no context exists below.

})}
data-test-subj="agentActionsBtn"
/>
>
{actionButton}
</EuiToolTip>
) : (
actionButton
)
}
isOpen={isOpen === undefined ? isOpenState : isOpen}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const PackagePolicyActionsMenu: React.FunctionComponent<{
const refreshAgentPolicy = useAgentPolicyRefresh();
const [isActionsMenuOpen, setIsActionsMenuOpen] = useState(defaultIsOpen);

const isExternallyManaged = Boolean(packagePolicy.is_externally_managed);

const onEnrollmentFlyoutClose = useMemo(() => {
return () => setIsEnrollmentFlyoutOpen(false);
}, []);
Expand Down Expand Up @@ -148,6 +150,7 @@ export const PackagePolicyActionsMenu: React.FunctionComponent<{
</EuiPortal>
)}
<ContextMenuActions
isExternallyManaged={isExternallyManaged}
isOpen={isActionsMenuOpen}
items={menuItems}
onChange={(open) => setIsActionsMenuOpen(open)}
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ const getSavedObjectTypes = (
description: { type: 'text' },
namespace: { type: 'keyword' },
enabled: { type: 'boolean' },
is_externally_managed: { type: 'boolean' },
policy_id: { type: 'keyword' },
output_id: { type: 'keyword' },
package: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
*/

import React, { memo, useMemo } from 'react';
import { i18n } from '@kbn/i18n';
import { PackagePolicyEditExtensionComponentProps } from '@kbn/fleet-plugin/public';
import { EuiButton, EuiCallOut } from '@elastic/eui';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { PolicyConfig, MonitorFields } from './types';
import { ConfigKey, DataStream, TLSFields } from './types';
import { SyntheticsPolicyEditExtension } from './synthetics_policy_edit_extension';
Expand Down Expand Up @@ -95,6 +98,20 @@ export const SyntheticsPolicyEditExtensionWrapper = memo<PackagePolicyEditExtens
return getDefaultConfig();
}, [currentPolicy]);

const { http } = useKibana().services;

if (currentPolicy.is_externally_managed) {
return (
<EuiCallOut>
<p>{EDIT_IN_UPTIME_DESC}</p>
{/* TODO Add a link to exact monitor*/}
<EuiButton href={`${http?.basePath.get()}/app/uptime/manage-monitors/all`}>
{EDIT_IN_UPTIME_LABEL}
</EuiButton>
</EuiCallOut>
);
}

return (
<PolicyConfigContextProvider
defaultMonitorType={monitorType}
Expand Down Expand Up @@ -122,3 +139,11 @@ export const SyntheticsPolicyEditExtensionWrapper = memo<PackagePolicyEditExtens
}
);
SyntheticsPolicyEditExtensionWrapper.displayName = 'SyntheticsPolicyEditExtensionWrapper';

const EDIT_IN_UPTIME_LABEL = i18n.translate('xpack.synthetics.editPackagePolicy.inUptime', {
defaultMessage: 'Edit in uptime',
});

const EDIT_IN_UPTIME_DESC = i18n.translate('xpack.synthetics.editPackagePolicy.inUptimeDesc', {
defaultMessage: 'This is externally managed integration policy, and cannot be edited here.',
});