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] Improve user messagging #184233

Merged
merged 13 commits into from
Jun 5, 2024

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('application-level user messages', () => {
"longMessage": "Visualization type not found.",
"severity": "error",
"shortMessage": "",
"uniqueId": "editor_missing_vis_type",
},
]
`);
Expand Down Expand Up @@ -73,6 +74,7 @@ describe('application-level user messages', () => {
"longMessage": "The visualization type id_for_type_that_doesnt_exist could not be resolved.",
"severity": "error",
"shortMessage": "Unknown visualization type",
"uniqueId": "editor_unknown_vis_type",
},
]
`);
Expand Down Expand Up @@ -102,6 +104,7 @@ describe('application-level user messages', () => {
"longMessage": "Could not find datasource for the visualization",
"severity": "error",
"shortMessage": "Unknown datasource type",
"uniqueId": "editor_unknown_datasource_type",
},
]
`);
Expand Down Expand Up @@ -210,41 +213,47 @@ describe('filtering user messages', () => {

const userMessages: UserMessage[] = [
{
uniqueId: 'unique_id_1',
severity: 'error',
fixableInEditor: true,
displayLocations: [{ id: 'dimensionButton', dimensionId: dimensionId1 }],
shortMessage: 'Warning on dimension 1!',
longMessage: '',
},
{
uniqueId: 'unique_id_2',
severity: 'warning',
fixableInEditor: true,
displayLocations: [{ id: 'dimensionButton', dimensionId: dimensionId2 }],
shortMessage: 'Warning on dimension 2!',
longMessage: '',
},
{
uniqueId: 'unique_id_3',
severity: 'warning',
fixableInEditor: true,
displayLocations: [{ id: 'banner' }],
shortMessage: 'Deprecation notice!',
longMessage: '',
},
{
uniqueId: 'unique_id_4',
severity: 'error',
fixableInEditor: true,
displayLocations: [{ id: 'visualization' }],
shortMessage: 'Visualization error!',
longMessage: '',
},
{
uniqueId: 'unique_id_5',
severity: 'error',
fixableInEditor: true,
displayLocations: [{ id: 'visualizationInEditor' }],
shortMessage: 'Visualization editor error!',
longMessage: '',
},
{
uniqueId: 'unique_id_6',
severity: 'warning',
fixableInEditor: true,
displayLocations: [{ id: 'visualizationOnEmbeddable' }],
Expand All @@ -266,6 +275,7 @@ describe('filtering user messages', () => {
"longMessage": "",
"severity": "warning",
"shortMessage": "Deprecation notice!",
"uniqueId": "unique_id_3",
},
]
`);
Expand All @@ -286,6 +296,7 @@ describe('filtering user messages', () => {
"longMessage": "",
"severity": "error",
"shortMessage": "Warning on dimension 1!",
"uniqueId": "unique_id_1",
},
]
`);
Expand All @@ -306,6 +317,7 @@ describe('filtering user messages', () => {
"longMessage": "",
"severity": "warning",
"shortMessage": "Warning on dimension 2!",
"uniqueId": "unique_id_2",
},
]
`);
Expand All @@ -322,6 +334,7 @@ describe('filtering user messages', () => {
"longMessage": "",
"severity": "error",
"shortMessage": "Visualization error!",
"uniqueId": "unique_id_4",
},
Object {
"displayLocations": Array [
Expand All @@ -333,6 +346,7 @@ describe('filtering user messages', () => {
"longMessage": "",
"severity": "error",
"shortMessage": "Visualization editor error!",
"uniqueId": "unique_id_5",
},
]
`);
Expand Down Expand Up @@ -364,6 +378,7 @@ describe('filtering user messages', () => {
"longMessage": "",
"severity": "warning",
"shortMessage": "Visualization embeddable warning!",
"uniqueId": "unique_id_6",
},
]
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ import type {
Visualization,
} from '../types';
import { getMissingIndexPattern } from '../editor_frame_service/editor_frame/state_helpers';
import {
EDITOR_MISSING_DATAVIEW,
EDITOR_MISSING_EXPRESSION_DATAVIEW,
EDITOR_MISSING_VIS_TYPE,
EDITOR_UNKNOWN_DATASOURCE_TYPE,
EDITOR_UNKNOWN_VIS_TYPE,
} from '../user_messages_ids';

/**
* Provides a place to register general user messages that don't belong in the datasource or visualization objects
Expand Down Expand Up @@ -78,6 +85,7 @@ export const getApplicationUserMessages = ({

function getMissingVisTypeError(): UserMessage {
return {
uniqueId: EDITOR_MISSING_VIS_TYPE,
severity: 'error',
displayLocations: [{ id: 'visualizationOnEmbeddable' }],
fixableInEditor: true,
Expand All @@ -90,6 +98,7 @@ function getMissingVisTypeError(): UserMessage {

function getUnknownVisualizationTypeError(visType: string): UserMessage {
return {
uniqueId: EDITOR_UNKNOWN_VIS_TYPE,
severity: 'error',
fixableInEditor: false,
displayLocations: [{ id: 'visualization' }],
Expand All @@ -107,6 +116,7 @@ function getUnknownVisualizationTypeError(visType: string): UserMessage {

function getUnknownDatasourceTypeError(): UserMessage {
return {
uniqueId: EDITOR_UNKNOWN_DATASOURCE_TYPE,
severity: 'error',
fixableInEditor: false,
displayLocations: [{ id: 'visualization' }],
Expand All @@ -130,6 +140,7 @@ function getMissingIndexPatternsErrors(
const canFix = isManagementEnabled && isIndexPatternManagementEnabled;
return [
{
uniqueId: EDITOR_MISSING_DATAVIEW,
severity: 'error',
fixableInEditor: canFix,
displayLocations: [{ id: 'visualizationInEditor' }],
Expand Down Expand Up @@ -176,6 +187,7 @@ function getMissingIndexPatternsErrors(
),
},
{
uniqueId: EDITOR_MISSING_EXPRESSION_DATAVIEW,
severity: 'error',
fixableInEditor: canFix,
displayLocations: [{ id: 'visualizationOnEmbeddable' }],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export function TimeShift({
defaultMessage: 'Enter the time shift number and unit',
})}
error={
warnings[0] ||
warnings[0] ??
(isLocalValueInvalid &&
i18n.translate('xpack.lens.indexPattern.timeShift.genericInvalidHelp', {
defaultMessage: 'Time shift value is not valid.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3095,6 +3095,7 @@ describe('IndexPattern Data Source', () => {
"longMessage": "error 1",
"severity": "error",
"shortMessage": "",
"uniqueId": "error 1",
},
Object {
"displayLocations": Array [
Expand All @@ -3106,6 +3107,7 @@ describe('IndexPattern Data Source', () => {
"longMessage": "error 2",
"severity": "error",
"shortMessage": "",
"uniqueId": "error 2",
},
]
`);
Expand Down Expand Up @@ -3160,6 +3162,7 @@ describe('IndexPattern Data Source', () => {
/>,
"severity": "error",
"shortMessage": "Layer 1 error: ",
"uniqueId": "error 1",
},
Object {
"displayLocations": Array [
Expand All @@ -3182,6 +3185,7 @@ describe('IndexPattern Data Source', () => {
/>,
"severity": "error",
"shortMessage": "Layer 1 error: ",
"uniqueId": "error 2",
},
]
`);
Expand Down Expand Up @@ -3248,6 +3252,7 @@ describe('IndexPattern Data Source', () => {
</p>,
"severity": "error",
"shortMessage": "",
"uniqueId": "editor_invalid_dimension",
},
]
`);
Expand Down Expand Up @@ -3286,6 +3291,7 @@ describe('IndexPattern Data Source', () => {
</React.Fragment>,
"severity": "error",
"shortMessage": "",
"uniqueId": undefined,
},
]
`);
Expand Down
71 changes: 41 additions & 30 deletions x-pack/plugins/lens/public/datasources/form_based/form_based.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import { isColumnOfType } from './operations/definitions/helpers';
import { LayerSettingsPanel } from './layer_settings';
import { FormBasedLayer, LastValueIndexPatternColumn } from '../..';
import { filterAndSortUserMessages } from '../../app_plugin/get_application_user_messages';
import { EDITOR_INVALID_DIMENSION } from '../../user_messages_ids';
export type { OperationType, GenericIndexPatternColumn } from './operations';
export { deleteColumn } from './operations';

Expand Down Expand Up @@ -760,48 +761,56 @@ export function getFormBasedDatasource({
layerErrorMessages,
(layerId, columnId) => {
const layer = state.layers[layerId];
return !isColumnInvalid(
const column = layer.columns[columnId];
const indexPattern = framePublicAPI.dataViews.indexPatterns[layer.indexPatternId];
if (!column || !indexPattern) {
// this is a different issue that should be catched earlier
return false;
}
return isColumnInvalid(
layer,
column,
columnId,
framePublicAPI.dataViews.indexPatterns[layer.indexPatternId],
indexPattern,
framePublicAPI.dateRange,
uiSettings.get(UI_SETTINGS.HISTOGRAM_BAR_TARGET)
);
}
);

const warningMessages = [
...[
...(getStateTimeShiftWarningMessages(data.datatableUtilities, state, framePublicAPI) ||
[]),
].map((longMessage) => {
const message: UserMessage = {
severity: 'warning',
fixableInEditor: true,
displayLocations: [{ id: 'toolbar' }],
shortMessage: '',
longMessage,
};
const timeShiftWarningMessages = getStateTimeShiftWarningMessages(
data.datatableUtilities,
state,
framePublicAPI
);

return message;
}),
...getPrecisionErrorWarningMessages(
data.datatableUtilities,
state,
framePublicAPI,
core.docLinks,
setState
),
...getUnsupportedOperationsWarningMessage(state, framePublicAPI, core.docLinks),
];
const precisionErrorWarningMsg = getPrecisionErrorWarningMessages(
data.datatableUtilities,
state,
framePublicAPI,
core.docLinks,
setState
);

const unsupportedOpsWarningMsg = getUnsupportedOperationsWarningMessage(
state,
framePublicAPI,
core.docLinks
);

const infoMessages = getNotifiableFeatures(state, framePublicAPI, visualizationInfo);

return layerErrorMessages.concat(dimensionErrorMessages, warningMessages, infoMessages);
return layerErrorMessages.concat(
dimensionErrorMessages,
timeShiftWarningMessages,
precisionErrorWarningMsg,
unsupportedOpsWarningMsg,
infoMessages
);
},

getSearchWarningMessages: (state, warning, request, response) => {
return [...getSearchWarningMessages(state, warning, request, response, core.theme)];
return getSearchWarningMessages(state, warning, request, response, core.theme);
},

checkIntegrity: (state, indexPatterns) => {
Expand Down Expand Up @@ -916,7 +925,7 @@ function getLayerErrorMessages(
setState: StateSetter<FormBasedPrivateState, unknown>,
core: CoreStart,
data: DataPublicPluginStart
) {
): UserMessage[] {
const indexPatterns = framePublicAPI.dataViews.indexPatterns;

const layerErrors: UserMessage[][] = Object.entries(state.layers)
Expand All @@ -927,6 +936,7 @@ function getLayerErrorMessages(
[]
).map((error) => {
const message: UserMessage = {
uniqueId: typeof error === 'string' ? error : error.uniqueId,
severity: 'error',
fixableInEditor: true,
displayLocations:
Expand Down Expand Up @@ -1005,7 +1015,7 @@ function getLayerErrorMessages(
function getInvalidDimensionErrorMessages(
state: FormBasedPrivateState,
currentErrorMessages: UserMessage[],
isValidColumn: (layerId: string, columnId: string) => boolean
isInvalidColumn: (layerId: string, columnId: string) => boolean
) {
// generate messages for invalid columns
const columnErrorMessages: UserMessage[] = Object.keys(state.layers)
Expand All @@ -1022,8 +1032,9 @@ function getInvalidDimensionErrorMessages(
continue;
}

if (!isValidColumn(layerId, columnId)) {
if (isInvalidColumn(layerId, columnId)) {
messages.push({
uniqueId: EDITOR_INVALID_DIMENSION,
severity: 'error',
displayLocations: [{ id: 'dimensionButton', dimensionId: columnId }],
fixableInEditor: true,
Expand Down
Loading