Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into kbn-55857-saved-o…
Browse files Browse the repository at this point in the history
…bjects-structure-change
  • Loading branch information
pgayvallet committed Feb 3, 2020
2 parents 6a1f4eb + 95e40e7 commit c69c81c
Show file tree
Hide file tree
Showing 162 changed files with 2,304 additions and 889 deletions.
23 changes: 14 additions & 9 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,7 @@
/src/plugins/dev_tools/ @elastic/kibana-app

# App Architecture
/src/plugins/data/ @elastic/kibana-app-arch
/src/plugins/embeddable/ @elastic/kibana-app-arch
/src/plugins/expressions/ @elastic/kibana-app-arch
/src/plugins/kibana_react/ @elastic/kibana-app-arch
/src/plugins/kibana_utils/ @elastic/kibana-app-arch
/src/plugins/navigation/ @elastic/kibana-app-arch
/src/plugins/ui_actions/ @elastic/kibana-app-arch
/src/plugins/visualizations/ @elastic/kibana-app-arch
/x-pack/plugins/advanced_ui_actions/ @elastic/kibana-app-arch
/packages/kbn-interpreter/ @elastic/kibana-app-arch
/src/legacy/core_plugins/data/ @elastic/kibana-app-arch
/src/legacy/core_plugins/elasticsearch/lib/create_proxy.js @elastic/kibana-app-arch
/src/legacy/core_plugins/embeddable_api/ @elastic/kibana-app-arch
Expand All @@ -48,6 +40,19 @@
/src/legacy/core_plugins/kibana/server/routes/api/suggestions/ @elastic/kibana-app-arch
/src/legacy/core_plugins/visualizations/ @elastic/kibana-app-arch
/src/legacy/server/index_patterns/ @elastic/kibana-app-arch
/src/plugins/bfetch/ @elastic/kibana-app-arch
/src/plugins/dashboard_embeddable_container/ @elastic/kibana-app-arch
/src/plugins/data/ @elastic/kibana-app-arch
/src/plugins/embeddable/ @elastic/kibana-app-arch
/src/plugins/expressions/ @elastic/kibana-app-arch
/src/plugins/inspector/ @elastic/kibana-app-arch
/src/plugins/kibana_react/ @elastic/kibana-app-arch
/src/plugins/kibana_utils/ @elastic/kibana-app-arch
/src/plugins/management/ @elastic/kibana-app-arch
/src/plugins/navigation/ @elastic/kibana-app-arch
/src/plugins/ui_actions/ @elastic/kibana-app-arch
/src/plugins/visualizations/ @elastic/kibana-app-arch
/x-pack/plugins/advanced_ui_actions/ @elastic/kibana-app-arch

# APM
/x-pack/legacy/plugins/apm/ @elastic/apm-ui
Expand Down
20 changes: 10 additions & 10 deletions src/dev/ci_setup/setup_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ export KIBANA_PKG_BRANCH="$kbnBranch"
###
### download node
###
nodeVersion="$(cat "$dir/.node-version")"
nodeDir="$cacheDir/node/$nodeVersion"
nodeBin="$nodeDir/bin"
classifier="x64.tar.gz"

UNAME=$(uname)
OS="linux"
if [[ "$UNAME" = *"MINGW64_NT"* ]]; then
OS="win"
nodeBin="$HOME/node"
classifier="x64.zip"
elif [[ "$UNAME" == "Darwin" ]]; then
OS="darwin"
fi
echo " -- Running on OS: $OS"

nodeVersion="$(cat "$dir/.node-version")"
nodeDir="$cacheDir/node/$nodeVersion"

if [[ "$OS" == "win" ]]; then
nodeBin="$HOME/node"
nodeUrl="https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache/dist/v$nodeVersion/node-v$nodeVersion-win-x64.zip"
else
nodeBin="$nodeDir/bin"
nodeUrl="https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache/dist/v$nodeVersion/node-v$nodeVersion-linux-x64.tar.gz"
fi
nodeUrl="https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache/dist/v$nodeVersion/node-v$nodeVersion-${OS}-${classifier}"

if [[ "$installNode" == "true" ]]; then
echo " -- node: version=v${nodeVersion} dir=$nodeDir"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@

import _ from 'lodash';
import moment from 'moment';
import { esFilters } from '../../../../../../../plugins/data/public';
import { esFilters } from '../../../../../../plugins/data/public';
import { deserializeAggConfig } from '../../search/expressions/utils';

