Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
}

.api-callee-name-count {
@include body-small($gray-3);
display: flex;
align-items: center;
justify-content: space-between;
Expand All @@ -14,18 +15,15 @@
.api-callee-name {
@include ellipsis-overflow();
max-width: 200px;
font-size: 13.5px;
color: $gray-2;
}

.api-callee-count {
color: white;
font-size: 15px;
margin-left: 50px;
}
}

.remaining-api-callee {
font-size: 13.5px;
@include body-small($gray-3);
padding: 2px;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { TooltipDirective } from '@hypertrace/components';
import { TableCellNoOpParser, tableCellProviders, tableCellRowDataProvider } from '@hypertrace/components';
import {
TableCellNoOpParser,
tableCellProviders,
tableCellRowDataProvider,
TooltipDirective
} from '@hypertrace/components';
import { createComponentFactory } from '@ngneat/spectator/jest';
import { MockComponent } from 'ng-mocks';
import { ExitCallsTableCellRendererComponent } from './exit-calls-table-cell-renderer.component';
Expand Down Expand Up @@ -28,7 +32,7 @@ describe('Exit Calls table cell renderer component', () => {
expect(spectator.query(TooltipDirective)).toExist();
});

test('testing getMaxShowAPICalleeNameCount function', () => {
test('testing component properties', () => {
const value = {
key1: '1',
key2: '2'
Expand All @@ -37,7 +41,11 @@ describe('Exit Calls table cell renderer component', () => {
providers: [tableCellRowDataProvider({ apiExitCalls: 2, apiCalleeNameCount: value })]
});

expect(spectator.component.getMaxShowAPICalleeNameCount(value)).toMatchObject(value);
expect(spectator.component.totalCountOfDifferentAPICallee).toBe(2);
expect(spectator.component.apiCalleeNameCount).toMatchObject([
Copy link
Contributor

Choose a reason for hiding this comment

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

This test has value, but what would be even better would be to verify that this data renders - for example by querying for the rendered spans and checking their content (e.g. expect(spectator.queryAll('.api-callee-name')[0]).toContainText('key1');)

That checks both how the data is processed but also that the template is correctly binding what we expect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, this change I can make.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind, discussed offline - because this is a template that's not rendered in the scope of this component, it's ugly to test and not worth it.

['key1', '1'],
['key2', '2']
]);
expect(spectator.component.totalCountOfDifferentApiCallee).toBe(2);
expect(spectator.component.apiExitCalls).toBe(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import {
} from '@hypertrace/components';
import { Trace } from '@hypertrace/distributed-tracing';
import { ExploreValue } from '@hypertrace/observability';

export const EXIT_CALLS_CELL = 'EXIT_CALLS_CELL';
import { ObservabilityTableCellType } from '../../observability-table-cell-type';

@Component({
selector: 'exit-calls-table-cell-renderer',
selector: 'ht-exit-calls-table-cell-renderer',
styleUrls: ['./exit-calls-table-cell-renderer.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
Expand All @@ -27,15 +26,15 @@ export const EXIT_CALLS_CELL = 'EXIT_CALLS_CELL';

<ng-template #exitCallsTooltip>
<ng-container *ngIf="this.apiExitCalls > 0">
Copy link
Contributor

@arjunlalb arjunlalb Apr 14, 2021

Choose a reason for hiding this comment

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

nit: This is an if-else use case. You can clean this up like below. There are many examples in the codebase.

<ng-container *ngIf="this.apiExitCalls > 0; else noExitCalls">
  Content goes here
</ng-container>
<ng-template #noExitCalls></ng-template>

<div *ngFor="let item of this.apiCalleeNameCount | keyvalue" class="api-callee-name-count">
<span class="api-callee-name">{{ item.key }}</span>
<span class="api-callee-count">{{ item.value }}</span>
<div *ngFor="let item of this.apiCalleeNameCount" class="api-callee-name-count">
<span class="api-callee-name">{{ item[0] }}</span>
<span class="api-callee-count">{{ item[1] }}</span>
</div>
<div
*ngIf="this.totalCountOfDifferentAPICallee > this.maxShowAPICalleeNameCount"
*ngIf="this.totalCountOfDifferentApiCallee > this.maxShowApiCalleeNameCount"
class="remaining-api-callee"
>
and {{ this.totalCountOfDifferentAPICallee - this.maxShowAPICalleeNameCount }} more
and {{ this.totalCountOfDifferentApiCallee - this.maxShowApiCalleeNameCount }} more
</div>
</ng-container>
<ng-container *ngIf="this.apiExitCalls <= 0" class="no-exit-calls">No exit calls</ng-container>
Expand All @@ -44,15 +43,15 @@ export const EXIT_CALLS_CELL = 'EXIT_CALLS_CELL';
`
})
@TableCellRenderer({
type: EXIT_CALLS_CELL,
type: ObservabilityTableCellType.ExitCalls,
alignment: TableCellAlignmentType.Left,
parser: CoreTableCellParserType.NoOp
})
export class ExitCallsTableCellRendererComponent extends TableCellRendererBase<ExploreValue, any> implements OnInit {
public readonly apiCalleeNameCount: any;
export class ExitCallsTableCellRendererComponent extends TableCellRendererBase<ExploreValue, Trace> implements OnInit {
public readonly apiCalleeNameCount: string[][];
public readonly apiExitCalls: number;
public readonly maxShowAPICalleeNameCount: number = 10;
public totalCountOfDifferentAPICallee!: number;
public readonly maxShowApiCalleeNameCount: number = 10;
public readonly totalCountOfDifferentApiCallee!: number;

public constructor(
@Inject(TABLE_COLUMN_CONFIG) columnConfig: TableColumnConfig,
Expand All @@ -62,23 +61,9 @@ export class ExitCallsTableCellRendererComponent extends TableCellRendererBase<E
@Inject(TABLE_ROW_DATA) rowData: Trace
) {
super(columnConfig, index, parser, cellData, rowData);
this.apiCalleeNameCount = this.getMaxShowAPICalleeNameCount(rowData.apiCalleeNameCount);
const apiCalleeNameCount: string[][] = Object.entries(Object(rowData.apiCalleeNameCount));
this.totalCountOfDifferentApiCallee = apiCalleeNameCount.length;
this.apiCalleeNameCount = apiCalleeNameCount.slice(0, this.maxShowApiCalleeNameCount);
this.apiExitCalls = Number(rowData.apiExitCalls);
}

public getMaxShowAPICalleeNameCount(apiCalleeNameCount: any): any {
if (apiCalleeNameCount) {
const showAPICalleeNameCount: any = {};
let count = 0;
Object.keys(apiCalleeNameCount).forEach((key: string) => {
if (count < this.maxShowAPICalleeNameCount) {
showAPICalleeNameCount[key] = apiCalleeNameCount[key];
count++;
}
});
this.totalCountOfDifferentAPICallee = Object.keys(apiCalleeNameCount).length;
return showAPICalleeNameCount;
}
return {};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const enum ObservabilityTableCellType {
Entity = 'entity',
BackendIcon = 'backend-icon'
BackendIcon = 'backend-icon',
ExitCalls = 'exit-calls'
}