Skip to content

Commit

Permalink
feat(south): Add a max instant per item field on south form
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerni10 committed Jun 21, 2023
1 parent b49ff51 commit 152cfc6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
12 changes: 11 additions & 1 deletion frontend/src/app/south/edit-south/edit-south.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h1 *ngIf="!southConnector" translate="south.create-title"></h1>
</div>
</div>

<div class="row justify-content-center">
<div class="row justify-content-center" *ngIf="manifest">
<div class="col-md-10 col-lg-8">
<form [formGroup]="southForm" (ngSubmit)="save()" id="south-form" class="mt-3">
<!-- General settings -->
Expand All @@ -30,7 +30,17 @@ <h2 translate="south.general-settings"></h2>
</div>
</div>
</div>

<div class="col-4" *ngIf="manifest.modes.historyFile || manifest.modes.historyPoint">
<div class="form-group">
<label for="south-max-instant-per-item" translate="south.max-instant-per-item"></label>
<div class="form-check form-switch">
<input formControlName="maxInstantPerItem" id="south-max-instant-per-item" type="checkbox" class="form-check-input" />
</div>
</div>
</div>
</div>

<div class="row mb-3">
<!-- Description -->
<div class="form-group">
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/app/south/edit-south/edit-south.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class EditSouthComponentTester extends ComponentTester<EditSouthComponent> {
return this.input('#south-enabled');
}

get maxInstant() {
return this.input('#south-max-instant-per-item')!;
}

get description() {
return this.textarea('#south-description');
}
Expand Down Expand Up @@ -67,6 +71,27 @@ describe('EditSouthComponent', () => {

scanModeService.getScanModes.and.returnValue(of([]));
proxyService.getProxies.and.returnValue(of([]));
southConnectorService.getSouthConnectorTypeManifest.and.returnValue(
of({
category: 'database',
name: 'SQL',
description: 'SQL description',
modes: {
subscription: false,
lastPoint: false,
lastFile: false,
historyPoint: false,
historyFile: true
},
items: {
scanMode: { subscriptionOnly: false, acceptSubscription: true },
settings: [],
schema: {} as unknown
},
settings: [],
schema: {} as unknown
} as SouthConnectorManifest)
);

tester = new EditSouthComponentTester();
tester.detectChanges();
Expand All @@ -75,6 +100,7 @@ describe('EditSouthComponent', () => {
it('should display general settings', () => {
expect(tester.title).toContainText('Create a South connector');
expect(tester.enabled).not.toBeChecked();
expect(tester.maxInstant).not.toBeChecked();
expect(tester.description).toHaveValue('');
expect(tester.specificForm).toBeDefined();

Expand Down Expand Up @@ -152,9 +178,12 @@ describe('EditSouthComponent', () => {
tester.detectChanges();
});
it('should display general settings', () => {
tester.maxInstant.check();
expect(southConnectorService.getSouthConnector).toHaveBeenCalledWith('id1');
expect(tester.title).toContainText('Edit South connector');
expect(tester.enabled).toBeChecked();
expect(tester.maxInstant).toBeChecked();

expect(tester.description).toHaveValue('My South connector description');
expect(tester.specificForm).toBeDefined();
expect(tester.specificTitle).toContainText('SQL settings');
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/app/south/edit-south/edit-south.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { NgForOf, NgIf } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { SouthConnectorCommandDTO, SouthConnectorDTO } from '../../../../../shared/model/south-connector.model';
import { SouthConnectorCommandDTO, SouthConnectorDTO, SouthConnectorManifest } from '../../../../../shared/model/south-connector.model';
import { SouthConnectorService } from '../../services/south-connector.service';
import { ObservableState, SaveButtonComponent } from '../../shared/save-button/save-button.component';
import { formDirectives } from '../../shared/form-directives';
Expand Down Expand Up @@ -34,10 +34,12 @@ export class EditSouthComponent implements OnInit {
scanModes: Array<ScanModeDTO> = [];
proxies: Array<ProxyDTO> = [];
southType = '';
manifest: SouthConnectorManifest | null = null;
southForm = this.fb.group({
name: ['', Validators.required],
description: '',
enabled: false,
maxInstantPerItem: false,
settings: this.fb.record({})
});

Expand Down Expand Up @@ -80,7 +82,8 @@ export class EditSouthComponent implements OnInit {
this.southForm.patchValue({
name: southConnector.name,
description: southConnector.description,
enabled: southConnector.enabled
enabled: southConnector.enabled,
maxInstantPerItem: southConnector.maxInstantPerItem
});
}
// If a south connector is not retrieved, the types are needed to create a new connector
Expand Down Expand Up @@ -118,6 +121,7 @@ export class EditSouthComponent implements OnInit {
});
});

this.manifest = manifest;
this.loading = false;
});
}
Expand Down Expand Up @@ -169,7 +173,7 @@ export class EditSouthComponent implements OnInit {
type: this.southType,
description: formValue.description!,
enabled: formValue.enabled!,
maxInstantPerItem: false,
maxInstantPerItem: formValue.maxInstantPerItem!,
settings: formValue.settings!
};
this.createOrUpdateSouthConnector(command);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
"name": "Name",
"description": "Description",
"enabled": "Enabled",
"max-instant-per-item": "Max instant per item",
"type": "Type",
"general-settings": "General settings",
"specific-settings": "{{ type }} settings",
Expand Down

0 comments on commit 152cfc6

Please sign in to comment.