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

[Cases] refactor useGetCases to use react-query #133505

Merged
merged 22 commits into from
Jun 8, 2022

Conversation

academo
Copy link
Contributor

@academo academo commented Jun 3, 2022

Summary

Refactors de useGetCases hook to use react-query.

This refactor changes many other components that use this hook.

@academo academo added release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature v8.4.0 labels Jun 3, 2022
@academo academo self-assigned this Jun 3, 2022
@academo academo requested review from peteharverson and cnasikas June 7, 2022 08:39
@academo academo requested a review from jonathan-buttner June 8, 2022 07:08
@academo academo marked this pull request as ready for review June 8, 2022 07:08
@academo academo requested a review from a team as a code owner June 8, 2022 07:08
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops-cases (Feature:Cases)

dispatchUpdateCaseProperty({
...args,
refetchCasesStatus: () => {
({ updateKey, updateValue, caseData }: UpdateByKey) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is one of the main logic-wise changes in this PR. The previous useGetCases hook was providing a "sub-hook" to update a case and I had to remove that.

Instead I reused the existing updateCaseproperty hook.

@@ -65,19 +72,21 @@ export const AllCasesList = React.memo<AllCasesListProps>(
...(!isEmpty(hiddenStatuses) && firstAvailableStatus && { status: firstAvailableStatus }),
owner: hasOwner ? owner : availableSolutions,
};
const [filterOptions, setFilterOptions] = useState<FilterOptions>({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the second logic change in the PR. the previous hook was working both as a fetch data hook and state management. I removed the state management part from it and move it here.

@@ -147,30 +156,28 @@ export const AllCasesList = React.memo<AllCasesListProps>(
const onFilterChangedCallback = useCallback(
(newFilterOptions: Partial<FilterOptions>) => {
if (newFilterOptions.status && newFilterOptions.status === CaseStatuses.closed) {
setQueryParams({ sortField: SortFieldCase.closedAt });
setQueryParams({ ...DEFAULT_QUERY_PARAMS, sortField: SortFieldCase.closedAt });
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we use the previous state?

setQueryParams((prev) => ({ ...prev, sortField: SortFieldCase.closedAt }))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct! thanks :D

@@ -240,8 +246,8 @@ export const AllCasesList = React.memo<AllCasesListProps>(
filterOptions={filterOptions}
goToCreateCase={onRowClick}
handleIsLoading={handleIsLoading}
isCasesLoading={isCasesLoading}
isCommentUpdating={isCasesLoading}
isCasesLoading={isLoadingCases && data.cases.length === 0}
Copy link
Member

Choose a reason for hiding this comment

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

What will happen if the are no cases in the response?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This actually a mistake. I removed the length check.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

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

id before after diff
cases 356.4KB 352.3KB -4.1KB
Unknown metric groups

ESLint disabled line counts

id before after diff
cases 73 71 -2

Total ESLint disabled count

id before after diff
cases 89 87 -2

History

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

cc @academo

@academo academo requested a review from cnasikas June 8, 2022 10:51
Copy link
Member

@cnasikas cnasikas left a comment

Choose a reason for hiding this comment

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

Code LTGM. Tested locally without any issues.

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

Tested and LGTM

@academo academo merged commit e9e6009 into elastic:main Jun 8, 2022
@academo academo deleted the refactor/create-form-hooks-part3 branch June 8, 2022 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Cases Cases feature release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants