Skip to content

Commit

Permalink
trying do decrease load bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
yctercero committed Dec 15, 2020
1 parent bd7e210 commit f957f55
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 59 deletions.
35 changes: 0 additions & 35 deletions x-pack/plugins/lists/common/utils.ts

This file was deleted.

30 changes: 28 additions & 2 deletions x-pack/plugins/lists/public/exceptions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,37 @@ import { get } from 'lodash/fp';

import { ENDPOINT_TRUSTED_APPS_LIST_ID } from '../../common/constants';
import { NamespaceType } from '../../common/schemas';
import { SavedObjectType } from '../../common/types';
import { getSavedObjectTypes } from '../../common/utils';
import { NamespaceTypeArray } from '../../common/schemas/types/default_namespace_array';
import {
SavedObjectType,
exceptionListAgnosticSavedObjectType,
exceptionListSavedObjectType,
} from '../../common/types';

import { ExceptionListFilter, ExceptionListIdentifiers } from './types';

export const getSavedObjectType = ({
namespaceType,
}: {
namespaceType: NamespaceType;
}): SavedObjectType => {
if (namespaceType === 'agnostic') {
return exceptionListAgnosticSavedObjectType;
} else {
return exceptionListSavedObjectType;
}
};

export const getSavedObjectTypes = ({
namespaceType,
}: {
namespaceType: NamespaceTypeArray;
}): SavedObjectType[] => {
return namespaceType.map((singleNamespaceType) =>
getSavedObjectType({ namespaceType: singleNamespaceType })
);
};

