-
Notifications
You must be signed in to change notification settings - Fork 11
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
Change return type of QrCode query to better indicate errors #1512
Conversation
564cafe
to
f7b634e
Compare
The unions may contain error types with detailed info
f7b634e
to
c1c8ecc
Compare
c1c8ecc
to
7ee08fb
Compare
@fhenrich33 I consider this completed from a BE perspective. Please check the first post about the different return types of the |
a7170c1
to
93beadb
Compare
Makes sense, will do! |
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 @pylipp! Great PR until now.
code review
It passes, but some FYI for @fhenrich33 :
- Philipp changed the input variable name for
qrCode
andqrExists
query. We should check the places where we execute the query.
functional review
passes as well. This is the query I used to test:
{
qrExists(code: "093f65e080a295f8076b1c5722a46aa2")
qrCodeFail: qrCode(code: "093f65e080a295f8076b1c5722a46aa2") {
... on QrCode {
id
box {
... on Box {
labelIdentifier
}
... on InsufficientPermissionError {
name
}
... on UnauthorizedForBaseError {
name
organisationName
}
}
}
... on InsufficientPermissionError {
name
}
... on InsufficientPermissionError {
name
}
}
qrCodeValid: qrCode (code: "9d7f34fbea04de63b0acdfb874f3ef59") {
... on QrCode {
id
box {
... on Box {
labelIdentifier
}
... on InsufficientPermissionError {
name
}
... on UnauthorizedForBaseError {
name
organisationName
}
}
}
... on InsufficientPermissionError {
name
}
... on InsufficientPermissionError {
name
}
}
}
Signed-off-by: Felipe Henrich <[email protected]>
…hange-qrcode-query-interface
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1512 +/- ##
==========================================
- Coverage 84.35% 84.33% -0.02%
==========================================
Files 236 236
Lines 14775 14823 +48
Branches 1579 1582 +3
==========================================
+ Hits 12463 12501 +38
- Misses 2273 2283 +10
Partials 39 39
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@fhenrich33 I'll merge master into this branch and try to resolve the conflict in the |
front/src/hooks/useQrResolver.ts
Outdated
// @ts-ignore | ||
if (!data?.qrCode?.box) { | ||
|
||
if (data.qrCode.__typename === "ResourceDoesNotExistError") { | ||
return { | ||
kind: IQrResolverResultKind.NOT_ASSIGNED_TO_BOX, |
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 think this should be NO_BOXTRIBUTE_QR
and also show an error toast?
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 handled at /front/src/components/QrReader/QrReaderContainer.tsx
case IQrResolverResultKind.NOT_ASSIGNED_TO_BOX: {
if (!multiScan) {
onSuccess();
navigate(`/bases/${baseId}/boxes/create/${qrResolvedValue?.qrHash}`);
} else {
triggerError({
message: "No box associated to this QR code!",
});
setIsProcessingQrCodeDelayed(false);
}
break;
}
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.
yes it works 👍 But I end up on an empty page http://localhost:3000/bases/1/boxes/create/13f12820c8010f2f7349962930e6bf4
(I used the last one of the invalid QR codes from the repo readme).
I'd expect to stay on /qrread
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.
Huh, this should've been handled at front/src/hooks/useQrResolver.ts
const resolveQrCode = useCallback(
async (qrCodeUrl: string, fetchPolicy: FetchPolicy): Promise<IQrResolvedValue> => {
setLoading(true);
const extractedQrHashFromUrl = extractQrCodeFromUrl(qrCodeUrl);
if (!extractedQrHashFromUrl) {
triggerError({
message: "This is not a Boxtribute QR code!",
});
setLoading(false);
return { kind: IQrResolverResultKind.NOT_BOXTRIBUTE_QR } as IQrResolvedValue;
}
const qrResolvedValue: IQrResolvedValue = await resolveQrHash(
extractedQrHashFromUrl,
fetchPolicy,
);
setLoading(false);
return qrResolvedValue;
},
[resolveQrHash, triggerError],
);
Cheking this out.
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.
@pylipp does this happen in the live version?
@pylipp By the way the tests that are failing doesn't reflect what actually happens in the real app, I didn't figure out a way to fix them yet. cc @HaGuesto The failing tests:
|
@pylipp this PR is ready to be merge. Pls do so when you think it is the right time. |
The unions may contain error types with detailed info. I hope the following table clarifies how to deal with the response of the query https://github.com/boxwise/boxtribute/blob/change-qrcode-query-interface/front/src/queries/queries.ts#L38-L66
qr:read
permission (e.g. a label-creation user)FORBIDDEN
BAD_USER_INPUT
stock:read
permissionstock:read
permission BUT NOT for the base that the requested box is inNote how currently the cases 1, 3a, 3b cannot be distinguished.
Also with the new interface design now in case of 3b information about the base/org of the box can be displayed.