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

Report argument modal translation #5483

Merged
merged 30 commits into from
Dec 17, 2024
Merged

Conversation

fergie-nz
Copy link
Contributor

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

  • Go to reports
  • Open item usage report
  • See translation

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

  • Part of an epic: But also documentation added in PR

@fergie-nz fergie-nz changed the base branch from develop to v2.4.0 November 19, 2024 23:36
@github-actions github-actions bot added this to the v2.4.0-RC2 milestone Nov 19, 2024
@github-actions github-actions bot added enhancement New feature or request Team Ruru πŸ¦‰ Roxy, Ferg, Noel feature: reports labels Nov 19, 2024
@fergie-nz
Copy link
Contributor Author

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)), []);
Copy link
Contributor Author

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.

@andreievg
Copy link
Collaborator

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 ?

@fergie-nz
Copy link
Contributor Author

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

@fergie-nz
Copy link
Contributor Author

Can you do an example of how it works for enums in that default patient schema ?

Yes with a small modification of how we add enums in our schema.

I will create an example of this and update the docs

@fergie-nz fergie-nz marked this pull request as draft November 20, 2024 00:09
Copy link

github-actions bot commented Nov 20, 2024

Bundle size difference

Comparing this PR to main

Old size New size Diff
4.99 MB 4.99 MB 1.5 KB (0.03%)

@fergie-nz
Copy link
Contributor Author

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'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.
I've paused now because not obvious to me. Do you think worth looking into?

There are a couple of factors:

  • Our custom renderers don't accept the inbuilt JsonForms translation functionality
  • We stringify our patient schema in rust. If we are passing into rust, might as well translate there now rather than converting then re translating on the front end? If I am understanding how we manage the patient schema correctly

@roxy-dao roxy-dao modified the milestones: v2.4.0-RC2, V2.4.0-RC3 Nov 20, 2024
@fergie-nz fergie-nz marked this pull request as ready for review November 21, 2024 01:11
@roxy-dao roxy-dao modified the milestones: V2.4.0-RC3, V2.4.0-RC4 Nov 22, 2024
@fergie-nz fergie-nz requested a review from andreievg November 27, 2024 00:59
@roxy-dao roxy-dao modified the milestones: V2.4.0-RC4, V2.4.0-RC5 Nov 27, 2024
@roxy-dao roxy-dao removed this from the V2.4.0-RC5 milestone Nov 28, 2024
Comment on lines 25 to 30
if (result.report.__typename == 'ReportNode') {
return result.report;
} else {
error(t('report.error-translating'))();
throw new Error('Could not translate report');
}
Copy link
Contributor Author

@fergie-nz fergie-nz Dec 2, 2024

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.

Copy link
Collaborator

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:

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 log the full result (console.error would be ok)

Comment on lines 343 to 350

pub struct FailedTranslation;
#[Object]
impl FailedTranslation {
pub async fn description(&self) -> &'static str {
"Translation failed."
}
}
Copy link
Contributor Author

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,
)?
Copy link
Contributor Author

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.

@andreievg
Copy link
Collaborator

@andreievg
Copy link
Collaborator

Report-argument-modal-translation...Report-argument-modal-translation(Use-translate-report-arugment-schema-method).

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

Copy link
Collaborator

@andreievg andreievg left a 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(
Copy link
Collaborator

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

server/report_builder/README.md Outdated Show resolved Hide resolved
server/report_builder/README.md Outdated Show resolved Hide resolved
Comment on lines 25 to 30
if (result.report.__typename == 'ReportNode') {
return result.report;
} else {
error(t('report.error-translating'))();
throw new Error('Could not translate report');
}
Copy link
Collaborator

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:

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 log the full result (console.error would be ok)

@@ -57,7 +57,7 @@
{
"type": "Control",
"scope": "#/properties/sort",
"label": "Sort by:",
"label": "T#report.sort-by",
Copy link
Contributor Author

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

Comment on lines +73 to +75
// TODO add never exhaustive error handling if adding more error types to QueryReportError
// default:
// noOtherVariants(query.reports.error.__typename);
Copy link
Contributor Author

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

@fergie-nz fergie-nz requested a review from andreievg December 16, 2024 23:17
Copy link
Collaborator

@andreievg andreievg left a 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
Copy link
Collaborator

Choose a reason for hiding this comment

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

that's great thanks

@fergie-nz fergie-nz merged commit e17fd11 into develop Dec 17, 2024
6 checks passed
@fergie-nz fergie-nz deleted the Report-argument-modal-translation branch December 17, 2024 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature: reports Team Ruru πŸ¦‰ Roxy, Ferg, Noel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reports: Translate arguments modal
3 participants