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

[8.17] [Security Solution] Implement refactoring remark from PR #201731 (#204022) #205904

Merged
merged 2 commits into from
Jan 9, 2025
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 @@ -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/lib/useBoolean';
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]
);
};
Loading