Skip to content

Refactor Rule Detail Page#146192

Closed
CoenWarmer wants to merge 24 commits intoelastic:mainfrom
CoenWarmer:chore/refactor-rules-detail-page
Closed

Refactor Rule Detail Page#146192
CoenWarmer wants to merge 24 commits intoelastic:mainfrom
CoenWarmer:chore/refactor-rules-detail-page

Conversation

@CoenWarmer
Copy link
Contributor

@CoenWarmer CoenWarmer commented Nov 23, 2022

Summary

This PR aims to refactor the Rule Details page for more maintainability and better legibility.

Functionally the page should behave exactly the same.

It is recommended to review this PR commit by commit.

Guidelines while refactoring:

  • Consistent use of page title components (pageTitle: string | component, rightSideItems: [<HeaderActions />])
  • Break up components to make them easier to read, mock, test
  • Separation of concerns
  • Place JSX defined before the return of the component in its own component
  • Reusable business logic into hooks
  • Reuse newly created hooks
  • Functions that are exported and only used once in the codebase don't have to be their own functions (yet), they can be defined inside the calling component

Part of refactoring effort of other AO pages:

@CoenWarmer CoenWarmer requested a review from a team November 23, 2022 16:57
@CoenWarmer CoenWarmer marked this pull request as draft November 23, 2022 16:57
@CoenWarmer CoenWarmer added the release_note:skip Skip the PR/issue when compiling release notes label Nov 23, 2022
@CoenWarmer CoenWarmer changed the title Refactor Rules Detail Page Refactor Rule Detail Page Nov 23, 2022
@CoenWarmer CoenWarmer marked this pull request as ready for review November 24, 2022 12:13
defaultMessage: 'Created',
});

export const confirmModalText = (
Copy link
Contributor Author

@CoenWarmer CoenWarmer Nov 24, 2022

Choose a reason for hiding this comment

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

These translation functions were only used in DeleteConfirmationModal.

DeleteConfirmationModal was set up in a way where it could only delete one thing at a time, so de facto numIdsToDelete would always be 1.

Since it would only allow the deletion of 1 thing at a time, it made no sense to pass a multipleTitle.

By removing these constraints, it became possible to increase the legibility of the i18n string by writing "You can't recover {title} after deleting." and just including it in the component that used it.

@@ -18,7 +17,9 @@ export function CenterJustifiedSpinner({ size }: Props) {
return (
<EuiFlexGroup data-test-subj="centerJustifiedSpinner" justifyContent="center">
Copy link
Contributor Author

@CoenWarmer CoenWarmer Nov 24, 2022

Choose a reason for hiding this comment

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

This makes the loading state for this page look nicer (the spinner is no longer at the top edge of the page).

I do think we need to unify the page loaders for Overview, Rules, Rule Details, Alerts, Alert Detail into one component so there's less code to manage and more UI consistency, but that can happen in a different PR.

};

const features = (
rule?.consumer === ALERTS_FEATURE_ID && ruleType?.producer ? ruleType.producer : rule?.consumer
Copy link
Contributor Author

@CoenWarmer CoenWarmer Nov 24, 2022

Choose a reason for hiding this comment

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

This looks slightly magical to me, but it is unchanged from the previous implementation. Perhaps someone can illuminate what this variable means and how the way it is derived makes sense?

multipleTitle={rule.name}
setIsLoadingState={() => setIsPageLoading(true)}
/>
{errorRule && toasts.addDanger({ title: errorRule })}
Copy link
Contributor Author

@CoenWarmer CoenWarmer Nov 24, 2022

Choose a reason for hiding this comment

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

This is calling a method on toasts. It is not a JSX component. It should not be placed in the return of the JSX component

onCancel={() => setRuleToDelete([])}
apiDeleteCall={deleteRules}
idsToDelete={ruleToDelete}
singleTitle={rule.name}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

singleTitle and multipleTitle are always the same, no need for separate props

}}
onCancel={() => setRuleToDelete([])}
apiDeleteCall={deleteRules}
idsToDelete={ruleToDelete}
Copy link
Contributor Author

@CoenWarmer CoenWarmer Nov 24, 2022

Choose a reason for hiding this comment

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

prop is called idsToDelete implying that at some point this component was meant to be able to remove multiple things at once, but the Rule Details page can't delete multiple things and the modal (which is in the components subfolder of Rule Details so is only meant to be used here) can not either.

Perhaps this component was copied over from another place where it could delete multiple things at once.

}}
/>
{editFlyoutVisible &&
getEditAlertFlyout({
Copy link
Contributor Author

@CoenWarmer CoenWarmer Nov 24, 2022

Choose a reason for hiding this comment

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

Component methods exported by TriggerActionsUI are JSX components, so used JSX component syntax (<EditAlertFlyout />)

pageHeader={{
pageTitle: <PageTitle rule={rule} />,
bottomBorder: false,
rightSideItems: hasEditButton
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Value of rightSideItems broken out to its own component

<RuleAlertsSummary rule={rule} filteredRuleTypes={filteredRuleTypes} />
</EuiFlexItem>

const statusMessage = isLicenseError
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Broken out into its own function getStatusMessage

@CoenWarmer
Copy link
Contributor Author

@elasticmachine merge upstream

@CoenWarmer
Copy link
Contributor Author

@elasticmachine merge upstream

setEditRuleFlyoutVisible(false);
};

const hasEditButton =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Broken out into its own hook: useIsRuleEditable

toasts.addDanger({ title: errorRule });
}

const tabs: EuiTabbedContentTab[] = [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Broken out into its own component: <RuleDetailTabs />

@@ -1,93 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to <DeleteConfirmationModal />

@@ -1,35 +0,0 @@
/*
Copy link
Contributor Author

@CoenWarmer CoenWarmer Nov 30, 2022

Choose a reason for hiding this comment

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

Renamed to /helpers/utils.ts as it provided helper utilities more so than configuration

@CoenWarmer
Copy link
Contributor Author

@elasticmachine merge upstream

@kibana-ci
Copy link

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
observability 449 454 +5

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
observability 497.9KB 497.8KB -94.0B
Unknown metric groups

ESLint disabled in files

id before after diff
osquery 1 2 +1

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
fleet 59 65 +6
osquery 109 115 +6
securitySolution 443 449 +6
total +20

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
fleet 68 74 +6
osquery 110 117 +7
securitySolution 520 526 +6
total +21

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@kdelemme
Copy link
Contributor

@CoenWarmer Does this PR still require review?

@CoenWarmer
Copy link
Contributor Author

@CoenWarmer Does this PR still require review?

I still think it's an improvement, but it's a little outdated now. Let me update it and I'll ping you.

@CoenWarmer CoenWarmer marked this pull request as draft February 6, 2023 14:19
@CoenWarmer CoenWarmer closed this Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_note:skip Skip the PR/issue when compiling release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants