Skip to content

Commit e33b05f

Browse files
authored
Fix update report (#2411)
Published tno-core:1.0.8
1 parent 56f626b commit e33b05f

File tree

13 files changed

+109
-32
lines changed

13 files changed

+109
-32
lines changed

api/net/Areas/Services/Controllers/ReportInstanceController.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ public IActionResult UpdateUserReportInstanceStatus(long id, int userId, Entitie
218218
}
219219
else throw new BadRequestException("Parameter 'type' must be 'link' or 'text'.");
220220
_reportInstanceService.UpdateAndSave(userInstance);
221+
221222
return new JsonResult(new UserReportInstanceModel(userInstance));
222223
}
223224

@@ -232,11 +233,22 @@ public IActionResult UpdateUserReportInstanceStatus(long id, int userId, Entitie
232233
[ProducesResponseType(typeof(UserReportInstanceModel), (int)HttpStatusCode.OK)]
233234
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
234235
[SwaggerOperation(Tags = new[] { "Report" })]
235-
public IActionResult UpdateReportInstanceStatus(long id, Entities.ReportStatus status)
236+
public async Task<IActionResult> UpdateReportInstanceStatusAsync(long id, Entities.ReportStatus status)
236237
{
237238
var instance = _reportInstanceService.FindById(id) ?? throw new NoContentException();
238239
instance.Status = status;
239240
_reportInstanceService.UpdateAndSave(instance);
241+
242+
var ownerId = instance.OwnerId ?? instance.Report?.OwnerId;
243+
if (ownerId.HasValue)
244+
{
245+
var user = _userService.FindById(ownerId.Value) ?? throw new NotAuthorizedException();
246+
await _kafkaMessenger.SendMessageAsync(
247+
_kafkaHubOptions.HubTopic,
248+
new KafkaHubMessage(HubEvent.SendUser, user.Username, new KafkaInvocationMessage(MessageTarget.ReportStatus, new[] { new ReportMessageModel(instance) { Message = "status" } }))
249+
);
250+
}
251+
240252
return new JsonResult(new ReportInstanceModel(instance, _serializerOptions));
241253
}
242254
#endregion

app/subscriber/.yarn/cache/tno-core-npm-1.0.7-2704faafb5-634b354d7b.zip renamed to app/subscriber/.yarn/cache/tno-core-npm-1.0.8-6bb9908e3f-7316655502.zip

2.01 MB
Binary file not shown.

app/subscriber/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"sheetjs": "file:packages/xlsx-0.20.1.tgz",
4646
"styled-components": "6.1.11",
4747
"stylis": "4.3.2",
48-
"tno-core": "1.0.7"
48+
"tno-core": "1.0.8"
4949
},
5050
"devDependencies": {
5151
"@testing-library/jest-dom": "6.4.5",

app/subscriber/src/components/layout/DefaultLayout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ export const DefaultLayout: React.FC<ILayoutProps> = ({ children, ...rest }) =>
6969
// Report has been updated, go fetch latest.
7070
try {
7171
if (message.status === ReportStatusName.Accepted)
72+
toast.info(`Report "${message.subject}" has been generated and email requested.`);
73+
else if (message.status === ReportStatusName.Completed)
7274
toast.info(`Report "${message.subject}" has been sent out by email.`);
7375
else if (message.status === ReportStatusName.Failed)
7476
toast.error(`Report "${message.subject}" failed to be sent out by email.`);

app/subscriber/src/features/my-reports/MyReports.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,21 @@ export const MyReports: React.FC = () => {
4646
hub.useHubEffect(MessageTargetKey.ReportStatus, async (message: IReportMessageModel) => {
4747
if (report) {
4848
try {
49-
const instance = await getReportInstance(message.id, false);
50-
if (instance) {
49+
if (message.message === 'status') {
5150
setReport({
5251
...report,
53-
instances: report.instances.map((i) => (i.id === message.id ? instance : i)),
52+
instances: report.instances.map((i) =>
53+
i.id === message.id ? { ...i, status: message.status, version: message.version } : i,
54+
),
5455
});
56+
} else {
57+
const instance = await getReportInstance(message.id, false);
58+
if (instance) {
59+
setReport({
60+
...report,
61+
instances: report.instances.map((i) => (i.id === message.id ? instance : i)),
62+
});
63+
}
5564
}
5665
} catch {}
5766
}

app/subscriber/src/features/my-reports/edit/ReportEditPage.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,26 @@ export const ReportEditPage = () => {
161161
// TODO: This can blow away a users' changes.
162162
try {
163163
if (message.reportId === report.id) {
164-
const instance = await getReportInstance(message.id, true);
165-
if (instance) {
166-
// If there is a new instance, prepend it.
167-
const add = !report.instances.some((i) => i.id === message.id);
164+
if (message.message === 'status') {
168165
setReport({
169166
...report,
170-
instances: add
171-
? [instance, ...report.instances]
172-
: report.instances.map((i) => (i.id === message.id ? instance : i)),
167+
instances: report.instances.map((i) =>
168+
i.id === message.id ? { ...i, status: message.status, version: message.version } : i,
169+
),
173170
});
174-
navigate(`/reports/${report.id}/content`);
171+
} else {
172+
const instance = await getReportInstance(message.id, true);
173+
if (instance) {
174+
// If there is a new instance, prepend it.
175+
const add = !report.instances.some((i) => i.id === message.id);
176+
setReport({
177+
...report,
178+
instances: add
179+
? [instance, ...report.instances]
180+
: report.instances.map((i) => (i.id === message.id ? instance : i)),
181+
});
182+
navigate(`/reports/${report.id}/content`);
183+
}
175184
}
176185
}
177186
} catch {}

app/subscriber/src/store/hooks/subscriber/useReportSync.ts

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,48 @@ export const useReportSync = () => {
2121

2222
// Only fetch the latest if the current report instance is older, or doesn't exist.
2323
if (report && (!instance || instance.version !== message.version)) {
24-
const response = await getReportInstance(message.id, true);
25-
if (response.status === 200 && response.data) {
26-
const instance = response.data;
24+
if (message.message === 'status') {
25+
// Update the status of the instance.
2726
storeMyReports((reports) => {
28-
let addInstance = true;
29-
let instances = report.instances.map((i) => {
30-
if (i.id === message.id) {
31-
addInstance = false;
32-
return instance;
33-
}
34-
return i;
35-
});
36-
if (addInstance) instances = [instance, ...instances];
3727
const results = reports.map((r) =>
3828
r.id === report.id
3929
? {
4030
...report,
41-
instances,
31+
instances: report.instances.map((i) =>
32+
i.id === message.id
33+
? { ...i, status: message.status, version: message.version }
34+
: i,
35+
),
4236
}
4337
: r,
4438
);
4539
return results;
4640
});
41+
} else {
42+
const response = await getReportInstance(message.id, true);
43+
if (response.status === 200 && response.data) {
44+
const instance = response.data;
45+
storeMyReports((reports) => {
46+
let addInstance = true;
47+
let instances = report.instances.map((i) => {
48+
if (i.id === message.id) {
49+
addInstance = false;
50+
return instance;
51+
}
52+
return i;
53+
});
54+
if (addInstance) instances = [instance, ...instances];
55+
const results = reports.map((r) =>
56+
r.id === report.id
57+
? {
58+
...report,
59+
instances,
60+
}
61+
: r,
62+
);
63+
return results;
64+
});
65+
}
4766
}
4867
}
4968
} catch {}

app/subscriber/yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10665,7 +10665,7 @@ __metadata:
1066510665
sheetjs: "file:packages/xlsx-0.20.1.tgz"
1066610666
styled-components: 6.1.11
1066710667
stylis: 4.3.2
10668-
tno-core: 1.0.7
10668+
tno-core: 1.0.8
1066910669
typescript: 4.9.5
1067010670
languageName: unknown
1067110671
linkType: soft
@@ -14698,9 +14698,9 @@ __metadata:
1469814698
languageName: node
1469914699
linkType: hard
1470014700

14701-
"tno-core@npm:1.0.7":
14702-
version: 1.0.7
14703-
resolution: "tno-core@npm:1.0.7"
14701+
"tno-core@npm:1.0.8":
14702+
version: 1.0.8
14703+
resolution: "tno-core@npm:1.0.8"
1470414704
dependencies:
1470514705
"@elastic/elasticsearch": ^8.13.1
1470614706
"@fortawesome/free-solid-svg-icons": ^6.4.2
@@ -14733,7 +14733,7 @@ __metadata:
1473314733
styled-components: ^6.1.11
1473414734
stylis: ^4.3.2
1473514735
yup: ^1.1.1
14736-
checksum: 634b354d7b527f378052b6fc57a4cd97fc281f2ae0c3fefa663e6672eeae8c8dc7ddaa38822144d0e4d1ed84def6b4b8a6b2f078bf8c8e5c2fb7302bfdcf8e42
14736+
checksum: 7316655502311ed6e399073aa5f107d55975c3d65ec095f13e92a9bc7ce6f4733ba3f36f38bd91e2d6988bdb75339d5a86972f3c8c94c77e27a5a9b6472bc01a
1473714737
languageName: node
1473814738
linkType: hard
1473914739

libs/net/models/Settings/ReportContentSettingsModel.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,25 @@ public class ReportContentSettingsModel
1212
public IEnumerable<int> ExcludeReports { get; set; } = Array.Empty<int>();
1313
public bool ShowLinkToStory { get; set; }
1414
public bool HighlightKeywords { get; set; }
15+
16+
/// <summary>
17+
/// get/set - Accumulate content on each run until sent.
18+
/// </summary>
1519
public bool CopyPriorInstance { get; set; }
20+
21+
/// <summary>
22+
/// get/set - Empty report when starting next report.
23+
/// </summary>
1624
public bool ClearOnStartNewReport { get; set; }
25+
26+
/// <summary>
27+
/// get/set - Exclude content in current unsent report.
28+
/// </summary>
1729
public bool ExcludeContentInUnsentReport { get; set; }
30+
31+
/// <summary>
32+
/// get/set - Whether to omit stories related to the BC Calendar.
33+
/// </summary>
1834
public bool OmitBCUpdates { get; set; }
1935
#endregion
2036

libs/net/models/SignalR/ReportMessageModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public class ReportMessageModel : AuditColumnsModel
3232
/// get/set - Foreign key to the user owns this report.
3333
/// </summary>
3434
public int? OwnerId { get; set; }
35+
36+
/// <summary>
37+
/// get/set - A message to identify what action was taken.
38+
/// </summary>
39+
public string? Message { get; set; }
3540
#endregion
3641

3742
#region Constructors

0 commit comments

Comments
 (0)