Skip to content

Commit

Permalink
Revert "Move URL state to hook"
Browse files Browse the repository at this point in the history
This reverts commit c61f5b1.
  • Loading branch information
Zacqary committed Dec 23, 2019
1 parent 94ae628 commit 9a7e15d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
*/

export * from './log_filter_state';
export * from './use_log_filter_url_state';
export * from './with_log_filter_url_state';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useContext } from 'react';
import { LogFilterState, LogFilterStateParams } from './log_filter_state';
import { replaceStateKeyInQueryString, UrlStateContainer } from '../../../utils/url_state';

type LogFilterUrlState = LogFilterStateParams['filterQueryAsKuery'];

export const WithLogFilterUrlState: React.FC = () => {
const { filterQueryAsKuery, applyLogFilterQuery } = useContext(LogFilterState.Context);
return (
<UrlStateContainer
urlState={filterQueryAsKuery}
urlStateKey="logFilter"
mapToUrlState={mapToFilterQuery}
onChange={urlState => {
if (urlState) {
applyLogFilterQuery(urlState.expression);
}
}}
onInitialize={urlState => {
if (urlState) {
applyLogFilterQuery(urlState.expression);
}
}}
/>
);
};

const mapToFilterQuery = (value: any): LogFilterUrlState | undefined =>
value?.kind === 'kuery' && typeof value.expression === 'string'
? {
kind: value.kind,
expression: value.expression,
}
: undefined;

export const replaceLogFilterInQueryString = (expression: string) =>
replaceStateKeyInQueryString<LogFilterUrlState>('logFilter', {
kind: 'kuery',
expression,
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { PageContent } from '../../../components/page';

import { WithSummary } from '../../../containers/logs/log_summary';
import { LogViewConfiguration } from '../../../containers/logs/log_view_configuration';
import { LogFilterState, useLogFilterUrlState } from '../../../containers/logs/log_filter';
import { LogFilterState } from '../../../containers/logs/log_filter';
import {
LogFlyout as LogFlyoutState,
WithFlyoutOptionsUrlState,
Expand All @@ -42,9 +42,6 @@ export const LogsPageLogsContent: React.FunctionComponent = () => {
flyoutItem,
isLoading,
} = useContext(LogFlyoutState.Context);

useLogFilterUrlState();

const { logSummaryHighlights } = useContext(LogHighlightsState.Context);
const { applyLogFilterQuery } = useContext(LogFilterState.Context);
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LogFlyout } from '../../../containers/logs/log_flyout';
import { LogViewConfiguration } from '../../../containers/logs/log_view_configuration';
import { LogHighlightsState } from '../../../containers/logs/log_highlights/log_highlights';
import { LogPositionState } from '../../../containers/logs/log_position';
import { LogFilterState } from '../../../containers/logs/log_filter';
import { LogFilterState, WithLogFilterUrlState } from '../../../containers/logs/log_filter';
import { LogEntriesState } from '../../../containers/logs/log_entries';

import { Source } from '../../../containers/source';
Expand All @@ -19,7 +19,10 @@ const LogFilterStateProvider: React.FC = ({ children }) => {
const { createDerivedIndexPattern } = useContext(Source.Context);
const derivedIndexPattern = createDerivedIndexPattern('logs');
return (
<LogFilterState.Provider indexPattern={derivedIndexPattern}>{children}</LogFilterState.Provider>
<LogFilterState.Provider indexPattern={derivedIndexPattern}>
<WithLogFilterUrlState />
{children}
</LogFilterState.Provider>
);
};

Expand Down
16 changes: 0 additions & 16 deletions x-pack/legacy/plugins/infra/public/utils/validate_url_rt.ts

This file was deleted.

0 comments on commit 9a7e15d

Please sign in to comment.