Skip to content

Commit

Permalink
[Security Solution] Hide Rule Upgrade disabling behind Prebuilt Rule …
Browse files Browse the repository at this point in the history
…Customization FF (#192919)

## Summary

With the merge of #191721, new
logic was introduce to disable the Upgrade rule button in the Rule
Upgrade table for rules which have conflicts in any of their fields.

**This change should be hidden behind a FF.** Otherwise the UI upgrade
flow might break for any users who might have customized the rule via
API and generated conflicts.
  • Loading branch information
jpdjere authored Sep 13, 2024
1 parent e0b5bdc commit a27a044
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@ export interface UpgradePrebuiltRulesTableState {
* List of rule IDs that are currently being upgraded
*/
loadingRules: RuleSignatureId[];
/**
/**
* The timestamp for when the rules were successfully fetched
*/
lastUpdated: number;
/**
* Feature Flag to enable prebuilt rules customization
*/
isPrebuiltRulesCustomizationEnabled: boolean;
}

export const PREBUILT_RULE_UPDATE_FLYOUT_ANCHOR = 'updatePrebuiltRulePreview';
Expand Down Expand Up @@ -315,6 +318,7 @@ export const UpgradePrebuiltRulesTableContextProvider = ({
isUpgradingSecurityPackages,
loadingRules,
lastUpdated: dataUpdatedAt,
isPrebuiltRulesCustomizationEnabled,
},
actions,
};
Expand All @@ -331,6 +335,7 @@ export const UpgradePrebuiltRulesTableContextProvider = ({
loadingRules,
dataUpdatedAt,
actions,
isPrebuiltRulesCustomizationEnabled,
]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,16 @@ const INTEGRATIONS_COLUMN: TableColumn = {
const createUpgradeButtonColumn = (
upgradeRules: UpgradePrebuiltRulesTableActions['upgradeRules'],
loadingRules: RuleSignatureId[],
isDisabled: boolean
isDisabled: boolean,
isPrebuiltRulesCustomizationEnabled: boolean
): TableColumn => ({
field: 'rule_id',
name: <RulesTableEmptyColumnName name={i18n.UPDATE_RULE_BUTTON} />,
render: (ruleId: RuleSignatureId, record) => {
const isRuleUpgrading = loadingRules.includes(ruleId);
const isUpgradeButtonDisabled = isRuleUpgrading || isDisabled || record.hasUnresolvedConflicts;
const isDisabledByConflicts =
isPrebuiltRulesCustomizationEnabled && record.hasUnresolvedConflicts;
const isUpgradeButtonDisabled = isRuleUpgrading || isDisabled || isDisabledByConflicts;
const spinner = (
<EuiLoadingSpinner
size="s"
Expand Down Expand Up @@ -141,7 +144,12 @@ export const useUpgradePrebuiltRulesTableColumns = (): TableColumn[] => {
const hasCRUDPermissions = hasUserCRUDPermission(canUserCRUD);
const [showRelatedIntegrations] = useUiSetting$<boolean>(SHOW_RELATED_INTEGRATIONS_SETTING);
const {
state: { loadingRules, isRefetching, isUpgradingSecurityPackages },
state: {
loadingRules,
isRefetching,
isUpgradingSecurityPackages,
isPrebuiltRulesCustomizationEnabled,
},
actions: { upgradeRules },
} = useUpgradePrebuiltRulesTableContext();
const isDisabled = isRefetching || isUpgradingSecurityPackages;
Expand Down Expand Up @@ -173,9 +181,23 @@ export const useUpgradePrebuiltRulesTableColumns = (): TableColumn[] => {
width: '12%',
},
...(hasCRUDPermissions
? [createUpgradeButtonColumn(upgradeRules, loadingRules, isDisabled)]
? [
createUpgradeButtonColumn(
upgradeRules,
loadingRules,
isDisabled,
isPrebuiltRulesCustomizationEnabled
),
]
: []),
],
[hasCRUDPermissions, loadingRules, isDisabled, showRelatedIntegrations, upgradeRules]
[
hasCRUDPermissions,
loadingRules,
isDisabled,
showRelatedIntegrations,
upgradeRules,
isPrebuiltRulesCustomizationEnabled,
]
);
};

0 comments on commit a27a044

Please sign in to comment.