Skip to content

Commit

Permalink
Merge pull request #27108 from qmonmert/simplifytemplate
Browse files Browse the repository at this point in the history
[Angular] Use let on metrics component
  • Loading branch information
mshima authored Aug 28, 2024
2 parents b276be7 + eb9ade6 commit 96f859f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,52 +27,53 @@

<h3>__jhiTranslateTag__('metrics.jvm.title')</h3>

@if (metrics() && !updatingMetrics()) {
@let metricsRef = metrics();
@if (metricsRef && !updatingMetrics()) {
<div class="row">
<<%= jhiPrefixDashed %>-jvm-memory class="col-md-4" [updating]="updatingMetrics()" [jvmMemoryMetrics]="metrics()?.jvm"></<%= jhiPrefixDashed %>-jvm-memory>
<<%= jhiPrefixDashed %>-jvm-memory class="col-md-4" [updating]="updatingMetrics()" [jvmMemoryMetrics]="metricsRef.jvm"></<%= jhiPrefixDashed %>-jvm-memory>

<<%= jhiPrefixDashed %>-jvm-threads class="col-md-4" [threads]="threads()"></<%= jhiPrefixDashed %>-jvm-threads>

<<%= jhiPrefixDashed %>-metrics-system class="col-md-4" [updating]="updatingMetrics()" [systemMetrics]="metrics()?.processMetrics"></<%= jhiPrefixDashed %>-metrics-system>
<<%= jhiPrefixDashed %>-metrics-system class="col-md-4" [updating]="updatingMetrics()" [systemMetrics]="metricsRef.processMetrics"></<%= jhiPrefixDashed %>-metrics-system>
</div>
}

@if (metrics() && metricsKeyExists('garbageCollector')) {
@if (metricsRef?.garbageCollector; as metricsRefGarbageCollector) {
<<%= jhiPrefixDashed %>-metrics-garbagecollector
[updating]="updatingMetrics()"
[garbageCollectorMetrics]="metrics()?.garbageCollector"
[garbageCollectorMetrics]="metricsRefGarbageCollector"
></<%= jhiPrefixDashed %>-metrics-garbagecollector>
}

@if (updatingMetrics()) {
<div class="well well-lg">__jhiTranslateTag__('metrics.updating')</div>
}

@if (metrics() && metricsKeyExists('http.server.requests')) {
@if (metricsRef?.['http.server.requests']; as metricsRefHttpServerRequests) {
<<%= jhiPrefixDashed %>-metrics-request
[updating]="updatingMetrics()"
[requestMetrics]="metrics()?.['http.server.requests']"
[requestMetrics]="metricsRefHttpServerRequests"
></<%= jhiPrefixDashed %>-metrics-request>
}

@if (metrics() && metricsKeyExists('services')) {
@if (metricsRef?.services; as metricsRefServices) {
<<%= jhiPrefixDashed %>-metrics-endpoints-requests
[updating]="updatingMetrics()"
[endpointsRequestsMetrics]="metrics()?.services"
[endpointsRequestsMetrics]="metricsRefServices"
></<%= jhiPrefixDashed %>-metrics-endpoints-requests>
}

@if (metrics() && metricsKeyExists('cache')) {
@if (metricsRef?.cache; as metricsRefCache) {
<<%= jhiPrefixDashed %>-metrics-cache
[updating]="updatingMetrics()"
[cacheMetrics]="metrics()?.cache"
[cacheMetrics]="metricsRefCache"
></<%= jhiPrefixDashed %>-metrics-cache>
}

@if (metrics() && metricsKeyExistsAndObjectNotEmpty('databases')) {
@if (metricsRef && metricsKeyExistsAndObjectNotEmpty('databases')) {
<<%= jhiPrefixDashed %>-metrics-datasource
[updating]="updatingMetrics()"
[datasourceMetrics]="metrics()?.databases"
[datasourceMetrics]="metricsRef.databases"
></<%= jhiPrefixDashed %>-metrics-datasource>
}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -80,52 +80,6 @@ describe('MetricsComponent', () => {
});
});

describe('metricsKeyExists', () => {
it('should check that metrics key exists', () => {
// GIVEN
comp.metrics.set({
garbageCollector: {
'PS Scavenge': {
collectionCount: 0,
collectionTime: 0,
},
'PS MarkSweep': {
collectionCount: 0,
collectionTime: 0,
},
},
} as unknown as Metrics);

// WHEN
const garbageCollectorKeyExists = comp.metricsKeyExists('garbageCollector');

// THEN
expect(garbageCollectorKeyExists).toBeTruthy();
});

it('should check that metrics key does not exist', () => {
// GIVEN
comp.metrics.set({
garbageCollector: {
'PS Scavenge': {
collectionCount: 0,
collectionTime: 0,
},
'PS MarkSweep': {
collectionCount: 0,
collectionTime: 0,
},
},
} as unknown as Metrics);

// WHEN
const databasesCollectorKeyExists = comp.metricsKeyExists('databases');

// THEN
expect(databasesCollectorKeyExists).toBeFalsy();
});
});

describe('metricsKeyExistsAndObjectNotEmpty', () => {
it('should check that metrics key exists and is not empty', () => {
// GIVEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ export default class MetricsComponent implements OnInit {
});
}

metricsKeyExists(key: keyof Metrics): boolean {
return Boolean(this.metrics()?.[key]);
}

metricsKeyExistsAndObjectNotEmpty(key: keyof Metrics): boolean {
return Boolean(this.metrics()?.[key] && JSON.stringify(this.metrics()?.[key]) !== '{}');
}
Expand Down

0 comments on commit 96f859f

Please sign in to comment.