Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TSVB] Enable dual mode, support index patterns and strings #92812

Merged
merged 61 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
6eeeddb
[TSVB] Enable `dual mode`, support index patterns and strings
alexwizp Feb 23, 2021
9218ccc
modify UI
alexwizp Feb 26, 2021
f8cc389
add migration script
alexwizp Feb 26, 2021
725d5e8
refactoring
alexwizp Mar 1, 2021
0f9d8ad
fix CI
alexwizp Mar 1, 2021
6fcdda5
prefill the index pattern name
alexwizp Mar 1, 2021
8a9113d
modify UI
alexwizp Mar 1, 2021
81110ac
Merge remote-tracking branch 'upstream/master' into dual_mode_tsvb_2
alexwizp Mar 1, 2021
eea56c6
modify UI
alexwizp Mar 2, 2021
6993121
Merge remote-tracking branch 'upstream/master' into dual_mode_tsvb_2
alexwizp Mar 2, 2021
5046545
update UI
alexwizp Mar 2, 2021
c41765d
fix functional test
alexwizp Mar 2, 2021
7cb454c
Merge branch 'master' into dual_mode_tsvb_2
kibanamachine Mar 3, 2021
47fc806
some work
alexwizp Mar 3, 2021
fd0d2a1
remove callouts
alexwizp Mar 3, 2021
79343e0
fix rollup test
alexwizp Mar 3, 2021
b438e57
update UI
alexwizp Mar 4, 2021
f41635b
fix typo
alexwizp Mar 4, 2021
62dee42
Merge branch 'master' into dual_mode_tsvb_2
kibanamachine Mar 4, 2021
b58329f
Merge remote-tracking branch 'upstream/master' into dual_mode_tsvb_2
alexwizp Mar 9, 2021
041a73f
add some unit tests
alexwizp Mar 9, 2021
cf1442e
Merge remote-tracking branch 'upstream/master' into dual_mode_tsvb_2
alexwizp Mar 9, 2021
d9271bf
add functional test
alexwizp Mar 9, 2021
ce17244
Merge remote-tracking branch 'upstream/master' into dual_mode_tsvb_2
alexwizp Mar 9, 2021
76c7922
Merge remote-tracking branch 'upstream/master' into dual_mode_tsvb_2
alexwizp Mar 9, 2021
ab38dc3
fix CI
alexwizp Mar 9, 2021
357af2f
correct labels
alexwizp Mar 10, 2021
46c5e56
Merge remote-tracking branch 'upstream/master' into dual_mode_tsvb_2
alexwizp Mar 11, 2021
be8ce17
fix ci group 12
alexwizp Mar 11, 2021
204b652
cleanup interface
alexwizp Mar 11, 2021
e290edf
fix CI
alexwizp Mar 12, 2021
6823b85
cleanup API
alexwizp Mar 12, 2021
7262822
Merge branch 'master' into dual_mode_tsvb_2
kibanamachine Mar 15, 2021
a5b6756
Merge branch 'master' into dual_mode_tsvb_2
kibanamachine Mar 16, 2021
3f1dfbe
Merge remote-tracking branch 'upstream/master' into dual_mode_tsvb_2
alexwizp Mar 16, 2021
d664312
fix some of PR comments
alexwizp Mar 16, 2021
f893afe
Merge remote-tracking branch 'upstream/master' into dual_mode_tsvb_2
alexwizp Mar 17, 2021
61ad553
move index patterns into so references
alexwizp Mar 18, 2021
c13ac4b
Merge branch 'master' into dual_mode_tsvb_2
kibanamachine Mar 18, 2021
4df3d13
remove wrong logic
alexwizp Mar 18, 2021
ecdb580
fix JEST
alexwizp Mar 19, 2021
bf69456
Merge remote-tracking branch 'upstream/master' into dual_mode_tsvb_2
alexwizp Mar 19, 2021
83d958d
fix some ui issues
alexwizp Mar 19, 2021
9fd52a9
update sample data
alexwizp Mar 19, 2021
61392d2
indexPatternObject -> indexPatternValue
alexwizp Mar 20, 2021
82e8a91
Merge branch 'master' into dual_mode_tsvb_2
kibanamachine Mar 22, 2021
21dfcc1
Merge branch 'master' into dual_mode_tsvb_2
kibanamachine Mar 23, 2021
ce806ab
Merge branch 'master' into dual_mode_tsvb_2
kibanamachine Mar 23, 2021
865477a
fix comments
alexwizp Mar 23, 2021
7f93d81
I have a dashboard with two TSVB viz. One with the default (haven't a…
alexwizp Mar 23, 2021
800c0e9
When I am on the string mode and try to write my index, sometimes som…
alexwizp Mar 23, 2021
12ef747
Merge remote-tracking branch 'upstream/master' into dual_mode_tsvb_2
alexwizp Mar 23, 2021
df49b43
fix merge conflicts
alexwizp Mar 23, 2021
47115a0
Does this PR also supports runtime fields? I created one from the edi…
alexwizp Mar 23, 2021
d600f39
Merge remote-tracking branch 'stratoula/master' into dual_mode_tsvb_2
alexwizp Mar 24, 2021
9715acc
fix UI issue
alexwizp Mar 25, 2021
9d7c237
If I create a viz with the string mode and a wildcard e.g. kibana_sam…
alexwizp Mar 25, 2021
9ddf39e
fix import/export refs for dashboard
alexwizp Mar 26, 2021
f882f11
remove MigrationPopover
alexwizp Mar 26, 2021
3416a94
Merge remote-tracking branch 'upstream/master' into dual_mode_tsvb_2
alexwizp Mar 26, 2021
4d5d75b
Merge branch 'master' into dual_mode_tsvb_2
kibanamachine Mar 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ export class CreateIndexPatternWizard extends Component<
context.services.setBreadcrumbs(getCreateBreadcrumbs());

const type = new URLSearchParams(props.location.search).get('type') || undefined;
const indexPattern = new URLSearchParams(props.location.search).get('name') || '';

this.state = {
step: 1,
indexPattern: '',
indexPattern,
allIndices: [],
remoteClustersExist: false,
isInitiallyLoadingIndices: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { extractIndexPatterns } from './extract_index_patterns';
import { extractIndexPatterns } from './index_patterns_utils';
import { PanelSchema } from './types';

describe('extractIndexPatterns(vis)', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
*/

import { uniq } from 'lodash';
import { PanelSchema } from '../common/types';
import { PanelSchema, IndexPatternObject } from '../common/types';

export function extractIndexPatterns(
panel: PanelSchema,
defaultIndex?: PanelSchema['default_index_pattern']
) {
const patterns: string[] = [];
const patterns: IndexPatternObject[] = [];

if (panel.index_pattern) {
patterns.push(panel.index_pattern);
Expand All @@ -39,5 +39,13 @@ export function extractIndexPatterns(
patterns.push(defaultIndex);
}

return uniq<string>(patterns).sort();
return uniq<IndexPatternObject>(patterns).sort();
}

export const convertIndexPatternObjectToStringRepresentation = (
indexPatternObject: IndexPatternObject
) =>
typeof indexPatternObject === 'string' ? indexPatternObject : indexPatternObject?.title ?? '';

export const getIndexPatternObjectKey = (indexPatternObject: IndexPatternObject) =>
typeof indexPatternObject === 'string' ? indexPatternObject : indexPatternObject?.id ?? '';
10 changes: 9 additions & 1 deletion src/plugins/vis_type_timeseries/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
*/

import { TypeOf } from '@kbn/config-schema';
import { metricsItems, panel, seriesItems, visPayloadSchema, fieldObject } from './vis_schema';
import {
metricsItems,
panel,
seriesItems,
visPayloadSchema,
fieldObject,
indexPattern,
} from './vis_schema';
import { PANEL_TYPES } from './panel_types';
import { TimeseriesUIRestrictions } from './ui_restrictions';

Expand All @@ -16,6 +23,7 @@ export type MetricsItemsSchema = TypeOf<typeof metricsItems>;
export type PanelSchema = TypeOf<typeof panel>;
export type VisPayload = TypeOf<typeof visPayloadSchema>;
export type FieldObject = TypeOf<typeof fieldObject>;
export type IndexPatternObject = TypeOf<typeof indexPattern>;

interface PanelData {
id: string;
Expand Down
16 changes: 13 additions & 3 deletions src/plugins/vis_type_timeseries/common/vis_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ const numberOptionalOrEmptyString = schema.maybe(
schema.oneOf([numberOptional, schema.literal('')])
);

export const indexPattern = schema.oneOf([
schema.maybe(schema.string()),
schema.object({
id: schema.string(),
title: schema.maybe(schema.string()),
}),
]);

export const fieldObject = stringOptionalNullable;

const annotationsItems = schema.object({
Expand All @@ -46,7 +54,7 @@ const annotationsItems = schema.object({
id: stringOptionalNullable,
ignore_global_filters: numberIntegerOptional,
ignore_panel_filters: numberIntegerOptional,
index_pattern: stringOptionalNullable,
index_pattern: indexPattern,
query_string: schema.maybe(queryObject),
template: stringOptionalNullable,
time_field: fieldObject,
Expand All @@ -67,6 +75,7 @@ const gaugeColorRulesItems = schema.object({
operator: stringOptionalNullable,
value: schema.maybe(schema.nullable(schema.number())),
});

export const metricsItems = schema.object({
field: fieldObject,
id: stringRequired,
Expand Down Expand Up @@ -166,7 +175,7 @@ export const seriesItems = schema.object({
point_size: numberOptionalOrEmptyString,
separate_axis: numberIntegerOptional,
seperate_axis: numberIntegerOptional,
series_index_pattern: stringOptionalNullable,
series_index_pattern: indexPattern,
series_max_bars: numberIntegerOptional,
series_time_field: fieldObject,
series_interval: stringOptionalNullable,
Expand All @@ -190,6 +199,7 @@ export const seriesItems = schema.object({
});

export const panel = schema.object({
use_kibana_indexes: schema.maybe(schema.boolean()),
annotations: schema.maybe(schema.arrayOf(annotationsItems)),
axis_formatter: stringRequired,
axis_position: stringRequired,
Expand Down Expand Up @@ -221,7 +231,7 @@ export const panel = schema.object({
id: stringRequired,
ignore_global_filters: numberOptional,
ignore_global_filter: numberOptional,
index_pattern: stringRequired,
index_pattern: indexPattern,
max_bars: numberIntegerOptional,
interval: stringRequired,
isModelInvalid: schema.maybe(schema.boolean()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiComboBox, EuiComboBoxProps, EuiComboBoxOptionOption } from '@elastic/eui';
import { METRIC_TYPES } from '../../../../common/metric_types';

import type { SanitizedFieldType } from '../../../../common/types';
import { getIndexPatternObjectKey } from '../../../../common/index_patterns_utils';
import type { SanitizedFieldType, IndexPatternObject } from '../../../../common/types';
import type { TimeseriesUIRestrictions } from '../../../../common/ui_restrictions';

// @ts-ignore
Expand All @@ -20,7 +20,7 @@ import { isFieldEnabled } from '../../lib/check_ui_restrictions';
interface FieldSelectProps {
type: string;
fields: Record<string, SanitizedFieldType[]>;
indexPattern: string;
indexPattern: IndexPatternObject;
value: string;
onChange: (options: Array<EuiComboBoxOptionOption<string>>) => void;
disabled?: boolean;
Expand Down Expand Up @@ -62,8 +62,10 @@ export function FieldSelect({

const selectedOptions: Array<EuiComboBoxOptionOption<string>> = [];
let newPlaceholder = placeholder;
const fieldsSelector = getIndexPatternObjectKey(indexPattern);

const groupedOptions: EuiComboBoxProps<string>['options'] = Object.values(
(fields[indexPattern] || []).reduce<Record<string, EuiComboBoxOptionOption<string>>>(
(fields[fieldsSelector] || []).reduce<Record<string, EuiComboBoxOptionOption<string>>>(
(acc, field) => {
if (placeholder === field?.name) {
newPlaceholder = field.label ?? field.name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { IndexPatternSelect } from './lib/index_pattern_select';

function newAnnotation() {
return {
Expand Down Expand Up @@ -125,11 +126,11 @@ export class AnnotationsEditor extends Component {
}
fullWidth
>
<EuiFieldText
onChange={this.handleChange(model, 'index_pattern')}
<IndexPatternSelect
value={model.index_pattern}
placeholder={defaultIndexPattern}
fullWidth
indexPatternName={'index_pattern'}
onChange={handleChange}
defaultIndexPattern={model.default_index_pattern}
/>
</EuiFormRow>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { FieldSelect } from './aggs/field_select';
import { createSelectHandler } from './lib/create_select_handler';
import { createTextHandler } from './lib/create_text_handler';
import { IndexPatternSelect } from './lib/index_pattern_select';
import { YesNo } from './yes_no';
import { KBN_FIELD_TYPES } from '../../../../../plugins/data/public';
import { FormValidationContext } from '../contexts/form_validation_context';
Expand Down Expand Up @@ -64,7 +65,8 @@ export const IndexPattern = ({
onChange,
disabled,
model: _model,
allowLevelofDetail,
allowLevelOfDetail,
allowSwitchUseKibanaIndexesMode,
}) => {
const config = getUISettings();
const timeFieldName = `${prefix}time_field`;
Expand Down Expand Up @@ -175,12 +177,13 @@ export const IndexPattern = ({
})
}
>
<EuiFieldText
data-test-subj="metricsIndexPatternInput"
disabled={disabled}
placeholder={model.default_index_pattern}
onChange={handleTextChange(indexPatternName)}
<IndexPatternSelect
value={model[indexPatternName]}
indexPatternName={indexPatternName}
onChange={onChange}
defaultIndexPattern={model.default_index_pattern}
disabled={disabled}
allowSwitchUseKibanaIndexesMode={allowSwitchUseKibanaIndexesMode}
/>
</EuiFormRow>
</EuiFlexItem>
Expand Down Expand Up @@ -243,7 +246,7 @@ export const IndexPattern = ({
</EuiFormRow>
</EuiFlexItem>
</EuiFlexGroup>
{allowLevelofDetail && (
{allowLevelOfDetail && (
<EuiFlexGroup>
<EuiFlexItem>
<EuiFormRow
Expand Down Expand Up @@ -330,5 +333,6 @@ IndexPattern.propTypes = {
prefix: PropTypes.string,
disabled: PropTypes.bool,
className: PropTypes.string,
allowLevelofDetail: PropTypes.bool,
allowLevelOfDetail: PropTypes.bool,
allowSwitchUseKibanaIndexesMode: PropTypes.bool,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React, { useCallback, useState, useEffect } from 'react';
import type { UnwrapPromise } from '@kbn/utility-types';
import { EuiComboBox, EuiComboBoxProps } from '@elastic/eui';
import { getDataStart } from '../../../../services';

import type { SelectIndexComponentProps } from './types';
import type { IndexPatternObject } from '../../../../../common/types';
import type { IndexPatternsService } from '../../../../../../data/public';
import { SwitchModePopover } from './switch_mode_popover';

/** @internal **/
type IdsWithTitle = UnwrapPromise<ReturnType<IndexPatternsService['getIdsWithTitle']>>;

const toSelectedOptions = (
value: IndexPatternObject
): EuiComboBoxProps<IndexPatternObject>['selectedOptions'] => {
if (value) {
if (typeof value === 'string') {
return [{ label: value ?? '' }];
}
return [
{
id: value.id ?? '',
label: value.title ?? '',
},
];
}
return [];
};

const toComboBoxOptions = (options: IdsWithTitle) =>
options.map(({ title, id }) => ({ label: title, id }));

export const ComboBoxSelect = ({
onIndexChange,
onModeChange,
disabled,
value,
placeholder,
allowSwitchUseKibanaIndexesMode,
'data-test-subj': dataTestSubj,
}: SelectIndexComponentProps) => {
const [availableIndexes, setAvailableIndexes] = useState<IdsWithTitle>([]);

const onComboBoxChange: EuiComboBoxProps<IndexPatternObject>['onChange'] = useCallback(
([selected]) => {
onIndexChange(selected ? { id: selected.id, title: selected.label } : '');
},
[onIndexChange]
);

useEffect(() => {
async function fetchIndexes() {
setAvailableIndexes(await getDataStart().indexPatterns.getIdsWithTitle());
}

fetchIndexes();
}, []);

return (
<EuiComboBox
singleSelection={{ asPlainText: true }}
onChange={onComboBoxChange}
options={toComboBoxOptions(availableIndexes)}
selectedOptions={toSelectedOptions(value)}
isDisabled={disabled}
placeholder={placeholder}
data-test-subj={dataTestSubj}
{...(allowSwitchUseKibanaIndexesMode && {
append: <SwitchModePopover isKibanaIndicesModeOn={true} onModeChange={onModeChange} />,
})}
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React, { useCallback } from 'react';
import { EuiFieldText, EuiFieldTextProps } from '@elastic/eui';
import { LegacyModePopover } from './legacy_mode_popover';
import { SwitchModePopover } from './switch_mode_popover';
import { convertIndexPatternObjectToStringRepresentation } from '../../../../../common/index_patterns_utils';

import type { SelectIndexComponentProps } from './types';

export const FieldTextSelect = ({
onIndexChange,
disabled,
value,
placeholder,
onModeChange,
allowSwitchUseKibanaIndexesMode,
'data-test-subj': dataTestSubj,
}: SelectIndexComponentProps) => {
const textualValue = convertIndexPatternObjectToStringRepresentation(value);
const append = [<LegacyModePopover index={textualValue} onModeChange={onModeChange} />];

const onFieldTextChange: EuiFieldTextProps['onChange'] = useCallback(
(e) => {
onIndexChange(e.target.value);
},
[onIndexChange]
);

if (allowSwitchUseKibanaIndexesMode) {
append.push(<SwitchModePopover isKibanaIndicesModeOn={false} onModeChange={onModeChange} />);
}

return (
<EuiFieldText
disabled={disabled}
onChange={onFieldTextChange}
value={textualValue}
placeholder={placeholder}
append={append}
data-test-subj={dataTestSubj}
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { IndexPatternSelect } from './index_pattern_select';
Loading