Skip to content

Commit

Permalink
chore(agent): use notification message to patch template table (#708)
Browse files Browse the repository at this point in the history
* chore(agent): use notification message to patch template table

Signed-off-by: Thuan Vo <thvo@redhat.com>

* chore(agent): remove console

Signed-off-by: Thuan Vo <thvo@redhat.com>
  • Loading branch information
Thuan Vo authored Dec 2, 2022
1 parent 69ff7d6 commit d4b8ae1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
24 changes: 16 additions & 8 deletions src/app/Agent/AgentProbeTemplates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,27 @@ export const AgentProbeTemplates: React.FunctionComponent<AgentProbeTemplatesPro

React.useEffect(() => {
addSubscription(
context.notificationChannel
.messages(NotificationCategory.ProbeTemplateUploaded)
.subscribe((v) => refreshTemplates())
context.notificationChannel.messages(NotificationCategory.ProbeTemplateUploaded).subscribe((event) => {
setTemplates((old) => {
return [
...old,
{
name: event.message.templateName,
xml: event.message.templateContent,
} as ProbeTemplate,
];
});
})
);
}, [addSubscription, context.notificationChannel, refreshTemplates]);
}, [addSubscription, context.notificationChannel, setTemplates]);

React.useEffect(() => {
addSubscription(
context.notificationChannel
.messages(NotificationCategory.ProbeTemplateDeleted)
.subscribe((v) => refreshTemplates())
context.notificationChannel.messages(NotificationCategory.ProbeTemplateDeleted).subscribe((event) => {
setTemplates((old) => old.filter((t) => t.name !== event.message.probeTemplate));
})
);
}, [addSubscription, context.notificationChannel, refreshTemplates]);
}, [addSubscription, context.notificationChannel, setTemplates]);

React.useEffect(() => {
let filtered: ProbeTemplate[];
Expand Down
6 changes: 4 additions & 2 deletions src/test/Agent/AgentProbeTemplates.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ const mockCreateTemplateNotification = {
type: mockMessageType,
} as MessageMeta,
message: {
template: mockAnotherProbeTemplate,
templateName: mockAnotherProbeTemplate.name,
templateContent: mockAnotherProbeTemplate.xml,
probeTemplate: 'files-uploads/abcdfg',
},
} as NotificationMessage;

Expand All @@ -83,7 +85,7 @@ const mockDeleteTemplateNotification = {
type: mockMessageType,
},
message: {
template: mockProbeTemplate,
probeTemplate: mockProbeTemplate.name,
},
} as NotificationMessage;

Expand Down

0 comments on commit d4b8ae1

Please sign in to comment.