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

Fix report charts #2239

Merged
merged 1 commit into from
Aug 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
10 changes: 5 additions & 5 deletions api/net/Areas/Subscriber/Controllers/ReportController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

using System.Net;
using System.Net.Mime;
using System.Text;
using System.Text.Json;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -11,15 +12,14 @@
using TNO.API.Helpers;
using TNO.API.Models;
using TNO.API.Models.SignalR;
using TNO.Ches.Configuration;
using TNO.Core.Exceptions;
using TNO.DAL.Services;
using TNO.Entities;
using TNO.Kafka;
using TNO.Kafka.SignalR;
using TNO.Keycloak;
using TNO.Models.Filters;
using System.Text;
using TNO.Entities;
using TNO.Ches.Configuration;
namespace TNO.API.Areas.Subscriber.Controllers;
using TNO.Ches;
using TNO.Core.Extensions;
Expand Down Expand Up @@ -356,7 +356,7 @@ public async Task<IActionResult> Generate(int id, [FromQuery] bool regenerate =
else if (regenerate && currentInstance.SentOn.HasValue)
{
// Generate a new instance because the prior was sent to CHES.
currentInstance = await _reportService.GenerateReportInstanceAsync(id, user.Id);
currentInstance = await _reportService.GenerateReportInstanceAsync(id, user.Id, null, regenerate);
_reportInstanceService.ClearChangeTracker();
currentInstance = _reportInstanceService.AddAndSave(currentInstance);
instances = _reportService.GetLatestInstances(id, user.Id);
Expand All @@ -368,7 +368,7 @@ public async Task<IActionResult> Generate(int id, [FromQuery] bool regenerate =
else if (regenerate && currentInstance.SentOn.HasValue == false)
{
// Regenerate the current instance, but do not create a new instance.
var regeneratedInstance = await _reportService.GenerateReportInstanceAsync(id, user.Id, currentInstance.Id);
var regeneratedInstance = await _reportService.GenerateReportInstanceAsync(id, user.Id, currentInstance.Id, regenerate);
_reportInstanceService.ClearChangeTracker();
currentInstance.ContentManyToMany.Clear();
var count = 0;
Expand Down
2 changes: 1 addition & 1 deletion app/subscriber/src/components/modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const Modal: React.FC<IModalProps> = ({
<Button
variant={type === 'delete' ? 'error' : 'primary'}
onClick={onConfirm}
disabled={isSubmitting && !enableConfirm}
disabled={isSubmitting || !enableConfirm}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If either then disable. The way this was implemented didn't make sense. I hope where ever else it's used it doesn't break.

>
{confirmText ?? 'Continue'}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { FaAngleDown, FaMinus } from 'react-icons/fa6';
import { useParams } from 'react-router-dom';
import { useReports, useUsers } from 'store/hooks';
import { useProfileStore } from 'store/slices';
import { Checkbox, Show, ToggleButton, useModal } from 'tno-core';
import { Checkbox, Loading, Show, ToggleButton, useModal } from 'tno-core';

import { useReportEditContext } from '../ReportEditContext';
import { ReportSections } from './stories';
Expand Down Expand Up @@ -156,6 +156,9 @@ export const ReportEditContentForm = React.forwardRef<
}}
/>
</Show>
<Show visible={isSubmitting}>
<Loading />
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The regenerate process takes a bit.

</Show>
<p>Do you want to proceed?</p>
</>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ export const ReportSectionMediaAnalyticsChart = React.forwardRef<
}, [values.instances]);

React.useEffect(() => {
setData(convertToChart(chart, showReportData ? reportContent : testData, values.sections));
}, [chart, reportContent, showReportData, testData, values.sections]);
const sectionContent =
section.filterId || section.folderId || section.linkedReportId
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only include content in the section when appropriate.

? reportContent.filter((rc) => rc.sectionName === section.name)
: reportContent;
setData(
convertToChart(section, chart, showReportData ? sectionContent : testData, values.sections),
);
}, [section, chart, reportContent, showReportData, testData, values.sections]);

React.useEffect(() => {
setReportContent(values.instances ? values.instances[0].content : []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ export interface IConvertToChartOptions {

/**
* Convert specified data into chart data for chart.js.
* @param section The section the chart belongs in.
* @param chart The chart to populate.
* @param content An array of report instance content.
* @param sections An array of sections in the report.
* @param options The converter config options.
* @returns Chart data.
*/
export const convertToChart = (
section: IReportSectionModel,
chart: IReportSectionChartTemplateModel,
content: IReportInstanceContentModel[],
sections: IReportSectionModel[],
Expand Down
4 changes: 3 additions & 1 deletion libs/net/dal/Services/Interfaces/IReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ public interface IReportService : IBaseService<Report, int>
/// <param name="id"></param>
/// <param name="requestorId"></param>
/// <param name="instanceId"></param>
/// <param name="regenerate"></param>
/// <returns></returns>
public Task<ReportInstance> GenerateReportInstanceAsync(
int id,
int? requestorId = null,
long? instanceId = null);
long? instanceId = null,
bool regenerate = false);

/// <summary>
/// Regenerate the content for the current report instance for the specified report 'id' and 'sectionId'.
Expand Down
6 changes: 4 additions & 2 deletions libs/net/dal/Services/ReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,17 +483,19 @@ public override void Delete(Report entity)
/// <param name="id"></param>
/// <param name="requestorId"></param>
/// <param name="instanceId"></param>
/// <param name="regenerate"></param>
/// <returns></returns>
public async Task<ReportInstance> GenerateReportInstanceAsync(
int id,
int? requestorId = null,
long? instanceId = null)
long? instanceId = null,
bool regenerate = false)
{
// Fetch content for every section within the report. This will include folders and filters.
var report = FindById(id) ?? throw new NoContentException("Report does not exist");
var reportSettings = JsonSerializer.Deserialize<ReportSettingsModel>(report.Settings, _serializerOptions) ?? new ReportSettingsModel();
List<ReportInstanceContent> instanceContent;
if (reportSettings.Content.CopyPriorInstance)
if (reportSettings.Content.CopyPriorInstance && !regenerate)
{
var currentInstance = GetCurrentReportInstance(report.Id, requestorId) ?? new ReportInstance(report.Id);
instanceContent = currentInstance.ContentManyToMany.Select(c => new ReportInstanceContent(0, c.ContentId, c.SectionName, c.SortOrder)).ToList();
Expand Down
Loading