-
Notifications
You must be signed in to change notification settings - Fork 15
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
5364 gis scanner handling #5382
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cff29bb
Add mock GraphQL node
CarlosNZ 3356e63
Add front-end functionality for scanning new asset
CarlosNZ 45fe39c
WIP Parsing GS1
jmbrunskill fbc3ed4
GS1 Parsing
jmbrunskill 0a179bf
Return Draft Asset for GS1 Scan Result
jmbrunskill fa9a086
Return after no matching asset
CarlosNZ bd6c56c
Handle asset data
CarlosNZ 28770a5
Update to new back-end API
CarlosNZ 1385511
Fix Serial Number Lookup
jmbrunskill fa27500
Use correct parse_scanned_data api from the Add Scan Button
jmbrunskill 616280d
Check model and serial number for duplicate asset, tidy up format check
jmbrunskill 76d409d
Try to catch errors...
jmbrunskill 06af3d6
re-order try catch
jmbrunskill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,13 @@ import { | |
useNavigate, | ||
useDisabledNotificationPopover, | ||
RouteBuilder, | ||
useConfirmationModal, | ||
FnUtils, | ||
AssetLogStatusInput, | ||
} from '@openmsupply-client/common'; | ||
import { AppRoute } from '@openmsupply-client/config'; | ||
import { useAssets } from '../api'; | ||
import { DraftAsset } from '../types'; | ||
|
||
export const AddFromScannerButtonComponent = () => { | ||
const t = useTranslation(); | ||
|
@@ -30,19 +34,60 @@ export const AddFromScannerButtonComponent = () => { | |
const equipmentRoute = RouteBuilder.create(AppRoute.Coldchain).addPart( | ||
AppRoute.Equipment | ||
); | ||
const { mutateAsync: fetchAsset } = useAssets.document.fetch(); | ||
const { mutateAsync: scanAsset } = useAssets.document.scan(); | ||
const { mutateAsync: saveNewAsset } = useAssets.document.insert(); | ||
const { insertLog, invalidateQueries } = useAssets.log.insert(); | ||
const newAssetData = useRef<DraftAsset>(); | ||
|
||
const showCreateConfirmation = useConfirmationModal({ | ||
onConfirm: () => { | ||
if (newAssetData.current) { | ||
saveNewAsset(newAssetData.current) | ||
.catch(e => error(t('error.unable-to-save-asset', { error: e }))()) | ||
.then(async () => { | ||
if (newAssetData.current) { | ||
await insertLog({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is duplicated functionality as the add new asset modal does this too. |
||
id: FnUtils.generateUUID(), | ||
assetId: newAssetData.current.id, | ||
comment: t('label.created'), | ||
status: AssetLogStatusInput.Functioning, | ||
}); | ||
invalidateQueries(); | ||
navigate(equipmentRoute.addPart(newAssetData.current.id).build()); | ||
} | ||
}); | ||
} | ||
}, | ||
message: t('heading.create-new-asset'), | ||
title: t('messages.create-new-asset-confirmation'), | ||
}); | ||
|
||
const handleScanResult = async (result: ScanResult) => { | ||
if (!!result.content) { | ||
const { content } = result; | ||
const id = content; | ||
const asset = await fetchAsset(id).catch(() => {}); | ||
if (asset) { | ||
navigate(equipmentRoute.addPart(id).build()); | ||
|
||
const asset = await scanAsset(content).catch(() => {}); | ||
|
||
if (asset?.__typename !== 'AssetNode') { | ||
error(t('error.no-matching-asset', { id: result.content }))(); | ||
return; | ||
} | ||
if (asset?.id) { | ||
navigate(equipmentRoute.addPart(asset?.id).build()); | ||
return; | ||
} | ||
|
||
error(t('error.no-matching-asset', { id }))(); | ||
// If not existing, offer to create from the parsed GS1 data | ||
if (!asset?.id) { | ||
newAssetData.current = { | ||
...asset, | ||
id: FnUtils.generateUUID(), | ||
locationIds: [], | ||
parsedProperties: {}, | ||
parsedCatalogProperties: {}, | ||
}; | ||
showCreateConfirmation(); | ||
} | ||
} | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 catch doesn't work for some reason!
I tired adding
throw e
into theuseAssets.document.insert();
useMutation:onError
but that didn't work.Help please!
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.
It appears to work fine for me? Though you'd need to add
{{ error }}
to the 'error.unable-to-save-asset' translation for the error message to show... not entirely sure it should though!The only time I can seem to see where it doesn't show a message is when
newAssetData.current
isn't defined.... I think somewhere we have an example of passing data into confirm (so we can pass directly from handleScanResult, and skip the ref thing completely) - but I can't find right now, and I know we're on a time crunch to get something for RC!Can be a clean up for another PR, maybe as part of that other issue?
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 would move the catch below the .then() though! If
saveNewAsset
errors, we don't want to catch, and then try do the insertLog/redirect, should throw to below that