From 2b77e45872c7a4e5974045a53f118f648036eed8 Mon Sep 17 00:00:00 2001 From: Faust1 Date: Mon, 22 Apr 2024 14:02:56 +0200 Subject: [PATCH 1/6] chore: rework settings visualisation and export data code --- package.json | 1 - pnpm-lock.yaml | 3 --- src/app/services/storage.service.ts | 19 +------------------ src/app/settings/index.component.html | 8 ++++++-- src/app/settings/index.component.ts | 9 +++++++++ src/styles.css | 19 +++++++++++++++++++ 6 files changed, 35 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 7be8b63aa..c7d63a2d9 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,6 @@ "@ngx-grpc/core": "^3.1.2", "@ngx-grpc/grpc-web-client": "^3.1.2", "@ungap/structured-clone": "^1.2.0", - "defu": "^6.1.4", "jest-junit": "^16.0.0", "luxon": "^3.4.4", "rxjs": "~7.8.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ff31efb00..c66fb8f8f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -59,9 +59,6 @@ importers: '@ungap/structured-clone': specifier: ^1.2.0 version: 1.2.0 - defu: - specifier: ^6.1.4 - version: 6.1.4 jest-junit: specifier: ^16.0.0 version: 16.0.0 diff --git a/src/app/services/storage.service.ts b/src/app/services/storage.service.ts index d13776cf9..ae6818800 100644 --- a/src/app/services/storage.service.ts +++ b/src/app/services/storage.service.ts @@ -1,5 +1,4 @@ import { Injectable, inject } from '@angular/core'; -import { createDefu } from 'defu'; import { ExportedDefaultConfig, Key } from '@app/types/config'; import { DefaultConfigService } from './default-config.service'; @@ -76,7 +75,7 @@ export class StorageService implements Storage { } } - return this.#defu()(data, this.#defaultConfigService.exportedDefaultConfig); + return data; } /** @@ -146,20 +145,4 @@ export class StorageService implements Storage { restoreKeys(): Set { return new Set(this.keys); } - - /** - * Add keys to the defaultConfig attributes. If a key is linked to an array, the default config - * of the GUI will be override by the array. - * @returns - */ - #defu() { - // If array, we return the storage array instead of merging it with default config. - return createDefu((obj, key, value) => { - if (Array.isArray(obj[key]) && Array.isArray(value)) { - obj[key] = value; - return true; - } - return; - }); - } } diff --git a/src/app/settings/index.component.html b/src/app/settings/index.component.html index 775a1d3ff..76d3096f2 100644 --- a/src/app/settings/index.component.html +++ b/src/app/settings/index.component.html @@ -111,8 +111,12 @@
- - + + + {{fileName}}
diff --git a/src/app/settings/index.component.ts b/src/app/settings/index.component.ts index 0f73345b1..fb5a2b58d 100644 --- a/src/app/settings/index.component.ts +++ b/src/app/settings/index.component.ts @@ -77,6 +77,10 @@ main { gap: 1rem; } +.file { + align-items: center; +} + .actions { margin-top: 1rem; @@ -131,6 +135,7 @@ main { }) export class IndexComponent implements OnInit { sharableURL = ''; + fileName: string | undefined; keys: Set = new Set(); sidebar: Sidebar[] = []; @@ -323,4 +328,8 @@ export class IndexComponent implements OnInit { #sortKeys(keys: Set): Set { return new Set([...keys].sort((a, b) => a.localeCompare(b))); } + + addConfigFile(event: Event): void { + this.fileName = (event.target as HTMLInputElement).files?.item(0)?.name; + } } diff --git a/src/styles.css b/src/styles.css index 891c89681..7b8dc6fcc 100644 --- a/src/styles.css +++ b/src/styles.css @@ -67,4 +67,23 @@ app-table-index-actions-toolbar, app-table-dashboard-actions-toolbar { height: auto !important; min-height: 64px !important; padding: 1rem !important; +} + +.custom-file-upload { + border: 1px solid rgba(189, 189, 189, 0.6); + border-radius: 0.4em; + display: flex; + justify-content: space-between; + align-items: center; + padding: 6px 12px; + cursor: pointer; + width: 60px; +} + +.custom-file-upload:hover { + background-color: rgba(189, 189, 189, 0.3); +} + +input[type="file"] { + display: none; } \ No newline at end of file From 2d14cee2a609544144f24a0565d06d2d783ca7bb Mon Sep 17 00:00:00 2001 From: Faust1 Date: Mon, 22 Apr 2024 15:52:32 +0200 Subject: [PATCH 2/6] feat: edit-name-line and add-name-line dialog rework --- ...e-dashboard-actions-toolbar.component.html | 2 +- .../components/add-line-dialog.component.html | 30 +++++++ .../add-line-dialog.component.spec.ts | 56 +++++++----- .../components/add-line-dialog.component.ts | 71 ++++++++++++--- .../edit-name-line-dialog.component.html | 14 +++ .../edit-name-line-dialog.component.ts | 32 +++---- .../components/form-name-line.component.html | 29 ------ .../form-name-line.component.spec.ts | 46 ---------- .../components/form-name-line.component.ts | 88 ------------------- .../lines/task-by-status-line.component.ts | 2 +- .../reorganize-lines-dialog.component.ts | 2 +- .../types/components/dashboard-line-table.ts | 2 +- src/app/types/dialog.ts | 9 +- 13 files changed, 162 insertions(+), 221 deletions(-) create mode 100644 src/app/dashboard/components/add-line-dialog.component.html create mode 100644 src/app/dashboard/components/edit-name-line-dialog.component.html delete mode 100644 src/app/dashboard/components/form-name-line.component.html delete mode 100644 src/app/dashboard/components/form-name-line.component.spec.ts delete mode 100644 src/app/dashboard/components/form-name-line.component.ts diff --git a/src/app/components/table-dashboard-actions-toolbar.component.html b/src/app/components/table-dashboard-actions-toolbar.component.html index 8109a3b21..3ba0c1f2a 100644 --- a/src/app/components/table-dashboard-actions-toolbar.component.html +++ b/src/app/components/table-dashboard-actions-toolbar.component.html @@ -17,7 +17,7 @@ + + + \ No newline at end of file diff --git a/src/app/dashboard/components/add-line-dialog.component.spec.ts b/src/app/dashboard/components/add-line-dialog.component.spec.ts index dd2b3032d..cc00b1681 100644 --- a/src/app/dashboard/components/add-line-dialog.component.spec.ts +++ b/src/app/dashboard/components/add-line-dialog.component.spec.ts @@ -1,35 +1,49 @@ -import { TestBed } from '@angular/core/testing'; -import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import { MatDialogRef } from '@angular/material/dialog'; +import { AddLineDialogResult } from '@app/types/dialog'; import { AddLineDialogComponent } from './add-line-dialog.component'; -describe('AddLineDialogComponent', () => { - let component: AddLineDialogComponent; - - const mockMatDialogRef = { +describe('FormNameLineComponent', () => { + const mockDialogRef = { close: jest.fn() - }; + } as unknown as MatDialogRef; - beforeEach(() => { - component = TestBed.configureTestingModule({ - providers: [ - AddLineDialogComponent, - { provide: MatDialogRef, useValue: mockMatDialogRef }, - { provide: MAT_DIALOG_DATA, useValue: {} } - ] - }).inject(AddLineDialogComponent); + const component = new AddLineDialogComponent(mockDialogRef, { + name: 'line', + type: 'Applications' }); + component.ngOnInit(); it('should create', () => { expect(component).toBeTruthy(); }); - it('should close with result on submit', () => { - component.onSubmit({name:'result', type: 'Tasks'}); - expect(mockMatDialogRef.close).toHaveBeenCalledWith({name:'result', type: 'Tasks'}); + it('should init', () => { + expect(component.lineForm.value.name).toEqual('line'); + expect(component.lineForm.value.type).toEqual('Applications'); + }); + + describe('onSubmit', () => { + it('should submit if there is a value', () => { + component.lineForm.value.name = 'line'; + component.lineForm.value.type = 'Applications'; + component.onSubmit(); + expect(mockDialogRef.close).toHaveBeenCalledWith({name: 'line', type: 'Applications'}); + }); + + it('should submit empty if there no value', () => { + component.lineForm.value.name = null; + component.lineForm.value.type = null; + component.onSubmit(); + expect(mockDialogRef.close).toHaveBeenCalledWith({name:'', type: ''}); + }); + }); + + it('should cancel', () => { + component.onCancel(); + expect(mockDialogRef.close).toHaveBeenCalled(); }); - it('should close on "no" click', () => { - component.onNoClick(); - expect(mockMatDialogRef.close).toHaveBeenCalled(); + it('should track by options', () => { + expect(component.trackByType(0, 'Applications')).toEqual('Applications'); }); }); \ No newline at end of file diff --git a/src/app/dashboard/components/add-line-dialog.component.ts b/src/app/dashboard/components/add-line-dialog.component.ts index 3b92d25b3..1af1fb402 100644 --- a/src/app/dashboard/components/add-line-dialog.component.ts +++ b/src/app/dashboard/components/add-line-dialog.component.ts @@ -1,38 +1,81 @@ -import { Component, Inject } from '@angular/core'; +import { NgFor, NgIf } from '@angular/common'; +import { Component, Inject, OnInit } from '@angular/core'; +import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; +import { MatButtonModule } from '@angular/material/button'; import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatInputModule } from '@angular/material/input'; +import { MatSelectModule } from '@angular/material/select'; import { AddLineDialogData, AddLineDialogResult } from '@app/types/dialog'; -import { FormNameLineComponent } from './form-name-line.component'; +import { LineType } from '../types'; @Component({ selector: 'app-add-line-dialog', - template: ` -

Add a line

- - - `, + templateUrl: 'add-line-dialog.component.html', styles: [` +mat-dialog-content { + padding-top: 0!important; + overflow: visible!important; + + display: grid; + grid-template-columns: repeat(2, 1fr); + gap: 1rem; +} `], standalone: true, providers: [], imports: [ MatDialogModule, - FormNameLineComponent + NgIf, + NgFor, + MatDialogModule, + MatButtonModule, + MatFormFieldModule, + MatInputModule, + ReactiveFormsModule, + MatSelectModule ] }) -export class AddLineDialogComponent { +export class AddLineDialogComponent implements OnInit { + + types: LineType[] = ['CountStatus', 'Applications', 'Sessions', 'Tasks', 'Partitions', 'Results']; + + lineForm = new FormGroup({ + name: new FormControl('', [ + Validators.required, + ]), + type: new FormControl('', [ + Validators.required + ]) + }); + constructor( public _dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: AddLineDialogData, ) {} - onSubmit(result: AddLineDialogResult) { + ngOnInit(): void { + if(this.data && this.data.name && this.data.type) { + this.lineForm.setValue({ + name: this.data.name, + type: this.data.type + }); + } + } + + onSubmit() { + const result = { + name: this.lineForm.value.name ?? '', + type: this.lineForm.value.type ?? '' + } as AddLineDialogResult; this._dialogRef.close(result); } - onNoClick(): void { + onCancel(): void { this._dialogRef.close(); } + + trackByType(_: number, item: LineType) { + return item; + } } diff --git a/src/app/dashboard/components/edit-name-line-dialog.component.html b/src/app/dashboard/components/edit-name-line-dialog.component.html new file mode 100644 index 000000000..4e5d77a12 --- /dev/null +++ b/src/app/dashboard/components/edit-name-line-dialog.component.html @@ -0,0 +1,14 @@ +

Edit the line name

+ +
+ + + Name + + + + + + + +
\ No newline at end of file diff --git a/src/app/dashboard/components/edit-name-line-dialog.component.ts b/src/app/dashboard/components/edit-name-line-dialog.component.ts index 304242665..30930432b 100644 --- a/src/app/dashboard/components/edit-name-line-dialog.component.ts +++ b/src/app/dashboard/components/edit-name-line-dialog.component.ts @@ -1,31 +1,26 @@ import { Component, Inject, OnInit } from '@angular/core'; +import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; +import { MatButtonModule } from '@angular/material/button'; import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog'; +import { MatInputModule } from '@angular/material/input'; import { EditNameLineData, EditNameLineResult } from '@app/types/dialog'; -import { FormNameLineComponent } from './form-name-line.component'; @Component({ selector: 'app-edit-name-line-dialog', - template: ` -

Edit the name line

- - - `, - styles: [` - `], + templateUrl: 'edit-name-line-dialog.component.html', standalone: true, providers: [ ], imports: [ - FormNameLineComponent, MatDialogModule, + MatInputModule, + MatButtonModule, + ReactiveFormsModule, ] }) export class EditNameLineDialogComponent implements OnInit { name: string; + nameForm: FormGroup; constructor( public _dialogRef: MatDialogRef, @@ -34,10 +29,17 @@ export class EditNameLineDialogComponent implements OnInit { ngOnInit(): void { this.name = this.data.name; + this.nameForm = new FormGroup({ + name: new FormControl(this.name, [ + Validators.required, + Validators.minLength(1) + ]) + }); } - onSubmit(result: {name: string, type: string}) { - this._dialogRef.close(result); + onSubmit() { + const name = this.nameForm.get('name')?.value; + this._dialogRef.close(name ?? this.name); } onNoClick(): void { diff --git a/src/app/dashboard/components/form-name-line.component.html b/src/app/dashboard/components/form-name-line.component.html deleted file mode 100644 index 01ee07dea..000000000 --- a/src/app/dashboard/components/form-name-line.component.html +++ /dev/null @@ -1,29 +0,0 @@ -
- - - - Name - - - Name is required - - - - - Type - - {{option}} - - - Type is required - - - - - - - - - -
- \ No newline at end of file diff --git a/src/app/dashboard/components/form-name-line.component.spec.ts b/src/app/dashboard/components/form-name-line.component.spec.ts deleted file mode 100644 index 93900861f..000000000 --- a/src/app/dashboard/components/form-name-line.component.spec.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { FormNameLineComponent } from './form-name-line.component'; - -describe('FormNameLineComponent', () => { - const component = new FormNameLineComponent(); - component.line = 'line'; - component.type = 'Applications'; - component.ngOnInit(); - - it('should create', () => { - expect(component).toBeTruthy(); - }); - - it('should init', () => { - expect(component.lineForm.value.name).toEqual('line'); - expect(component.lineForm.value.type).toEqual('Applications'); - }); - - describe('onSubmit', () => { - - const spySubmit = jest.spyOn(component.submitChange, 'emit'); - - it('should submit if there is a value', () => { - component.lineForm.value.name = 'line'; - component.lineForm.value.type = 'Applications'; - component.onSubmit(); - expect(spySubmit).toHaveBeenCalledWith({name: 'line', type: 'Applications'}); - }); - - it('should submit empty if there no value', () => { - component.lineForm.value.name = null; - component.lineForm.value.type = null; - component.onSubmit(); - expect(spySubmit).toHaveBeenCalledWith({name:'', type: ''}); - }); - }); - - it('should cancel', () => { - const spyCancel = jest.spyOn(component.cancelChange, 'emit'); - component.onCancel(); - expect(spyCancel).toHaveBeenCalled(); - }); - - it('should track by status', () => { - expect(component.trackByStatus(0, {value: 'value', name: 'name'})).toEqual('value'); - }); -}); \ No newline at end of file diff --git a/src/app/dashboard/components/form-name-line.component.ts b/src/app/dashboard/components/form-name-line.component.ts deleted file mode 100644 index 567629655..000000000 --- a/src/app/dashboard/components/form-name-line.component.ts +++ /dev/null @@ -1,88 +0,0 @@ -import { NgFor, NgIf } from '@angular/common'; -import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; -import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; -import { MatButtonModule } from '@angular/material/button'; -import { MatCheckboxModule } from '@angular/material/checkbox'; -import { MatDialogModule } from '@angular/material/dialog'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatInputModule } from '@angular/material/input'; -import { MatSelectModule } from '@angular/material/select'; -import { AddLineDialogResult } from '@app/types/dialog'; -import { LineType } from '../types'; - -@Component({ - selector: 'app-form-name-line', - templateUrl: './form-name-line.component.html', - styles: [` -mat-dialog-content { - padding-top: 0!important; - overflow: visible!important; - - display: grid; - grid-template-columns: repeat(2, 1fr); - gap: 1rem; -} - `], - standalone: true, - providers: [ - ], - imports: [ - NgIf, - NgFor, - MatDialogModule, - MatButtonModule, - MatCheckboxModule, - MatFormFieldModule, - MatInputModule, - ReactiveFormsModule, - MatSelectModule - ] -}) -export class FormNameLineComponent implements OnInit { - @Input() line: string | null = null; - @Input() type: string | null = null; - types: LineType[] = ['CountStatus', 'Applications', 'Sessions', 'Tasks', 'Partitions', 'Results']; - - @Output() cancelChange = new EventEmitter(); - @Output() submitChange = new EventEmitter(); - - lineForm = new FormGroup({ - name: new FormControl('', [ - Validators.required, - ]), - type: new FormControl('', [ - Validators.required - ]) - }); - - ngOnInit() { - - if(this.line && this.type) { - this.lineForm.setValue({ - name: this.line, - type: this.type - }); - } - - } - - onSubmit() { - const result = { - name: this.lineForm.value.name ?? '', - type: this.lineForm.value.type ?? '' - } as AddLineDialogResult; - this.submitChange.emit(result); - } - - onCancel() { - this.cancelChange.emit(); - } - - trackByStatus(_: number, item: { value: string, name: string }) { - return item.value; - } - - trackByOption(_: number, item: string) { - return item; - } -} diff --git a/src/app/dashboard/components/lines/task-by-status-line.component.ts b/src/app/dashboard/components/lines/task-by-status-line.component.ts index 91e375e6d..6954422e6 100644 --- a/src/app/dashboard/components/lines/task-by-status-line.component.ts +++ b/src/app/dashboard/components/lines/task-by-status-line.component.ts @@ -167,7 +167,7 @@ export class TaskByStatusLineComponent implements OnInit, AfterViewInit,OnDestro dialogRef.afterClosed().subscribe((result) => { if (!result) return; - this.line.name = result.name; + this.line.name = result; this.lineChange.emit(); }); } diff --git a/src/app/dashboard/components/reorganize-lines-dialog.component.ts b/src/app/dashboard/components/reorganize-lines-dialog.component.ts index 8a3b77ad4..15ef0ec82 100644 --- a/src/app/dashboard/components/reorganize-lines-dialog.component.ts +++ b/src/app/dashboard/components/reorganize-lines-dialog.component.ts @@ -121,7 +121,7 @@ export class ReorganizeLinesDialogComponent implements OnInit { const selectedLine = this.lines[index]; const changeSelectedNameLine = (line: Line, oldName: string): void => { if(line.name === oldName) { - line.name = result.name; + line.name = result; } }; this.lines.map(line => changeSelectedNameLine(line, selectedLine.name)); diff --git a/src/app/types/components/dashboard-line-table.ts b/src/app/types/components/dashboard-line-table.ts index 2db27e62e..766292ca4 100644 --- a/src/app/types/components/dashboard-line-table.ts +++ b/src/app/types/components/dashboard-line-table.ts @@ -133,7 +133,7 @@ export abstract class DashboardLineTableComponent { if (result) { - this.line.name = result.name; + this.line.name = result; this.lineChange.emit(); } }); diff --git a/src/app/types/dialog.ts b/src/app/types/dialog.ts index 717be110d..5a00fa42c 100644 --- a/src/app/types/dialog.ts +++ b/src/app/types/dialog.ts @@ -51,7 +51,10 @@ export interface ViewArrayDialogData { export type ViewArrayDialogResult = Record; -export type AddLineDialogData = Record; +export type AddLineDialogData = { + name: string; + type: LineType | ''; +}; export type AddLineDialogResult = { name: string; @@ -62,9 +65,7 @@ export type EditNameLineData = { name: string; }; -export type EditNameLineResult = { - name: string; -}; +export type EditNameLineResult = string; export type ReorganizeLinesDialogData = { lines: Line[]; From 44b8f1cac81332c56b7f63274b6303fcf17495d3 Mon Sep 17 00:00:00 2001 From: Faust1 Date: Mon, 22 Apr 2024 16:10:35 +0200 Subject: [PATCH 3/6] update failling tests --- .../edit-name-line-dialog-component.spec.ts | 40 ----------------- .../edit-name-line-dialog.component.spec.ts | 44 +++++++++++++++++++ .../edit-name-line-dialog.component.ts | 12 ++--- .../task-by-status-line.component.spec.ts | 6 +-- 4 files changed, 54 insertions(+), 48 deletions(-) delete mode 100644 src/app/dashboard/components/edit-name-line-dialog-component.spec.ts create mode 100644 src/app/dashboard/components/edit-name-line-dialog.component.spec.ts diff --git a/src/app/dashboard/components/edit-name-line-dialog-component.spec.ts b/src/app/dashboard/components/edit-name-line-dialog-component.spec.ts deleted file mode 100644 index bc9c8d28d..000000000 --- a/src/app/dashboard/components/edit-name-line-dialog-component.spec.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { TestBed } from '@angular/core/testing'; -import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; -import { EditNameLineDialogComponent } from './edit-name-line-dialog.component'; - -describe('', () => { - let component: EditNameLineDialogComponent; - - const mockMatDialogRef = { - close: jest.fn() - }; - - beforeEach(() => { - component = TestBed.configureTestingModule({ - providers: [ - EditNameLineDialogComponent, - { provide: MatDialogRef, useValue: mockMatDialogRef }, - { provide: MAT_DIALOG_DATA, useValue: {name: 'name'} } - ] - }).inject(EditNameLineDialogComponent); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); - - it('should init', () => { - component.ngOnInit(); - expect(component.name).toEqual('name'); - }); - - it('should close with result on submit', () => { - component.onSubmit({name:'result', type: 'Tasks'}); - expect(mockMatDialogRef.close).toHaveBeenCalledWith({name:'result', type: 'Tasks'}); - }); - - it('should close on "no" click', () => { - component.onNoClick(); - expect(mockMatDialogRef.close).toHaveBeenCalled(); - }); -}); \ No newline at end of file diff --git a/src/app/dashboard/components/edit-name-line-dialog.component.spec.ts b/src/app/dashboard/components/edit-name-line-dialog.component.spec.ts new file mode 100644 index 000000000..be8971230 --- /dev/null +++ b/src/app/dashboard/components/edit-name-line-dialog.component.spec.ts @@ -0,0 +1,44 @@ +import { MatDialogRef } from '@angular/material/dialog'; +import { EditNameLineResult } from '@app/types/dialog'; +import { EditNameLineDialogComponent } from './edit-name-line-dialog.component'; + +describe('', () => { + const mockMatDialogRef = { + close: jest.fn() + } as unknown as MatDialogRef; + + const defaultName = 'Tasks'; + + const component = new EditNameLineDialogComponent(mockMatDialogRef, { + name: defaultName + }); + + component.ngOnInit(); + + it('should create', () => { + expect(component).toBeTruthy(); + }); + + it('should init', () => { + expect(component.nameForm).toBeDefined(); + }); + + describe('onSubmit', () => { + it('should close with result', () => { + component.nameForm.setValue({name: 'result'}); + component.onSubmit(); + expect(mockMatDialogRef.close).toHaveBeenCalledWith('result'); + }); + + it('should close with previous name', () => { + component.nameForm.setValue({name: ''}); + component.onSubmit(); + expect(mockMatDialogRef.close).toHaveBeenCalledWith(defaultName); + }); + }); + + it('should close on "no" click', () => { + component.onNoClick(); + expect(mockMatDialogRef.close).toHaveBeenCalled(); + }); +}); \ No newline at end of file diff --git a/src/app/dashboard/components/edit-name-line-dialog.component.ts b/src/app/dashboard/components/edit-name-line-dialog.component.ts index 30930432b..b4e9f2666 100644 --- a/src/app/dashboard/components/edit-name-line-dialog.component.ts +++ b/src/app/dashboard/components/edit-name-line-dialog.component.ts @@ -19,7 +19,6 @@ import { EditNameLineData, EditNameLineResult } from '@app/types/dialog'; ] }) export class EditNameLineDialogComponent implements OnInit { - name: string; nameForm: FormGroup; constructor( @@ -28,9 +27,8 @@ export class EditNameLineDialogComponent implements OnInit { ) {} ngOnInit(): void { - this.name = this.data.name; this.nameForm = new FormGroup({ - name: new FormControl(this.name, [ + name: new FormControl(this.data.name, [ Validators.required, Validators.minLength(1) ]) @@ -38,8 +36,12 @@ export class EditNameLineDialogComponent implements OnInit { } onSubmit() { - const name = this.nameForm.get('name')?.value; - this._dialogRef.close(name ?? this.name); + if (this.nameForm.invalid) { + this._dialogRef.close(this.data.name); + } else { + const name = this.nameForm.value.name; + this._dialogRef.close(name); + } } onNoClick(): void { diff --git a/src/app/dashboard/components/lines/task-by-status-line.component.spec.ts b/src/app/dashboard/components/lines/task-by-status-line.component.spec.ts index 3e161ae55..aa6783600 100644 --- a/src/app/dashboard/components/lines/task-by-status-line.component.spec.ts +++ b/src/app/dashboard/components/lines/task-by-status-line.component.spec.ts @@ -12,7 +12,7 @@ import { TasksStatusesGroup } from '../../types'; describe('TaskByStatusLineComponent', () => { let component: TaskByStatusLineComponent; - let dialogRefSubject: Observable<{name: string} | {groups: TasksStatusesGroup[]} | null>; + let dialogRefSubject: Observable; const mockMatDialog = { open: jest.fn(() => { return { @@ -133,7 +133,7 @@ describe('TaskByStatusLineComponent', () => { it('should update the line name on edit name line', () => { const newName = 'newName'; - dialogRefSubject = of({name: newName}); + dialogRefSubject = of(newName); component.onEditNameLine(newName); expect(component.line.name).toEqual(newName); }); @@ -148,7 +148,7 @@ describe('TaskByStatusLineComponent', () => { it('should emit on edit name', () => { const spyLineChange = jest.spyOn(component.lineChange, 'emit'); const newName = 'newName'; - dialogRefSubject = of({name: newName}); + dialogRefSubject = of(newName); component.onEditNameLine(newName); expect(spyLineChange).toHaveBeenCalled(); }); From 21f161be5265a20147c14a5af8b11b4ce5f19d65 Mon Sep 17 00:00:00 2001 From: Faust1 Date: Mon, 22 Apr 2024 16:12:47 +0200 Subject: [PATCH 4/6] update tests --- .../components/reorganize-lines-dialog.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/dashboard/components/reorganize-lines-dialog.component.spec.ts b/src/app/dashboard/components/reorganize-lines-dialog.component.spec.ts index a54765e89..73d3cba76 100644 --- a/src/app/dashboard/components/reorganize-lines-dialog.component.spec.ts +++ b/src/app/dashboard/components/reorganize-lines-dialog.component.spec.ts @@ -115,7 +115,7 @@ describe('ReorganizeLinesDialogComponent', () => { }); it('should edit a name line', () => { - const newName = {name: 'newLineName'}; + const newName = 'newLineName'; dialogRef$ = of(newName); component.onEditNameLine(component.lines[1], 1); expect(component.lines[1].name).toEqual('newLineName'); From 866535aa48cab90aeb9681035403c3690b059fe2 Mon Sep 17 00:00:00 2001 From: Faust1 Date: Mon, 22 Apr 2024 16:15:32 +0200 Subject: [PATCH 5/6] address sonarcloud issue --- src/app/dashboard/components/add-line-dialog.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/dashboard/components/add-line-dialog.component.ts b/src/app/dashboard/components/add-line-dialog.component.ts index 1af1fb402..86f8e81c1 100644 --- a/src/app/dashboard/components/add-line-dialog.component.ts +++ b/src/app/dashboard/components/add-line-dialog.component.ts @@ -51,11 +51,11 @@ export class AddLineDialogComponent implements OnInit { constructor( public _dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: AddLineDialogData, + @Inject(MAT_DIALOG_DATA) public data?: AddLineDialogData, ) {} ngOnInit(): void { - if(this.data && this.data.name && this.data.type) { + if(this.data?.name && this.data?.type) { this.lineForm.setValue({ name: this.data.name, type: this.data.type From 85ef8b34922228b82a27998b363deb0c30968004 Mon Sep 17 00:00:00 2001 From: Faust1 Date: Mon, 22 Apr 2024 16:41:39 +0200 Subject: [PATCH 6/6] update css and html --- src/app/settings/index.component.html | 2 +- src/styles.css | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app/settings/index.component.html b/src/app/settings/index.component.html index 76d3096f2..4235112b8 100644 --- a/src/app/settings/index.component.html +++ b/src/app/settings/index.component.html @@ -113,7 +113,7 @@
{{fileName}} diff --git a/src/styles.css b/src/styles.css index 7b8dc6fcc..ce6658777 100644 --- a/src/styles.css +++ b/src/styles.css @@ -77,7 +77,10 @@ app-table-index-actions-toolbar, app-table-dashboard-actions-toolbar { align-items: center; padding: 6px 12px; cursor: pointer; - width: 60px; +} + +.custom-file-upload > span { + padding-left: 10px; } .custom-file-upload:hover {