Skip to content

Commit 4e671d7

Browse files
XavierMcnasikas
andcommitted
[SIEM] CASES Bugs BC2 (#62170)
* fix persistence between filter * Fix API filtering bug * Show username if full name is empty * fix user in avatar * do not allow push to service now when connector is none * fix types * Show errors from actions * update connector name in configure Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>
1 parent 117cfa9 commit 4e671d7

9 files changed

Lines changed: 51 additions & 24 deletions

File tree

x-pack/legacy/plugins/siem/public/containers/case/api.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import {
4747
decodeServiceConnectorCaseResponse,
4848
} from './utils';
4949

50+
import * as i18n from './translations';
51+
5052
export const getCase = async (
5153
caseId: string,
5254
includeComments: boolean = true,
@@ -240,6 +242,11 @@ export const pushToService = async (
240242
signal,
241243
}
242244
);
245+
246+
if (response.status === 'error') {
247+
throw new Error(response.serviceMessage ?? response.message ?? i18n.ERROR_PUSH_TO_SERVICE);
248+
}
249+
243250
return decodeServiceConnectorCaseResponse(response.data);
244251
};
245252

x-pack/legacy/plugins/siem/public/containers/case/configure/use_configure.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ interface PersistCaseConfigure {
2121
export interface ReturnUseCaseConfigure {
2222
loading: boolean;
2323
refetchCaseConfigure: () => void;
24-
persistCaseConfigure: ({ connectorId, closureType }: PersistCaseConfigure) => unknown;
24+
persistCaseConfigure: ({
25+
connectorId,
26+
connectorName,
27+
closureType,
28+
}: PersistCaseConfigure) => unknown;
2529
persistLoading: boolean;
2630
}
2731

@@ -97,19 +101,20 @@ export const useCaseConfigure = ({
97101
const saveCaseConfiguration = async () => {
98102
try {
99103
setPersistLoading(true);
104+
const connectorObj = {
105+
connector_id: connectorId,
106+
connector_name: connectorName,
107+
closure_type: closureType,
108+
};
100109
const res =
101110
version.length === 0
102-
? await postCaseConfigure(
111+
? await postCaseConfigure(connectorObj, abortCtrl.signal)
112+
: await patchCaseConfigure(
103113
{
104-
connector_id: connectorId,
105-
connector_name: connectorName,
106-
closure_type: closureType,
114+
...connectorObj,
115+
version,
107116
},
108117
abortCtrl.signal
109-
)
110-
: await patchCaseConfigure(
111-
{ connector_id: connectorId, closure_type: closureType, version },
112-
abortCtrl.signal
113118
);
114119
if (!didCancel) {
115120
setPersistLoading(false);

x-pack/legacy/plugins/siem/public/containers/case/translations.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,10 @@ export const SUCCESS_SEND_TO_EXTERNAL_SERVICE = i18n.translate(
6363
defaultMessage: 'Successfully sent to ServiceNow',
6464
}
6565
);
66+
67+
export const ERROR_PUSH_TO_SERVICE = i18n.translate(
68+
'xpack.siem.case.configure.errorPushingToService',
69+
{
70+
defaultMessage: 'Error pushing to service',
71+
}
72+
);

x-pack/legacy/plugins/siem/public/containers/case/use_get_cases.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export type Action =
3535
}
3636
| { type: 'FETCH_FAILURE'; payload: string }
3737
| { type: 'FETCH_UPDATE_CASE_SUCCESS' }
38-
| { type: 'UPDATE_FILTER_OPTIONS'; payload: FilterOptions }
38+
| { type: 'UPDATE_FILTER_OPTIONS'; payload: Partial<FilterOptions> }
3939
| { type: 'UPDATE_QUERY_PARAMS'; payload: Partial<QueryParams> }
4040
| { type: 'UPDATE_TABLE_SELECTIONS'; payload: Case[] };
4141

@@ -68,7 +68,10 @@ const dataFetchReducer = (state: UseGetCasesState, action: Action): UseGetCasesS
6868
case 'UPDATE_FILTER_OPTIONS':
6969
return {
7070
...state,
71-
filterOptions: action.payload,
71+
filterOptions: {
72+
...state.filterOptions,
73+
...action.payload,
74+
},
7275
};
7376
case 'UPDATE_QUERY_PARAMS':
7477
return {
@@ -119,8 +122,8 @@ interface UseGetCases extends UseGetCasesState {
119122
refetchCasesStatus,
120123
}: UpdateCase) => void;
121124
refetchCases: (filters: FilterOptions, queryParams: QueryParams) => void;
122-
setFilters: (filters: FilterOptions) => void;
123-
setQueryParams: (queryParams: QueryParams) => void;
125+
setFilters: (filters: Partial<FilterOptions>) => void;
126+
setQueryParams: (queryParams: Partial<QueryParams>) => void;
124127
setSelectedCases: (mySelectedCases: Case[]) => void;
125128
}
126129

@@ -139,11 +142,11 @@ export const useGetCases = (initialQueryParams?: QueryParams): UseGetCases => {
139142
dispatch({ type: 'UPDATE_TABLE_SELECTIONS', payload: mySelectedCases });
140143
}, []);
141144

142-
const setQueryParams = useCallback((newQueryParams: QueryParams) => {
145+
const setQueryParams = useCallback((newQueryParams: Partial<QueryParams>) => {
143146
dispatch({ type: 'UPDATE_QUERY_PARAMS', payload: newQueryParams });
144147
}, []);
145148

146-
const setFilters = useCallback((newFilters: FilterOptions) => {
149+
const setFilters = useCallback((newFilters: Partial<FilterOptions>) => {
147150
dispatch({ type: 'UPDATE_FILTER_OPTIONS', payload: newFilters });
148151
}, []);
149152

x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/columns.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const getCasesColumns = (
7777
size="s"
7878
/>
7979
<Spacer data-test-subj="case-table-column-createdBy">
80-
{createdBy.fullName ?? createdBy.username ?? ''}
80+
{createdBy.fullName ? createdBy.fullName : createdBy.username ?? ''}
8181
</Spacer>
8282
</>
8383
);

x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ export const AllCases = React.memo<AllCasesProps>(({ userCanCrud }) => {
254254
const onFilterChangedCallback = useCallback(
255255
(newFilterOptions: Partial<FilterOptions>) => {
256256
if (newFilterOptions.status && newFilterOptions.status === 'closed') {
257-
setQueryParams({ ...queryParams, sortField: SortFieldCase.closedAt });
257+
setQueryParams({ sortField: SortFieldCase.closedAt });
258258
} else if (newFilterOptions.status && newFilterOptions.status === 'open') {
259-
setQueryParams({ ...queryParams, sortField: SortFieldCase.createdAt });
259+
setQueryParams({ sortField: SortFieldCase.createdAt });
260260
}
261-
setFilters({ ...filterOptions, ...newFilterOptions });
261+
setFilters(newFilterOptions);
262262
},
263263
[filterOptions, queryParams]
264264
);

x-pack/legacy/plugins/siem/public/pages/case/components/use_push_to_service/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ export const usePushToService = ({
7474
if (actionLicense != null && !actionLicense.enabledInLicense) {
7575
errors = [...errors, getLicenseError()];
7676
}
77-
if (connector == null && !loadingCaseConfigure && !loadingLicense) {
77+
if (
78+
(connector == null || (connector != null && connector.connectorId === 'none')) &&
79+
!loadingCaseConfigure &&
80+
!loadingLicense
81+
) {
7882
errors = [
7983
...errors,
8084
{

x-pack/legacy/plugins/siem/public/pages/case/components/user_action_tree/user_action_item.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ export const UserActionItem = ({
134134
<EuiFlexItem>
135135
<EuiFlexGroup gutterSize={'none'}>
136136
<EuiFlexItem data-test-subj={`user-action-${id}-avatar`} grow={false}>
137-
{(fullName && fullName.length > 0) || username.length > 0 ? (
138-
<UserActionAvatar name={fullName ?? username} />
137+
{(fullName && fullName.length > 0) || (username && username.length > 0) ? (
138+
<UserActionAvatar name={fullName && fullName.length > 0 ? fullName : username ?? ''} />
139139
) : (
140140
<EuiLoadingSpinner className="userAction_loadingAvatar" />
141141
)}

x-pack/plugins/case/server/routes/api/cases/find_cases.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ const buildFilter = (
3131
): string =>
3232
filters != null && filters.length > 0
3333
? Array.isArray(filters)
34-
? filters
34+
? // Be aware of the surrounding parenthesis (as string inside literal) around filters.
35+
`(${filters
3536
.map(filter => `${CASE_SAVED_OBJECT}.attributes.${field}: ${filter}`)
36-
?.join(` ${operator} `)
37+
?.join(` ${operator} `)})`
3738
: `${CASE_SAVED_OBJECT}.attributes.${field}: ${filters}`
3839
: '';
3940

0 commit comments

Comments
 (0)