-
Notifications
You must be signed in to change notification settings - Fork 196
Fix DQT filter counts when no fields selected #10229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
|
||
| } | ||
|
|
||
| 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 = { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is added to the payload but isn't expected by the back-end