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

fix(legacy-charts): tune chartoptions type check #821

Merged
merged 1 commit into from Apr 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions legacy/src/Charts.js
Expand Up @@ -73,12 +73,10 @@ export function generateChart(chartId, chartType, chartController) {
},
computed: {
hasAnnotationPlugin() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
hasAnnotationPlugin() {
hasAnnotationPlugin() {
return this.chartOptions?.plugins?.hasOwnProperty(ANNOTATION_PLUGIN_KEY)

maybe better like that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dangreen Do not access Object.prototype method 'hasOwnProperty' from target object.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@thabarbados

Reflect.hasOwnProperty(this.chartOptions?.plugins, ANNOTATION_PLUGIN_KEY)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dangreen has the same error((

Copy link
Collaborator

Choose a reason for hiding this comment

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

@thabarbados

const plugins = this.chartOptions?.plugins

return plugins && Reflect.has(plugins, ANNOTATION_PLUGIN_KEY)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dangreen has Vue error in build version[Vue warn]: Property or method "chartOptions" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@thabarbados ok. please find short variant of current code, cause current variant is too long

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dangreen fixed

return (
Object.keys(this.chartOptions).length > 0 &&
'plugins' in this.chartOptions &&
Object.keys(this.chartOptions.plugins).length > 0 &&
ANNOTATION_PLUGIN_KEY in this.chartOptions.plugins
)
const pluginSettings =
this.chartOptions?.plugins?.[ANNOTATION_PLUGIN_KEY]

return typeof pluginSettings !== 'undefined'
}
},
created() {
Expand Down