Skip to content

Commit

Permalink
refactor(history): update search parameters
Browse files Browse the repository at this point in the history
Backend renamed search parameters for some fields.
This will adjust frontend code to convert search params to
 backend search params for compatibility since we want to
 preserve old links working

Signed-off-by: Danil Kostromin <[email protected]>
  • Loading branch information
Danil Kostromin committed Mar 27, 2024
1 parent 738c23d commit f6bf92f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 12 deletions.
14 changes: 6 additions & 8 deletions libs/bublik/features/history/src/lib/hooks/use-history-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
/* SPDX-FileCopyrightText: 2021-2023 OKTET Labs Ltd. */
import { useMemo } from 'react';
import { useSearchParams } from 'react-router-dom';
import { camelizeKeys } from 'humps';

import { HistoryAPIQuery } from '@/shared/types';
import { HistoryAPIBackendQuery, HistoryAPIQuery } from '@/shared/types';
import { searchQueryToBackendQuery } from '../slice/history-slice.utils';

export const useHistoryQuery = () => {
const [searchParams] = useSearchParams();

const query = useMemo(() => {
const rawQuery = camelizeKeys(
Object.fromEntries(searchParams.entries())
const query = useMemo<HistoryAPIBackendQuery>(() => {
const rawQuery = Object.fromEntries(
searchParams.entries()
) as HistoryAPIQuery;

rawQuery.verdict = decodeURIComponent(rawQuery.verdict || '');

return rawQuery;
return searchQueryToBackendQuery(rawQuery);
}, [searchParams]);

return { query };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {
DEFAULT_HISTORY_END_DATE,
DEFAULT_HISTORY_START_DATE
} from '@/bublik/config';
import { HistoryAPIQuery, VERDICT_TYPE } from '@/shared/types';
import {
HistoryAPIBackendQuery,
HistoryAPIQuery,
VERDICT_TYPE
} from '@/shared/types';
import { BadgeItem } from '@/shared/tailwind-ui';
import { formatTimeToAPI } from '@/shared/utils';

Expand Down Expand Up @@ -110,6 +114,37 @@ export const historySearchStateToForm = (
};
};

export function searchQueryToBackendQuery(
query: HistoryAPIQuery
): HistoryAPIBackendQuery {
return {
testName: query.testName,
hash: query.hash,
testArgs: query.parameters,
revisions: query.revisions,
branches: query.branches,
/* Run section */
tags: query.runData,
tagExpr: query.tagExpr,
branchExpr: query.branchExpr,
labelExpr: query.labelExpr,
testArgExpr: query.testArgExpr,
revExpr: query.revisionExpr,
verdictExpr: query.verdictExpr,
fromDate: query.startDate,
toDate: query.finishDate,
/* Result section */
resultTypes: query.resultProperties,
runProperties: query.runProperties,
resultStatuses: query.results,
/* Verdict section */
verdictLookup: query.verdictLookup,
verdict: query.verdict,
page: query.page,
pageSize: query.pageSize
};
}

export const historySearchStateToQuery = (
state: HistorySearchFormState
): HistoryAPIQuery => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { EndpointBuilder } from '@reduxjs/toolkit/dist/query/endpointDefinitions';

import {
HistoryAPIQuery,
HistoryAPIBackendQuery,
HistoryDataAggregationAPIResponse,
HistoryLinearAPIResponse
} from '@/shared/types';
Expand All @@ -17,15 +17,18 @@ export const historyEndpoints = {
endpoints: (
build: EndpointBuilder<BublikBaseQueryFn, BUBLIK_TAG, API_REDUCER_PATH>
) => ({
getHistoryLinear: build.query<HistoryLinearAPIResponse, HistoryAPIQuery>({
getHistoryLinear: build.query<
HistoryLinearAPIResponse,
HistoryAPIBackendQuery
>({
query: (query) => {
return { url: withApiV2('/history'), params: prepareForSend(query) };
},
providesTags: () => [{ type: BUBLIK_TAG.HistoryData }]
}),
getHistoryAggregation: build.query<
HistoryDataAggregationAPIResponse,
HistoryAPIQuery
HistoryAPIBackendQuery
>({
query: (query) => {
return {
Expand Down
29 changes: 29 additions & 0 deletions libs/shared/types/src/lib/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,35 @@ import { Pagination } from './utils';
/** History page mode */
export type HistoryMode = 'linear' | 'aggregation' | 'measurements';

export type HistoryAPIBackendQuery = {
testName?: string;
hash?: string;
testArgs?: string;
revisions?: string;
branches?: string;

fromDate?: string;
toDate?: string;
tags?: string;
tagExpr?: string;

labelExpr?: string;
revExpr?: string;
branchExpr?: string;
verdictExpr?: string;
testArgExpr?: string;

runProperties?: string;
resultTypes?: string;
resultStatuses?: string;

verdictLookup?: VERDICT_TYPE;
verdict?: string;

page?: string;
pageSize?: string;
};

export type HistoryAPIQuery = {
page?: string;
pageSize?: string;
Expand Down

0 comments on commit f6bf92f

Please sign in to comment.