Skip to content

Commit

Permalink
feat: inspection display components (#1188)
Browse files Browse the repository at this point in the history
Co-authored-by: faustin <[email protected]>
Co-authored-by: ngruelaneo <[email protected]>
  • Loading branch information
3 people authored Aug 1, 2024
1 parent 7b3c401 commit 557055b
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/app/components/inspection/inspection-card.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<mat-card>
<app-inspection [fields]="fields" [optionsFields]="optionsFields" [data]="data" [statuses]="statuses" />
</mat-card>
81 changes: 81 additions & 0 deletions src/app/components/inspection/inspection-card.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { TaskStatus } from '@aneoconsultingfr/armonik.api.angular';
import { TaskOptions, TaskRaw } from '@app/tasks/types';
import { Field } from '@app/types/column.type';
import { Status } from '@app/types/data';
import { InspectionCardComponent } from './inspection-card.component';

describe('InspectionCardComponent', () => {
const component = new InspectionCardComponent<TaskRaw, TaskStatus, TaskOptions>();

const data: TaskRaw = {
id: 'taskId',
options: {
applicationName: 'string',
}
} as TaskRaw;

const fields: Field<TaskRaw>[] = [
{
key: 'id',
type: 'link',
link: 'tasks'
},
{
key: 'sessionId',
type: 'link',
link: 'sessions'
},
{
key: 'options',
type: 'object'
},
{
key: 'createdAt',
type: 'date'
}
];

const optionsFields: Field<TaskOptions>[] = [
{
key: 'applicationName',
},
{
key: 'options',
type: 'object'
}
];

const statuses = {
[TaskStatus.TASK_STATUS_COMPLETED]: 'Completed',
[TaskStatus.TASK_STATUS_CANCELLING]: 'Cancelling',
} as Record<Status, string>;

beforeEach(() => {
component.fields = fields;
component.optionsFields = optionsFields;
component.data = data;
component.statuses = statuses;
});

it('should run', () => {
expect(component).toBeTruthy();
});

describe('initialisation', () => {
it('should init fields', () => {
expect(component.fields).toEqual(fields);
});

it('should init options fields', () => {
expect(component.optionsFields).toEqual(optionsFields);
});

it('should init data', () => {
expect(component.data).toEqual(data);
});

it('should init statuses', () => {
expect(component.statuses).toEqual(statuses);
});
});
});
24 changes: 24 additions & 0 deletions src/app/components/inspection/inspection-card.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { MatCardModule } from '@angular/material/card';
import { TaskOptions } from '@app/tasks/types';
import { Field } from '@app/types/column.type';
import { DataRaw, Status } from '@app/types/data';
import { InspectionComponent } from './inspection.component';

@Component({
selector: 'app-inspection-card',
templateUrl: 'inspection-card.component.html',
standalone: true,
imports: [
MatCardModule,
InspectionComponent
],
styleUrl: '../../../inspections.css',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class InspectionCardComponent<T extends DataRaw, S extends Status, O extends TaskOptions | null = null> {
@Input({ required: false }) fields: Field<T>[];
@Input({ required: false }) optionsFields: Field<O>[];
@Input({ required: false }) statuses: Record<S, string>;
@Input({ required: true }) data: T | null;
}
11 changes: 11 additions & 0 deletions src/app/components/inspection/inspection.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<app-inspection-object [fields]="fields" [statuses]="statuses" [data]="data" />
@if(optionsFields) {
<mat-accordion>
<mat-expansion-panel id="options">
<mat-expansion-panel-header>
<strong>Options</strong>
</mat-expansion-panel-header>
<app-inspection-object [fields]="optionsFields" [statuses]="statuses" [data]="options" />
</mat-expansion-panel>
</mat-accordion>
}
80 changes: 80 additions & 0 deletions src/app/components/inspection/inspection.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { TaskStatus } from '@aneoconsultingfr/armonik.api.angular';
import { TaskOptions, TaskRaw } from '@app/tasks/types';
import { Field } from '@app/types/column.type';
import { InspectionComponent } from './inspection.component';

describe('InspectionComponent', () => {
const component = new InspectionComponent<TaskRaw, TaskStatus, TaskOptions>();

const data: TaskRaw = {
id: 'taskId',
options: {
applicationName: 'string',
}
} as TaskRaw;

const optionsFields: Field<TaskOptions>[] = [
{
key: 'applicationName',
},
{
key: 'options',
type: 'object'
}
];

const fields: Field<TaskRaw>[] = [
{
key: 'id',
type: 'link',
link: 'tasks'
},
{
key: 'sessionId',
type: 'link',
link: 'sessions'
},
{
key: 'options',
type: 'object'
},
{
key: 'createdAt',
type: 'date'
}
];

const statuses: Record<TaskStatus, string> = {
0: 'Undefined',
1: 'completed'
} as Record<TaskStatus, string>;

beforeEach(() => {
component.fields = fields;
component.optionsFields = optionsFields;
component.data = data;
component.statuses = statuses;
});

describe('initialisation', () => {
it('should set fields without options fields', () => {
expect(component.fields).toEqual(fields);
});

it('should set optionsFields', () => {
expect(component.optionsFields).toEqual(optionsFields);
});

it('should set data', () => {
expect(component.data).toEqual(data);
});

it('should set "options" object', () => {
expect(component.options).toEqual(data.options);
});

it('should set statuses', () => {
expect(component.statuses).toEqual(statuses);
});
});
});
52 changes: 52 additions & 0 deletions src/app/components/inspection/inspection.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { MatExpansionModule } from '@angular/material/expansion';
import { TaskOptions } from '@app/tasks/types';
import { Field } from '@app/types/column.type';
import { DataRaw, Status } from '@app/types/data';
import { InspectionObjectComponent } from './inspection-object.component';

@Component({
selector: 'app-inspection',
templateUrl: 'inspection.component.html',
standalone: true,
imports: [
InspectionObjectComponent,
MatExpansionModule,
],
changeDetection: ChangeDetectionStrategy.OnPush,
styleUrl: '../../../inspections.css',
})
export class InspectionComponent<T extends DataRaw, S extends Status, O extends TaskOptions | null = null> {
private _data: T = {} as T;
private _options: NonNullable<O> = {} as NonNullable<O>;

/**
* Displayed fields and their types.
* If none are provided, every field will be displayed as a "string".
*/
@Input({ required: false }) fields: Field<T>[] | undefined;

@Input({ required: false }) optionsFields: Field<O>[] | undefined;

@Input({ required: true }) set data(entry: T | null) {
if (entry) {
this._data = entry;
if (entry['options' as keyof (T | O)]) {
this._options = entry['options' as keyof (T | O)] as NonNullable<O>;
}
}
}

/**
* Required to display a status label.
*/
@Input({ required: false }) statuses: Record<S, string>;

get data(): T {
return this._data;
}

get options() {
return this._options;
}
}

1 comment on commit 557055b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 99%
99.93% (4390/4393) 100% (846/846) 99.74% (1183/1186)

JUnit

Tests Skipped Failures Errors Time
1634 0 💤 0 ❌ 0 🔥 1m 13s ⏱️
Files coverage (99%)
File% Stmts% Branch% Funcs% LinesUncovered Line #s
All files99.9310099.7499.95 
applications100100100100 
   index.component.html100100100100 
   index.component.ts100100100100 
applications/components100100100100 
   table.component.html100100100100 
   table.component.ts100100100100 
applications/services100100100100 
   applications-filters.service.ts100100100100 
   applications-grpc.service.ts100100100100 
   applications-index.service.ts100100100100 
components99.6610098.8299.62 
   actions-toolbar-group.component.ts100100100100 
   actions-toolbar.component.ts100100100100 
   auto-complete.component.html100100100100 
   auto-complete.component.ts100100100100 
   auto-refresh-button.component.html100100100100 
   auto-refresh-button.component.ts100100100100 
   auto-refresh-dialog.component.html100100100100 
   auto-refresh-dialog.component.ts100100100100 
   columns-button.component.ts951008094.7342
   columns-modify-dialog.component.html100100100100 
   columns-modify-dialog.component.ts100100100100 
   count-tasks-by-status.component.ts100100100100 
   icon-picker-dialog.component.html100100100100 
   icon-picker-dialog.component.ts100100100100 
   inspect-list.component.html100100100100 
   inspect-list.component.ts100100100100 
   inspection-header.component.html100100100100 
   inspection-header.component.ts100100100100 
   inspection-toolbar.component.html100100100100 
   inspection-toolbar.component.ts100100100100 
   manage-custom-dialog.component.html100100100100 
   manage-custom-dialog.component.ts100100100100 
   page-header.component.html100100100100 
   page-header.component.ts100100100100 
   page-section-header.component.ts100100100100 
   page-section.component.ts100100100100 
   refresh-button.component.ts92.31007591.6632
   share-url.component.ts100100100100 
   show-action-area.component.html100100100100 
   show-action-area.component.ts100100100100 
   show-actions.component.html100100100100 
   show-actions.component.ts100100100100 
   show-card-content.component.html100100100100 
   show-card-content.component.ts100100100100 
   show-card.component.html100100100100 
   show-card.component.ts100100100100 
   show-page.component.html100100100100 
   show-page.component.ts100100100100 
   spinner.component.ts100100100100 
   table-actions-toolbar.component.html100100100100 
   table-actions-toolbar.component.ts100100100100 
   table-container.component.ts100100100100 
   table-dashboard-actions-toolbar.component.html100100100100 
   table-dashboard-actions-toolbar.component.ts100100100100 
   table-index-actions-toolbar.component.html100100100100 
   table-index-actions-toolbar.component.ts100100100100 
   view-tasks-by-status.component.ts100100100100 
components/filters100100100100 
   filters-chips.component.html100100100100 
   filters-chips.component.ts100100100100 
   filters-dialog-and.component.html100100100100 
   filters-dialog-and.component.ts100100100100 
   filters-dialog-filter-field.component.html100100100100 
   filters-dialog-filter-field.component.ts100100100100 
   filters-dialog-input.component.html100100100100 
   filters-dialog-input.component.ts100100100100 
   filters-dialog-or.component.html100100100100 
   filters-dialog-or.component.ts100100100100 
   filters-dialog.component.html100100100100 
   filters-dialog.component.ts100100100100 
   filters-toolbar.component.html100100100100 
   filters-toolbar.component.ts100100100100 
components/inspection100100100100 
   field-content.component.html100100100100 
   field-content.component.ts100100100100 
   inspection-card.component.html100100100100 
   inspection-card.component.ts100100100100 
   inspection-list-grid.component.html100100100100 
   inspection-list-grid.component.ts100100100100 
   inspection-object.component.html100100100100 
   inspection-object.component.ts100100100100 
   inspection.component.html100100100100 
   inspection.component.ts100100100100 
components/navigation100100100100 
   add-external-service-dialog.component.html100100100100 
   add-external-service-dialog.component.ts100100100100 
   change-language-button.component.html100100100100 
   change-language-button.component.ts100100100100 
   edit-external-service-dialog.component.html100100100100 
   edit-external-service-dialog.component.ts100100100100 
   external-services.component.html100100100100 
   external-services.component.ts100100100100 
   form-external-service.component.html100100100100 
   form-external-service.component.ts100100100100 
   manage-external-services-dialog.component.html100100100100 
   manage-external-services-dialog.component.ts100100100100 
   navigation.component.html100100100100 
   navigation.component.ts100100100100 
   theme-selector.component.html100100100100 
   theme-selector.component.ts100100100100 
components/statuses100100100100 
   add-statuses-group-dialog.component.ts100100100100 
   edit-status-group-dialog.component.ts100100100100 
   form-statuses-group.component.html100100100100 
   form-statuses-group.component.ts100100100100 
   manage-groups-dialog.component.html100100100100 
   manage-groups-dialog.component.ts100100100100 
components/table100100100100 
   table-actions.component.html100100100100 
   table-actions.component.ts100100100100 
   table-cell.component.html100100100100 
   table-cell.component.ts100100100100 
   table-column-header.component.html100100100100 
   table-column-header.component.ts100100100100 
   table-empty-data.component.ts100100100100 
   table-inspect-object-dialog.component.html100100100100 
   table-inspect-object-dialog.component.ts100100100100 
   table-inspect-object.component.html100100100100 
   table-inspect-object.component.ts100100100100 
   table.component.html100100100100 
   table.component.ts100100100100 
dashboard100100100100 
   index.component.html100100100100 
   index.component.ts100100100100 
dashboard/components100100100100 
   add-line-dialog.component.html100100100100 
   add-line-dialog.component.ts100100100100 
   edit-name-line-dialog.component.html100100100100 
   edit-name-line-dialog.component.ts100100100100 
   reorganize-lines-dialog.component.html100100100100 
   reorganize-lines-dialog.component.ts100100100100 
   split-lines-dialog.component.ts100100100100 
   statuses-group-card.component.html100100100100 
   statuses-group-card.component.ts100100100100 
dashboard/components/lines100100100100 
   applications-line.component.html100100100100 
   applications-line.component.ts100100100100 
   partitions-line.component.html100100100100 
   partitions-line.component.ts100100100100 
   results-line.component.html100100100100 
   results-line.component.ts100100100100 
   sessions-line.component.html100100100100 
   sessions-line.component.ts100100100100 
   task-by-status-line.component.html100100100100 
   task-by-status-line.component.ts100100100100 
   tasks-line.component.html100100100100 
   tasks-line.component.ts100100100100 
dashboard/services100100100100 
   dashboard-index.service.ts100100100100 
   dashboard-storage.service.ts100100100100 
healthcheck100100100100 
   healthcheck.component.html100100100100 
   healthcheck.component.ts100100100100 
healthcheck/services100100100100 
   healthcheck-grpc.service.ts100100100100 
partitions100100100100 
   index.component.html100100100100 
   index.component.ts100100100100 
   show.component.ts100100100100 
partitions/components100100100100 
   table.component.html100100100100 
   table.component.ts100100100100 
partitions/services100100100100 
   partitions-filters.service.ts100100100100 
   partitions-grpc.service.ts100100100100 
   partitions-index.service.ts100100100100 
pipes100100100100 
   duration.pipe.ts100100100100 
   empty-cell.pipe.ts100100100100 
   pretty.pipe.ts100100100100 
profile100100100100 
   index.component.html100100100100 
   index.component.ts100100100100 
   types.ts100100100100 
results100100100100 
   index.component.html100100100100 
   index.component.ts100100100100 
   show.component.ts100100100100 
results/components100100100100 
   table.component.html100100100100 
   table.component.ts100100100100 
results/services100100100100 
   results-filters.service.ts100100100100 
   results-grpc.service.ts100100100100 
   results-index.service.ts100100100100 
   results-statuses.service.ts100100100100 
services100100100100 
   auto-refresh.service.ts100100100100 
   cache.service.ts100100100100 
   default-config.service.ts100100100100 
   environment.service.ts100100100100 
   filters.service.ts100100100100 
   grpc-build-request.service.ts100100100100 
   grpc-sort-field.service.ts100100100100 
   icons.service.ts100100100100 
   navigation.service.ts100100100100 
   notification.service.ts100100100100 
   query-params.service.ts100100100100 
   share-url.service.ts100100100100 
   storage.service.ts100100100100 
   table-storage.service.ts100100100100 
   table-url.service.ts100100100100 
   table.service.ts100100100100 
   tasks-by-status.service.ts100100100100 
   user-grpc.service.ts100100100100 
   user.service.ts100100100100 
   utils.service.ts100100100100 
   versions-grpc.service.ts100100100100 
   versions.service.ts100100100100 
sessions100100100100 
   index.component.html100100100100 
   index.component.ts100100100100 
   show.component.ts100100100100 
sessions/components100100100100 
   table.component.html100100100100 
   table.component.ts100100100100 
sessions/services100100100100 
   sessions-filters.service.ts100100100100 
   sessions-grpc.service.ts100100100100 
   sessions-index.service.ts100100100100 
   sessions-statuses.service.ts100100100100 
tasks100100100100 
   index.component.html100100100100 
   index.component.ts100100100100 
   show.component.ts100100100100 
tasks/components100100100100 
   manage-view-in-logs-dialog.component.html100100100100 
   manage-view-in-logs-dialog.component.ts100100100100 
   table.component.html100100100100 
   table.component.ts100100100100 
tasks/services100100100100 
   tasks-filters.service.ts100100100100 
   tasks-grpc.service.ts100100100100 
   tasks-index.service.ts100100100100 
   tasks-statuses.service.ts100100100100 
tokens100100100100 
   filters.token.ts100100100100 
types100100100100 
   navigation.ts100100100100 
types/components99.7110099.12100 
   dashboard-line-table.ts100100100100 
   index.ts99.1510097.29100 
   show.ts100100100100 
   table.ts100100100100 
types/services100100100100 
   grpcService.ts100100100100 

Please sign in to comment.