Skip to content

Commit

Permalink
Filter deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Koustavd18 committed Dec 18, 2024
1 parent 53352ce commit 3177eba
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/pages/Stream/Views/Explore/LogsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Stream/components/Querier/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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 {
Expand Down
29 changes: 15 additions & 14 deletions src/pages/Stream/hooks/useParamsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -117,27 +118,27 @@ 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'));
}
if (storeAsParams.rows !== presentParams.rows && LOG_QUERY_LIMITS.includes(_.toNumber(presentParams.rows))) {
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[]));
}
Expand Down
9 changes: 9 additions & 0 deletions src/pages/Stream/providers/FilterProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -378,6 +386,7 @@ const filterStoreReducers: FilterStoreReducers = {
updateParentCombinator,
updateAppliedQuery,
updateRule,
updateQuery,
parseQuery,
toggleSubmitBtn,
toggleSaveFiltersModal,
Expand Down

0 comments on commit 3177eba

Please sign in to comment.