-
Notifications
You must be signed in to change notification settings - Fork 16
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
Report argument modal translation #5483
Conversation
Also made a PR to update reports repo docs: https://github.com/msupply-foundation/open-msupply-reports/pull/118 |
@@ -154,8 +161,18 @@ const FormComponent = ({ | |||
// This allows "default" values to be set in the JSON schema | |||
const handleDefaultsAjv = createAjv({ useDefaults: true }); | |||
|
|||
const commonKeys = useMemo(() => new Set(Object.keys(common)), []); |
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.
memoized keys in case checking Object.keys repeatedly is expensive. Unsure if it would be for how many keys we have.
Looks great, does it work for our patient schema too:
Can you do an example of how it works for enums in that default patient schema ? Also do you have a list of tasks to finish this issue fully ? |
I hadn't considered the patient schema! I'll have a look. I do not have a list of tasks to finish this issue fully |
Yes with a small modification of how we add enums in our schema. I will create an example of this and update the docs |
Bundle size differenceComparing this PR to
|
I've had a look and this requires a few more changes. It is a little over my head so will take a bit of time to figure out. There are a couple of factors:
|
if (result.report.__typename == 'ReportNode') { | ||
return result.report; | ||
} else { | ||
error(t('report.error-translating'))(); | ||
throw new Error('Could not translate report'); | ||
} |
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.
Right now error handling is just a toast. But I thought good to have this in to distinguish between repository errors and translation errors from users' perspective.
We could handle errors in a more structured way, but I am thinking it is not necessary now.
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.
Can you please map as per:
open-msupply/client/packages/common/src/authentication/hooks/useUpdateUserInfo.ts
Lines 58 to 70 in aae44ff
switch (update.error.__typename) { | |
case 'ConnectionError': | |
setError(t('error.connection-error')); | |
break; | |
case 'InvalidCredentials': | |
setError(t('error.invalid-credentials')); | |
break; | |
case 'MissingCredentials': | |
setError(t('error.invalid-credentials')); | |
break; | |
default: | |
noOtherVariants(update.error); | |
} |
|
||
pub struct FailedTranslation; | ||
#[Object] | ||
impl FailedTranslation { | ||
pub async fn description(&self) -> &'static str { | ||
"Translation failed." | ||
} | ||
} |
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 have added this as a generic error for future use case of translating any json.
key: key.to_string(), | ||
}, | ||
user_language, | ||
)? |
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.
Translation won't fail here on missing or incorrect translation keys, as we are providing a fallback.
Keen to have a quick catch up |
With this one, I put the translate_report_argument_schema method in the wrong place should be in lib.rs under report not in root of service |
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.
A few little fix up after our chat, and should be good to go
|
||
const UNIQUE_TRANSLATE_KEY: &str = "T#"; | ||
|
||
pub fn crawl_and_translate( |
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 excellent, good use of existing standard library (strip_prefix), and I like the tests too, thanks
if (result.report.__typename == 'ReportNode') { | ||
return result.report; | ||
} else { | ||
error(t('report.error-translating'))(); | ||
throw new Error('Could not translate report'); | ||
} |
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.
Can you please map as per:
open-msupply/client/packages/common/src/authentication/hooks/useUpdateUserInfo.ts
Lines 58 to 70 in aae44ff
switch (update.error.__typename) { | |
case 'ConnectionError': | |
setError(t('error.connection-error')); | |
break; | |
case 'InvalidCredentials': | |
setError(t('error.invalid-credentials')); | |
break; | |
case 'MissingCredentials': | |
setError(t('error.invalid-credentials')); | |
break; | |
default: | |
noOtherVariants(update.error); | |
} |
And rebuild standard reports
@@ -57,7 +57,7 @@ | |||
{ | |||
"type": "Control", | |||
"scope": "#/properties/sort", | |||
"label": "Sort by:", | |||
"label": "T#report.sort-by", |
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 realise missed the 'Sort by', and 'Sort direction' keys and their translations - so have added these in also
// TODO add never exhaustive error handling if adding more error types to QueryReportError | ||
// default: | ||
// noOtherVariants(query.reports.error.__typename); |
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.
Thought would be helpful to leave this here for if and when we add errors? Wasn't sure on this one
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.
Looks great, thanks @fergie-nz !
key: report.error.description, | ||
}); | ||
break; | ||
// TODO add never exhaustive error handling if adding more error types to QueryReportError |
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.
that's great thanks
Fixes #4951
π©π»βπ» What does this PR do?
Adds translations to report modal via json schema or UI schema.
Utilised inbuilt JSON form translation.
Maintains type safety of locale keys!
π Any notes for the reviewer?
π§ͺ Testing
You can test by running the 'Report-argument-modal-translation-example' branch which includes an example translation in the itemUsage report for both methods of adding translations
Note - you may need to clear out existing reports in your database to view.
Delete reports, then run your back end. This will populate with updated report automatically
π Documentation