Skip to content

Commit 5a3bd2c

Browse files
committed
list UI is backwards compatible
1 parent 060f089 commit 5a3bd2c

File tree

6 files changed

+42
-21
lines changed

6 files changed

+42
-21
lines changed

x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/store/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe('EndpointList store concerns', () => {
5858
patternsError: undefined,
5959
isAutoRefreshEnabled: true,
6060
autoRefreshInterval: DEFAULT_POLL_INTERVAL,
61+
queryStrategyVersion: undefined,
6162
});
6263
});
6364

x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/store/middleware.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
nonExistingPolicies,
1818
patterns,
1919
searchBarQuery,
20+
isTransformEnabled,
2021
} from './selectors';
2122
import { EndpointState, PolicyIds } from '../types';
2223
import {
@@ -70,24 +71,6 @@ export const endpointMiddlewareFactory: ImmutableMiddlewareFactory<EndpointState
7071
const { page_index: pageIndex, page_size: pageSize } = uiQueryParams(getState());
7172
let endpointResponse;
7273

73-
// get index pattern and fields for search bar
74-
if (patterns(getState()).length === 0) {
75-
try {
76-
const indexPatterns = await fetchIndexPatterns();
77-
if (indexPatterns !== undefined) {
78-
dispatch({
79-
type: 'serverReturnedMetadataPatterns',
80-
payload: indexPatterns,
81-
});
82-
}
83-
} catch (error) {
84-
dispatch({
85-
type: 'serverFailedToReturnMetadataPatterns',
86-
payload: error,
87-
});
88-
}
89-
}
90-
9174
try {
9275
const decodedQuery: Query = searchBarQuery(getState());
9376

@@ -134,6 +117,24 @@ export const endpointMiddlewareFactory: ImmutableMiddlewareFactory<EndpointState
134117
});
135118
}
136119

120+
// get index pattern and fields for search bar
121+
if (patterns(getState()).length === 0 && isTransformEnabled(getState())) {
122+
try {
123+
const indexPatterns = await fetchIndexPatterns();
124+
if (indexPatterns !== undefined) {
125+
dispatch({
126+
type: 'serverReturnedMetadataPatterns',
127+
payload: indexPatterns,
128+
});
129+
}
130+
} catch (error) {
131+
dispatch({
132+
type: 'serverFailedToReturnMetadataPatterns',
133+
payload: error,
134+
});
135+
}
136+
}
137+
137138
// No endpoints, so we should check to see if there are policies for onboarding
138139
if (endpointResponse && endpointResponse.hosts.length === 0) {
139140
const http = coreStart.http;

x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/store/reducer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const initialEndpointListState: Immutable<EndpointState> = {
3636
patternsError: undefined,
3737
isAutoRefreshEnabled: true,
3838
autoRefreshInterval: DEFAULT_POLL_INTERVAL,
39+
queryStrategyVersion: undefined,
3940
};
4041

4142
/* eslint-disable-next-line complexity */
@@ -49,13 +50,15 @@ export const endpointListReducer: ImmutableReducer<EndpointState, AppAction> = (
4950
total,
5051
request_page_size: pageSize,
5152
request_page_index: pageIndex,
53+
query_strategy_version: queryStrategyVersion,
5254
} = action.payload;
5355
return {
5456
...state,
5557
hosts,
5658
total,
5759
pageSize,
5860
pageIndex,
61+
queryStrategyVersion,
5962
loading: false,
6063
error: undefined,
6164
};

x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/store/selectors.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
HostPolicyResponseAppliedAction,
1515
HostPolicyResponseConfiguration,
1616
HostPolicyResponseActionStatus,
17+
MetadataQueryStrategyVersions,
1718
} from '../../../../../common/endpoint/types';
1819
import { EndpointState, EndpointIndexUIQueryParams } from '../types';
1920
import { extractListPaginationParams } from '../../../common/routing';
@@ -54,11 +55,18 @@ export const isAutoRefreshEnabled = (state: Immutable<EndpointState>) => state.i
5455

5556
export const autoRefreshInterval = (state: Immutable<EndpointState>) => state.autoRefreshInterval;
5657

58+
const queryStrategyVersion = (state: Immutable<EndpointState>) => state.queryStrategyVersion;
59+
5760
export const endpointPackageVersion = createSelector(
5861
endpointPackageInfo,
5962
(info) => info?.version ?? undefined
6063
);
6164

65+
export const isTransformEnabled = createSelector(
66+
queryStrategyVersion,
67+
(version) => version !== MetadataQueryStrategyVersions.VERSION_1
68+
);
69+
6270
/**
6371
* Returns the index patterns for the SearchBar to use for autosuggest
6472
*/

x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
HostPolicyResponse,
1212
AppLocation,
1313
PolicyData,
14+
MetadataQueryStrategyVersions,
1415
} from '../../../../common/endpoint/types';
1516
import { ServerApiError } from '../../../common/types';
1617
import { GetPackagesResponse } from '../../../../../ingest_manager/common';
@@ -65,6 +66,8 @@ export interface EndpointState {
6566
isAutoRefreshEnabled: boolean;
6667
/** The current auto refresh interval for data in ms */
6768
autoRefreshInterval: number;
69+
/** The query strategy version that informs whether the transform for KQL is enabled or not */
70+
queryStrategyVersion: MetadataQueryStrategyVersions;
6871
}
6972

7073
/**

x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export const EndpointList = () => {
135135
autoRefreshInterval,
136136
isAutoRefreshEnabled,
137137
patternsError,
138+
isTransformEnabled,
138139
} = useEndpointSelector(selector);
139140
const { formatUrl, search } = useFormatUrl(SecurityPageName.administration);
140141

@@ -532,8 +533,8 @@ export const EndpointList = () => {
532533
const hasListData = listData && listData.length > 0;
533534

534535
const refreshStyle = useMemo(() => {
535-
return { display: endpointsExist ? 'flex' : 'none', maxWidth: 200 };
536-
}, [endpointsExist]);
536+
return { display: endpointsExist && isTransformEnabled ? 'flex' : 'none', maxWidth: 200 };
537+
}, [endpointsExist, isTransformEnabled]);
537538

538539
const refreshIsPaused = useMemo(() => {
539540
return !endpointsExist ? false : hasSelectedEndpoint ? true : !isAutoRefreshEnabled;
@@ -543,6 +544,10 @@ export const EndpointList = () => {
543544
return !endpointsExist ? DEFAULT_POLL_INTERVAL : autoRefreshInterval;
544545
}, [endpointsExist, autoRefreshInterval]);
545546

547+
const shouldShowKQLBar = useMemo(() => {
548+
return endpointsExist && !patternsError && isTransformEnabled;
549+
}, [endpointsExist, patternsError, isTransformEnabled]);
550+
546551
return (
547552
<AdministrationListPage
548553
data-test-subj="endpointPage"
@@ -563,7 +568,7 @@ export const EndpointList = () => {
563568
{hasSelectedEndpoint && <EndpointDetailsFlyout />}
564569
<>
565570
<EuiFlexGroup>
566-
{endpointsExist && !patternsError && (
571+
{shouldShowKQLBar && (
567572
<EuiFlexItem>
568573
<AdminSearchBar />
569574
</EuiFlexItem>

0 commit comments

Comments
 (0)