-
Notifications
You must be signed in to change notification settings - Fork 27
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 DataSourceVariable doesn't use options
from initial state
#984
Conversation
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.
LGTM
if (this.state.options?.length) { | ||
return of(this.state.options); | ||
} | ||
|
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.
not sure about this, this will make it never update the options list (based on the pluginId), making it just a statically defined variable (might as well use CustomVariable) ?
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.
In my opinion we should then at least remove options
from initialState
in
public constructor(initialState: Partial<DataSourceVariableState>) { |
I needed a way to use multiple pluginId
and thought options
might be a good property, but it wasn't applied in the constructor. Instead I'm just setting the DataSourceVariable
state later than the constructor now.
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.
but it wasn't applied in the constructor.
what do you mean?
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.
The example like this, where you pass options
in the DataSourceVariable
constructor does not work right now:
const dataSourceList = getDataSourceSrv()
.getList({
filter: (datasource) => {
if (
[
'mysql',
].includes(datasource.type)
) {
return true;
}
return false;
},
})
.map((ds) => {
return { label: ds.name, value: ds.uid };
});
const dsVar = new DataSourceVariable({ label: 'Data Source', options: dataSourceList });
What I needed to do was to deliberately call dsVar.setState({options: dataSourceList});
after I created the var.
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.
@svennergr confused,
super({
type: 'datasource',
value: '',
text: '',
options: [],
name: '',
regex: '',
pluginId: '',
...initialState,
});
looks like options passed in via initialState is set, of course it will be cleared when variable activates (or the set activates). But that is it's correct behavior, options is not to be set externally really it's something it looks up using the pluginId
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.
Yea, if it's the foreseen behavior it makes sense. From just looking at the types when using the variable as a "consumer"/developer, you see options
and think it could be used.
What do you think about omitting that type in initalState
like constructor(initialState: Omit<Partial<DataSourceVariableState>, 'options'>);
Since
DataSourceVariable
is aMultiSelectVariable
the initial state can containoptions
like this:However, these
options
are not valued in its implementation ofgetValueOptions
.