Skip to content

Commit

Permalink
Update Kpi host UI to handle no data for charts (elastic#36424)
Browse files Browse the repository at this point in the history
* update types for areachart and barchart

* handle no buckets returns for charts

* update data types for histogram data
  • Loading branch information
angorayc committed May 10, 2019
1 parent c3f749f commit e356490
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe.each([
],
[
[
{ key: 'uniqueSourceIps', value: [{ x: 0, y: 'uniqueSourceIps' }], color: '#DB1374' },
{ key: 'uniqueSourceIps', value: [{ x: 1714, y: 'uniqueSourceIps' }], color: '#DB1374' },
{
key: 'uniqueDestinationIps',
value: [{ x: 0, y: 'uniqueDestinationIps' }],
Expand Down Expand Up @@ -129,6 +129,16 @@ describe.each([
},
],
],
[
[
{ key: 'uniqueSourceIps', value: [{ x: 0, y: 'uniqueSourceIps' }], color: '#DB1374' },
{
key: 'uniqueDestinationIps',
value: [{ x: 0, y: 'uniqueDestinationIps' }],
color: '#490092',
},
],
],
[
[
{ key: 'uniqueSourceIps', value: [{ x: null, y: 'uniqueSourceIps' }], color: '#DB1374' },
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/siem/public/components/stat_items/barchart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ export const BarChartWithCustomPrompt = pure<{
}>(({ data, height, width }) => {
return data &&
data.length &&
data.every(
({ value }) => value != null && value.length > 0 && value.every(chart => chart.x != null)
data.some(
({ value }) =>
value != null && value.length > 0 && value.every(chart => chart.x != null && chart.x > 0)
) ? (
<BarChartBaseComponent height={height} width={width} data={data} />
) : (
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/siem/public/components/stat_items/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const WrappedByAutoSizer = styled.div`
`;

const FlexGroup = styled(EuiFlexGroup)`
height: '100%';
height: 100%;
`;

const FlexItem = styled(EuiFlexItem)`
Expand Down Expand Up @@ -67,7 +67,7 @@ export interface ChartData {

export interface BarChartData {
key: string;
value: ChartData[] | [] | null;
value: [ChartData] | [] | null;
color?: string | undefined;
}

Expand Down Expand Up @@ -120,7 +120,7 @@ export const StatItemsComponent = pure<StatItemsProps>(
<FlexItem>
<StatValue>
<p data-test-subj="stat-title">
{field.value ? field.value.toLocaleString() : getEmptyTagValue()}{' '}
{field.value != null ? field.value.toLocaleString() : getEmptyTagValue()}{' '}
{field.description}
</p>
</StatValue>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import gql from 'graphql-tag';

export const kpiHostsQuery = gql`
fragment ChartFields on HistogramData {
fragment ChartFields on KpiHostHistogramData {
x: key_as_string
y: count {
value
Expand Down
10 changes: 6 additions & 4 deletions x-pack/plugins/siem/public/containers/kpi_hosts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ const formatHistogramData = (
y: { value: number; doc_count: number };
}>
): ChartData[] => {
return data.map(({ x, y }) => ({
x,
y: y.value || y.doc_count,
}));
return data.length > 0
? data.map(({ x, y }) => ({
x,
y: y.value || y.doc_count,
}))
: [];
};

export const KpiHostsQuery = pure<KpiHostsProps>(
Expand Down
32 changes: 26 additions & 6 deletions x-pack/plugins/siem/public/graphql/introspection.json
Original file line number Diff line number Diff line change
Expand Up @@ -6280,7 +6280,11 @@
"type": {
"kind": "LIST",
"name": null,
"ofType": { "kind": "OBJECT", "name": "HistogramData", "ofType": null }
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null }
}
},
"isDeprecated": false,
"deprecationReason": null
Expand All @@ -6300,7 +6304,11 @@
"type": {
"kind": "LIST",
"name": null,
"ofType": { "kind": "OBJECT", "name": "HistogramData", "ofType": null }
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null }
}
},
"isDeprecated": false,
"deprecationReason": null
Expand All @@ -6320,7 +6328,11 @@
"type": {
"kind": "LIST",
"name": null,
"ofType": { "kind": "OBJECT", "name": "HistogramData", "ofType": null }
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null }
}
},
"isDeprecated": false,
"deprecationReason": null
Expand All @@ -6340,7 +6352,11 @@
"type": {
"kind": "LIST",
"name": null,
"ofType": { "kind": "OBJECT", "name": "HistogramData", "ofType": null }
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null }
}
},
"isDeprecated": false,
"deprecationReason": null
Expand All @@ -6360,7 +6376,11 @@
"type": {
"kind": "LIST",
"name": null,
"ofType": { "kind": "OBJECT", "name": "HistogramData", "ofType": null }
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null }
}
},
"isDeprecated": false,
"deprecationReason": null
Expand All @@ -6373,7 +6393,7 @@
},
{
"kind": "OBJECT",
"name": "HistogramData",
"name": "KpiHostHistogramData",
"description": "",
"fields": [
{
Expand Down
24 changes: 12 additions & 12 deletions x-pack/plugins/siem/public/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,26 +1037,26 @@ export interface KpiNetworkData {
export interface KpiHostsData {
hosts?: number | null;

hostsHistogram?: (HistogramData | null)[] | null;
hostsHistogram?: KpiHostHistogramData[] | null;

authSuccess?: number | null;

authSuccessHistogram?: (HistogramData | null)[] | null;
authSuccessHistogram?: KpiHostHistogramData[] | null;

authFailure?: number | null;

authFailureHistogram?: (HistogramData | null)[] | null;
authFailureHistogram?: KpiHostHistogramData[] | null;

uniqueSourceIps?: number | null;

uniqueSourceIpsHistogram?: (HistogramData | null)[] | null;
uniqueSourceIpsHistogram?: KpiHostHistogramData[] | null;

uniqueDestinationIps?: number | null;

uniqueDestinationIpsHistogram?: (HistogramData | null)[] | null;
uniqueDestinationIpsHistogram?: KpiHostHistogramData[] | null;
}

export interface HistogramData {
export interface KpiHostHistogramData {
key?: number | null;

key_as_string?: string | null;
Expand Down Expand Up @@ -2474,23 +2474,23 @@ export namespace GetKpiHostsQuery {

hosts?: number | null;

hostsHistogram?: (HostsHistogram | null)[] | null;
hostsHistogram?: HostsHistogram[] | null;

authSuccess?: number | null;

authSuccessHistogram?: (AuthSuccessHistogram | null)[] | null;
authSuccessHistogram?: AuthSuccessHistogram[] | null;

authFailure?: number | null;

authFailureHistogram?: (AuthFailureHistogram | null)[] | null;
authFailureHistogram?: AuthFailureHistogram[] | null;

uniqueSourceIps?: number | null;

uniqueSourceIpsHistogram?: (UniqueSourceIpsHistogram | null)[] | null;
uniqueSourceIpsHistogram?: UniqueSourceIpsHistogram[] | null;

uniqueDestinationIps?: number | null;

uniqueDestinationIpsHistogram?: (UniqueDestinationIpsHistogram | null)[] | null;
uniqueDestinationIpsHistogram?: UniqueDestinationIpsHistogram[] | null;
};

export type HostsHistogram = ChartFields.Fragment;
Expand Down Expand Up @@ -3889,7 +3889,7 @@ export namespace GetUsersQuery {

export namespace ChartFields {
export type Fragment = {
__typename?: 'HistogramData';
__typename?: 'KpiHostHistogramData';

x?: string | null;

Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/siem/server/graphql/kpi_hosts/schema.gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ export const kpiHostsSchema = gql`
doc_count: Float
}
type HistogramData {
type KpiHostHistogramData {
key: Float
key_as_string: String
count: Count
}
type KpiHostsData {
hosts: Float
hostsHistogram: [HistogramData]
hostsHistogram: [KpiHostHistogramData!]
authSuccess: Float
authSuccessHistogram: [HistogramData]
authSuccessHistogram: [KpiHostHistogramData!]
authFailure: Float
authFailureHistogram: [HistogramData]
authFailureHistogram: [KpiHostHistogramData!]
uniqueSourceIps: Float
uniqueSourceIpsHistogram: [HistogramData]
uniqueSourceIpsHistogram: [KpiHostHistogramData!]
uniqueDestinationIps: Float
uniqueDestinationIpsHistogram: [HistogramData]
uniqueDestinationIpsHistogram: [KpiHostHistogramData!]
}
extend type Source {
Expand Down
Loading

0 comments on commit e356490

Please sign in to comment.