-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Improves error messages when in Dashboard #90668
Changes from 5 commits
1f08396
c428ac9
fa208ea
6fa7501
c0c78e3
a4f0edf
34ec35d
a971da9
e901240
32426a0
fd7e430
926052f
18922cd
673fe2a
a1aab98
84e67e7
d140471
2e84b4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ import { | |
import { buildExpression } from './expression_helpers'; | ||
import { Document } from '../../persistence/saved_object_store'; | ||
import { VisualizeFieldContext } from '../../../../../../src/plugins/ui_actions/public'; | ||
import { getActiveDatasourceIdFromDoc } from './state_management'; | ||
import { ErrorMessage } from '../types'; | ||
import { getMissingCurrentDatasource, getMissingVisualizationTypeError } from '../error_helper'; | ||
|
||
export async function initializeDatasources( | ||
datasourceMap: Record<string, Datasource>, | ||
|
@@ -72,15 +75,20 @@ export async function persistedStateToExpression( | |
datasources: Record<string, Datasource>, | ||
visualizations: Record<string, Visualization>, | ||
doc: Document | ||
): Promise<Ast | null> { | ||
): Promise<{ ast: Ast | null; errors: ErrorMessage[] | undefined }> { | ||
const { | ||
state: { visualization: visualizationState, datasourceStates: persistedDatasourceStates }, | ||
visualizationType, | ||
references, | ||
title, | ||
description, | ||
} = doc; | ||
if (!visualizationType) return null; | ||
if (!visualizationType) { | ||
return { | ||
ast: null, | ||
errors: [{ shortMessage: '', longMessage: getMissingVisualizationTypeError() }], | ||
}; | ||
} | ||
const visualization = visualizations[visualizationType!]; | ||
const datasourceStates = await initializeDatasources( | ||
datasources, | ||
|
@@ -97,15 +105,33 @@ export async function persistedStateToExpression( | |
|
||
const datasourceLayers = createDatasourceLayers(datasources, datasourceStates); | ||
|
||
return buildExpression({ | ||
title, | ||
description, | ||
const datasourceId = getActiveDatasourceIdFromDoc(doc); | ||
if (datasourceId == null) { | ||
return { | ||
ast: null, | ||
errors: [{ shortMessage: '', longMessage: getMissingCurrentDatasource() }], | ||
}; | ||
} | ||
const validationResult = validateDatasourceAndVisualization( | ||
datasources[datasourceId], | ||
datasourceStates[datasourceId].state, | ||
visualization, | ||
visualizationState, | ||
datasourceMap: datasources, | ||
datasourceStates, | ||
datasourceLayers, | ||
}); | ||
{ datasourceLayers } as FramePublicAPI | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a little scary - can be tighten the types here a bit? I went through our current consumers and there's one place using something besides Can we change the type of the second parameter of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Managed to isolate it and remove |
||
); | ||
|
||
return { | ||
ast: buildExpression({ | ||
title, | ||
description, | ||
visualization, | ||
visualizationState, | ||
datasourceMap: datasources, | ||
datasourceStates, | ||
datasourceLayers, | ||
}), | ||
errors: validationResult, | ||
}; | ||
} | ||
|
||
export const validateDatasourceAndVisualization = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm just realizing this function is only operating on a single datasource - I guess this is something we have to revisit once we introduce additional datasource that can be active at the same time (like SQL). Nothing for this PR though. |
||
|
@@ -114,12 +140,7 @@ export const validateDatasourceAndVisualization = ( | |
currentVisualization: Visualization | null, | ||
currentVisualizationState: unknown | undefined, | ||
frameAPI: FramePublicAPI | ||
): | ||
| Array<{ | ||
shortMessage: string; | ||
longMessage: string; | ||
}> | ||
| undefined => { | ||
): ErrorMessage[] | undefined => { | ||
const layersGroups = currentVisualizationState | ||
? currentVisualization | ||
?.getLayerIds(currentVisualizationState) | ||
|
@@ -141,7 +162,7 @@ export const validateDatasourceAndVisualization = ( | |
: undefined; | ||
|
||
const visualizationValidationErrors = currentVisualizationState | ||
? currentVisualization?.getErrorMessages(currentVisualizationState, frameAPI) | ||
? currentVisualization?.getErrorMessages(currentVisualizationState) | ||
: undefined; | ||
|
||
if (datasourceValidationErrors?.length || visualizationValidationErrors?.length) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strict equality works here, I'm surprised the linter allows ==
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any particular meaning for
null
andundefined
here, or do they have the same meaning?eslint has a special option for
null
orundefined
case in the ruleeqeqeq
, which is usually enabled.As in steps 2 and 3 of the ECMA262 Abstract Equality spec the
==
operator treat them the same exact way. So unless specific distinct meaning of the two there's no difference.