export function onBrushEvent(event) {
export async function onBrushEvent(event, getIndexPatterns) {
const isNumber = event.data.ordered;
const isDate = isNumber && event.data.ordered.date;

const xRaw = _.get(event.data, 'series[0].values[0].xRaw');
if (!xRaw) return [];
const column = xRaw.table.columns[xRaw.column];
if (!column) return [];
const aggConfig = event.aggConfigs[xRaw.column];
if (!aggConfig) return [];
const indexPattern = aggConfig.getIndexPattern();
if (!column.meta) return [];
const indexPattern = await getIndexPatterns().get(column.meta.indexPatternId);
const aggConfig = deserializeAggConfig({
...column.meta,
indexPattern,
});
const field = aggConfig.params.field;
if (!field) return [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,36 @@
import _ from 'lodash';
import moment from 'moment';
import expect from '@kbn/expect';

jest.mock('../../../../../ui/public/agg_types/agg_configs', () => ({
AggConfigs: function AggConfigs() {
return {
createAggConfig: ({ params }) => ({
params,
getIndexPattern: () => ({
timeFieldName: 'time',
}),
}),
};
},
}));

import { onBrushEvent } from './brush_event';

describe('brushEvent', () => {
const DAY_IN_MS = 24 * 60 * 60 * 1000;
const JAN_01_2014 = 1388559600000;

const aggConfigs = [
{
params: {},
getIndexPattern: () => ({
timeFieldName: 'time',
}),
},
];

const baseEvent = {
aggConfigs: [
{
params: {},
getIndexPattern: () => ({
timeFieldName: 'time',
}),
},
],
data: {
fieldFormatter: _.constant({}),
series: [
Expand All @@ -47,6 +62,11 @@ describe('brushEvent', () => {
columns: [
{
id: '1',
meta: {
type: 'histogram',
indexPatternId: 'indexPatternId',
aggConfigParams: aggConfigs[0].params,
},
},
],
},
Expand All @@ -69,9 +89,11 @@ describe('brushEvent', () => {
expect(onBrushEvent).to.be.a(Function);
});

test('ignores event when data.xAxisField not provided', () => {
test('ignores event when data.xAxisField not provided', async () => {
const event = _.cloneDeep(baseEvent);
const filters = onBrushEvent(event);
const filters = await onBrushEvent(event, () => ({
get: () => baseEvent.data.indexPattern,
}));
expect(filters.length).to.equal(0);
});

Expand All @@ -84,22 +106,26 @@ describe('brushEvent', () => {
};

beforeEach(() => {
aggConfigs[0].params.field = dateField;
dateEvent = _.cloneDeep(baseEvent);
dateEvent.aggConfigs[0].params.field = dateField;
dateEvent.data.ordered = { date: true };
});

test('by ignoring the event when range spans zero time', () => {
test('by ignoring the event when range spans zero time', async () => {
const event = _.cloneDeep(dateEvent);
event.range = [JAN_01_2014, JAN_01_2014];
const filters = onBrushEvent(event);
const filters = await onBrushEvent(event, () => ({
get: () => dateEvent.data.indexPattern,
}));
expect(filters.length).to.equal(0);
});

test('by updating the timefilter', () => {
test('by updating the timefilter', async () => {
const event = _.cloneDeep(dateEvent);
event.range = [JAN_01_2014, JAN_01_2014 + DAY_IN_MS];
const filters = onBrushEvent(event);
const filters = await onBrushEvent(event, () => ({
get: async () => dateEvent.data.indexPattern,
}));
expect(filters[0].range.time.gte).to.be(new Date(JAN_01_2014).toISOString());
// Set to a baseline timezone for comparison.
expect(filters[0].range.time.lt).to.be(new Date(JAN_01_2014 + DAY_IN_MS).toISOString());
Expand All @@ -114,17 +140,19 @@ describe('brushEvent', () => {
};

beforeEach(() => {
aggConfigs[0].params.field = dateField;
dateEvent = _.cloneDeep(baseEvent);
dateEvent.aggConfigs[0].params.field = dateField;
dateEvent.data.ordered = { date: true };
});

test('creates a new range filter', () => {
test('creates a new range filter', async () => {
const event = _.cloneDeep(dateEvent);
const rangeBegin = JAN_01_2014;
const rangeEnd = rangeBegin + DAY_IN_MS;
event.range = [rangeBegin, rangeEnd];
const filters = onBrushEvent(event);
const filters = await onBrushEvent(event, () => ({
get: () => dateEvent.data.indexPattern,
}));
expect(filters.length).to.equal(1);
expect(filters[0].range.anotherTimeField.gte).to.equal(moment(rangeBegin).toISOString());
expect(filters[0].range.anotherTimeField.lt).to.equal(moment(rangeEnd).toISOString());
Expand All @@ -142,22 +170,26 @@ describe('brushEvent', () => {
};

beforeEach(() => {
aggConfigs[0].params.field = numberField;
numberEvent = _.cloneDeep(baseEvent);
numberEvent.aggConfigs[0].params.field = numberField;
numberEvent.data.ordered = { date: false };
});

test('by ignoring the event when range does not span at least 2 values', () => {
test('by ignoring the event when range does not span at least 2 values', async () => {
const event = _.cloneDeep(numberEvent);
event.range = [1];
const filters = onBrushEvent(event);
const filters = await onBrushEvent(event, () => ({
get: () => numberEvent.data.indexPattern,
}));
expect(filters.length).to.equal(0);
});

test('by creating a new filter', () => {
test('by creating a new filter', async () => {
const event = _.cloneDeep(numberEvent);
event.range = [1, 2, 3, 4];
const filters = onBrushEvent(event);
const filters = await onBrushEvent(event, () => ({
get: () => numberEvent.data.indexPattern,
}));
expect(filters.length).to.equal(1);
expect(filters[0].range.numberField.gte).to.equal(1);
expect(filters[0].range.numberField.lt).to.equal(4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { chromeServiceMock } from '../../../../../../../core/public/mocks';
import { chromeServiceMock } from '../../../../../../core/public/mocks';

jest.doMock('ui/new_platform', () => ({
npStart: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
* under the License.
*/

import { onBrushEvent } from './brush_event';
import { esFilters } from '../../../../../../../plugins/data/public';
import { esFilters } from '../../../../../../plugins/data/public';
import { deserializeAggConfig } from '../../search/expressions/utils';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getIndexPatterns } from '../../../../../../plugins/data/public/services';

/**
* For terms aggregations on `__other__` buckets, this assembles a list of applicable filter
Expand Down Expand Up @@ -63,11 +65,16 @@ const getOtherBucketFilterTerms = (table, columnIndex, rowIndex) => {
* @param {string} cellValue - value of the current cell
* @return {array|string} - filter or list of filters to provide to queryFilter.addFilters()
*/
const createFilter = (aggConfigs, table, columnIndex, rowIndex, cellValue) => {
const createFilter = async (table, columnIndex, rowIndex) => {
if (!table || !table.columns || !table.columns[columnIndex]) return;
const column = table.columns[columnIndex];
const aggConfig = aggConfigs[columnIndex];
const aggConfig = deserializeAggConfig({
type: column.meta.type,
aggConfigParams: column.meta.aggConfigParams,
indexPattern: await getIndexPatterns().get(column.meta.indexPatternId),
});
let filter = [];
const value = rowIndex > -1 ? table.rows[rowIndex][column.id] : cellValue;
const value = rowIndex > -1 ? table.rows[rowIndex][column.id] : null;
if (value === null || value === undefined || !aggConfig.isFilterable()) {
return;
}
Expand All @@ -85,26 +92,28 @@ const createFilter = (aggConfigs, table, columnIndex, rowIndex, cellValue) => {
return filter;
};

const createFiltersFromEvent = event => {
const createFiltersFromEvent = async event => {
const filters = [];
const dataPoints = event.data || [event];

dataPoints
.filter(point => point)
.forEach(val => {
const { table, column, row, value } = val;
const filter = createFilter(event.aggConfigs, table, column, row, value);
if (filter) {
filter.forEach(f => {
if (event.negate) {
f = esFilters.toggleFilterNegated(f);
}
filters.push(f);
});
}
});
await Promise.all(
dataPoints
.filter(point => point)
.map(async val => {
const { table, column, row } = val;
const filter = await createFilter(table, column, row);
if (filter) {
filter.forEach(f => {
if (event.negate) {
f = esFilters.toggleFilterNegated(f);
}
filters.push(f);
});
}
})
);

return filters;
};

export { createFilter, createFiltersFromEvent, onBrushEvent };
export { createFilter, createFiltersFromEvent };
Loading

0 comments on commit c69c81c

Please sign in to comment.