diff --git a/src/pages/Stream/Views/Explore/LogsView.tsx b/src/pages/Stream/Views/Explore/LogsView.tsx index 951f83f4..92601a78 100644 --- a/src/pages/Stream/Views/Explore/LogsView.tsx +++ b/src/pages/Stream/Views/Explore/LogsView.tsx @@ -4,13 +4,16 @@ import JsonView from './JSONView'; import LogTable from './StaticLogTable'; import useLogsFetcher from './useLogsFetcher'; import LogsViewConfig from './LogsViewConfig'; +import { useFilterStore, filterStoreReducers } from '../../providers/FilterProvider'; import { useEffect } from 'react'; import _ from 'lodash'; const { setPageAndPageData, setTargetPage, setTargetColumns, setDisabledColumns } = logsStoreReducers; +const { toogleQueryParamsFlag } = filterStoreReducers; const LogsView = (props: { schemaLoading: boolean; infoLoading: boolean }) => { + const [, setFilterStore] = useFilterStore((store) => store); const { schemaLoading, infoLoading } = props; const { errorMessage, hasNoData, showTable, isFetchingCount, logsLoading } = useLogsFetcher({ schemaLoading, @@ -36,6 +39,7 @@ const LogsView = (props: { schemaLoading: boolean; infoLoading: boolean }) => { setLogsStore((store) => setTargetPage(store, undefined)); } } + if (showTable) setFilterStore((store) => toogleQueryParamsFlag(store, false)); }, [showTable, currentPage]); useEffect(() => { diff --git a/src/pages/Stream/components/Querier/index.tsx b/src/pages/Stream/components/Querier/index.tsx index 4ca6dbb8..8559f13d 100644 --- a/src/pages/Stream/components/Querier/index.tsx +++ b/src/pages/Stream/components/Querier/index.tsx @@ -133,7 +133,7 @@ const Querier = () => { }, []); const [schema] = useStreamStore((store) => store.schema); const [streamInfo] = useStreamStore((store) => store.info); - const [{ query, isSumbitDisabled }, setFilterStore] = useFilterStore((store) => store); + const [{ query, isSumbitDisabled, isQueryFromParams }, setFilterStore] = useFilterStore((store) => store); const timePartitionColumn = _.get(streamInfo, 'time_partition', 'p_timestamp'); useEffect(() => { @@ -202,7 +202,7 @@ const Querier = () => { // trigger query fetch if the rules were updated by the remove btn on pills // ----------------------------------- - if (!showQueryBuilder && (activeMode === 'filters' || savedFilterId)) { + if (!showQueryBuilder && (activeMode === 'filters' || savedFilterId) && !isQueryFromParams) { if (!shouldSumbitDisabled) { onFiltersApply({ isUncontrolled: true }); } else { diff --git a/src/pages/Stream/hooks/useParamsController.ts b/src/pages/Stream/hooks/useParamsController.ts index 50792273..ca4526d9 100644 --- a/src/pages/Stream/hooks/useParamsController.ts +++ b/src/pages/Stream/hooks/useParamsController.ts @@ -16,7 +16,8 @@ const { getRelativeStartAndEndDate, formatDateWithTimezone, getLocalTimezone } = const { setTimeRange, syncTimeRange } = appStoreReducers; const { onToggleView, setPerPage, setCustQuerySearchState, setTargetPage, setCurrentOffset, setTargetColumns } = logsStoreReducers; -const { toogleQueryParamsFlag, setAppliedFilterQuery, applySavedFilters, updateAppliedQuery } = filterStoreReducers; +const { toogleQueryParamsFlag, setAppliedFilterQuery, applySavedFilters, updateQuery, updateAppliedQuery } = + filterStoreReducers; const timeRangeFormat = 'DD-MMM-YYYY_HH-mmz'; const keys = ['view', 'rows', 'page', 'interval', 'from', 'to', 'query', 'filterType', 'fields']; @@ -117,7 +118,20 @@ const useParamsController = () => { fields: `${joinOrSplit(!_.isEmpty(targetColumns) ? targetColumns : activeHeaders)}`, }); const presentParams = paramsStringToParamsObj(searchParams); + if (storeAsParams.query !== presentParams.query) { + if (presentParams.filterType === 'filters') { + setFilterStore((store) => updateQuery(store, generateQueryBuilderASTFromSQL(presentParams.query) as QueryType)); + setFilterStore((store) => updateAppliedQuery(store, store.query)); + + setFilterStore((store) => setAppliedFilterQuery(store, presentParams.query)); + setFilterStore((store) => toogleQueryParamsFlag(store, true)); + } + setAppStore((store) => syncTimeRange(store)); + setLogsStore((store) => setCustQuerySearchState(store, presentParams.query, presentParams.filterType)); + } + syncTimeRangeToStore(storeAsParams, presentParams); + if (['table', 'json'].includes(presentParams.view) && presentParams.view !== storeAsParams.view) { setLogsStore((store) => onToggleView(store, presentParams.view as 'table' | 'json')); } @@ -125,19 +139,6 @@ const useParamsController = () => { setLogsStore((store) => setPerPage(store, _.toNumber(presentParams.rows))); } - if (storeAsParams.query !== presentParams.query) { - setAppStore((store) => syncTimeRange(store)); - setLogsStore((store) => setCustQuerySearchState(store, presentParams.query, presentParams.filterType)); - - if (presentParams.filterType === 'filters') { - setFilterStore((store) => - updateAppliedQuery(store, generateQueryBuilderASTFromSQL(presentParams.query) as QueryType), - ); - setFilterStore((store) => setAppliedFilterQuery(store, presentParams.query)); - setFilterStore((store) => toogleQueryParamsFlag(store, true)); - } - } - if (storeAsParams.fields !== presentParams.fields) { setLogsStore((store) => setTargetColumns(store, joinOrSplit(presentParams.fields) as string[])); } diff --git a/src/pages/Stream/providers/FilterProvider.tsx b/src/pages/Stream/providers/FilterProvider.tsx index 805efe6c..c0b6a173 100644 --- a/src/pages/Stream/providers/FilterProvider.tsx +++ b/src/pages/Stream/providers/FilterProvider.tsx @@ -134,6 +134,7 @@ type FilterStoreReducers = { updateParentCombinator: (store: FilterStore, combinator: Combinator) => ReducerOutput; updateAppliedQuery: (store: FilterStore, appliedQuery: QueryType) => ReducerOutput; updateRule: (store: FilterStore, groupId: string, ruleId: string, updateOpts: RuleUpdateOpts) => ReducerOutput; + updateQuery: (store: FilterStore, query: QueryType) => ReducerOutput; parseQuery: ( queryEngine: 'Parseable' | 'Trino' | undefined, query: QueryType, @@ -358,6 +359,13 @@ const updateAppliedQuery = (store: FilterStore, appliedQuery: QueryType) => { }; }; +const updateQuery = (store: FilterStore, query: QueryType) => { + return { + ...store, + query, + }; +}; + const applySavedFilters = (store: FilterStore, query: QueryType) => { return { ...store, @@ -378,6 +386,7 @@ const filterStoreReducers: FilterStoreReducers = { updateParentCombinator, updateAppliedQuery, updateRule, + updateQuery, parseQuery, toggleSubmitBtn, toggleSaveFiltersModal,