Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 55 additions & 27 deletions modules/dataquery/jsx/definefilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,40 +75,68 @@ function DefineFilters(props: {
const [queryMatches, setQueryMatches] = useState(null);
useEffect(() => {
setQueryMatches(null);
const payload = calcPayload(props.fields, props.query);
fetch(
'/dataquery/queries',
{
method: 'POST',
credentials: 'same-origin',
body: JSON.stringify(payload),
},
).then(
(resp) => {
if (!resp.ok) {
if (!props.fields || props.fields.length === 0) {
return;
}

let cancelled = false;
const controller = new AbortController();

/**
* Fetches the current candidate count preview for the
* provided field/filter selection.
*/
const updateQueryCount = async () => {
try {
const payload = calcPayload(props.fields, props.query);
const createResp = await fetch(
'/dataquery/queries',
{
method: 'POST',
credentials: 'same-origin',
body: JSON.stringify(payload),
signal: controller.signal,
},
);

if (!createResp.ok) {
throw new Error('Error creating query.');
}
return resp.json();
}
).then(
(data) => {
fetch(
'/dataquery/queries/'
+ data.QueryID + '/count',

const data = await createResp.json();
const countResp = await fetch(
`/dataquery/queries/${data.QueryID}/count`,
{
method: 'GET',
credentials: 'same-origin',
}
).then((resp) => {
if (!resp.ok) {
throw new Error('Could not get count.');
}
return resp.json();
}).then((result) => {
signal: controller.signal,
},
);

if (!countResp.ok) {
throw new Error('Could not get count.');
Comment on lines 103 to +117
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error messages "Error creating query." and "Could not get count." are generic and don't provide helpful context for debugging. Consider including the HTTP status code or response details to help identify the root cause when these errors occur. For example: throw new Error(\Error creating query: ${createResp.status} ${createResp.statusText}`);`

Copilot uses AI. Check for mistakes.
}

const result = await countResp.json();
if (!cancelled) {
setQueryMatches(result.count);
});
}
} catch (error) {
if (!controller.signal.aborted) {
console.error(error);
if (!cancelled) {
setQueryMatches(null);
}
}
}
);
};

updateQueryCount();

return () => {
cancelled = true;
controller.abort();
};
}, [props.fields, props.query]);

const bGroupStyle = {
Expand Down