Skip to content

Commit

Permalink
SortField
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykkopycinski committed Aug 31, 2020
1 parent b2101f5 commit 8d59de5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
Maybe,
PageInfoPaginated,
RequestOptionsPaginated,
SortField,
TimerangeInput,
} from '..';

Expand All @@ -29,6 +28,11 @@ export enum HostPolicyResponseActionStatus {
warning = 'warning',
}

export enum HostsFields {
lastSeen = 'lastSeen',
hostName = 'hostName',
}

export interface EndpointFields {
endpointPolicy?: Maybe<string>;

Expand Down Expand Up @@ -69,12 +73,12 @@ export interface HostOverviewStrategyResponse extends IEsSearchResponse, HostIte
inspect?: Maybe<Inspect>;
}

export interface HostsRequestOptions extends RequestOptionsPaginated {
sort: SortField;
export interface HostsRequestOptions extends RequestOptionsPaginated<HostsFields> {
defaultIndex: string[];
}

export interface HostLastFirstSeenRequestOptions extends Partial<RequestOptionsPaginated> {
export interface HostLastFirstSeenRequestOptions
extends Partial<RequestOptionsPaginated<HostsFields>> {
hostName: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { NetworkQueries, NetworkTlsStrategyResponse, NetworkTlsRequestOptions } from './network';

export * from './hosts';
export * from './network';
export type Maybe<T> = T | null;

export type FactoryQueryTypes = HostsQueries | NetworkQueries;
Expand All @@ -41,8 +42,8 @@ export enum Direction {
desc = 'desc',
}

export interface SortField {
field: 'lastSeen' | 'hostName';
export interface SortField<Field = string> {
field: Field;
direction: Direction;
}

Expand Down Expand Up @@ -88,14 +89,14 @@ export interface RequestBasicOptions extends IEsSearchRequest {
factoryQueryType?: FactoryQueryTypes;
}

export interface RequestOptions extends RequestBasicOptions {
export interface RequestOptions<Field = string> extends RequestBasicOptions {
pagination: PaginationInput;
sortField?: SortField;
sort: SortField<Field>;
}

export interface RequestOptionsPaginated extends RequestBasicOptions {
export interface RequestOptionsPaginated<Field = string> extends RequestBasicOptions {
pagination: PaginationInputPaginated;
sortField?: SortField;
sort: SortField<Field>;
}

export type StrategyResponseType<T extends FactoryQueryTypes> = T extends HostsQueries.hosts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { IEsSearchResponse } from '../../../../../../../src/plugins/data/common';
import { CursorType, Inspect, Maybe, PageInfoPaginated, RequestOptionsPaginated } from '..';
import { IEsSearchResponse } from '../../../../../../../../src/plugins/data/common';
import { CursorType, Inspect, Maybe, PageInfoPaginated, RequestOptionsPaginated } from '../..';

export interface TlsBuckets {
key: string;
Expand Down Expand Up @@ -50,20 +50,9 @@ export interface TlsEdges {
cursor: CursorType;
}

export enum Direction {
asc = 'asc',
desc = 'desc',
}

export interface TlsSortField {
field: TlsFields;
direction: Direction;
}

export interface NetworkTlsRequestOptions extends RequestOptionsPaginated {
export interface NetworkTlsRequestOptions extends RequestOptionsPaginated<TlsFields> {
ip: string;
flowTarget: FlowTargetSourceDest;
sort: TlsSortField;
defaultIndex: string[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,6 @@ export const useNetworkTls = ({
);

useEffect(() => {
if (skip) {
return;
}

setHostRequest((prevRequest) => {
const myRequest = {
...prevRequest,
Expand All @@ -185,7 +181,7 @@ export const useNetworkTls = ({
},
sort,
};
if (!deepEqual(prevRequest, myRequest)) {
if (!skip && !deepEqual(prevRequest, myRequest)) {
return myRequest;
}
return prevRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import {
Direction,
HostsRequestOptions,
SortField,
HostsFields,
} from '../../../../../../common/search_strategy/security_solution';
import { createQueryFilterClauses } from '../../../../../utils/build_query';
import { assertUnreachable } from '../../../../../../common/utility_types';

export const buildHostsQuery = ({
defaultIndex,
Expand Down Expand Up @@ -77,11 +79,13 @@ export const buildHostsQuery = ({

type QueryOrder = { lastSeen: Direction } | { _key: Direction };

const getQueryOrder = (sort: SortField): QueryOrder => {
const getQueryOrder = (sort: SortField<HostsFields>): QueryOrder => {
switch (sort.field) {
case 'lastSeen':
return { lastSeen: sort.direction };
case 'hostName':
return { _key: sort.direction };
default:
return assertUnreachable(sort.field as never);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
import { assertUnreachable } from '../../../../../../common/utility_types';
import { createQueryFilterClauses } from '../../../../../utils/build_query';

import { NetworkTlsRequestOptions } from '../../../../../../common/search_strategy/security_solution/network';
import { TlsSortField, Direction, TlsFields } from '../../../../../graphql/types';
import {
NetworkTlsRequestOptions,
SortField,
Direction,
TlsFields,
} from '../../../../../../common/search_strategy/security_solution';

const getAggs = (querySize: number, sort: TlsSortField) => ({
const getAggs = (querySize: number, sort: SortField<TlsFields>) => ({
count: {
cardinality: {
field: 'tls.server.hash.sha1',
Expand Down Expand Up @@ -94,7 +98,7 @@ interface QueryOrder {
_key: Direction;
}

const getQueryOrder = (sort: TlsSortField): QueryOrder => {
const getQueryOrder = (sort: SortField<TlsFields>): QueryOrder => {
switch (sort.field) {
case TlsFields._id:
return { _key: sort.direction };
Expand Down

0 comments on commit 8d59de5

Please sign in to comment.