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

[ML] Add index pattern management to index Data Visualizer #101316

Merged
merged 18 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
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 @@ -216,7 +216,11 @@ const FieldEditorComponent = ({
Boolean(field?.type) && field?.type !== (updatedType && updatedType[0].value);

return (
<Form form={form} className="indexPatternFieldEditor__form">
<Form
form={form}
className="indexPatternFieldEditor__form"
data-test-subj={'indexPatternFieldEditorForm'}
>
<EuiFlexGroup>
{/* Name */}
<EuiFlexItem>
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/data_visualizer/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"security",
"maps",
"home",
"lens"
"lens",
"indexPatternFieldEditor"
],
"requiredBundles": [
"home",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {

import { useUrlState } from '../../util/url_state';
import { useDataVisualizerKibana } from '../../../kibana_context';
import { dataVisualizerTimefilterRefresh$ } from '../../../index_data_visualizer/services/timefilter_refresh_service';
import { dataVisualizerRefresh$ } from '../../../index_data_visualizer/services/timefilter_refresh_service';

interface TimePickerQuickRange {
from: string;
Expand Down Expand Up @@ -50,7 +50,7 @@ function getRecentlyUsedRangesFactory(timeHistory: TimeHistoryContract) {
}

function updateLastRefresh(timeRange: OnRefreshProps) {
dataVisualizerTimefilterRefresh$.next({ lastRefresh: Date.now(), timeRange });
dataVisualizerRefresh$.next({ lastRefresh: Date.now(), timeRange });
}

export const DatePickerWrapper: FC = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,37 @@

import { i18n } from '@kbn/i18n';
import { Action } from '@elastic/eui/src/components/basic_table/action_types';
import { MutableRefObject } from 'react';
import { getCompatibleLensDataType, getLensAttributes } from './lens_utils';
import { IndexPattern } from '../../../../../../../../../src/plugins/data/common/index_patterns/index_patterns';
import { CombinedQuery } from '../../../../index_data_visualizer/types/combined_query';
import { FieldVisConfig } from '../../stats_table/types';
import { LensPublicStart } from '../../../../../../../lens/public';
import { DataVisualizerKibanaReactContextValue } from '../../../../kibana_context';
import {
dataVisualizerRefresh$,
Refresh,
} from '../../../../index_data_visualizer/services/timefilter_refresh_service';

export function getActions(
indexPattern: IndexPattern,
lensPlugin: LensPublicStart,
combinedQuery: CombinedQuery
services: DataVisualizerKibanaReactContextValue['services'],
combinedQuery: CombinedQuery,
actionFlyoutRef: MutableRefObject<(() => void | undefined) | undefined>
): Array<Action<FieldVisConfig>> {
const canUseLensEditor = lensPlugin.canUseEditor();
return [
{
const { lens: lensPlugin, indexPatternFieldEditor } = services;

const actions: Array<Action<FieldVisConfig>> = [];

const refreshPage = () => {
const refresh: Refresh = {
lastRefresh: Date.now(),
};
dataVisualizerRefresh$.next(refresh);
};
// Navigate to Lens with prefilled chart for data field
if (lensPlugin !== undefined) {
const canUseLensEditor = lensPlugin?.canUseEditor();
actions.push({
name: i18n.translate('xpack.dataVisualizer.index.dataGrid.exploreInLensTitle', {
defaultMessage: 'Explore in Lens',
}),
Expand All @@ -40,6 +58,56 @@ export function getActions(
}
},
'data-test-subj': 'dataVisualizerActionViewInLensButton',
},
];
});
}

// Allow to edit index pattern field
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see in Discover you get the option to delete runtime fields that have been added to the index pattern? Did you look into providing that functionality? Not a requirement for this PR, but just wondered how much work that would involve?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note as far I'm aware, the delete action should only be added for runtime fields defined in the index pattern.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the delete index pattern field option here if it's a runtime field and if user has edit index pattern permission. Note that the current EUI behavior automatically makes it a dropdown menu if there's > 2 actions. This seems to be a strict EUI guideline so I think we should revisit where would be the best place for the delete button
Screen Shot 2021-06-14 at 20 24 07

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks ok, and follows the EUI guidelines with the ellipses icon used when there are more than 2 actions.

if (indexPatternFieldEditor?.userPermissions.editIndexPattern()) {
actions.push({
name: i18n.translate('xpack.dataVisualizer.index.dataGrid.editIndexPatternFieldTitle', {
defaultMessage: 'Edit index pattern field',
}),
description: i18n.translate(
'xpack.dataVisualizer.index.dataGrid.editIndexPatternFieldDescription',
{
defaultMessage: 'Edit index pattern field',
}
),
type: 'icon',
icon: 'indexEdit',
onClick: (item: FieldVisConfig) => {
actionFlyoutRef.current = indexPatternFieldEditor?.openEditor({
ctx: { indexPattern },
fieldName: item.fieldName,
onSave: refreshPage,
});
},
'data-test-subj': 'dataVisualizerActionEditIndexPatternFieldButton',
});
actions.push({
name: i18n.translate('xpack.dataVisualizer.index.dataGrid.deleteIndexPatternFieldTitle', {
defaultMessage: 'Delete index pattern field',
}),
description: i18n.translate(
'xpack.dataVisualizer.index.dataGrid.deleteIndexPatternFieldDescription',
{
defaultMessage: 'Delete index pattern field',
}
),
type: 'icon',
icon: 'trash',
available: (item: FieldVisConfig) => {
return item.deletable === true;
},
onClick: (item: FieldVisConfig) => {
actionFlyoutRef.current = indexPatternFieldEditor?.openDeleteModal({
ctx: { indexPattern },
fieldName: item.fieldName!,
onDelete: refreshPage,
});
},
'data-test-subj': 'dataVisualizerActionDeleteIndexPatternFieldButton',
});
}
return actions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
EuiIcon,
EuiInMemoryTable,
EuiText,
EuiToolTip,
HorizontalAlignment,
LEFT_ALIGNMENT,
RIGHT_ALIGNMENT,
Expand Down Expand Up @@ -111,6 +112,7 @@ export const DataVisualizerTable = <T extends DataVisualizerTableItem>({
width: '40px',
isExpander: true,
render: (item: DataVisualizerTableItem) => {
const displayName = item.displayName ?? item.fieldName;
if (item.fieldName === undefined) return null;
const direction = expandedRowItemIds.includes(item.fieldName) ? 'arrowUp' : 'arrowDown';
return (
Expand All @@ -121,11 +123,11 @@ export const DataVisualizerTable = <T extends DataVisualizerTableItem>({
expandedRowItemIds.includes(item.fieldName)
? i18n.translate('xpack.dataVisualizer.dataGrid.rowCollapse', {
defaultMessage: 'Hide details for {fieldName}',
values: { fieldName: item.fieldName },
values: { fieldName: displayName },
})
: i18n.translate('xpack.dataVisualizer.dataGrid.rowExpand', {
defaultMessage: 'Show details for {fieldName}',
values: { fieldName: item.fieldName },
values: { fieldName: displayName },
})
}
iconType={direction}
Expand Down Expand Up @@ -157,11 +159,15 @@ export const DataVisualizerTable = <T extends DataVisualizerTableItem>({
}),
sortable: true,
truncateText: true,
render: (fieldName: string) => (
<EuiText size="s">
<b>{fieldName}</b>
</EuiText>
),
render: (fieldName: string, item: DataVisualizerTableItem) => {
const displayName = item.displayName ?? item.fieldName;

return (
<EuiText size="s">
<b data-test-subj={`dataVisualizerDisplayName-${item.fieldName}`}>{displayName}</b>
</EuiText>
);
},
align: LEFT_ALIGNMENT as HorizontalAlignment,
'data-test-subj': 'dataVisualizerTableColumnName',
},
Expand Down Expand Up @@ -194,18 +200,33 @@ export const DataVisualizerTable = <T extends DataVisualizerTableItem>({
{i18n.translate('xpack.dataVisualizer.dataGrid.distributionsColumnName', {
defaultMessage: 'Distributions',
})}
<EuiButtonIcon
style={{ marginLeft: 4 }}
size={'s'}
iconType={showDistributions ? 'eye' : 'eyeClosed'}
onClick={() => toggleShowDistribution()}
aria-label={i18n.translate(
'xpack.dataVisualizer.dataGrid.showDistributionsAriaLabel',
{
defaultMessage: 'Show distributions',
<EuiToolTip
content={
!showDistributions
? i18n.translate('xpack.dataVisualizer.dataGrid.showDistributionsTooltip', {
defaultMessage: 'Show distributions',
})
: i18n.translate('xpack.dataVisualizer.dataGrid.hideDistributionsTooltip', {
defaultMessage: 'Hide distributions',
})
}
>
<EuiButtonIcon
style={{ marginLeft: 4 }}
size={'s'}
iconType={showDistributions ? 'eye' : 'eyeClosed'}
onClick={() => toggleShowDistribution()}
aria-label={
!showDistributions
? i18n.translate('xpack.dataVisualizer.dataGrid.showDistributionsAriaLabel', {
defaultMessage: 'Show distributions',
})
: i18n.translate('xpack.dataVisualizer.dataGrid.hideDistributionsAriaLabel', {
defaultMessage: 'Hide distributions',
})
}
)}
/>
/>
</EuiToolTip>
</div>
),
render: (item: DataVisualizerTableItem) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ export interface MetricFieldVisStats {
export interface FieldVisConfig {
type: JobFieldType;
fieldName?: string;
displayName?: string;
existsInDocs: boolean;
aggregatable: boolean;
loading: boolean;
stats?: FieldVisStats;
fieldFormat?: any;
isUnsupportedType?: boolean;
deletable?: boolean;
}

export interface FileBasedFieldVisConfig {
type: JobFieldType;
fieldName?: string;
displayName?: string;
stats?: FieldVisStats;
format?: string;
}
Expand Down
Loading