From ae9cbfcb27b298380a7495033562b4f2e5bbb872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loix?= Date: Thu, 30 Jan 2020 12:11:38 +0530 Subject: [PATCH 058/108] [Mappings editor] Bring improvements from #55804 PR to master (#56282) --- .../helpers/mappings_editor.helpers.ts | 2 +- .../mappings_editor.test.tsx | 4 +- .../load_mappings_provider.test.tsx | 77 +++++++++++++++++++ .../load_mappings/load_mappings_provider.tsx | 2 +- .../lib/extract_mappings_definition.ts | 9 +-- .../lib/mappings_validator.test.ts | 26 ++++++- .../mappings_editor/lib/mappings_validator.ts | 74 +++++++++++++----- 7 files changed, 159 insertions(+), 35 deletions(-) create mode 100644 x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/components/load_mappings/load_mappings_provider.test.tsx diff --git a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.ts b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.ts index b8b67a0f36bd2..dcee956130a29 100644 --- a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.ts +++ b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.ts @@ -13,4 +13,4 @@ export const setup = (props: any) => wrapComponent: false, }, defaultProps: props, - }); + })(); diff --git a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/__jest__/client_integration/mappings_editor.test.tsx b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/__jest__/client_integration/mappings_editor.test.tsx index 9e390e785c7d5..723c105d403b8 100644 --- a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/__jest__/client_integration/mappings_editor.test.tsx +++ b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/__jest__/client_integration/mappings_editor.test.tsx @@ -28,7 +28,7 @@ describe('', () => { }, }, }; - const testBed = await setup({ onUpdate: mockOnUpdate, defaultValue })(); + const testBed = await setup({ onUpdate: mockOnUpdate, defaultValue }); const { exists } = testBed; expect(exists('mappingsEditor')).toBe(true); @@ -44,7 +44,7 @@ describe('', () => { }, }, }; - const testBed = await setup({ onUpdate: mockOnUpdate, defaultValue })(); + const testBed = await setup({ onUpdate: mockOnUpdate, defaultValue }); const { exists } = testBed; expect(exists('mappingsEditor')).toBe(true); diff --git a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/components/load_mappings/load_mappings_provider.test.tsx b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/components/load_mappings/load_mappings_provider.test.tsx new file mode 100644 index 0000000000000..a9433d3a7530f --- /dev/null +++ b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/components/load_mappings/load_mappings_provider.test.tsx @@ -0,0 +1,77 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +import React from 'react'; +import { act } from 'react-dom/test-utils'; + +jest.mock('@elastic/eui', () => ({ + ...jest.requireActual('@elastic/eui'), + // Mocking EuiCodeEditor, which uses React Ace under the hood + EuiCodeEditor: (props: any) => ( + { + props.onChange(syntheticEvent.jsonString); + }} + /> + ), +})); + +import { registerTestBed, nextTick, TestBed } from '../../../../../../../../../test_utils'; +import { LoadMappingsProvider } from './load_mappings_provider'; + +const ComponentToTest = ({ onJson }: { onJson: () => void }) => ( + + {openModal => ( + + )} + +); + +const setup = (props: any) => + registerTestBed(ComponentToTest, { + memoryRouter: { wrapComponent: false }, + defaultProps: props, + })(); + +const openModalWithJsonContent = ({ find, component }: TestBed) => async (json: any) => { + find('load-json-button').simulate('click'); + component.update(); + + // Set the mappings to load + // @ts-ignore + await act(async () => { + find('mockCodeEditor').simulate('change', { + jsonString: JSON.stringify(json), + }); + await nextTick(300); // There is a debounce in the JsonEditor that we need to wait for + }); +}; + +describe('', () => { + test('it should forward valid mapping definition', async () => { + const mappingsToLoad = { + properties: { + title: { + type: 'text', + }, + }, + }; + + const onJson = jest.fn(); + const testBed = await setup({ onJson }); + + // Open the modal and add the JSON + await openModalWithJsonContent(testBed)(mappingsToLoad); + + // Confirm + testBed.find('confirmModalConfirmButton').simulate('click'); + + const [jsonReturned] = onJson.mock.calls[0]; + expect(jsonReturned).toEqual({ ...mappingsToLoad, dynamic_templates: [] }); + }); +}); diff --git a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/components/load_mappings/load_mappings_provider.tsx b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/components/load_mappings/load_mappings_provider.tsx index a55bd96dce3d0..6bc360a1ec70e 100644 --- a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/components/load_mappings/load_mappings_provider.tsx +++ b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/components/load_mappings/load_mappings_provider.tsx @@ -25,7 +25,7 @@ type OpenJsonModalFunc = () => void; interface Props { onJson(json: { [key: string]: any }): void; - children: (deleteProperty: OpenJsonModalFunc) => React.ReactNode; + children: (openModal: OpenJsonModalFunc) => React.ReactNode; } interface State { diff --git a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/extract_mappings_definition.ts b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/extract_mappings_definition.ts index eae3c5b15759c..817b0f4a4d3d0 100644 --- a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/extract_mappings_definition.ts +++ b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/extract_mappings_definition.ts @@ -6,15 +6,10 @@ import { isPlainObject } from 'lodash'; import { GenericObject } from '../types'; -import { - validateMappingsConfiguration, - mappingsConfigurationSchemaKeys, -} from './mappings_validator'; - -const ALLOWED_PARAMETERS = [...mappingsConfigurationSchemaKeys, 'dynamic_templates', 'properties']; +import { validateMappingsConfiguration, VALID_MAPPINGS_PARAMETERS } from './mappings_validator'; const isMappingDefinition = (obj: GenericObject): boolean => { - const areAllKeysValid = Object.keys(obj).every(key => ALLOWED_PARAMETERS.includes(key)); + const areAllKeysValid = Object.keys(obj).every(key => VALID_MAPPINGS_PARAMETERS.includes(key)); if (!areAllKeysValid) { return false; diff --git a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/mappings_validator.test.ts b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/mappings_validator.test.ts index f1e6efb06c649..d67c267dda6ae 100644 --- a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/mappings_validator.test.ts +++ b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/mappings_validator.test.ts @@ -18,6 +18,24 @@ describe('Mappings configuration validator', () => { }); }); + it('should detect valid mappings configuration', () => { + const mappings = { + _source: { + includes: [], + excludes: [], + enabled: true, + }, + _meta: {}, + _routing: { + required: false, + }, + dynamic: true, + }; + + const { errors } = validateMappings(mappings); + expect(errors).toBe(undefined); + }); + it('should strip out unknown configuration', () => { const mappings = { dynamic: true, @@ -30,6 +48,7 @@ describe('Mappings configuration validator', () => { excludes: ['abc'], }, properties: { title: { type: 'text' } }, + dynamic_templates: [], unknown: 123, }; @@ -37,7 +56,7 @@ describe('Mappings configuration validator', () => { const { unknown, ...expected } = mappings; expect(value).toEqual(expected); - expect(errors).toBe(undefined); + expect(errors).toEqual([{ code: 'ERR_CONFIG', configName: 'unknown' }]); }); it('should strip out invalid configuration and returns the errors for each of them', () => { @@ -47,9 +66,8 @@ describe('Mappings configuration validator', () => { dynamic_date_formats: false, // wrong format _source: { enabled: true, - includes: 'abc', + unknownProp: 'abc', // invalid excludes: ['abc'], - wrong: 123, // parameter not allowed }, properties: 'abc', }; @@ -59,10 +77,10 @@ describe('Mappings configuration validator', () => { expect(value).toEqual({ dynamic: true, properties: {}, + dynamic_templates: [], }); expect(errors).not.toBe(undefined); - expect(errors!.length).toBe(3); expect(errors!).toEqual([ { code: 'ERR_CONFIG', configName: '_source' }, { code: 'ERR_CONFIG', configName: 'dynamic_date_formats' }, diff --git a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/mappings_validator.ts b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/mappings_validator.ts index 6ccbfeb50dcf4..78d638e398593 100644 --- a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/mappings_validator.ts +++ b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/mappings_validator.ts @@ -196,23 +196,30 @@ export const validateProperties = (properties = {}): PropertiesValidatorResponse * Single source of truth to validate the *configuration* of the mappings. * Whenever a user loads a JSON object it will be validate against this Joi schema. */ -export const mappingsConfigurationSchema = t.partial({ - dynamic: t.union([t.literal(true), t.literal(false), t.literal('strict')]), - date_detection: t.boolean, - numeric_detection: t.boolean, - dynamic_date_formats: t.array(t.string), - _source: t.partial({ - enabled: t.boolean, - includes: t.array(t.string), - excludes: t.array(t.string), - }), - _meta: t.UnknownRecord, - _routing: t.partial({ - required: t.boolean, - }), -}); - -export const mappingsConfigurationSchemaKeys = Object.keys(mappingsConfigurationSchema.props); +export const mappingsConfigurationSchema = t.exact( + t.partial({ + dynamic: t.union([t.literal(true), t.literal(false), t.literal('strict')]), + date_detection: t.boolean, + numeric_detection: t.boolean, + dynamic_date_formats: t.array(t.string), + _source: t.exact( + t.partial({ + enabled: t.boolean, + includes: t.array(t.string), + excludes: t.array(t.string), + }) + ), + _meta: t.UnknownRecord, + _routing: t.interface({ + required: t.boolean, + }), + }) +); + +const mappingsConfigurationSchemaKeys = Object.keys(mappingsConfigurationSchema.type.props); +const sourceConfigurationSchemaKeys = Object.keys( + mappingsConfigurationSchema.type.props._source.type.props +); export const validateMappingsConfiguration = ( mappingsConfiguration: any @@ -222,8 +229,20 @@ export const validateMappingsConfiguration = ( let copyOfMappingsConfig = { ...mappingsConfiguration }; const result = mappingsConfigurationSchema.decode(mappingsConfiguration); + const isSchemaInvalid = isLeft(result); - if (isLeft(result)) { + const unknownConfigurationParameters = Object.keys(mappingsConfiguration).filter( + key => mappingsConfigurationSchemaKeys.includes(key) === false + ); + + const unknownSourceConfigurationParameters = + mappingsConfiguration._source !== undefined + ? Object.keys(mappingsConfiguration._source).filter( + key => sourceConfigurationSchemaKeys.includes(key) === false + ) + : []; + + if (isSchemaInvalid) { /** * To keep the logic simple we will strip out the parameters that contain errors */ @@ -235,6 +254,15 @@ export const validateMappingsConfiguration = ( }); } + if (unknownConfigurationParameters.length > 0) { + unknownConfigurationParameters.forEach(configName => configurationRemoved.add(configName)); + } + + if (unknownSourceConfigurationParameters.length > 0) { + configurationRemoved.add('_source'); + delete copyOfMappingsConfig._source; + } + copyOfMappingsConfig = pick(copyOfMappingsConfig, mappingsConfigurationSchemaKeys); const errors: MappingsValidationError[] = toArray(ordString)(configurationRemoved) @@ -252,7 +280,7 @@ export const validateMappings = (mappings: any = {}): MappingsValidatorResponse return { value: {} }; } - const { properties, dynamic_templates, ...mappingsConfiguration } = mappings; + const { properties, dynamic_templates: dynamicTemplates, ...mappingsConfiguration } = mappings; const { value: parsedConfiguration, errors: configurationErrors } = validateMappingsConfiguration( mappingsConfiguration @@ -265,8 +293,14 @@ export const validateMappings = (mappings: any = {}): MappingsValidatorResponse value: { ...parsedConfiguration, properties: parsedProperties, - dynamic_templates, + dynamic_templates: dynamicTemplates ?? [], }, errors: errors.length ? errors : undefined, }; }; + +export const VALID_MAPPINGS_PARAMETERS = [ + ...mappingsConfigurationSchemaKeys, + 'dynamic_templates', + 'properties', +]; From 326afbc304653123277c82ed82570f592aba39ac Mon Sep 17 00:00:00 2001 From: Shahzad Date: Thu, 30 Jan 2020 08:01:40 +0100 Subject: [PATCH 059/108] [Uptime] In Ping histogram use auto date histogram (#55605) * update ping histogram API * update test * fix tests * update test * unused code Co-authored-by: Elastic Machine --- .../uptime/common/domain_types/monitors.ts | 7 - .../uptime/common/graphql/introspection.json | 137 ------------- .../plugins/uptime/common/graphql/types.ts | 86 -------- .../plugins/uptime/common/types/index.ts | 7 + .../uptime/common/types/ping/histogram.ts | 32 +++ .../connected/charts/ping_histogram.tsx | 76 +++++++ .../public/components/connected/index.ts | 7 + .../__snapshots__/chart_wrapper.test.tsx.snap | 8 +- .../ping_histogram.test.tsx.snap | 48 +++++ .../snapshot_histogram.test.tsx.snap | 7 - ...ogram.test.tsx => ping_histogram.test.tsx} | 9 +- .../charts/chart_wrapper/chart_wrapper.tsx | 8 +- .../components/functional/charts/index.ts | 2 +- ...pshot_histogram.tsx => ping_histogram.tsx} | 47 ++--- .../public/components/functional/index.ts | 2 +- .../components/functional/monitor_charts.tsx | 8 +- .../components/functional/status_panel.tsx | 11 +- .../plugins/uptime/public/pages/overview.tsx | 1 - .../queries/snapshot_histogram_query.ts | 38 ---- .../uptime/public/state/actions/index.ts | 1 + .../uptime/public/state/actions/ping.ts | 12 ++ .../plugins/uptime/public/state/api/index.ts | 1 + .../uptime/public/state/api/monitor.ts | 6 +- .../plugins/uptime/public/state/api/ping.ts | 35 ++++ .../plugins/uptime/public/state/api/types.ts | 2 + .../uptime/public/state/effects/index.ts | 2 + .../uptime/public/state/effects/ping.ts | 17 ++ .../uptime/public/state/reducers/index.ts | 2 + .../uptime/public/state/reducers/ping.ts | 45 +++++ .../state/selectors/__tests__/index.test.ts | 5 + .../uptime/public/state/selectors/index.ts | 4 + .../server/graphql/monitors/resolvers.ts | 42 +--- .../server/graphql/monitors/schema.gql.ts | 26 --- .../elasticsearch_pings_adapter.test.ts.snap | 12 +- .../elasticsearch_pings_adapter.test.ts | 48 ++--- .../adapters/pings/es_get_ping_historgram.ts | 82 ++++++++ ...ticsearch_pings_adapter.ts => es_pings.ts} | 80 +------- .../uptime/server/lib/adapters/pings/index.ts | 4 +- .../pings/{adapter_types.ts => types.ts} | 15 +- .../server/lib/helper/assert_close_to.ts | 5 + .../plugins/uptime/server/lib/helper/index.ts | 1 - .../plugins/uptime/server/rest_api/index.ts | 2 + .../rest_api/pings/get_ping_histogram.ts | 44 ++++ .../graphql/fixtures/snapshot_histogram.json | 188 ------------------ .../snapshot_histogram_by_filter.json | 188 ------------------ .../fixtures/snapshot_histogram_by_id.json | 188 ------------------ .../apis/uptime/graphql/index.js | 1 - .../apis/uptime/graphql/snapshot_histogram.ts | 88 -------- .../uptime/rest/fixtures/ping_histogram.json | 24 +++ .../fixtures/ping_histogram_by_filter.json | 24 +++ .../rest/fixtures/ping_histogram_by_id.json | 24 +++ .../api_integration/apis/uptime/rest/index.ts | 1 + .../apis/uptime/rest/ping_histogram.ts | 64 ++++++ 53 files changed, 644 insertions(+), 1180 deletions(-) create mode 100644 x-pack/legacy/plugins/uptime/common/types/index.ts create mode 100644 x-pack/legacy/plugins/uptime/common/types/ping/histogram.ts create mode 100644 x-pack/legacy/plugins/uptime/public/components/connected/charts/ping_histogram.tsx create mode 100644 x-pack/legacy/plugins/uptime/public/components/connected/index.ts create mode 100644 x-pack/legacy/plugins/uptime/public/components/functional/charts/__tests__/__snapshots__/ping_histogram.test.tsx.snap delete mode 100644 x-pack/legacy/plugins/uptime/public/components/functional/charts/__tests__/__snapshots__/snapshot_histogram.test.tsx.snap rename x-pack/legacy/plugins/uptime/public/components/functional/charts/__tests__/{snapshot_histogram.test.tsx => ping_histogram.test.tsx} (64%) rename x-pack/legacy/plugins/uptime/public/components/functional/charts/{snapshot_histogram.tsx => ping_histogram.tsx} (76%) delete mode 100644 x-pack/legacy/plugins/uptime/public/queries/snapshot_histogram_query.ts create mode 100644 x-pack/legacy/plugins/uptime/public/state/actions/ping.ts create mode 100644 x-pack/legacy/plugins/uptime/public/state/api/ping.ts create mode 100644 x-pack/legacy/plugins/uptime/public/state/effects/ping.ts create mode 100644 x-pack/legacy/plugins/uptime/public/state/reducers/ping.ts create mode 100644 x-pack/legacy/plugins/uptime/server/lib/adapters/pings/es_get_ping_historgram.ts rename x-pack/legacy/plugins/uptime/server/lib/adapters/pings/{elasticsearch_pings_adapter.ts => es_pings.ts} (67%) rename x-pack/legacy/plugins/uptime/server/lib/adapters/pings/{adapter_types.ts => types.ts} (79%) create mode 100644 x-pack/legacy/plugins/uptime/server/rest_api/pings/get_ping_histogram.ts delete mode 100644 x-pack/test/api_integration/apis/uptime/graphql/fixtures/snapshot_histogram.json delete mode 100644 x-pack/test/api_integration/apis/uptime/graphql/fixtures/snapshot_histogram_by_filter.json delete mode 100644 x-pack/test/api_integration/apis/uptime/graphql/fixtures/snapshot_histogram_by_id.json delete mode 100644 x-pack/test/api_integration/apis/uptime/graphql/snapshot_histogram.ts create mode 100644 x-pack/test/api_integration/apis/uptime/rest/fixtures/ping_histogram.json create mode 100644 x-pack/test/api_integration/apis/uptime/rest/fixtures/ping_histogram_by_filter.json create mode 100644 x-pack/test/api_integration/apis/uptime/rest/fixtures/ping_histogram_by_id.json create mode 100644 x-pack/test/api_integration/apis/uptime/rest/ping_histogram.ts diff --git a/x-pack/legacy/plugins/uptime/common/domain_types/monitors.ts b/x-pack/legacy/plugins/uptime/common/domain_types/monitors.ts index 296df279b8eec..7f5699eb7e8a4 100644 --- a/x-pack/legacy/plugins/uptime/common/domain_types/monitors.ts +++ b/x-pack/legacy/plugins/uptime/common/domain_types/monitors.ts @@ -4,14 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { HistogramDataPoint } from '../graphql/types'; - export interface UMGqlRange { dateRangeStart: string; dateRangeEnd: string; } - -export interface HistogramResult { - histogram: HistogramDataPoint[]; - interval: number; -} diff --git a/x-pack/legacy/plugins/uptime/common/graphql/introspection.json b/x-pack/legacy/plugins/uptime/common/graphql/introspection.json index 19d9cf19cc7f8..e5d9816ebd28e 100644 --- a/x-pack/legacy/plugins/uptime/common/graphql/introspection.json +++ b/x-pack/legacy/plugins/uptime/common/graphql/introspection.json @@ -166,65 +166,6 @@ "isDeprecated": false, "deprecationReason": null }, - { - "name": "getSnapshotHistogram", - "description": "", - "args": [ - { - "name": "dateRangeStart", - "description": "", - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { "kind": "SCALAR", "name": "String", "ofType": null } - }, - "defaultValue": null - }, - { - "name": "dateRangeEnd", - "description": "", - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { "kind": "SCALAR", "name": "String", "ofType": null } - }, - "defaultValue": null - }, - { - "name": "filters", - "description": "", - "type": { "kind": "SCALAR", "name": "String", "ofType": null }, - "defaultValue": null - }, - { - "name": "statusFilter", - "description": "", - "type": { "kind": "SCALAR", "name": "String", "ofType": null }, - "defaultValue": null - }, - { - "name": "monitorId", - "description": "", - "type": { "kind": "SCALAR", "name": "String", "ofType": null }, - "defaultValue": null - } - ], - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "LIST", - "name": null, - "ofType": { - "kind": "NON_NULL", - "name": null, - "ofType": { "kind": "OBJECT", "name": "HistogramDataPoint", "ofType": null } - } - } - }, - "isDeprecated": false, - "deprecationReason": null - }, { "name": "getMonitorChartsData", "description": "", @@ -2172,57 +2113,6 @@ "enumValues": null, "possibleTypes": null }, - { - "kind": "OBJECT", - "name": "HistogramDataPoint", - "description": "", - "fields": [ - { - "name": "upCount", - "description": "", - "args": [], - "type": { "kind": "SCALAR", "name": "Int", "ofType": null }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "downCount", - "description": "", - "args": [], - "type": { "kind": "SCALAR", "name": "Int", "ofType": null }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "x", - "description": "", - "args": [], - "type": { "kind": "SCALAR", "name": "UnsignedInteger", "ofType": null }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "x0", - "description": "", - "args": [], - "type": { "kind": "SCALAR", "name": "UnsignedInteger", "ofType": null }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "y", - "description": "", - "args": [], - "type": { "kind": "SCALAR", "name": "UnsignedInteger", "ofType": null }, - "isDeprecated": false, - "deprecationReason": null - } - ], - "inputFields": null, - "interfaces": [], - "enumValues": null, - "possibleTypes": null - }, { "kind": "OBJECT", "name": "MonitorChart", @@ -3944,33 +3834,6 @@ ], "possibleTypes": null }, - { - "kind": "OBJECT", - "name": "DataPoint", - "description": "", - "fields": [ - { - "name": "x", - "description": "", - "args": [], - "type": { "kind": "SCALAR", "name": "UnsignedInteger", "ofType": null }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "y", - "description": "", - "args": [], - "type": { "kind": "SCALAR", "name": "Float", "ofType": null }, - "isDeprecated": false, - "deprecationReason": null - } - ], - "inputFields": null, - "interfaces": [], - "enumValues": null, - "possibleTypes": null - }, { "kind": "OBJECT", "name": "MonitorDurationAreaPoint", diff --git a/x-pack/legacy/plugins/uptime/common/graphql/types.ts b/x-pack/legacy/plugins/uptime/common/graphql/types.ts index 92e27d20323a7..c58dd9111cc3f 100644 --- a/x-pack/legacy/plugins/uptime/common/graphql/types.ts +++ b/x-pack/legacy/plugins/uptime/common/graphql/types.ts @@ -24,8 +24,6 @@ export interface Query { getSnapshot?: Snapshot | null; - getSnapshotHistogram: HistogramDataPoint[]; - getMonitorChartsData?: MonitorChart | null; /** Fetch the most recent event data for a monitor ID, date range, location. */ getLatestMonitors: Ping[]; @@ -419,17 +417,7 @@ export interface SnapshotCount { total: number; } -export interface HistogramDataPoint { - upCount?: number | null; - - downCount?: number | null; - - x?: UnsignedInteger | null; - - x0?: UnsignedInteger | null; - y?: UnsignedInteger | null; -} /** The data used to populate the monitor charts. */ export interface MonitorChart { /** The average values for the monitor duration. */ @@ -616,47 +604,6 @@ export interface StatesIndexStatus { docCount?: DocCount | null; } -export interface DataPoint { - x?: UnsignedInteger | null; - - y?: number | null; -} -/** Represents a monitor's duration performance in microseconds at a point in time. */ -export interface MonitorDurationAreaPoint { - /** The timeseries value for this point in time. */ - x: UnsignedInteger; - /** The min duration value in microseconds at this time. */ - yMin?: number | null; - /** The max duration value in microseconds at this point. */ - yMax?: number | null; -} - -export interface MonitorSummaryUrl { - domain?: string | null; - - fragment?: string | null; - - full?: string | null; - - original?: string | null; - - password?: string | null; - - path?: string | null; - - port?: number | null; - - query?: string | null; - - scheme?: string | null; - - username?: string | null; -} - -// ==================================================== -// Arguments -// ==================================================== - export interface AllPingsQueryArgs { /** Optional: the direction to sort by. Accepts 'asc' and 'desc'. Defaults to 'desc'. */ sort?: string | null; @@ -673,35 +620,7 @@ export interface AllPingsQueryArgs { /** Optional: agent location to filter by. */ location?: string | null; } -export interface GetMonitorsQueryArgs { - dateRangeStart: string; - - dateRangeEnd: string; - - filters?: string | null; - - statusFilter?: string | null; -} -export interface GetSnapshotQueryArgs { - dateRangeStart: string; - - dateRangeEnd: string; - - filters?: string | null; - statusFilter?: string | null; -} -export interface GetSnapshotHistogramQueryArgs { - dateRangeStart: string; - - dateRangeEnd: string; - - filters?: string | null; - - statusFilter?: string | null; - - monitorId?: string | null; -} export interface GetMonitorChartsDataQueryArgs { monitorId: string; @@ -711,11 +630,6 @@ export interface GetMonitorChartsDataQueryArgs { location?: string | null; } -export interface GetFilterBarQueryArgs { - dateRangeStart: string; - - dateRangeEnd: string; -} export interface GetMonitorStatesQueryArgs { dateRangeStart: string; diff --git a/x-pack/legacy/plugins/uptime/common/types/index.ts b/x-pack/legacy/plugins/uptime/common/types/index.ts new file mode 100644 index 0000000000000..34bfbc540672f --- /dev/null +++ b/x-pack/legacy/plugins/uptime/common/types/index.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export * from './ping/histogram'; diff --git a/x-pack/legacy/plugins/uptime/common/types/ping/histogram.ts b/x-pack/legacy/plugins/uptime/common/types/ping/histogram.ts new file mode 100644 index 0000000000000..7ac8d1f7b0151 --- /dev/null +++ b/x-pack/legacy/plugins/uptime/common/types/ping/histogram.ts @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export type UnsignedInteger = any; + +export interface HistogramDataPoint { + upCount?: number | null; + + downCount?: number | null; + + x?: UnsignedInteger | null; + + x0?: UnsignedInteger | null; + + y?: UnsignedInteger | null; +} + +export interface GetPingHistogramParams { + dateStart: string; + dateEnd: string; + filters?: string; + monitorId?: string; + statusFilter?: string; +} + +export interface HistogramResult { + histogram: HistogramDataPoint[]; + interval: string; +} diff --git a/x-pack/legacy/plugins/uptime/public/components/connected/charts/ping_histogram.tsx b/x-pack/legacy/plugins/uptime/public/components/connected/charts/ping_histogram.tsx new file mode 100644 index 0000000000000..a6607ca81fc18 --- /dev/null +++ b/x-pack/legacy/plugins/uptime/public/components/connected/charts/ping_histogram.tsx @@ -0,0 +1,76 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React, { useEffect } from 'react'; +import { connect } from 'react-redux'; +import { AppState } from '../../../state'; +import { + PingHistogramComponent, + PingHistogramComponentProps, +} from '../../functional/charts/ping_histogram'; +import { getPingHistogram } from '../../../state/actions'; +import { selectPingHistogram } from '../../../state/selectors'; +import { withResponsiveWrapper, ResponsiveWrapperProps } from '../../higher_order'; +import { GetPingHistogramParams, HistogramResult } from '../../../../common/types'; + +type Props = GetPingHistogramParams & + ResponsiveWrapperProps & + PingHistogramComponentProps & + DispatchProps & { lastRefresh: number }; + +const PingHistogramContainer: React.FC = ({ + data, + loadData, + statusFilter, + filters, + dateStart, + dateEnd, + absoluteStartDate, + absoluteEndDate, + monitorId, + lastRefresh, + ...props +}) => { + useEffect(() => { + loadData({ monitorId, dateStart, dateEnd, statusFilter, filters }); + }, [loadData, dateStart, dateEnd, monitorId, filters, statusFilter, lastRefresh]); + return ( + + ); +}; + +interface StateProps { + data: HistogramResult | null; + loading: boolean; + lastRefresh: number; +} + +interface DispatchProps { + loadData: typeof getPingHistogram; +} + +const mapStateToProps = (state: AppState): StateProps => ({ ...selectPingHistogram(state) }); + +const mapDispatchToProps = (dispatch: any): DispatchProps => ({ + loadData: (params: GetPingHistogramParams) => { + return dispatch(getPingHistogram(params)); + }, +}); + +export const PingHistogram = connect< + StateProps, + DispatchProps, + PingHistogramComponentProps, + AppState +>( + mapStateToProps, + mapDispatchToProps +)(withResponsiveWrapper(PingHistogramContainer)); diff --git a/x-pack/legacy/plugins/uptime/public/components/connected/index.ts b/x-pack/legacy/plugins/uptime/public/components/connected/index.ts new file mode 100644 index 0000000000000..f9f6aa263ed27 --- /dev/null +++ b/x-pack/legacy/plugins/uptime/public/components/connected/index.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { PingHistogram } from './charts/ping_histogram'; diff --git a/x-pack/legacy/plugins/uptime/public/components/functional/charts/__tests__/__snapshots__/chart_wrapper.test.tsx.snap b/x-pack/legacy/plugins/uptime/public/components/functional/charts/__tests__/__snapshots__/chart_wrapper.test.tsx.snap index 3f3e6b0b929e1..c1b5970f6456c 100644 --- a/x-pack/legacy/plugins/uptime/public/components/functional/charts/__tests__/__snapshots__/chart_wrapper.test.tsx.snap +++ b/x-pack/legacy/plugins/uptime/public/components/functional/charts/__tests__/__snapshots__/chart_wrapper.test.tsx.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ChartWrapper component renders the component with loading false 1`] = ` - +
-
+ `; exports[`ChartWrapper component renders the component with loading true 1`] = ` - +