Skip to content

Commit

Permalink
Add query filters to url
Browse files Browse the repository at this point in the history
  • Loading branch information
jennypavlova committed Oct 20, 2022
1 parent b88984f commit 0ed7b5a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions x-pack/plugins/infra/public/pages/metrics/hosts/hosts_content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { HostsTable } from './components/hosts_table';
import { InfraClientStartDeps } from '../../../types';
import { useSourceContext } from '../../../containers/metrics_source';
import { useTimeRangeUrlState } from './hooks/use_time_range_url_state';
import { useWaffleFiltersContext } from '../inventory_view/hooks/use_waffle_filters';

export const HostsContent: React.FunctionComponent = () => {
const {
Expand All @@ -24,12 +25,13 @@ export const HostsContent: React.FunctionComponent = () => {
const { source } = useSourceContext();
const { timeRange: selectedTimeRange, setTimeRange: setSelectedTimeRange } =
useTimeRangeUrlState();
const { filterQuery, setWaffleFiltersState } = useWaffleFiltersContext();

const [dateRange, setDateRange] = useState<TimeRange>({
from: selectedTimeRange.startTime,
to: selectedTimeRange.endTime,
});
const [query, setQuery] = useState<Query>({ query: '', language: 'kuery' });
const [query, setQuery] = useState<Query>({ query: filterQuery.expression, language: 'kuery' });
const { metricsDataView, hasFailedCreatingDataView, hasFailedFetchingDataView } =
useMetricsDataViewContext();
// needed to refresh the lens table when filters havent changed
Expand All @@ -50,6 +52,9 @@ export const HostsContent: React.FunctionComponent = () => {
(payload: { dateRange: TimeRange; query?: Query }) => {
setDateRange(payload.dateRange);
if (payload.query) {
if (payload.query.language === 'kuery' && typeof payload.query.query === 'string') {
setWaffleFiltersState({ kind: payload.query.language, expression: payload.query.query });
}
setQuery(payload.query);
}
setIsLensLoading(true);
Expand All @@ -60,7 +65,13 @@ export const HostsContent: React.FunctionComponent = () => {
isInvalid: false,
});
},
[setDateRange, setQuery, data.search.session, handleSelectedTimeRangeChange]
[
setDateRange,
setQuery,
data.search.session,
handleSelectedTimeRangeChange,
setWaffleFiltersState,
]
);

const onLoading = useCallback(
Expand Down

0 comments on commit 0ed7b5a

Please sign in to comment.