export const getIdsAndNamespaces = ({
lists,
showDetection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import { SavedObjectsClientContract } from 'kibana/server';
import uuid from 'uuid';

import { getSavedObjectType } from '../../../common/utils';
import {
ENDPOINT_LIST_DESCRIPTION,
ENDPOINT_LIST_ID,
ENDPOINT_LIST_NAME,
} from '../../../common/constants';
import { ExceptionListSchema, ExceptionListSoSchema, Version } from '../../../common/schemas';

import { transformSavedObjectToExceptionList } from './utils';
import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils';

interface CreateEndpointListOptions {
savedObjectsClient: SavedObjectsClientContract;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import { SavedObjectsClientContract } from 'kibana/server';
import uuid from 'uuid';

import { getSavedObjectType } from '../../../common/utils';
import {
ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION,
ENDPOINT_TRUSTED_APPS_LIST_ID,
ENDPOINT_TRUSTED_APPS_LIST_NAME,
} from '../../../common/constants';
import { ExceptionListSchema, ExceptionListSoSchema, Version } from '../../../common/schemas';

import { transformSavedObjectToExceptionList } from './utils';
import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils';

interface CreateEndpointListOptions {
savedObjectsClient: SavedObjectsClientContract;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { SavedObjectsClientContract } from 'kibana/server';
import uuid from 'uuid';

import { getSavedObjectType } from '../../../common/utils';
import {
Description,
ExceptionListSchema,
Expand All @@ -22,7 +21,7 @@ import {
Version,
} from '../../../common/schemas';

import { transformSavedObjectToExceptionList } from './utils';
import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils';

interface CreateExceptionListOptions {
listId: ListId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { SavedObjectsClientContract } from 'kibana/server';
import uuid from 'uuid';

import { getSavedObjectType } from '../../../common/utils';
import {
CreateCommentsArray,
Description,
Expand All @@ -25,6 +24,7 @@ import {
} from '../../../common/schemas';

import {
getSavedObjectType,
transformCreateCommentsToComments,
transformSavedObjectToExceptionListItem,
} from './utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

import { SavedObjectsClientContract } from 'kibana/server';

import { getSavedObjectType } from '../../../common/utils';
import {
ExceptionListSchema,
IdOrUndefined,
ListIdOrUndefined,
NamespaceType,
} from '../../../common/schemas';

import { getSavedObjectType } from './utils';
import { getExceptionList } from './get_exception_list';
import { deleteExceptionListItemByList } from './delete_exception_list_items_by_list';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import { SavedObjectsClientContract } from 'kibana/server';

import { getSavedObjectType } from '../../../common/utils';
import {
ExceptionListItemSchema,
Id,
Expand All @@ -15,6 +14,7 @@ import {
NamespaceType,
} from '../../../common/schemas';

import { getSavedObjectType } from './utils';
import { getExceptionListItem } from './get_exception_list_item';

interface DeleteExceptionListItemOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { getSavedObjectType } from '../../../common/utils';
import { SavedObjectsClientContract } from '../../../../../../src/core/server/';
import { ListId, NamespaceType } from '../../../common/schemas';

import { findExceptionListItem } from './find_exception_list_item';
import { getSavedObjectType } from './utils';

const PER_PAGE = 100;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
exceptionListAgnosticSavedObjectType,
exceptionListSavedObjectType,
} from '../../../common/types';
import { getSavedObjectTypes } from '../../../common/utils';
import {
ExceptionListSoSchema,
FilterOrUndefined,
Expand All @@ -23,7 +22,7 @@ import {
SortOrderOrUndefined,
} from '../../../common/schemas';

import { transformSavedObjectsToFoundExceptionList } from './utils';
import { getSavedObjectTypes, transformSavedObjectsToFoundExceptionList } from './utils';

interface FindExceptionListOptions {
namespaceType: NamespaceTypeArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
import { SavedObjectsClientContract } from 'kibana/server';

import { getSavedObjectTypes } from '../../../common/utils';
import { SavedObjectType } from '../../../common/types';
import { EmptyStringArrayDecoded } from '../../../common/schemas/types/empty_string_array';
import { NamespaceTypeArray } from '../../../common/schemas/types/default_namespace_array';
Expand All @@ -19,7 +18,7 @@ import {
SortOrderOrUndefined,
} from '../../../common/schemas';

import { transformSavedObjectsToFoundExceptionListItem } from './utils';
import { getSavedObjectTypes, transformSavedObjectsToFoundExceptionListItem } from './utils';
import { getExceptionList } from './get_exception_list';

interface FindExceptionListItemsOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { getSavedObjectType } from '../../../common/utils';
import {
SavedObjectsClientContract,
SavedObjectsErrorHelpers,
Expand All @@ -17,7 +16,7 @@ import {
NamespaceType,
} from '../../../common/schemas';

import { transformSavedObjectToExceptionList } from './utils';
import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils';

interface GetExceptionListOptions {
id: IdOrUndefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { getSavedObjectType } from '../../../common/utils';
import {
SavedObjectsClientContract,
SavedObjectsErrorHelpers,
Expand All @@ -17,7 +16,7 @@ import {
NamespaceType,
} from '../../../common/schemas';

import { transformSavedObjectToExceptionListItem } from './utils';
import { getSavedObjectType, transformSavedObjectToExceptionListItem } from './utils';

interface GetExceptionListItemOptions {
id: IdOrUndefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import { SavedObjectsClientContract } from 'kibana/server';

import { getSavedObjectType } from '../../../common/utils';
import {
DescriptionOrUndefined,
ExceptionListSchema,
Expand All @@ -23,7 +22,7 @@ import {
_VersionOrUndefined,
} from '../../../common/schemas';

import { transformSavedObjectUpdateToExceptionList } from './utils';
import { getSavedObjectType, transformSavedObjectUpdateToExceptionList } from './utils';
import { getExceptionList } from './get_exception_list';

interface UpdateExceptionListOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import { SavedObjectsClientContract } from 'kibana/server';

import { getSavedObjectType } from '../../../common/utils';
import {
DescriptionOrUndefined,
EntriesArray,
Expand All @@ -25,6 +24,7 @@ import {
} from '../../../common/schemas';

import {
getSavedObjectType,
transformSavedObjectUpdateToExceptionListItem,
transformUpdateCommentsToComments,
} from './utils';
Expand Down
29 changes: 28 additions & 1 deletion x-pack/plugins/lists/server/services/exception_lists/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import uuid from 'uuid';
import { SavedObject, SavedObjectsFindResponse, SavedObjectsUpdateResponse } from 'kibana/server';

import { exceptionListAgnosticSavedObjectType } from '../../../common/types';
import {
SavedObjectType,
exceptionListAgnosticSavedObjectType,
exceptionListSavedObjectType,
} from '../../../common/types';
import { NamespaceTypeArray } from '../../../common/schemas/types/default_namespace_array';
import {
CommentsArray,
CreateComment,
Expand All @@ -22,6 +27,18 @@ import {
exceptionListType,
} from '../../../common/schemas';

export const getSavedObjectType = ({
namespaceType,
}: {
namespaceType: NamespaceType;
}): SavedObjectType => {
if (namespaceType === 'agnostic') {
return exceptionListAgnosticSavedObjectType;
} else {
return exceptionListSavedObjectType;
}
};

export const getExceptionListType = ({
savedObjectType,
}: {
Expand All @@ -34,6 +51,16 @@ export const getExceptionListType = ({
}
};

export const getSavedObjectTypes = ({
namespaceType,
}: {
namespaceType: NamespaceTypeArray;
}): SavedObjectType[] => {
return namespaceType.map((singleNamespaceType) =>
getSavedObjectType({ namespaceType: singleNamespaceType })
);
};

export const transformSavedObjectToExceptionList = ({
savedObject,
}: {
Expand Down

0 comments on commit f957f55

Please sign in to comment.