Skip to content

Commit

Permalink
fix(rules): allow selection of event templates when no targets are av…
Browse files Browse the repository at this point in the history
…ailable
  • Loading branch information
andrewazores committed Dec 5, 2024
1 parent 2e5202b commit 9725f51
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/app/Rules/CreateRule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export const CreateRuleForm: React.FC<CreateRuleFormProps> = (_props) => {
: [];
}),
),
of([]),
context.api.getEventTemplates().pipe(catchError((_) => of<EventTemplate[]>([]))),
),
),
)
Expand Down
6 changes: 5 additions & 1 deletion src/app/Shared/Services/Api.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down Expand Up @@ -1361,6 +1361,10 @@ export class ApiService {
return this.doGet(`targets/${target.id}/recordings`, 'v4', undefined, suppressNotifications, skipStatusCheck);
}

getEventTemplates(suppressNotifications = false, skipStatusCheck = false): Observable<EventTemplate[]> {
return this.doGet<EventTemplate[]>('event_templates', 'v4', undefined, suppressNotifications, skipStatusCheck);
}

getTargetEventTemplates(
target: TargetStub,
suppressNotifications = false,
Expand Down
7 changes: 7 additions & 0 deletions src/test/Rules/CreateRule.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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]));
Expand Down

0 comments on commit 9725f51

Please sign in to comment.