Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ <h2 class="settings-drawer-header-title">System settings</h2>
[options]="vm.internetOptions">
</app-settings-dropdown>
</ng-container>
<p class="message">
<p class="message" [ngClass]="{ disabled: settingsDisable }">
If a port is missing from this list, you can
<a
#reloadSettingLink
(click)="reloadSetting()"
(keydown.enter)="reloadSetting()"
(keydown.space)="reloadSetting()"
Expand Down
11 changes: 11 additions & 0 deletions modules/ui/src/app/pages/settings/general-settings.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,14 @@
background-color: rgba(255, 255, 255, 0.7);
z-index: 2;
}

.disabled {
.message-link {
cursor: default;
pointer-events: none;

&:focus-visible {
outline: none;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,47 @@ describe('GeneralSettingsComponent', () => {
expect(mockLoaderService.setLoading).toHaveBeenCalledWith(true);
});

describe('#settingsDisable', () => {
it('should disable setting form when get settingDisable as true ', () => {
spyOn(component.settingForm, 'disable');

component.settingsDisable = true;

expect(component.settingForm.disable).toHaveBeenCalled();
});

it('should enable setting form when get settingDisable as false ', () => {
spyOn(component.settingForm, 'enable');

component.settingsDisable = false;

expect(component.settingForm.enable).toHaveBeenCalled();
});

it('should disable "Save" button when get settingDisable as true', () => {
component.settingsDisable = true;

const saveBtn = compiled.querySelector(
'.save-button'
) as HTMLButtonElement;

expect(saveBtn.disabled).toBeTrue();
});

it('should disable "Refresh" link when settingDisable', () => {
component.settingsDisable = true;

const refreshLink = compiled.querySelector(
'.message-link'
) as HTMLAnchorElement;

refreshLink.click();

expect(refreshLink.hasAttribute('aria-disabled')).toBeTrue();
expect(mockLoaderService.setLoading).not.toHaveBeenCalled();
});
});

describe('#closeSetting', () => {
beforeEach(() => {
component.ngOnInit();
Expand Down Expand Up @@ -152,32 +193,6 @@ describe('GeneralSettingsComponent', () => {

expect(mockSettingsStore.setDefaultFormValues).toHaveBeenCalled();
});

it('should disable setting form when get settingDisable as true ', () => {
spyOn(component.settingForm, 'disable');

component.settingsDisable = true;

expect(component.settingForm.disable).toHaveBeenCalled();
});

it('should enable setting form when get settingDisable as false ', () => {
spyOn(component.settingForm, 'enable');

component.settingsDisable = false;

expect(component.settingForm.enable).toHaveBeenCalled();
});

it('should disable "Save" button when get settingDisable as true', () => {
component.settingsDisable = true;

const saveBtn = compiled.querySelector(
'.save-button'
) as HTMLButtonElement;

expect(saveBtn.disabled).toBeTrue();
});
});

describe('#saveSetting', () => {
Expand Down
12 changes: 10 additions & 2 deletions modules/ui/src/app/pages/settings/general-settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/
import {
Component,
ElementRef,
EventEmitter,
Input,
OnDestroy,
OnInit,
Output,
ViewChild,
} from '@angular/core';
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { Subject, takeUntil, tap } from 'rxjs';
Expand All @@ -39,6 +41,7 @@ import { LoaderService } from '../../services/loader.service';
providers: [SettingsStore],
})
export class GeneralSettingsComponent implements OnInit, OnDestroy {
@ViewChild('reloadSettingLink') public reloadSettingLink!: ElementRef;
@Output() closeSettingEvent = new EventEmitter<void>();

private isSettingsDisable = false;
Expand Down Expand Up @@ -98,6 +101,9 @@ export class GeneralSettingsComponent implements OnInit, OnDestroy {
}

reloadSetting(): void {
if (this.settingsDisable) {
return;
}
this.showLoading();
this.getSystemInterfaces();
this.settingsStore.getSystemConfig();
Expand All @@ -122,11 +128,13 @@ export class GeneralSettingsComponent implements OnInit, OnDestroy {
}

private disableSettings(): void {
this.settingForm.disable();
this.settingForm?.disable();
this.reloadSettingLink?.nativeElement.setAttribute('aria-disabled', 'true');
}

private enableSettings(): void {
this.settingForm.enable();
this.settingForm?.enable();
this.reloadSettingLink?.nativeElement.removeAttribute('aria-disabled');
}

private createSettingForm() {
Expand Down