Skip to content

Commit

Permalink
fix(history): fixed filters incorrect reset when global filter has no…
Browse files Browse the repository at this point in the history
… values

We should default to using present filter in such case
  • Loading branch information
Danil Kostromin committed Oct 31, 2024
1 parent c7797bd commit d330224
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions libs/bublik/features/history/src/lib/hooks/use-history-refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,56 @@ const globalFilterToQueryAdapter = (
globalFilter;

const getResultProperties = (): RESULT_PROPERTIES[] => {
const resultProperties: RESULT_PROPERTIES[] = [];

if (resultType == null && isNotExpected == null) {
return DEFAULT_RESULT_PROPERTIES;
if (resultType != null || isNotExpected != null) {
const resultProperties: RESULT_PROPERTIES[] = [];
const isNotRun =
resultType === RESULT_TYPE.Skipped ||
resultType === RESULT_TYPE.Killed ||
resultType === RESULT_TYPE.Incomplete;

if (isNotExpected) resultProperties.push(RESULT_PROPERTIES.Unexpected);
if (!isNotExpected) resultProperties.push(RESULT_PROPERTIES.Expected);
if (isNotRun) resultProperties.push(RESULT_PROPERTIES.NotRun);

return resultProperties;
}

const isNotRun =
resultType === RESULT_TYPE.Skipped ||
resultType === RESULT_TYPE.Killed ||
resultType === RESULT_TYPE.Incomplete;

if (isNotExpected) {
resultProperties.push(RESULT_PROPERTIES.Unexpected);
if (query.resultProperties?.length) {
return query.resultProperties.split(';') as RESULT_PROPERTIES[];
}

if (!isNotExpected) {
resultProperties.push(RESULT_PROPERTIES.Expected);
}

if (isNotRun) resultProperties.push(RESULT_PROPERTIES.NotRun);

return resultProperties;
return DEFAULT_RESULT_PROPERTIES;
};

const getResultType = (): RESULT_TYPE[] => {
if (!resultType) return DEFAULT_RESULT_TYPES;
if (resultType) return [resultType];
if (query.results?.length) return query.results.split(';') as RESULT_TYPE[];

return [resultType];
return DEFAULT_RESULT_TYPES;
};

const mergeWithPriority = (
globalFilterValue: string[],
queryValue: string | undefined
) => {
if (globalFilterValue.length) return globalFilterValue.join(';');
if (queryValue?.length) return queryValue;
return '';
};

console.log('PARAMS', parameters, query.parameters);
console.log('FINAL', mergeWithPriority(parameters, query.parameters));

return {
...query,
results: getResultType().join(';'),
resultProperties: getResultProperties().join(';'),
runData: tags.join(';'),
parameters: parameters.join(';'),
verdict: encodeURIComponent(verdicts.join(';')),
runData: mergeWithPriority(tags, query.runData),
parameters: mergeWithPriority(parameters, query.parameters),
verdict: mergeWithPriority(verdicts, query.verdict),
page: '1'
};
};

export const useHistoryRefresh = () => {
const { state } = useHistoryFormSearchState();
const [searchParams, setSearchParams] = useSearchParams();
Expand All @@ -82,7 +91,7 @@ export const useHistoryRefresh = () => {
params.set('mode', mode);
params.set('page', String(1));
params.set('pageSize', String(pageSize));
setSearchParams(params);
setSearchParams(params, { replace: true });
},
[mode, pageSize, setSearchParams, state]
);
Expand Down

0 comments on commit d330224

Please sign in to comment.