Skip to content

Commit

Permalink
[Cases] Fix _find API total bug (#95235) (#95517)
Browse files Browse the repository at this point in the history
* Cherry-picking 7.12 find total fix

* Starting fix for total bug in master with new field

* Adding feature flag for sub cases

* Disabling case as a connector in security solution

* Adding additional tests for pagination

* Removing other api integration tests

* Fixing up problems from merge

* Fixing sub case tests and type errors

* Renaming comment tag for case connector
  • Loading branch information
jonathan-buttner authored Mar 26, 2021
1 parent 5bba03b commit c841686
Show file tree
Hide file tree
Showing 6 changed files with 979 additions and 524 deletions.
6 changes: 4 additions & 2 deletions x-pack/plugins/cases/server/routes/api/cases/find_cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ export function initFindCasesApi({ caseService, router, logger }: RouteDeps) {
return response.ok({
body: CasesFindResponseRt.encode(
transformCases({
...cases,
casesMap: cases.casesMap,
page: cases.page,
perPage: cases.perPage,
total: cases.total,
countOpenCases: openCases,
countInProgressCases: inProgressCases,
countClosedCases: closedCases,
total: cases.casesMap.size,
})
),
});
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/server/routes/api/cases/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import {
CaseConnector,
ESCaseConnector,
ESCasesConfigureAttributes,
ConnectorTypeFields,
ConnectorTypes,
CaseStatuses,
CaseType,
SavedObjectFindOptions,
} from '../../../../common/api';
import { ESConnectorFields, ConnectorTypeFields } from '../../../../common/api/connectors';
import { ESConnectorFields } from '../../../../common/api/connectors';
import { CASE_SAVED_OBJECT, SUB_CASE_SAVED_OBJECT } from '../../../saved_object_types';
import { sortToSnake } from '../utils';
import { combineFilters } from '../../../common';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ export function initFindSubCasesApi({ caseService, router, logger }: RouteDeps)
return response.ok({
body: SubCasesFindResponseRt.encode(
transformSubCases({
...subCases,
page: subCases.page,
perPage: subCases.perPage,
total: subCases.total,
subCasesMap: subCases.subCasesMap,
open,
inProgress,
closed,
// there should only be one entry in the map for the requested case ID
total: subCases.subCasesMap.get(request.params.case_id)?.length ?? 0,
})
),
});
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/cases/server/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ interface SubCasesMapWithPageInfo {
subCasesMap: Map<string, SubCaseResponse[]>;
page: number;
perPage: number;
total: number;
}

interface CaseCommentStats {
Expand All @@ -194,6 +195,7 @@ interface CasesMapWithPageInfo {
casesMap: Map<string, CaseResponse>;
page: number;
perPage: number;
total: number;
}

type FindCaseOptions = CasesFindRequest & SavedObjectFindOptions;
Expand Down Expand Up @@ -348,6 +350,7 @@ export class CaseService implements CaseServiceSetup {
casesMap: casesWithComments,
page: cases.page,
perPage: cases.per_page,
total: cases.total,
};
}

Expand Down Expand Up @@ -529,6 +532,7 @@ export class CaseService implements CaseServiceSetup {
subCasesMap: new Map<string, SubCaseResponse[]>(),
page: 0,
perPage: 0,
total: 0,
};

if (!options) {
Expand Down Expand Up @@ -585,7 +589,7 @@ export class CaseService implements CaseServiceSetup {
return accMap;
}, new Map<string, SubCaseResponse[]>());

return { subCasesMap, page: subCases.page, perPage: subCases.per_page };
return { subCasesMap, page: subCases.page, perPage: subCases.per_page, total: subCases.total };
}

/**
Expand Down
Loading

0 comments on commit c841686

Please sign in to comment.