-
Notifications
You must be signed in to change notification settings - Fork 19
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
[TO MAIN] DESENG-513 - Add poll results to results tab #2422
Conversation
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.
LGTM!
You're welcome to merge but perhaps consider some of the places where we could save a few lines of code - like with the finally
block, removing unneeded Promise.reject()
calls.
CHANGELOG.MD
Outdated
@@ -1,4 +1,10 @@ | |||
<<<<<<< HEAD |
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.
Thanks for fixing this 😅
|
||
|
||
def test_get_poll_response(client, jwt, session, setup_admin_user_and_claims): | ||
"""Assert that a response for a poll widget can be retrived.""" |
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.
"""Assert that a response for a poll widget can be retrived.""" | |
"""Assert that a response for a poll widget can be retrieved.""" |
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.
Thanks :)
} catch (err) { | ||
setIsWidgetsLoading(false); | ||
dispatch(openNotification({ severity: 'error', text: 'Error fetching engagement widgets' })); | ||
} |
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.
} | |
} finally { | |
setItWidgetsLoading(false); | |
} |
You could add this block in to make sure you set this state regardless of whether try
or catch
runs
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.
Doable. Will update other useEffect functions too.
} | ||
try { | ||
const result = await fetchPollWidgets(widget.id); | ||
setPollWidget(result[result.length - 1]); |
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.
Another way to get the last item in an array which is a bit more pythonic:
setPollWidget(result[result.length - 1]); | |
setPollWidget(result.at(-1)); |
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.
Doable, i need to update the interface type also to accept undefined
<Box sx={{ mb: 2 }}> | ||
<Typography variant="subtitle1">{label}</Typography> | ||
<Box sx={{ display: 'flex', alignItems: 'center' }}> | ||
<LinearProgress variant="determinate" value={percentage} sx={{ flexGrow: 1, mr: 1 }} /> |
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.
I'd be curious what a screenreader would say if you were to navigate over this component with a keyboard
const response = await http.GetRequest<PollResultResponse>(url); | ||
return response.data || Promise.reject('Failed to fetch Poll Results'); | ||
} catch (err) { | ||
return Promise.reject(err); |
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.
You shouldn't need to call Promise.reject()
within an async
prefixed function as this happens automatically. To reject the promise, you can just return the result of the catch block (or throw
it if there's other code you want to execute within the catch block.)
return Promise.reject(err); | |
return err; |
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.
Agree. I followed the convention used in other service files.
export const fetchPollResults = async (widget_id: number, poll_id: number): Promise<PollResultResponse> => { | ||
try { | ||
let url = replaceUrl(Endpoints.PollWidgets.RECORD_RESPONSE, 'widget_id', String(widget_id)); | ||
url = replaceUrl(url, 'poll_id', String(poll_id)); |
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.
Why does url
get immediately reassigned?
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.
As replaceUrl only replaces one string at a time and here we need to replace both widget_id and poll_id, we need to call it twice.
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.
Oh okay got it. Could replaceAllInURL
be used to make it just one function call?
Quality Gate passedIssues Measures |
Issue #: https://apps.itsm.gov.bc.ca/jira/browse/DESENG-513
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the met-public license (Apache 2.0).