Skip to content

Commit 049dffc

Browse files
committed
feat: refactor components to use standalone modules and improve change detection
- Updated CopilotComponent, TableCopilotUsageComponent, and other components to use standalone modules. - Added NoopAnimationsModule to testing modules for smoother tests. - Implemented ChangeDetectionStrategy.OnPush for better performance. - Introduced new pipes: DurationPipe and FormatFileSizePipe for formatting data. - Enhanced UsageComponent to handle file uploads and data parsing more efficiently. - Removed unnecessary MaterialModule and directly imported Material components in relevant modules. - Updated usage of observables and improved error handling in service methods. - Cleaned up HTML templates by removing unnecessary elements and improving structure.
1 parent dc6c1d3 commit 049dffc

49 files changed

Lines changed: 482 additions & 654 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[ 1404ms] [WARNING] Highcharts warning: Consider including the "accessibility.js" module to make your chart more usable for people with disabilities. Set the "accessibility.enabled" option to false to remove this warning. See https://www.highcharts.com/docs/accessibility/accessibility-module. @ http://localhost:4200/@fs/C:/Users/auste/source/github-actions-usage-report/.angular/cache/19.2.14/github-actions-usage-report/vite/deps/highcharts.js?v=c024a960:64
2+
[ 77652ms] [WARNING] NG0956: The configured tracking expression (track by identity) caused re-creation of the entire collection of size 6. This is an expensive operation requiring destruction and subsequent creation of DOM nodes, directives, components etc. Please review the "track expression" and make sure that it uniquely identifies items in a collection. Find more at https://angular.dev/errors/NG0956 @ http://localhost:4200/@fs/C:/Users/auste/source/github-actions-usage-report/.angular/cache/19.2.14/github-actions-usage-report/vite/deps/chunk-MS4FAMMM.js?v=429c1b72:18749
67.4 KB
Loading

src/app/app.component.spec.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
import { TestBed } from '@angular/core/testing';
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
22
import { AppComponent } from './app.component';
3-
import { UsageComponent } from './components/usage/usage.component';
3+
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
4+
import { provideHttpClientTesting } from '@angular/common/http/testing';
5+
import { provideHttpClient } from '@angular/common/http';
6+
import { provideNativeDateAdapter } from '@angular/material/core';
47

58
describe('AppComponent', () => {
9+
let component: AppComponent;
10+
let fixture: ComponentFixture<AppComponent>;
11+
612
beforeEach(async () => {
713
await TestBed.configureTestingModule({
8-
declarations: [
9-
AppComponent,
10-
UsageComponent
11-
],
14+
imports: [AppComponent, NoopAnimationsModule],
15+
providers: [provideHttpClient(), provideHttpClientTesting(), provideNativeDateAdapter()]
1216
}).compileComponents();
17+
18+
fixture = TestBed.createComponent(AppComponent);
19+
component = fixture.componentInstance;
20+
fixture.detectChanges();
1321
});
1422

15-
it('should create the app', () => {
16-
const fixture = TestBed.createComponent(AppComponent);
17-
const app = fixture.componentInstance;
18-
expect(app).toBeTruthy();
23+
it('should create', () => {
24+
expect(component).toBeTruthy();
1925
});
2026
});

src/app/app.component.ts

Lines changed: 38 additions & 192 deletions
Large diffs are not rendered by default.

src/app/app.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
2+
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
3+
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
4+
import { provideNativeDateAdapter } from '@angular/material/core';
5+
6+
export const appConfig: ApplicationConfig = {
7+
providers: [
8+
provideZoneChangeDetection({ eventCoalescing: true }),
9+
provideHttpClient(withInterceptorsFromDi()),
10+
provideAnimationsAsync(),
11+
provideNativeDateAdapter(),
12+
],
13+
};

src/app/app.module.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<app-table-workflow-usage [data]="data" [currency]="currency"></app-table-workflow-usage>
22
<app-chart-line-usage-daily [data]="data" [currency]="currency"></app-chart-line-usage-daily>
3-
<!-- <app-chart-line-usage-time [data]="data" [currency]="currency"></app-chart-line-usage-time> -->
4-
<div style="display: flex; flex: 1 1 0px; flex-wrap: wrap; align-items: center; justify-content: center;">
3+
<div class="pie-charts-row">
54
<app-chart-pie-user [data]="data" [currency]="currency"></app-chart-pie-user>
65
<app-chart-pie-sku [data]="data" [currency]="currency"></app-chart-pie-sku>
76
</div>
8-
<app-chart-bar-top-time [data]="data" [currency]="currency"></app-chart-bar-top-time>
9-
<!-- <app-usage-table [data]="data"></app-usage-table> -->
7+
<app-chart-bar-top-time [data]="data" [currency]="currency"></app-chart-bar-top-time>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.pie-charts-row {
2+
display: flex;
3+
flex: 1 1 0px;
4+
flex-wrap: wrap;
5+
align-items: center;
6+
justify-content: center;
7+
}

src/app/components/usage/actions/actions.component.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
2-
32
import { ActionsComponent } from './actions.component';
3+
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
44

55
describe('ActionsComponent', () => {
66
let component: ActionsComponent;
77
let fixture: ComponentFixture<ActionsComponent>;
88

99
beforeEach(async () => {
1010
await TestBed.configureTestingModule({
11-
imports: [ActionsComponent]
12-
})
13-
.compileComponents();
14-
11+
imports: [ActionsComponent, NoopAnimationsModule]
12+
}).compileComponents();
13+
1514
fixture = TestBed.createComponent(ActionsComponent);
1615
component = fixture.componentInstance;
16+
component.data = [];
17+
component.currency = 'cost';
1718
fixture.detectChanges();
1819
});
1920

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1-
import { Component, Input, OnInit } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
22
import { CustomUsageReportLine, UsageReportService } from 'src/app/usage-report.service';
3+
import { TableWorkflowUsageComponent } from './table-workflow-usage/table-workflow-usage.component';
4+
import { ChartLineUsageDailyComponent } from './charts/chart-line-usage-daily/chart-line-usage-daily.component';
5+
import { ChartPieUserComponent } from './charts/chart-pie-user/chart-pie-user.component';
6+
import { ChartPieSkuComponent } from './charts/chart-pie-sku/chart-pie-sku.component';
7+
import { ChartBarTopTimeComponent } from './charts/chart-bar-top-time/chart-bar-top-time.component';
38

49
@Component({
510
selector: 'app-actions',
611
templateUrl: './actions.component.html',
712
styleUrl: './actions.component.scss',
8-
standalone: false
13+
standalone: true,
14+
imports: [
15+
TableWorkflowUsageComponent,
16+
ChartLineUsageDailyComponent,
17+
ChartPieUserComponent,
18+
ChartPieSkuComponent,
19+
ChartBarTopTimeComponent,
20+
],
21+
changeDetection: ChangeDetectionStrategy.OnPush,
922
})
1023
export class ActionsComponent implements OnInit {
1124
@Input() data!: CustomUsageReportLine[];
@@ -16,7 +29,7 @@ export class ActionsComponent implements OnInit {
1629
constructor(
1730
public usageReportService: UsageReportService,
1831
) { }
19-
32+
2033
ngOnInit() {
2134
this.usageReportService.getActionsTotalMinutes().subscribe((totalMinutes) => {
2235
this.totalMinutes = totalMinutes;
@@ -25,5 +38,4 @@ export class ActionsComponent implements OnInit {
2538
this.totalCost = totalCost;
2639
});
2740
}
28-
2941
}

0 commit comments

Comments
 (0)