Skip to content

Commit

Permalink
[8.16] [Security Solution] Implement refactoring remark from PR #201731
Browse files Browse the repository at this point in the history
… (#204022) (#205903)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[Security Solution] Implement refactoring remark from PR #201731
(#204022)](#204022)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Jacek
Kolezynski","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-08T14:01:47Z","message":"[Security
Solution] Implement refactoring remark from PR #201731 (#204022)\n\n##
Summary\n\nIn the PR #201731 for ticket #180660 @banderror advised to
refactor code\nin that PR to better separate the concerns (business
logic from\ncomponents). This is the implementation of that
review\n[remark](https://github.com/elastic/kibana/pull/201731/files#r1860492191).\n\nRecording:\n\n\nhttps://github.com/user-attachments/assets/471a0986-bcdb-4611-ab1a-bdcbe5151f47\n\n---------\n\nCo-authored-by:
Elastic Machine
<[email protected]>\nCo-authored-by: Nikita Indik
<[email protected]>","sha":"20eb87d778a69b6b0d7132732cbea9cce44e895c","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["refactoring","release_note:skip","v9.0.0","Team:Detections
and Resp","Team: SecuritySolution","Team:Detection Rule
Management","Feature:Prebuilt Detection
Rules","ci:cloud-deploy","ci:project-deploy-security","backport:version","v8.18.0","v8.16.3","v8.17.1"],"title":"[Security
Solution] Implement refactoring remark from PR
#201731","number":204022,"url":"https://github.com/elastic/kibana/pull/204022","mergeCommit":{"message":"[Security
Solution] Implement refactoring remark from PR #201731 (#204022)\n\n##
Summary\n\nIn the PR #201731 for ticket #180660 @banderror advised to
refactor code\nin that PR to better separate the concerns (business
logic from\ncomponents). This is the implementation of that
review\n[remark](https://github.com/elastic/kibana/pull/201731/files#r1860492191).\n\nRecording:\n\n\nhttps://github.com/user-attachments/assets/471a0986-bcdb-4611-ab1a-bdcbe5151f47\n\n---------\n\nCo-authored-by:
Elastic Machine
<[email protected]>\nCo-authored-by: Nikita Indik
<[email protected]>","sha":"20eb87d778a69b6b0d7132732cbea9cce44e895c"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.16","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204022","number":204022,"mergeCommit":{"message":"[Security
Solution] Implement refactoring remark from PR #201731 (#204022)\n\n##
Summary\n\nIn the PR #201731 for ticket #180660 @banderror advised to
refactor code\nin that PR to better separate the concerns (business
logic from\ncomponents). This is the implementation of that
review\n[remark](https://github.com/elastic/kibana/pull/201731/files#r1860492191).\n\nRecording:\n\n\nhttps://github.com/user-attachments/assets/471a0986-bcdb-4611-ab1a-bdcbe5151f47\n\n---------\n\nCo-authored-by:
Elastic Machine
<[email protected]>\nCo-authored-by: Nikita Indik
<[email protected]>","sha":"20eb87d778a69b6b0d7132732cbea9cce44e895c"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.16","label":"v8.16.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Jacek Kolezynski <[email protected]>
  • Loading branch information
kibanamachine and jkelas authored Jan 8, 2025
1 parent 2e63133 commit 6114bd8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ export const AddPrebuiltRulesHeaderButtons = () => {
const {
state: {
selectedRules,
loadingRules,
isRefetching,
isUpgradingSecurityPackages,
isInstallingAllRules,
isAnyRuleInstalling,
hasRulesToInstall,
},
actions: { installAllRules, installSelectedRules },
Expand All @@ -39,8 +38,7 @@ export const AddPrebuiltRulesHeaderButtons = () => {
const numberOfSelectedRules = selectedRules.length ?? 0;
const shouldDisplayInstallSelectedRulesButton = numberOfSelectedRules > 0;

const isRuleInstalling = loadingRules.length > 0 || isInstallingAllRules;
const isRequestInProgress = isRuleInstalling || isRefetching || isUpgradingSecurityPackages;
const isRequestInProgress = isAnyRuleInstalling || isRefetching || isUpgradingSecurityPackages;

const [isOverflowPopoverOpen, setOverflowPopover] = useBoolean(false);

Expand Down Expand Up @@ -81,7 +79,7 @@ export const AddPrebuiltRulesHeaderButtons = () => {
data-test-subj="installSelectedRulesButton"
>
{i18n.INSTALL_SELECTED_RULES(numberOfSelectedRules)}
{isRuleInstalling && <EuiLoadingSpinner size="s" />}
{isAnyRuleInstalling && <EuiLoadingSpinner size="s" />}
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
Expand Down Expand Up @@ -116,7 +114,7 @@ export const AddPrebuiltRulesHeaderButtons = () => {
aria-label={i18n.INSTALL_ALL_ARIA_LABEL}
>
{i18n.INSTALL_ALL}
{isRuleInstalling && <EuiLoadingSpinner size="s" />}
{isAnyRuleInstalling && <EuiLoadingSpinner size="s" />}
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import React, { useCallback, useMemo } from 'react';
import { useBoolean } from 'react-use';
import type { Rule } from '../../../../rule_management/logic';
import type { RuleSignatureId } from '../../../../../../common/api/detection_engine';
import { type AddPrebuiltRulesTableActions } from './add_prebuilt_rules_table_context';
import {
useAddPrebuiltRulesTableContext,
type AddPrebuiltRulesTableActions,
} from './add_prebuilt_rules_table_context';
import * as i18n from './translations';

export interface PrebuiltRulesInstallButtonProps {
Expand All @@ -28,7 +31,6 @@ export interface PrebuiltRulesInstallButtonProps {
installOneRule: AddPrebuiltRulesTableActions['installOneRule'];
loadingRules: RuleSignatureId[];
isDisabled: boolean;
isInstallingAllRules: boolean;
}

export const PrebuiltRulesInstallButton = ({
Expand All @@ -37,8 +39,10 @@ export const PrebuiltRulesInstallButton = ({
installOneRule,
loadingRules,
isDisabled,
isInstallingAllRules,
}: PrebuiltRulesInstallButtonProps) => {
const {
state: { isInstallingAllRules },
} = useAddPrebuiltRulesTableContext();
const isRuleInstalling = loadingRules.includes(ruleId) || isInstallingAllRules;
const isInstallButtonDisabled = isRuleInstalling || isDisabled;
const [isPopoverOpen, setPopover] = useBoolean(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ export interface AddPrebuiltRulesTableState {
* package in background
*/
isUpgradingSecurityPackages: boolean;

/**
* Is true when performing Install All Rules mutation
*/
isInstallingAllRules: boolean;
/**
* Is true when any rule is currently being installed
*/
isAnyRuleInstalling: boolean;
/**
* List of rule IDs that are currently being upgraded
*/
Expand Down Expand Up @@ -145,6 +148,8 @@ export const AddPrebuiltRulesTableContextProvider = ({
}),
});

const isAnyRuleInstalling = loadingRules.length > 0 || isInstallingAllRules;

const { mutateAsync: installAllRulesRequest } = usePerformInstallAllRules();
const { mutateAsync: installSpecificRulesRequest } = usePerformInstallSpecificRules();

Expand Down Expand Up @@ -281,6 +286,7 @@ export const AddPrebuiltRulesTableContextProvider = ({
isRefetching,
isUpgradingSecurityPackages,
isInstallingAllRules,
isAnyRuleInstalling,
selectedRules,
lastUpdated: dataUpdatedAt,
},
Expand All @@ -297,6 +303,7 @@ export const AddPrebuiltRulesTableContextProvider = ({
isRefetching,
isUpgradingSecurityPackages,
isInstallingAllRules,
isAnyRuleInstalling,
selectedRules,
dataUpdatedAt,
actions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ const INTEGRATIONS_COLUMN: TableColumn = {
const createInstallButtonColumn = (
installOneRule: AddPrebuiltRulesTableActions['installOneRule'],
loadingRules: RuleSignatureId[],
isDisabled: boolean,
isInstallingAllRules: boolean
isDisabled: boolean
): TableColumn => ({
field: 'rule_id',
name: <RulesTableEmptyColumnName name={i18n.INSTALL_RULE_BUTTON} />,
Expand All @@ -122,7 +121,6 @@ const createInstallButtonColumn = (
installOneRule={installOneRule}
loadingRules={loadingRules}
isDisabled={isDisabled}
isInstallingAllRules={isInstallingAllRules}
/>
),
width: '10%',
Expand Down Expand Up @@ -166,23 +164,9 @@ export const useAddPrebuiltRulesTableColumns = (): TableColumn[] => {
width: '12%',
},
...(hasCRUDPermissions
? [
createInstallButtonColumn(
installOneRule,
loadingRules,
isDisabled,
isInstallingAllRules
),
]
? [createInstallButtonColumn(installOneRule, loadingRules, isDisabled)]
: []),
],
[
hasCRUDPermissions,
installOneRule,
loadingRules,
isDisabled,
showRelatedIntegrations,
isInstallingAllRules,
]
[hasCRUDPermissions, installOneRule, loadingRules, isDisabled, showRelatedIntegrations]
);
};

0 comments on commit 6114bd8

Please sign in to comment.