Skip to content

Commit

Permalink
fix(dashboard): passing filters to api route
Browse files Browse the repository at this point in the history
- passing filters to api route that handles history charts data

Part of #264
  • Loading branch information
Francisco2002 committed Oct 25, 2024
1 parent 217ea20 commit ca3e989
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
36 changes: 29 additions & 7 deletions dashboard/src/api/TreeDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const fetchTreeDetailData = async (
return res.data;
};

/** @deprecated */
const mapFiltersToUrlSearchParams = (
filter: TTreeDetailsFilter | Record<string, never>,
): URLSearchParams => {
Expand Down Expand Up @@ -256,15 +257,19 @@ const fetchTreeCommitHistory = async (
origin: string,
gitUrl: string,
gitBranch: string,
filters: TTreeDetailsFilter,
): Promise<TTreeCommitHistoryResponse> => {
// TODO: remove deprecated function
const searchParam = mapFiltersToUrlSearchParams(filters);

searchParam.append('origin', origin);
searchParam.append('git_url', gitUrl);
searchParam.append('git_branch', gitBranch);

const res = await http.get<TTreeCommitHistoryResponse>(
`/api/tree/${commitHash}/commits`,
{
params: {
origin,
git_url: gitUrl,
git_branch: gitBranch,
},
params: searchParam,
},
);
return res.data;
Expand All @@ -276,19 +281,36 @@ export const useTreeCommitHistory = (
origin,
gitUrl,
gitBranch,
filter,
}: {
commitHash: string;
origin: string;
gitUrl: string;
gitBranch: string;
filter: TTreeDetailsFilter;
},
{ enabled = true },
): UseQueryResult<TTreeCommitHistoryResponse> => {
const testFilter = getTargetFilter(filter, 'test');
const treeDetailsFilter = getTargetFilter(filter, 'treeDetails');

const filters = {
...treeDetailsFilter,
...testFilter,
};

return useQuery({
queryKey: ['treeCommitHistory', commitHash, origin, gitUrl, gitBranch],
queryKey: [
'treeCommitHistory',
commitHash,
origin,
gitUrl,
gitBranch,
filters,
],
enabled,
queryFn: () =>
fetchTreeCommitHistory(commitHash, origin, gitUrl, gitBranch),
fetchTreeCommitHistory(commitHash, origin, gitUrl, gitBranch, filters),
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { TLineChartProps } from '@/components/LineChart/LineChart';
import QuerySwitcher from '@/components/QuerySwitcher/QuerySwitcher';
import { MessagesKey } from '@/locales/messages';
import { formatDate } from '@/utils/utils';
import { mapFilterToReq } from '@/pages/TreeDetails/TreeDetailsFilter';

const graphDisplaySize = 7;

Expand All @@ -22,6 +23,7 @@ const CommitNavigationGraph = (): JSX.Element => {
const {
origin,
currentTreeDetailsTab,
diffFilter,
treeInfo: { gitUrl, gitBranch, headCommitHash },
} = useSearch({ from: '/tree/$treeId/' });

Expand All @@ -33,12 +35,15 @@ const CommitNavigationGraph = (): JSX.Element => {
from: '/tree/$treeId',
});

const reqFilter = mapFilterToReq(diffFilter);

const { data, status } = useTreeCommitHistory(
{
gitBranch: gitBranch ?? '',
gitUrl: gitUrl ?? '',
commitHash: headCommitHash ?? '',
origin: origin,
filter: reqFilter,
},
{
enabled: !!gitBranch && !!gitUrl,
Expand Down

0 comments on commit ca3e989

Please sign in to comment.