Skip to content

Commit

Permalink
Respond to dataView changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry350 committed Oct 20, 2022
1 parent 1007c0b commit 6cdbe6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const unsupportedLanguageError = i18n.translate(
}
);

export const useLogFilterState = ({ indexPattern }: { indexPattern?: DataViewBase }) => {
export const useLogFilterState = ({ dataView }: { dataView?: DataViewBase }) => {
const {
notifications: { toasts },
data: {
Expand Down Expand Up @@ -83,8 +83,10 @@ export const useLogFilterState = ({ indexPattern }: { indexPattern?: DataViewBas
}, [logFilterState.validationError, queryString, toasts]);

const parseQuery = useCallback(
(filterQuery: Query) => buildEsQuery(indexPattern, filterQuery, [], kibanaQuerySettings),
[indexPattern, kibanaQuerySettings]
(filterQuery: Query) => {
return buildEsQuery(dataView, filterQuery, [], kibanaQuerySettings);
},
[dataView, kibanaQuerySettings]
);

const getNewLogFilterState = useCallback(
Expand Down Expand Up @@ -132,6 +134,13 @@ export const useLogFilterState = ({ indexPattern }: { indexPattern?: DataViewBas
}, [getNewLogFilterState, queryString])
);

// NOTE: If the dataView changes the query will need to be reparsed and the filter regenerated.
useEffect(() => {
if (dataView) {
setLogFilterState(getNewLogFilterState(queryString.getQuery()));
}
}, [dataView, getNewLogFilterState, queryString]);

return {
queryStringQuery: logFilterState.queryStringQuery, // NOTE: Query String Manager query.
filterQuery: logFilterState.filterQuery, // NOTE: Valid and syntactically correct query applied to requests etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const LogFilterState: React.FC = ({ children }) => {
const { derivedDataView } = useLogViewContext();

return (
<LogFilterStateProvider indexPattern={derivedDataView}>
<LogFilterStateProvider dataView={derivedDataView}>
<WithLogFilterUrlState />
{children}
</LogFilterStateProvider>
Expand Down

0 comments on commit 6cdbe6b

Please sign in to comment.