Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into migrate-rollup-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Apr 15, 2020
2 parents 9250352 + 8264352 commit 927acdd
Show file tree
Hide file tree
Showing 302 changed files with 9,881 additions and 5,736 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ <h1 class="euiScreenReaderOnly">{{screenTitle}}</h1>
position="'top'"
></icon-tip>
<span
data-test-subj="discoverIntervalSelectScaledToDesc"
i18n-id="kbn.discover.scaledToDescription"
i18n-default-message="Scaled to {bucketIntervalDescription}"
i18n-values="{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,17 +675,6 @@ function discoverController(
}
});

$scope.$watch('vis.aggs', function() {
// no timefield, no vis, nothing to update
if (!getTimeField() || !$scope.vis) return;

const buckets = $scope.vis.data.aggs.byTypeName('buckets');

if (buckets && buckets.length === 1) {
$scope.bucketInterval = buckets[0].buckets.getInterval();
}
});

$scope.$watchMulti(
['rows', 'fetchStatus'],
(function updateResultState() {
Expand Down Expand Up @@ -891,6 +880,9 @@ function discoverController(
tabifiedData,
getDimensions($scope.vis.data.aggs.aggs, $scope.timeRange)
);
if ($scope.vis.data.aggs.aggs[1]) {
$scope.bucketInterval = $scope.vis.data.aggs.aggs[1].buckets.getInterval();
}
}

$scope.hits = resp.hits.total;
Expand Down
99 changes: 48 additions & 51 deletions src/plugins/data/public/ui/saved_query_form/save_query_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useCallback } from 'react';
import {
EuiButtonEmpty,
EuiOverlayMask,
Expand Down Expand Up @@ -63,6 +63,7 @@ export function SaveQueryForm({
showTimeFilterOption = true,
}: Props) {
const [title, setTitle] = useState(savedQuery ? savedQuery.title : '');
const [enabledSaveButton, setEnabledSaveButton] = useState(Boolean(savedQuery));
const [description, setDescription] = useState(savedQuery ? savedQuery.description : '');
const [savedQueries, setSavedQueries] = useState<SavedQuery[]>([]);
const [shouldIncludeFilters, setShouldIncludeFilters] = useState(
Expand All @@ -76,49 +77,31 @@ export function SaveQueryForm({
);
const [formErrors, setFormErrors] = useState<string[]>([]);

useEffect(() => {
const fetchQueries = async () => {
const allSavedQueries = await savedQueryService.getAllSavedQueries();
const sortedAllSavedQueries = sortBy(allSavedQueries, 'attributes.title') as SavedQuery[];
setSavedQueries(sortedAllSavedQueries);
};
fetchQueries();
}, [savedQueryService]);

const savedQueryDescriptionText = i18n.translate(
'data.search.searchBar.savedQueryDescriptionText',
{
defaultMessage: 'Save query text and filters that you want to use again.',
}
);

const titleConflictErrorText = i18n.translate(
'data.search.searchBar.savedQueryForm.titleConflictText',
{
defaultMessage: 'Name conflicts with an existing saved query',
}
);
const titleMissingErrorText = i18n.translate(
'data.search.searchBar.savedQueryForm.titleMissingText',
{
defaultMessage: 'Name is required',
}
);
const whitespaceErrorText = i18n.translate(
'data.search.searchBar.savedQueryForm.whitespaceErrorText',

const savedQueryDescriptionText = i18n.translate(
'data.search.searchBar.savedQueryDescriptionText',
{
defaultMessage: 'Name cannot contain leading or trailing whitespace',
defaultMessage: 'Save query text and filters that you want to use again.',
}
);

const validate = () => {
useEffect(() => {
const fetchQueries = async () => {
const allSavedQueries = await savedQueryService.getAllSavedQueries();
const sortedAllSavedQueries = sortBy(allSavedQueries, 'attributes.title') as SavedQuery[];
setSavedQueries(sortedAllSavedQueries);
};
fetchQueries();
}, [savedQueryService]);

const validate = useCallback(() => {
const errors = [];
if (!title.length) {
errors.push(titleMissingErrorText);
}
if (title.length > title.trim().length) {
errors.push(whitespaceErrorText);
}
if (
!!savedQueries.find(
existingSavedQuery => !savedQuery && existingSavedQuery.attributes.title === title
Expand All @@ -129,14 +112,37 @@ export function SaveQueryForm({

if (!isEqual(errors, formErrors)) {
setFormErrors(errors);
return false;
}
};

const hasErrors = formErrors.length > 0;
return !formErrors.length;
}, [savedQueries, savedQuery, title, titleConflictErrorText, formErrors]);

const onClickSave = useCallback(() => {
if (validate()) {
onSave({
title,
description,
shouldIncludeFilters,
shouldIncludeTimefilter,
});
}
}, [validate, onSave, title, description, shouldIncludeFilters, shouldIncludeTimefilter]);

const onInputChange = useCallback(event => {
setEnabledSaveButton(Boolean(event.target.value));
setFormErrors([]);
setTitle(event.target.value);
}, []);

const autoTrim = useCallback(() => {
const trimmedTitle = title.trim();
if (title.length > trimmedTitle.length) {
setTitle(trimmedTitle);
}
}, [title]);

if (hasErrors) {
validate();
}
const hasErrors = formErrors.length > 0;

const saveQueryForm = (
<EuiForm isInvalid={hasErrors} error={formErrors} data-test-subj="saveQueryForm">
Expand All @@ -157,12 +163,10 @@ export function SaveQueryForm({
disabled={!!savedQuery}
value={title}
name="title"
onChange={event => {
setTitle(event.target.value);
}}
onChange={onInputChange}
data-test-subj="saveQueryFormTitle"
isInvalid={hasErrors}
onBlur={validate}
onBlur={autoTrim}
/>
</EuiFormRow>

Expand Down Expand Up @@ -235,17 +239,10 @@ export function SaveQueryForm({
</EuiButtonEmpty>

<EuiButton
onClick={() =>
onSave({
title,
description,
shouldIncludeFilters,
shouldIncludeTimefilter,
})
}
onClick={onClickSave}
fill
data-test-subj="savedQueryFormSaveButton"
disabled={hasErrors}
disabled={hasErrors || !enabledSaveButton}
>
{i18n.translate('data.search.searchBar.savedQueryFormSaveButtonText', {
defaultMessage: 'Save',
Expand Down
20 changes: 10 additions & 10 deletions test/functional/apps/discover/_discover_histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,34 @@ export default function({ getService, getPageObjects }) {
});

it('should visualize monthly data with different day intervals', async () => {
//Nov 1, 2017 @ 01:00:00.000 - Mar 21, 2018 @ 02:00:00.000
const fromTime = '2017-11-01 00:00:00.000';
const toTime = '2018-03-21 00:00:00.000';
const fromTime = 'Nov 01, 2017 @ 00:00:00.000';
const toTime = 'Mar 21, 2018 @ 00:00:00.000';
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
await PageObjects.discover.setChartInterval('Monthly');
await PageObjects.header.waitUntilLoadingHasFinished();
const chartCanvasExist = await elasticChart.canvasExists();
expect(chartCanvasExist).to.be(true);
});
it('should visualize weekly data with within DST changes', async () => {
//Nov 1, 2017 @ 01:00:00.000 - Mar 21, 2018 @ 02:00:00.000
const fromTime = '2018-03-01 00:00:00.000';
const toTime = '2018-05-01 00:00:00.000';
const fromTime = 'Mar 01, 2018 @ 00:00:00.000';
const toTime = 'May 01, 2018 @ 00:00:00.000';
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
await PageObjects.discover.setChartInterval('Weekly');
await PageObjects.header.waitUntilLoadingHasFinished();
const chartCanvasExist = await elasticChart.canvasExists();
expect(chartCanvasExist).to.be(true);
});
it('should visualize monthly data with different years Scaled to 30d', async () => {
//Nov 1, 2017 @ 01:00:00.000 - Mar 21, 2018 @ 02:00:00.000
const fromTime = '2010-01-01 00:00:00.000';
const toTime = '2018-03-21 00:00:00.000';
it('should visualize monthly data with different years Scaled to 30 days', async () => {
const fromTime = 'Jan 01, 2010 @ 00:00:00.000';
const toTime = 'Mar 21, 2019 @ 00:00:00.000';

await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
await PageObjects.discover.setChartInterval('Daily');
await PageObjects.header.waitUntilLoadingHasFinished();
const chartCanvasExist = await elasticChart.canvasExists();
expect(chartCanvasExist).to.be(true);
const chartIntervalScaledDesc = await PageObjects.discover.getChartIntervalScaledToDesc();
expect(chartIntervalScaledDesc).to.be('Scaled to 30 days');
});
});
}
24 changes: 5 additions & 19 deletions test/functional/page_objects/common_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,25 +247,11 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
}

currentUrl = (await browser.getCurrentUrl()).replace(/\/\/\w+:\w+@/, '//');
const maxAdditionalLengthOnNavUrl = 230;

// On several test failures at the end of the TileMap test we try to navigate back to
// Visualize so we can create the next Vertical Bar Chart, but we can see from the
// logging and the screenshot that it's still on the TileMap page. Why didn't the "get"
// with a new timestamped URL go? I thought that sleep(700) between the get and the
// refresh would solve the problem but didn't seem to always work.
// So this hack fails the navSuccessful check if the currentUrl doesn't match the
// appUrl plus up to 230 other chars.
// Navigating to Settings when there is a default index pattern has a URL length of 196
// (from debug output). Some other tabs may also be long. But a rather simple configured
// visualization is about 1000 chars long. So at least we catch that case.

// Browsers don't show the ':port' if it's 80 or 443 so we have to
// remove that part so we can get a match in the tests.
const navSuccessful = new RegExp(
appUrl.replace(':80/', '/').replace(':443/', '/') +
`.{0,${maxAdditionalLengthOnNavUrl}}$`
).test(currentUrl);

const navSuccessful = currentUrl
.replace(':80/', '/')
.replace(':443/', '/')
.startsWith(appUrl);

if (!navSuccessful) {
const msg = `App failed to load: ${appName} in ${defaultFindTimeout}ms appUrl=${appUrl} currentUrl=${currentUrl}`;
Expand Down
5 changes: 5 additions & 0 deletions test/functional/page_objects/discover_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ export function DiscoverPageProvider({ getService, getPageObjects }: FtrProvider
return selectedOption.getVisibleText();
}

public async getChartIntervalScaledToDesc() {
await header.waitUntilLoadingHasFinished();
return await testSubjects.getVisibleText('discoverIntervalSelectScaledToDesc');
}

public async setChartInterval(interval: string) {
const optionElement = await find.byCssSelector(`option[label="${interval}"]`, 5000);
await optionElement.click();
Expand Down
2 changes: 1 addition & 1 deletion test/typings/rison_node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

declare module 'rison-node' {
export type RisonValue = null | boolean | number | string | RisonObject | RisonArray;
export type RisonValue = undefined | null | boolean | number | string | RisonObject | RisonArray;

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface RisonArray extends Array<RisonValue> {}
Expand Down
2 changes: 1 addition & 1 deletion typings/rison_node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

declare module 'rison-node' {
export type RisonValue = null | boolean | number | string | RisonObject | RisonArray;
export type RisonValue = undefined | null | boolean | number | string | RisonObject | RisonArray;

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface RisonArray extends Array<RisonValue> {}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"xpack.lens": "legacy/plugins/lens",
"xpack.licenseMgmt": "plugins/license_management",
"xpack.licensing": "plugins/licensing",
"xpack.logstash": "legacy/plugins/logstash",
"xpack.logstash": ["plugins/logstash", "legacy/plugins/logstash"],
"xpack.main": "legacy/plugins/xpack_main",
"xpack.maps": ["plugins/maps", "legacy/plugins/maps"],
"xpack.ml": ["plugins/ml", "legacy/plugins/ml"],
Expand Down
Loading

0 comments on commit 927acdd

Please sign in to comment.