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

(feat) Better script loading error #1020

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/framework/esm-dynamic-loading/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"access": "public"
},
"peerDependencies": {
"@openmrs/esm-globals": "5.x"
"@openmrs/esm-globals": "5.x",
"@openmrs/esm-translations": "5.x"
},
"devDependencies": {
"@openmrs/esm-globals": "workspace:*"
Expand Down
13 changes: 10 additions & 3 deletions packages/framework/esm-dynamic-loading/src/dynamic-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';
// hack to make the types defined in esm-globals available here
import { dispatchToastShown, type ImportMap } from '@openmrs/esm-globals';
import { getCoreTranslation } from '@openmrs/esm-translations';
Copy link
Member

Choose a reason for hiding this comment

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

Could you mark @openmrs/esm-translations as a peer dep of this sub-component. I think that will fix the size growth.


/**
* @internal
Expand Down Expand Up @@ -144,9 +145,15 @@ export async function preloadImport(jsPackage: string, importMap?: ImportMap) {
if (isOverridden) {
dispatchToastShown({
kind: 'error',
title: 'Error loading script',
description: `Failed to load overridden script from ${url}. Click below to reset all overrides.`,
actionButtonLabel: 'Reload',
title: getCoreTranslation('scriptLoadingFailed', 'Error: Script failed to load'),
description: getCoreTranslation(
'scriptLoadingError',
'Failed to load overridden script from {{- url}}. Please check that the bundled script is available at the expected URL. Click the button below to reset all import map overrides.',
{
url,
},
),
actionButtonLabel: getCoreTranslation('resetOverrides', 'Reset overrides'),
onActionButtonClick() {
window.importMapOverrides.resetOverrides();
window.location.reload();
Expand Down
4 changes: 4 additions & 0 deletions packages/framework/esm-translations/src/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export const coreTranslations = {
other: 'Other',
patientLists: 'Patient Lists',
relationships: 'Relationships',
resetOverrides: 'Reset overrides',
scriptLoadingFailed: 'Error: Script failed to load',
scriptLoadingError:
'Failed to load overridden script from {{url}}. Please check that the bundled script is available at the expected URL. Click the button below to reset all import map overrides.',
seeMoreLists: 'See {{count}} more lists',
showDetails: 'Show details',
unknown: 'Unknown',
Expand Down
3 changes: 3 additions & 0 deletions packages/framework/esm-translations/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"patientLists": "Patient Lists",
"postalCode": "Postal code",
"relationships": "Relationships",
"resetOverrides": "Reset overrides",
"scriptLoadingError": "Failed to load overridden script from {{url}}. Please check that the bundled script is available at the expected URL. Click the button below to reset all import map overrides.",
"scriptLoadingFailed": "Error: Script failed to load",
"seeMoreLists": "See {{count}} more lists",
"showDetails": "Show details",
"state": "State",
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3084,6 +3084,7 @@ __metadata:
"@openmrs/esm-globals": "workspace:*"
peerDependencies:
"@openmrs/esm-globals": 5.x
"@openmrs/esm-translations": 5.x
languageName: unknown
linkType: soft

Expand Down
Loading