From e649ae25c02ab4ca20fd49cdcbf86fd5be577ffe Mon Sep 17 00:00:00 2001 From: Luciano Gorza <103193307+lucianogorza@users.noreply.github.com> Date: Thu, 28 Dec 2023 15:01:15 -0300 Subject: [PATCH] Allow edit groups from an agent (#6250) * Agent groups column refactor and allow remove * Agent groups allow edit * Edit agent groups modal * Fix links las registered agent * Agent table with actions * Extend funtionality from button with permissions and restore groups trucate component * Modularize agents table actions * Fix table filters * Add form modal message * Add CHANGELOG * Update snapshot * Fix return * Fix actions field * Fix snapshot * Disable 'View details' actions when agent never connected * Delete 'Upgrade' action --- CHANGELOG.md | 1 + .../components/common/permissions/button.tsx | 115 ++-- .../components/common/permissions/element.tsx | 109 ++++ .../components/common/permissions/prompt.tsx | 2 +- .../agent_group_truncate.tsx | 81 --- .../agent-group-truncate/group-truncate.tsx | 8 +- .../common/util/agent-group-truncate/index.ts | 3 +- .../public/components/common/util/index.ts | 10 +- .../components/common/welcome/agents-info.js | 1 - .../endpoints-summary/endpoints-summary.tsx | 54 +- .../endpoints-summary/hooks/agents.ts | 31 ++ .../endpoints-summary/hooks/endpoints.ts | 37 -- .../endpoints-summary/hooks/groups.ts | 32 ++ .../endpoints-summary/hooks/index.ts | 2 +- .../components/endpoints-summary/index.tsx | 11 +- .../services/add-agent-to-group.tsx | 4 + .../endpoints-summary/services/get-groups.tsx | 8 + .../services/get-total-agents.tsx | 12 + .../endpoints-summary/services/index.tsx | 5 + .../services/remove-agent-from-group.tsx | 6 + .../services/remove-agent-from-groups.tsx | 11 + .../__snapshots__/agents-table.test.tsx.snap | 6 - .../endpoints-summary/table/actions.tsx | 81 +++ .../endpoints-summary/table/agents-table.js | 523 ------------------ .../endpoints-summary/table/agents-table.tsx | 484 ++++++++++++++++ .../table/edit-groups-modal.tsx | 155 ++++++ 26 files changed, 1032 insertions(+), 760 deletions(-) create mode 100644 plugins/main/public/components/common/permissions/element.tsx delete mode 100644 plugins/main/public/components/common/util/agent-group-truncate/agent_group_truncate.tsx create mode 100644 plugins/main/public/components/endpoints-summary/hooks/agents.ts delete mode 100644 plugins/main/public/components/endpoints-summary/hooks/endpoints.ts create mode 100644 plugins/main/public/components/endpoints-summary/hooks/groups.ts create mode 100644 plugins/main/public/components/endpoints-summary/services/add-agent-to-group.tsx create mode 100644 plugins/main/public/components/endpoints-summary/services/get-groups.tsx create mode 100644 plugins/main/public/components/endpoints-summary/services/get-total-agents.tsx create mode 100644 plugins/main/public/components/endpoints-summary/services/index.tsx create mode 100644 plugins/main/public/components/endpoints-summary/services/remove-agent-from-group.tsx create mode 100644 plugins/main/public/components/endpoints-summary/services/remove-agent-from-groups.tsx create mode 100644 plugins/main/public/components/endpoints-summary/table/actions.tsx delete mode 100644 plugins/main/public/components/endpoints-summary/table/agents-table.js create mode 100644 plugins/main/public/components/endpoints-summary/table/agents-table.tsx create mode 100644 plugins/main/public/components/endpoints-summary/table/edit-groups-modal.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index f67cd225da..ce55f82853 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to the Wazuh app project will be documented in this file. - Added AngularJS dependencies [#6145](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6145) - Remove embedded discover [#6120](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6120) - Develop logic of a new index for the fim module [#6227](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6227) +- Allow editing groups for an agent from Endpoints Summary [#6250](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6250) ## Wazuh v4.8.1 - OpenSearch Dashboards 2.10.0 - Revision 00 diff --git a/plugins/main/public/components/common/permissions/button.tsx b/plugins/main/public/components/common/permissions/button.tsx index 8bfa0b34c6..799f5539ae 100644 --- a/plugins/main/public/components/common/permissions/button.tsx +++ b/plugins/main/public/components/common/permissions/button.tsx @@ -10,9 +10,7 @@ * Find more information about this on the LICENSE file. */ -import React, { Fragment } from 'react'; -import { useUserPermissionsRequirements } from '../hooks/useUserPermissions'; -import { useUserRolesRequirements } from '../hooks/useUserRoles'; +import React from 'react'; import { EuiSwitch, @@ -20,73 +18,60 @@ import { EuiButtonEmpty, EuiButtonIcon, EuiLink, - EuiToolTip, - EuiSpacer } from '@elastic/eui'; -import { WzPermissionsFormatted } from './format'; +import { IWzElementPermissionsProps, WzElementPermissions } from './element'; -export interface IUserPermissionsObject{action: string, resource: string}; -export type TUserPermissionsFunction = (props : any) => TUserPermissions; -export type TUserPermissions = (string | IUserPermissionsObject)[] | null; -export type TUserRoles = string[] | null; -export type TUserRolesFunction = (props : any) => TUserRoles; +interface IWzButtonPermissionsProps + extends Omit< + IWzElementPermissionsProps, + 'children' | 'additionalPropsFunction' + > { + buttonType?: 'default' | 'empty' | 'icon' | 'link' | 'switch'; + rest: any; +} -interface IWzButtonPermissionsProps{ - permissions?: TUserPermissions | TUserPermissionsFunction - roles?: TUserRoles | TUserRolesFunction - buttonType?: 'default' | 'empty' | 'icon' | 'link' | 'switch' - tooltip?: any - rest?: any -}; - -export const WzButtonPermissions = ({permissions = null, roles = null, buttonType = 'default', tooltip, ...rest} : IWzButtonPermissionsProps) => { - const [userPermissionRequirements, userPermissions] = useUserPermissionsRequirements(typeof permissions === 'function' ? permissions(rest) : permissions); - const [userRolesRequirements, userRoles] = useUserRolesRequirements(typeof roles === 'function' ? roles(rest) : roles); +export const WzButtonPermissions = ({ + buttonType = 'default', + permissions, + roles, + tooltip, + ...rest +}: IWzButtonPermissionsProps) => { + const Button = + buttonType === 'empty' + ? EuiButtonEmpty + : buttonType === 'icon' + ? EuiButtonIcon + : buttonType === 'link' + ? EuiLink + : buttonType === 'switch' + ? EuiSwitch + : EuiButton; - const Button = buttonType === 'default' ? EuiButton - : buttonType === 'empty' ? EuiButtonEmpty - : buttonType === 'icon' ? EuiButtonIcon - : buttonType === 'link' ? EuiLink - : buttonType === 'switch' ? EuiSwitch - : null - const disabled = Boolean(userRolesRequirements || userPermissionRequirements || rest.isDisabled || rest.disabled); - const disabledProp = !['link', 'switch'].includes(buttonType) ? { isDisabled: disabled } : { disabled }; - const onClick = disabled || !rest.onClick ? undefined : rest.onClick; - const onChange = disabled || !rest.onChange ? undefined : rest.onChange; - const customProps = { ...rest, onChange, onClick }; + return ( + { + const additionalProps = { + ...(!['link', 'switch'].includes(buttonType) + ? { isDisabled: disabled } + : { disabled }), + onClick: + disabled || !rest.onClick || buttonType == 'switch' + ? undefined + : rest.onClick, + onChange: disabled || !rest.onChange ? undefined : rest.onChange, + }; - if (buttonType == 'switch') delete customProps.onClick; + if (buttonType == 'switch') delete additionalProps.onClick; - const button =