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

TNO-2159: Additional fix for reports missing content sometimes #1408

Merged
merged 2 commits into from
Jan 12, 2024

Conversation

mihailistov
Copy link
Contributor

No description provided.

@@ -129,7 +129,7 @@ export const ReportAdmin: React.FC<IReportAdminProps> = ({ path: defaultPath = '
if (existingReport) {
setReport(toForm(existingReport));
} else {
getReport(reportId, true)
getReport(reportId)
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 reversed this back to how it was before as we don't need report content in ReportAdmin page

if (open && !existingReport?.instances?.length) {
fetchReport(report.id);
}
}}
Copy link
Contributor Author

@mihailistov mihailistov Jan 12, 2024

Choose a reason for hiding this comment

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

Another optimization, whereas prior to this we were re-fetching the report data every time someone expanded the ReportCard, even if the report had already been fetched

Now we only fetch the report + instance data if it's not present

Copy link
Collaborator

Choose a reason for hiding this comment

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

This should work for most cases, but doesn't account for the background processes which run auto-reports.

React.useEffect(() => {
const reportId = parseInt(id ?? '0');
if (!!reportId && myReports?.length) {
const existingReport = myReports.find((r) => r.id === reportId);
if (existingReport) {
const hasFetchedContent = existingReport?.instances.some((r) => r.content?.length);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the best I can do given the current data structure. I am assuming that if there's any content present for any of the instances, that means we have fetched content for this report before, so there's no need to refetch

Here's the rough breakdown of what data is present & when:

  • fetchMyReports() -> returns reports with no instance data, so instances: []
  • getReport(id) -> returns report with instances data but NO content, instances: [{ ...instanceData, content: [] }]
  • getReport(id, true) -> returns report + instance + content
  • generateReport(id) -> reports instance + content

As long as one of getReport(id, true) or generateReport(id) have been called by this point. All content data needed should be present.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's a reasonable approach.

if (open && !existingReport?.instances?.length) {
fetchReport(report.id);
}
}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should work for most cases, but doesn't account for the background processes which run auto-reports.

React.useEffect(() => {
const reportId = parseInt(id ?? '0');
if (!!reportId && myReports?.length) {
const existingReport = myReports.find((r) => r.id === reportId);
if (existingReport) {
const hasFetchedContent = existingReport?.instances.some((r) => r.content?.length);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's a reasonable approach.

@Fosol Fosol merged commit 48df9dd into dev Jan 12, 2024
1 check passed
@Fosol Fosol deleted the tno-2159-fix-reports-missing-fix branch January 12, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants