Skip to content

Commit d22ec0d

Browse files
committed
Handle filter timeout separately
when the filter value population based on option selection times out, don't error out the whole table
1 parent 21ae911 commit d22ec0d

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

frontend/src/components/filtering/result-filter.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ const ResultFilter = ({ hideFilters, runs, maxHeight = '600px' }) => {
8282
// Dynamic metadata values
8383
const [valueOptions, setValueOptions] = useState([]);
8484
const [isValueOpen, setIsValueOpen] = useState(false);
85+
const [loadError, setLoadError] = useState(null);
8586

8687
useEffect(() => {
8788
if (fieldSelection && fieldSelection.startsWith('metadata.')) {
89+
setLoadError(null);
8890
// Filter out project_id since we pass it as 'project' parameter
8991
const filtersWithoutProject = activeFilters.filter(
9092
(f) => f.field !== 'project_id',
@@ -96,16 +98,14 @@ const ResultFilter = ({ hideFilters, runs, maxHeight = '600px' }) => {
9698
const params = {
9799
group_field: fieldSelection,
98100
project: projectId,
101+
days: 90,
99102
};
100103

101104
// Only add additional_filters if there are filters to add
102105
if (apiFilter) {
103106
params.additional_filters = apiFilter;
104107
}
105108

106-
// Note: We don't include 'days' parameter to get all historical data
107-
// If we want to limit to recent results, we could add: days: 30
108-
109109
HttpClient.get(
110110
[Settings.serverUrl, 'widget', 'result-aggregator'],
111111
params,
@@ -117,9 +117,11 @@ const ResultFilter = ({ hideFilters, runs, maxHeight = '600px' }) => {
117117
.catch((error) => {
118118
console.error('Error fetching dynamic values:', error);
119119
setValueOptions([]);
120+
setLoadError('Error loading values');
120121
});
121122
} else {
122123
setValueOptions([]);
124+
setLoadError(null);
123125
}
124126
}, [fieldSelection, activeFilters, primaryObject]);
125127

@@ -606,6 +608,17 @@ const ResultFilter = ({ hideFilters, runs, maxHeight = '600px' }) => {
606608
</SelectList>
607609
</Select>
608610
)}
611+
{loadError && (
612+
<div
613+
style={{
614+
color: 'var(--pf-v6-global--danger-color--100)',
615+
fontSize: 'var(--pf-v6-global--FontSize--sm)',
616+
marginTop: '0.25rem',
617+
}}
618+
>
619+
{loadError}
620+
</div>
621+
)}
609622
</FlexItem>
610623
</Flex>
611624
<FlexItem>

frontend/src/components/filtering/result-filter.test.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
/* eslint-env jest */
2-
import { render, screen, fireEvent } from '@testing-library/react';
2+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
33
import { MemoryRouter } from 'react-router-dom';
44
import ResultFilter from './result-filter';
55
import { FilterContext } from '../contexts/filter-context';
6+
import { HttpClient } from '../../utilities/http';
7+
8+
jest.mock('../../utilities/http');
69

710
describe('ResultFilter', () => {
811
const mockUpdateFilters = jest.fn();
@@ -831,4 +834,44 @@ describe('ResultFilter', () => {
831834
// Values should be trimmed
832835
});
833836
});
837+
838+
describe('Dynamic Metadata Values Error Handling', () => {
839+
it('should display error message when dynamic values fetch fails', async () => {
840+
HttpClient.get.mockReturnValue(Promise.reject(new Error('Fetch failed')));
841+
842+
renderComponent(
843+
{},
844+
{
845+
fieldSelection: 'metadata.browser',
846+
filterMode: 'text',
847+
operationMode: 'single',
848+
}
849+
);
850+
851+
await waitFor(() => {
852+
expect(screen.getByText('Error loading values')).toBeInTheDocument();
853+
});
854+
});
855+
856+
it('should fetch with days=90 parameter', async () => {
857+
HttpClient.get.mockReturnValue(Promise.resolve({ ok: true, json: () => [] }));
858+
HttpClient.handleResponse.mockReturnValue([]);
859+
860+
renderComponent(
861+
{},
862+
{
863+
fieldSelection: 'metadata.browser',
864+
filterMode: 'text',
865+
operationMode: 'single',
866+
}
867+
);
868+
869+
await waitFor(() => {
870+
expect(HttpClient.get).toHaveBeenCalledWith(
871+
expect.anything(),
872+
expect.objectContaining({ days: 90 })
873+
);
874+
});
875+
});
876+
});
834877
});

0 commit comments

Comments
 (0)