Skip to content
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

Merged
merged 7 commits into from
Mar 20, 2024

Conversation

ratheesh-aot
Copy link
Collaborator

@ratheesh-aot ratheesh-aot commented Mar 19, 2024

Issue #: https://apps.itsm.gov.bc.ca/jira/browse/DESENG-513

Description of changes:

  • Added poll results to the results tab.
  • Added poll results API.
  • Added Unit tests.

image

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).

Copy link
Collaborator

@Baelx Baelx left a 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
Copy link
Collaborator

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."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""Assert that a response for a poll widget can be retrived."""
"""Assert that a response for a poll widget can be retrieved."""

Copy link
Collaborator Author

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' }));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
}
} finally {
setItWidgetsLoading(false);
}

You could add this block in to make sure you set this state regardless of whether try or catch runs

Copy link
Collaborator Author

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]);
Copy link
Collaborator

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:

Suggested change
setPollWidget(result[result.length - 1]);
setPollWidget(result.at(-1));

Copy link
Collaborator Author

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 }} />
Copy link
Collaborator

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);
Copy link
Collaborator

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.)

Suggested change
return Promise.reject(err);
return err;

Copy link
Collaborator Author

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));
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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?

@ratheesh-aot ratheesh-aot merged commit 50999d4 into bcgov:main Mar 20, 2024
12 of 13 checks passed
Copy link

Quality Gate Passed Quality Gate passed

Issues
6 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants