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

[Lens] provide the ability to update/modify the User Messages #184985

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
14 changes: 9 additions & 5 deletions x-pack/plugins/lens/public/embeddable/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ interface LensBaseEmbeddableInput extends EmbeddableInput {
data: Simplify<LensTableRowContextMenuEvent['data'] & PreventableEvent>
) => void;
abortController?: AbortController;
handleUserMessages?: (userMessages: UserMessage[]) => UserMessage[];
}

export type LensByValueInput = {
Expand Down Expand Up @@ -611,6 +612,7 @@ export class Embeddable
private fullAttributes: LensSavedObjectAttributes | undefined;

public getUserMessages: UserMessagesGetter = (locationId, filters) => {
const externalUserMessagesHandler = this.input.handleUserMessages ?? ((m: UserMessage[]) => m);
const userMessages: UserMessage[] = [];
userMessages.push(
...getApplicationUserMessages({
Expand All @@ -637,7 +639,7 @@ export class Embeddable
);

if (!this.savedVis) {
return userMessages;
return externalUserMessagesHandler(userMessages);
}
const mergedSearchContext = this.getMergedSearchContext();

Expand Down Expand Up @@ -683,10 +685,12 @@ export class Embeddable
}) ?? [])
);

return filterAndSortUserMessages(
[...userMessages, ...Object.values(this.additionalUserMessages)],
locationId,
filters ?? {}
return externalUserMessagesHandler(
filterAndSortUserMessages(
[...userMessages, ...Object.values(this.additionalUserMessages)],
locationId,
filters ?? {}
)
);
};

Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/lens/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,5 @@ export { LENS_EMBEDDABLE_TYPE } from '../common/constants';
export type { LensPublicStart, LensPublicSetup, LensSuggestionsApi } from './plugin';

export const plugin = () => new LensPlugin();

export { USER_MESSAGE_IDS } from './user_messages_ids';
64 changes: 64 additions & 0 deletions x-pack/plugins/lens/public/user_messages_ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,67 @@ export const GAUGE_METRIC_GT_MAX = 'gauge_metric_gt_max';
export const GAUGE_GOAL_GT_MAX = 'gauge_goal_gt_max';

export const TEXT_BASED_LANGUAGE_ERROR = 'text_based_lang_error';

export const USER_MESSAGE_IDS = {
PRECISION_ERROR_ACCURACY_MODE_ENABLED,
PRECISION_ERROR_ACCURACY_MODE_DISABLED,
PRECISION_ERROR_ASC_COUNT_PRECISION,
TSDB_UNSUPPORTED_COUNTER_OP,
LAYER_SETTINGS_RANDOM_SAMPLING_INFO,
LAYER_SETTINGS_IGNORE_GLOBAL_FILTERS,
EDITOR_MISSING_VIS_TYPE,
EDITOR_UNKNOWN_VIS_TYPE,
EDITOR_UNKNOWN_DATASOURCE_TYPE,
EDITOR_MISSING_DATAVIEW,
EDITOR_MISSING_EXPRESSION_DATAVIEW,
EDITOR_INVALID_DIMENSION,
TIMESHIFT_LT_INTERVAL,
TIMESHIFT_NOT_MULTIPLE_INTERVAL,
TERMS_WITH_MULTIPLE_TIMESHIFT,
TERMS_MULTI_TERMS_AND_SCRIPTED_FIELDS,
REDUCED_TIME_RANGE_NO_DATE_HISTOGRAM,
REDUCED_TIME_RANGE_DEFAULT_DATE_FIELD,
FIELD_NOT_FOUND,
FIELD_WRONG_TYPE,
UNSUPPORTED_DOWNSAMPLED_INDEX_AGG_PREFIX,
INCOMPLETE_ES_RESULTS,
CALCULATIONS_DATE_HISTOGRAM_REQUIRED,
CALCULATIONS_MISSING_COLUMN_REFERENCE,
CALCULATIONS_WRONG_DIMENSION_CONFIG,
TIME_SHIFT_MULTIPLE_DATE_HISTOGRAMS,
INTERVAL_OP_MISSING_UI_SETTINGS_HISTOGRAM_BAR_TARGET,
INTERVAL_OP_MISSING_TIME_RANGE,
INTERVAL_OP_MISSING_DATE_HISTOGRAM_TO_COMPUTE_INTERVAL,
TIMERANGE_OP_DATAVIEW_NOT_TIME_BASED,
TIMERANGE_OP_MISSING_TIME_RANGE,
LAST_VALUE_OP_SORT_FIELD_NOT_FOUND,
LAST_VALUE_OP_SORT_FIELD_INVALID_TYPE,
FORMULA_LAYER_ONLY_STATIC_VALUES,
STATIC_VALUE_NOT_VALID_NUMBER,
ANNOTATION_MISSING_DATE_HISTOGRAM,
ANNOTATION_MISSING_TIME_FIELD,
ANNOTATION_MISSING_TOOLTIP_FIELD,
ANNOTATION_TIME_FIELD_NOT_FOUND,
ANNOTATION_TEXT_FIELD_NOT_FOUND,
ANNOTATION_INVALID_FILTER_QUERY,
XY_BREAKDOWN_MISSING_AXIS,
XY_Y_MISSING_AXIS,
XY_X_WRONG_DATA_TYPE,
XY_Y_WRONG_DATA_TYPE,
XY_RENDER_ARRAY_VALUES,
XY_MIXED_LOG_SCALE,
XY_MIXED_LOG_SCALE_DIMENSION,
PIE_TOO_MANY_DIMENSIONS,
PIE_RENDER_ARRAY_VALUES,
WAFFLE_SMALL_VALUES,
METRIC_NUMERIC_MAX,
HEATMAP_X_MISSING_AXIS,
HEATMAP_RENDER_ARRAY_VALUES,
GAUGE_MIN_GT_MAX,
GAUGE_MIN_GT_METRIC,
GAUGE_MIN_GT_GOAL,
GAUGE_MIN_NE_MAX,
GAUGE_METRIC_GT_MAX,
GAUGE_GOAL_GT_MAX,
TEXT_BASED_LANGUAGE_ERROR,
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import React from 'react';
import { EuiPanel, EuiToolTip, type EuiPanelProps } from '@elastic/eui';
import { Action } from '@kbn/ui-actions-plugin/public';
import { css } from '@emotion/react';
import { USER_MESSAGE_IDS } from '@kbn/lens-plugin/public';
import { i18n } from '@kbn/i18n';
import { UserMessage } from '@kbn/lens-plugin/public/types';
import { useLensAttributes, type UseLensAttributesParams } from '../../hooks/use_lens_attributes';
import type { BaseChartProps } from './types';
import type { TooltipContentProps } from './metric_explanation/tooltip_content';
Expand Down Expand Up @@ -70,6 +73,45 @@ export const LensChart = React.memo(
onBrushEnd={onBrushEnd}
searchSessionId={searchSessionId}
onFilter={onFilter}
handleUserMessages={(messages) => {
return messages.reduce<{ filtered: UserMessage[]; ids: Set<string> }>(
(acc, m) => {
if (
m.displayLocations.find((d) => d.id === 'embeddableBadge') !== undefined &&
m.uniqueId === USER_MESSAGE_IDS.FIELD_NOT_FOUND &&
!acc.ids.has(USER_MESSAGE_IDS.FIELD_NOT_FOUND)
) {
acc.ids.add(USER_MESSAGE_IDS.FIELD_NOT_FOUND);
acc.filtered.push({
...m,
severity: 'warning' as const,
longMessage: (
<p>
<b>
{i18n.translate('xpack.infra.lens.b.noResultsFoundLabel', {
defaultMessage: 'No Results found',
})}
</b>
<br />
{i18n.translate('xpack.infra.lens.p.youCanShowTheLabel', {
defaultMessage:
'You can show the cpu by declaring metrics in your system integration',
})}
<br />
<a>
{i18n.translate('xpack.infra.lens.a.learnHowLabel', {
defaultMessage: 'Learn how',
})}
</a>
</p>
),
});
}
return acc;
},
{ filtered: [], ids: new Set() }
).filtered;
}}
/>
);
const content = !toolTip ? (
Expand Down