From 974a2849281b000549b52cfd54631bd7c3d9e120 Mon Sep 17 00:00:00 2001 From: sperry94 Date: Wed, 2 Oct 2019 17:14:28 -0400 Subject: [PATCH 1/8] adding file/pcap download capability --- .../public/query_bar/components/query_bar.tsx | 2 +- .../kbn_doc_views/public/views/table.html | 2 +- .../common/field_formats/types/boolean.js | 86 ++++++--- .../doc_table/components/table_header.html | 5 + .../doc_table/components/table_header.js | 2 + .../public/discover/doc_table/doc_table.html | 3 + .../public/discover/doc_table/doc_table.js | 15 ++ .../core_plugins/kibana/public/kibana.js | 1 + src/legacy/ui/field_formats/content_types.js | 4 + src/netmon/components/attach_download.tsx | 104 ++++++++++ src/netmon/components/capture_download.tsx | 105 ++++++++++ src/netmon/components/capture_header.tsx | 167 ++++++++++++++++ .../file_download/file_download_modal.tsx | 179 ++++++++++++++++++ .../file_download/file_download_row.tsx | 142 ++++++++++++++ .../components/{ => save_rule}/save_rule.tsx | 0 .../{ => save_rule}/save_rule_form.tsx | 0 .../directives/attach_download_directive.js | 34 ++++ .../directives/bind_html_compile_directive.js | 24 +++ .../directives/capture_download_directive.js | 33 ++++ .../directives/capture_header_directive.js | 35 ++++ src/netmon/directives/index.js | 24 +++ src/netmon/field_formats/boolean_formats.ts | 51 +++++ .../field_formats/should_bind_format.ts | 22 +++ 23 files changed, 1016 insertions(+), 24 deletions(-) create mode 100644 src/netmon/components/attach_download.tsx create mode 100644 src/netmon/components/capture_download.tsx create mode 100644 src/netmon/components/capture_header.tsx create mode 100644 src/netmon/components/file_download/file_download_modal.tsx create mode 100644 src/netmon/components/file_download/file_download_row.tsx rename src/netmon/components/{ => save_rule}/save_rule.tsx (100%) rename src/netmon/components/{ => save_rule}/save_rule_form.tsx (100%) create mode 100644 src/netmon/directives/attach_download_directive.js create mode 100644 src/netmon/directives/bind_html_compile_directive.js create mode 100644 src/netmon/directives/capture_download_directive.js create mode 100644 src/netmon/directives/capture_header_directive.js create mode 100644 src/netmon/directives/index.js create mode 100644 src/netmon/field_formats/boolean_formats.ts create mode 100644 src/netmon/field_formats/should_bind_format.ts diff --git a/src/legacy/core_plugins/data/public/query_bar/components/query_bar.tsx b/src/legacy/core_plugins/data/public/query_bar/components/query_bar.tsx index d61ff6a17e9de..57e547797af4d 100644 --- a/src/legacy/core_plugins/data/public/query_bar/components/query_bar.tsx +++ b/src/legacy/core_plugins/data/public/query_bar/components/query_bar.tsx @@ -44,7 +44,7 @@ import { QueryBarInput } from './query_bar_input'; import { getQueryLog } from '../lib/get_query_log'; -import { SaveRule } from '../../../../../../netmon/components/save_rule'; +import { SaveRule } from '../../../../../../netmon/components/save_rule/save_rule'; const config = chrome.getUiSettingsClient(); diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/table.html b/src/legacy/core_plugins/kbn_doc_views/public/views/table.html index 24c2d13b54746..62254b433b978 100644 --- a/src/legacy/core_plugins/kbn_doc_views/public/views/table.html +++ b/src/legacy/core_plugins/kbn_doc_views/public/views/table.html @@ -96,7 +96,7 @@ tooltip-placement="top" tooltip="{{ ::'kbnDocViews.table.objectsInArraysAreNotWellSupportedTooltip' | i18n: { defaultMessage: 'Objects in arrays are not well supported.' } }}" class="fa fa-warning text-color-warning kbnDocViewer__objectArray"> -
+
diff --git a/src/legacy/core_plugins/kibana/common/field_formats/types/boolean.js b/src/legacy/core_plugins/kibana/common/field_formats/types/boolean.js index ade71b4a5c228..ed142b5115425 100644 --- a/src/legacy/core_plugins/kibana/common/field_formats/types/boolean.js +++ b/src/legacy/core_plugins/kibana/common/field_formats/types/boolean.js @@ -17,33 +17,75 @@ * under the License. */ +import _ from 'lodash'; import { asPrettyString } from '../../utils/as_pretty_string'; +import { getHighlightHtml } from '../../../../../core_plugins/kibana/common/highlight/highlight_html'; +import { formatNetmonBoolean } from '../../../../../../netmon/field_formats/boolean_formats'; export function createBoolFormat(FieldFormat) { - return class BoolFormat extends FieldFormat { - _convert(value) { - if (typeof value === 'string') { - value = value.trim().toLowerCase(); - } - - switch (value) { - case false: - case 0: - case 'false': - case 'no': - return 'false'; - case true: - case 1: - case 'true': - case 'yes': - return 'true'; - default: - return asPrettyString(value); - } - } - + class BoolFormat extends FieldFormat { static id = 'boolean'; static title = 'Boolean'; static fieldType = ['boolean', 'number', 'string']; + } + + const getTruthy = (value) => { + switch (value) { + case false: + case 0: + case 'false': + case 'no': + return false; + case true: + case 1: + case 'true': + case 'yes': + return true; + default: + return null; + } }; + + const formatText = (value) => { + if (typeof value === 'string') { + value = value.trim().toLowerCase(); + } + + const truthy = getTruthy(value); + + if(truthy) { + return 'true'; + } else if (truthy === false) { + return 'false'; + } + + return asPrettyString(value); + }; + + const defaultHtml = (value, field, hit) => { + const formatted = _.escape(formatText(value)); + + if(!hit || !hit.highlight || !hit.highlight[field.name]) { + return formatted; + } else { + return getHighlightHtml(formatted, hit.highlight[field.name]); + } + }; + + BoolFormat.prototype._convert = { + text: function (value) { + return formatText(value); + }, + html: function (value, field, hit) { + const truthy = getTruthy(value); + + if(!field || truthy === null) { + return defaultHtml(value, field, hit); + } + + return formatNetmonBoolean(value, field, hit) || defaultHtml(value, field, hit); + } + }; + + return BoolFormat; } diff --git a/src/legacy/core_plugins/kibana/public/discover/doc_table/components/table_header.html b/src/legacy/core_plugins/kibana/public/discover/doc_table/components/table_header.html index b254461f70429..71d098a890354 100644 --- a/src/legacy/core_plugins/kibana/public/discover/doc_table/components/table_header.html +++ b/src/legacy/core_plugins/kibana/public/discover/doc_table/components/table_header.html @@ -30,6 +30,11 @@ data-test-subj="docTableHeader-{{name}}" > {{getShortDotsName(name)}} +