-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
academo
merged 22 commits into
elastic:main
from
academo:refactor/create-form-hooks-part3
Jun 8, 2022
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5691e40
refactor usetags to use react-query
181a3b5
rename hook to useGetTags
9280332
Remove caseId parameter from useUpdateField
9cd7cb6
remove dispatchUpdateCaseProperty from getCases hook
b63fc1f
Merge remote-tracking branch 'upstream/main' into refactor/create-for…
08a17a0
Merge remote-tracking branch 'origin/refactor/create-form-hooks-p2' i…
9c83ab4
WIP: fixing tests
8ed85c8
Merge remote-tracking branch 'upstream/main' into refactor/create-for…
c02acac
Update broken tests
4b5dab6
Fix tests
74cbacc
Merge remote-tracking branch 'upstream/main' into refactor/create-for…
82bca36
Fix possible problem with empty prefixed key
c8ee55a
invalidate tags cache view when refreshing case view pag
b63e63b
Merge remote-tracking branch 'upstream/main' into refactor/create-for…
9e6c917
Fix jest tests timing out
1c91720
fix broken test
2453d45
remove unused variable
20df8b9
Merge remote-tracking branch 'origin/refactor/create-form-hooks-p2' i…
c35f5e2
Merge remote-tracking branch 'upstream/main' into refactor/create-for…
15e167a
rename hook to previous name
64abe42
Use previous params
24ee910
do not check for data length to show loading bar
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
263 changes: 101 additions & 162 deletions
263
x-pack/plugins/cases/public/components/all_cases/all_cases_list.test.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ import { | |
import { RIGHT_ALIGNMENT } from '@elastic/eui/lib/services'; | ||
import styled from 'styled-components'; | ||
|
||
import { Case, DeleteCase } from '../../../common/ui/types'; | ||
import { Case, DeleteCase, UpdateByKey } from '../../../common/ui/types'; | ||
import { CaseStatuses, ActionConnector, CaseSeverity } from '../../../common/api'; | ||
import { OWNER_INFO } from '../../../common/constants'; | ||
import { getEmptyTagValue } from '../empty_value'; | ||
|
@@ -33,7 +33,6 @@ import { CaseDetailsLink } from '../links'; | |
import * as i18n from './translations'; | ||
import { ALERTS } from '../../common/translations'; | ||
import { getActions } from './actions'; | ||
import { UpdateCase } from '../../containers/use_get_cases'; | ||
import { useDeleteCases } from '../../containers/use_delete_cases'; | ||
import { ConfirmDeleteCaseModal } from '../confirm_delete_case'; | ||
import { useApplicationCapabilities, useKibana } from '../../common/lib/kibana'; | ||
|
@@ -43,6 +42,7 @@ import { getConnectorIcon } from '../utils'; | |
import type { CasesOwners } from '../../client/helpers/can_use_cases'; | ||
import { useCasesFeatures } from '../cases_context/use_cases_features'; | ||
import { severities } from '../severity/config'; | ||
import { useUpdateCase } from '../../containers/use_update_case'; | ||
|
||
export type CasesColumns = | ||
| EuiTableActionsColumnType<Case> | ||
|
@@ -57,10 +57,8 @@ const renderStringField = (field: string, dataTestSubj: string) => | |
field != null ? <span data-test-subj={dataTestSubj}>{field}</span> : getEmptyTagValue(); | ||
|
||
export interface GetCasesColumn { | ||
dispatchUpdateCaseProperty: (u: UpdateCase) => void; | ||
filterStatus: string; | ||
handleIsLoading: (a: boolean) => void; | ||
isLoadingCases: string[]; | ||
refreshCases?: (a?: boolean) => void; | ||
isSelectorView: boolean; | ||
userCanCrud: boolean; | ||
|
@@ -70,10 +68,8 @@ export interface GetCasesColumn { | |
showSolutionColumn?: boolean; | ||
} | ||
export const useCasesColumns = ({ | ||
dispatchUpdateCaseProperty, | ||
filterStatus, | ||
handleIsLoading, | ||
isLoadingCases, | ||
refreshCases, | ||
isSelectorView, | ||
userCanCrud, | ||
|
@@ -98,6 +94,8 @@ export const useCasesColumns = ({ | |
title: '', | ||
}); | ||
|
||
const { updateCaseProperty, isLoading: isLoadingUpdateCase } = useUpdateCase(); | ||
|
||
const toggleDeleteModal = useCallback( | ||
(deleteCase: Case) => { | ||
handleToggleModal(); | ||
|
@@ -107,15 +105,17 @@ export const useCasesColumns = ({ | |
); | ||
|
||
const handleDispatchUpdate = useCallback( | ||
(args: Omit<UpdateCase, 'refetchCasesStatus'>) => { | ||
dispatchUpdateCaseProperty({ | ||
...args, | ||
refetchCasesStatus: () => { | ||
({ updateKey, updateValue, caseData }: UpdateByKey) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
updateCaseProperty({ | ||
updateKey, | ||
updateValue, | ||
caseData, | ||
onSuccess: () => { | ||
if (refreshCases != null) refreshCases(); | ||
}, | ||
}); | ||
}, | ||
[dispatchUpdateCaseProperty, refreshCases] | ||
[refreshCases, updateCaseProperty] | ||
); | ||
|
||
const actions = useMemo( | ||
|
@@ -136,8 +136,8 @@ export const useCasesColumns = ({ | |
); | ||
|
||
useEffect(() => { | ||
handleIsLoading(isDeleting || isLoadingCases.indexOf('caseUpdate') > -1); | ||
}, [handleIsLoading, isDeleting, isLoadingCases]); | ||
handleIsLoading(isDeleting || isLoadingUpdateCase); | ||
}, [handleIsLoading, isDeleting, isLoadingUpdateCase]); | ||
|
||
useEffect(() => { | ||
if (isDeleted) { | ||
|
@@ -319,13 +319,12 @@ export const useCasesColumns = ({ | |
return ( | ||
<StatusContextMenu | ||
currentStatus={theCase.status} | ||
disabled={!userCanCrud || isLoadingCases.length > 0} | ||
disabled={!userCanCrud || isLoadingUpdateCase} | ||
onStatusChanged={(status) => | ||
handleDispatchUpdate({ | ||
updateKey: 'status', | ||
updateValue: status, | ||
caseId: theCase.id, | ||
version: theCase.version, | ||
caseData: theCase, | ||
}) | ||
} | ||
/> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.