From 9725f5150f62c91b851383b74e79dc3f73846c68 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Thu, 5 Dec 2024 10:09:36 -0500 Subject: [PATCH] fix(rules): allow selection of event templates when no targets are available --- src/app/Rules/CreateRule.tsx | 2 +- src/app/Shared/Services/Api.service.tsx | 6 +++++- src/test/Rules/CreateRule.test.tsx | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/Rules/CreateRule.tsx b/src/app/Rules/CreateRule.tsx index e032e0376..ba05bf742 100644 --- a/src/app/Rules/CreateRule.tsx +++ b/src/app/Rules/CreateRule.tsx @@ -285,7 +285,7 @@ export const CreateRuleForm: React.FC = (_props) => { : []; }), ), - of([]), + context.api.getEventTemplates().pipe(catchError((_) => of([]))), ), ), ) diff --git a/src/app/Shared/Services/Api.service.tsx b/src/app/Shared/Services/Api.service.tsx index 246f731bb..46474c6e9 100644 --- a/src/app/Shared/Services/Api.service.tsx +++ b/src/app/Shared/Services/Api.service.tsx @@ -592,7 +592,7 @@ export class ApiService { const body = new window.FormData(); body.append('template', file); - return this.sendLegacyRequest('v4', 'templates', 'Template Upload Failed', { + return this.sendLegacyRequest('v4', 'event_templates', 'Template Upload Failed', { body: body, method: 'POST', headers: {}, @@ -1361,6 +1361,10 @@ export class ApiService { return this.doGet(`targets/${target.id}/recordings`, 'v4', undefined, suppressNotifications, skipStatusCheck); } + getEventTemplates(suppressNotifications = false, skipStatusCheck = false): Observable { + return this.doGet('event_templates', 'v4', undefined, suppressNotifications, skipStatusCheck); + } + getTargetEventTemplates( target: TargetStub, suppressNotifications = false, diff --git a/src/test/Rules/CreateRule.test.tsx b/src/test/Rules/CreateRule.test.tsx index b9e4de28a..e7f7145df 100644 --- a/src/test/Rules/CreateRule.test.tsx +++ b/src/test/Rules/CreateRule.test.tsx @@ -43,6 +43,12 @@ const mockEventTemplate: EventTemplate = { provider: 'some provider', description: 'some description', }; +const mockCustomEventTemplate: EventTemplate = { + name: 'CustomTemplate', + type: 'CUSTOM', + provider: 'some provider', + description: 'some description', +}; const mockRule: Rule = { name: 'mockRule', @@ -64,6 +70,7 @@ jest.mock('react-router-dom', () => ({ useNavigate: () => mockNavigate, })); +jest.spyOn(defaultServices.api, 'getEventTemplates').mockReturnValue(of([mockCustomEventTemplate])); jest.spyOn(defaultServices.api, 'getTargetEventTemplates').mockReturnValue(of([mockEventTemplate])); jest.spyOn(defaultServices.targets, 'targets').mockReturnValue(of([mockTarget]));