Skip to content

Commit 9a7e15d

Browse files
committed
Revert "Move URL state to hook"
This reverts commit c61f5b1.
1 parent 94ae628 commit 9a7e15d

File tree

6 files changed

+53
-67
lines changed

6 files changed

+53
-67
lines changed

x-pack/legacy/plugins/infra/public/containers/logs/log_filter/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
*/
66

77
export * from './log_filter_state';
8-
export * from './use_log_filter_url_state';
8+
export * from './with_log_filter_url_state';

x-pack/legacy/plugins/infra/public/containers/logs/log_filter/use_log_filter_url_state.tsx

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React, { useContext } from 'react';
8+
import { LogFilterState, LogFilterStateParams } from './log_filter_state';
9+
import { replaceStateKeyInQueryString, UrlStateContainer } from '../../../utils/url_state';
10+
11+
type LogFilterUrlState = LogFilterStateParams['filterQueryAsKuery'];
12+
13+
export const WithLogFilterUrlState: React.FC = () => {
14+
const { filterQueryAsKuery, applyLogFilterQuery } = useContext(LogFilterState.Context);
15+
return (
16+
<UrlStateContainer
17+
urlState={filterQueryAsKuery}
18+
urlStateKey="logFilter"
19+
mapToUrlState={mapToFilterQuery}
20+
onChange={urlState => {
21+
if (urlState) {
22+
applyLogFilterQuery(urlState.expression);
23+
}
24+
}}
25+
onInitialize={urlState => {
26+
if (urlState) {
27+
applyLogFilterQuery(urlState.expression);
28+
}
29+
}}
30+
/>
31+
);
32+
};
33+
34+
const mapToFilterQuery = (value: any): LogFilterUrlState | undefined =>
35+
value?.kind === 'kuery' && typeof value.expression === 'string'
36+
? {
37+
kind: value.kind,
38+
expression: value.expression,
39+
}
40+
: undefined;
41+
42+
export const replaceLogFilterInQueryString = (expression: string) =>
43+
replaceStateKeyInQueryString<LogFilterUrlState>('logFilter', {
44+
kind: 'kuery',
45+
expression,
46+
});

x-pack/legacy/plugins/infra/public/pages/logs/stream/page_logs_content.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { PageContent } from '../../../components/page';
1515

1616
import { WithSummary } from '../../../containers/logs/log_summary';
1717
import { LogViewConfiguration } from '../../../containers/logs/log_view_configuration';
18-
import { LogFilterState, useLogFilterUrlState } from '../../../containers/logs/log_filter';
18+
import { LogFilterState } from '../../../containers/logs/log_filter';
1919
import {
2020
LogFlyout as LogFlyoutState,
2121
WithFlyoutOptionsUrlState,
@@ -42,9 +42,6 @@ export const LogsPageLogsContent: React.FunctionComponent = () => {
4242
flyoutItem,
4343
isLoading,
4444
} = useContext(LogFlyoutState.Context);
45-
46-
useLogFilterUrlState();
47-
4845
const { logSummaryHighlights } = useContext(LogHighlightsState.Context);
4946
const { applyLogFilterQuery } = useContext(LogFilterState.Context);
5047
return (

x-pack/legacy/plugins/infra/public/pages/logs/stream/page_providers.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { LogFlyout } from '../../../containers/logs/log_flyout';
1010
import { LogViewConfiguration } from '../../../containers/logs/log_view_configuration';
1111
import { LogHighlightsState } from '../../../containers/logs/log_highlights/log_highlights';
1212
import { LogPositionState } from '../../../containers/logs/log_position';
13-
import { LogFilterState } from '../../../containers/logs/log_filter';
13+
import { LogFilterState, WithLogFilterUrlState } from '../../../containers/logs/log_filter';
1414
import { LogEntriesState } from '../../../containers/logs/log_entries';
1515

1616
import { Source } from '../../../containers/source';
@@ -19,7 +19,10 @@ const LogFilterStateProvider: React.FC = ({ children }) => {
1919
const { createDerivedIndexPattern } = useContext(Source.Context);
2020
const derivedIndexPattern = createDerivedIndexPattern('logs');
2121
return (
22-
<LogFilterState.Provider indexPattern={derivedIndexPattern}>{children}</LogFilterState.Provider>
22+
<LogFilterState.Provider indexPattern={derivedIndexPattern}>
23+
<WithLogFilterUrlState />
24+
{children}
25+
</LogFilterState.Provider>
2326
);
2427
};
2528

x-pack/legacy/plugins/infra/public/utils/validate_url_rt.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)