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

receivable types: fetch beyond page limit #534

Merged
merged 7 commits into from
Oct 21, 2024

Conversation

NC-jsAhonen
Copy link
Contributor

The default limit for receivable_type/ request is 30, but there are more receivable types for AKV than 30. This change makes the request in the mvj-ui to make several requests in order to get all the available receivable types for the given service unit.

@NC-jsAhonen NC-jsAhonen marked this pull request as draft October 11, 2024 14:21
@NC-jsAhonen
Copy link
Contributor Author

Sorting the receivable types by name in the saga does not work. I think the solution is to sort the choices in the select component.

@juho-kettunen-nc
Copy link
Contributor

Should this PR be reviewed yet because it is in the draft phase, or after the sorting is added?

@NC-jsAhonen NC-jsAhonen marked this pull request as ready for review October 16, 2024 07:10
@juho-kettunen-nc
Copy link
Contributor

Great. In my opinion this should be merged in addition to #749 in the API repo, to fix the issue now, and be future-proof if more than 50 are added.

@juho-kettunen-nc
Copy link
Contributor

@henrinie-nc what do you think?

},
bodyAsJson
} = yield call(fetchReceivableTypes);
while (typeof nextUrl === 'string') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this enough of a check to see whether to continue? Maybe something else could be checked to ensure it doesn't end up in infinite loop

Copy link
Contributor

Choose a reason for hiding this comment

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

If there are more pages, bodyAsJson.next will be a string that contains the URL. If there are no pages left, bodyAsJson.next will be null.

In all cases of the switch case below, the nextUrl will be either a string (should continue), or null (should stop). If there is an error in the call(fetchRecceivableTypes, nextUrl) line, the error is caught and nextUrl is again set to null, just in case even though we are out of the loop by then.

The condition could also be (nextUrl !== null), but it should achieve the same thing.

@@ -44,7 +44,7 @@ function* fetchReceivableTypesSaga(): Generator<any, any, any> {
switch (statusCode) {
case 200:
allReceivableTypes.push(...bodyAsJson.results);
nextUrl = bodyAsJson.next;
nextUrl = bodyAsJson.next || null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there some value in bodyAsJson.next that is not the next URL, or already null if there are no more receivable types?

Copy link
Contributor

Choose a reason for hiding this comment

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

I just thought the value is null already, if there's no more data coming from backend.

Copy link
Contributor

Choose a reason for hiding this comment

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

If what Juho says is correct then the or is a bit rendundant right?

@NC-jsAhonen NC-jsAhonen force-pushed the MVJ-527-fetch-all-receivable-types branch from 3153632 to af6c91b Compare October 21, 2024 09:38
@NC-jsAhonen NC-jsAhonen force-pushed the MVJ-527-fetch-all-receivable-types branch from af6c91b to c86e1b3 Compare October 21, 2024 09:39
Copy link
Contributor

@juho-kettunen-nc juho-kettunen-nc left a comment

Choose a reason for hiding this comment

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

Looks good

@NC-jsAhonen NC-jsAhonen merged commit 02a5a7c into develop Oct 21, 2024
4 checks passed
@NC-jsAhonen NC-jsAhonen deleted the MVJ-527-fetch-all-receivable-types branch October 21, 2024 10:51
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.

3 participants