Skip to content

Commit

Permalink
Support client versions table in details card (jaegertracing#568)
Browse files Browse the repository at this point in the history
Signed-off-by: Everett Ross <[email protected]>
  • Loading branch information
everett980 authored May 12, 2020
1 parent 8b8a694 commit e01d90f
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import cx from 'classnames';
import _isEmpty from 'lodash/isEmpty';
import MdKeyboardArrowDown from 'react-icons/lib/md/keyboard-arrow-down';

import ExamplesLink from '../../../QualityMetrics/ExamplesLink';

import {
TExample,
TPadColumnDef,
TPadColumnDefs,
TPadDetails,
Expand Down Expand Up @@ -87,7 +90,7 @@ export default class DetailsCard extends React.PureComponent<TProps> {
title,
onCell: (row: TPadRow) => {
const cellData = row[dataIndex];
if (!cellData || typeof cellData !== 'object') return null;
if (!cellData || typeof cellData !== 'object' || Array.isArray(cellData)) return null;
const { styling } = cellData;
if (_isEmpty(styling)) return null;
return {
Expand All @@ -99,6 +102,7 @@ export default class DetailsCard extends React.PureComponent<TProps> {
}),
render: (cellData: undefined | string | TStyledValue) => {
if (!cellData || typeof cellData !== 'object') return cellData;
if (Array.isArray(cellData)) return <ExamplesLink examples={cellData} />;
if (!cellData.linkTo) return cellData.value;
return (
<a href={cellData.linkTo} target="_blank" rel="noopener noreferrer">
Expand All @@ -110,9 +114,17 @@ export default class DetailsCard extends React.PureComponent<TProps> {
sortable &&
((a: TPadRow, b: TPadRow) => {
const aData = a[dataIndex];
const aValue = typeof aData === 'object' && typeof aData.value === 'string' ? aData.value : aData;
let aValue;
if (Array.isArray(aData)) aValue = aData.length;
else if (typeof aData === 'object' && typeof aData.value === 'string') aValue = aData.value;
else aValue = aData;

const bData = b[dataIndex];
const bValue = typeof bData === 'object' && typeof bData.value === 'string' ? bData.value : bData;
let bValue;
if (Array.isArray(bData)) bValue = bData.length;
else if (typeof bData === 'object' && typeof bData.value === 'string') bValue = bData.value;
else bValue = bData;

if (aValue < bValue) return -1;
return bValue < aValue ? 1 : 0;
}),
Expand Down Expand Up @@ -154,12 +166,13 @@ export default class DetailsCard extends React.PureComponent<TProps> {
rowKey={(row: TPadRow) =>
JSON.stringify(row, function replacer(
key: string,
value: TPadRow | string | number | TStyledValue
value: TPadRow | string | number | TStyledValue | TExample[]
) {
function isRow(v: typeof value): v is TPadRow {
return v === row;
}
if (isRow(value)) return value;
if (Array.isArray(value)) return JSON.stringify(value);
if (typeof value === 'object') {
if (typeof value.value === 'string') return value.value;
return value.value.key || 'Unknown';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as React from 'react';

import ExamplesLink from './ExamplesLink';

import { TExample } from './types';
import { TExample } from '../../model/path-agnostic-decorations/types';

import './CountCard.css';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as React from 'react';
import NewWindowIcon from '../common/NewWindowIcon';
import { getUrl } from '../SearchTracePage/url';

import { TExample } from './types';
import { TExample } from '../../model/path-agnostic-decorations/types';

export type TProps = {
examples?: TExample[];
Expand Down
70 changes: 39 additions & 31 deletions packages/jaeger-ui/src/components/QualityMetrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,37 +145,45 @@ export class UnconnectedQualityMetrics extends React.PureComponent<TProps, TStat
<MetricCard key={metric.name} metric={metric} />
))}
</div>
<DetailsCard
className="QualityMetrics--ClientVersions"
columnDefs={[
{
key: 'version',
label: 'Version',
},
{
key: 'minVersion',
label: 'Minimum Version',
},
{
key: 'count',
label: 'Count',
},
{
key: 'examples',
label: 'Examples',
preventSort: true,
},
]}
details={qualityMetrics.clients.map(clientRow => ({
...clientRow,
examples: {
value: (
<ExamplesLink examples={clientRow.examples} key={`${clientRow.version}--examples`} />
),
},
}))}
header="Client Versions"
/>
{qualityMetrics.clients && (
<DetailsCard
className="QualityMetrics--ClientVersions"
columnDefs={[
{
key: 'version',
label: 'Version',
},
{
key: 'minVersion',
label: 'Minimum Version',
},
{
key: 'count',
label: 'Count',
},
{
key: 'examples',
label: 'Examples',
preventSort: true,
},
]}
details={
qualityMetrics.clients &&
qualityMetrics.clients.map(clientRow => ({
...clientRow,
examples: {
value: (
<ExamplesLink
examples={clientRow.examples}
key={`${clientRow.version}--examples`}
/>
),
},
}))
}
header="Client Versions"
/>
)}
</div>
</>
)}
Expand Down
9 changes: 2 additions & 7 deletions packages/jaeger-ui/src/components/QualityMetrics/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@

import * as React from 'react';

import { TPadColumnDef, TPadRow } from '../../model/path-agnostic-decorations/types';

export type TExample = {
spanIDs?: string[];
traceID: string;
};
import { TExample, TPadColumnDef, TPadRow } from '../../model/path-agnostic-decorations/types';

export type TQualityMetrics = {
traceQualityDocumentationLink: string;
Expand Down Expand Up @@ -54,7 +49,7 @@ export type TQualityMetrics = {
rows: TPadRow[];
}[];
}[];
clients: {
clients?: {
version: string;
minVersion: string;
count: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

import React from 'react';

export type TExample = {
spanIDs?: string[];
traceID: string;
};

export type TPathAgnosticDecorationSchema = {
acronym: string;
id: string;
Expand Down Expand Up @@ -46,7 +51,7 @@ export type TPadColumnDef = {

export type TPadColumnDefs = (string | TPadColumnDef)[];

export type TPadRow = Record<string, TStyledValue | string | number>;
export type TPadRow = Record<string, TStyledValue | string | number | TExample[]>;

export type TPadDetails = string | string[] | TPadRow[];

Expand Down

0 comments on commit e01d90f

Please sign in to comment.