-
Notifications
You must be signed in to change notification settings - Fork 15
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
GroupBy: Fetch options when opening menu #687
Conversation
@ashharrison90 - I've made a couple of changes to this PR. In particular:
@torkelo - I would appreciate your eyes on this too, as I'm touching on the |
@@ -14,6 +14,7 @@ export interface SceneVariableState extends SceneObjectState { | |||
loading?: boolean; | |||
error?: any | null; | |||
description?: string | null; | |||
isLazy?: boolean; |
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.
Thinking about putting this in the SceneVariable
interface rather than in the SceneVariableState
, don't think that would ever be needed to dynamically modify the nature of a variable during runtime. Thoughts?
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.
@dprokop would we not need it in state (to make it an persisted & UI option for QueryVariable?
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.
Yes, it would, but... I think we can lift it to the public variable API (SceneVariableState) when we work on the general problem of variables lazy loading (ref #214). I'm afraid putting it in the state right now might be confusing for consumers, as this is now an exclusive feature of Group By. I.e. configuring Query variable as lazy now makes it not usable.
@@ -67,7 +67,7 @@ export class SceneVariableSet extends SceneObjectBase<SceneVariableSetState> imp | |||
|
|||
// Add all variables that need updating to queue | |||
for (const variable of this.state.variables) { | |||
if (this._variableNeedsUpdate(variable)) { | |||
if (!variable.state.isLazy && this._variableNeedsUpdate(variable)) { |
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.
can we move this !variable.state.isLazy
condition to _variableNeedsUpdate ?
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.
Yes, I think we can. I initially thought this is called in update code paths, but it's called only for variables initialisation so it's OK to move it there. Addressed in 4a5f0db
const { value, key, maxVisibleValues, noValueOnClear } = model.useState(); | ||
const arrayValue = useMemo(() => (isArray(value) ? value : [value]), [value]); | ||
const [isFetchingOptions, setIsFetchingOptions] = useState(false); | ||
const [isOptionsOpen, setIsOptionsOpen] = useState(false); | ||
|
||
// To not trigger queries on every selection we store this state locally here and only update the variable onBlur | ||
const [uncommittedValue, setUncommittedValue] = useState(arrayValue); | ||
|
||
// Detect value changes outside | ||
useEffect(() => { | ||
setUncommittedValue(arrayValue); | ||
}, [arrayValue]); | ||
|
||
const onInputChange = model.onSearchChange | ||
? (value: string, meta: InputActionMeta) => { | ||
if (meta.action === 'input-change') { | ||
model.onSearchChange!(value); | ||
} | ||
} | ||
: undefined; | ||
|
||
const placeholder = 'Select value'; | ||
|
||
return ( |
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.
Any specific reason not doing this in the renderSelectForVariable? limit potential for bugs?
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.
Similar to my comment above - i think we need to tackle this with #214 as currently the selects rendered for variables do not have onOpenMenu
handler implemented. I've tried to change it so thast it uses the renderSelectForVariable
but this is a bigger effort that we need to address both in SceneVariableSet
and the UI for variables.
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 this is a bigger effort that we need to address both in SceneVariableSet and the UI for variables.
what more changes are needed in SceneVariableSet and UI for variables?
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.
feels weird reviewing a PR where i'm marked as author 😂
think this looks good 👍
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 🚀
🚀 PR was released in |
delivered in core with grafana/grafana#86671 |
i think this does what we want, but leaving as draft for now to check the approach before adding tests etc
what this does:
VariableValueSelectMulti
isFetchingOptions
andisOptionsOpen
logic controlled byonOpenMenu
/onCloseMenu
model.validateAndUpdate()
some questions:
VariableValueSelectMulti
🤔Fixes #686
📦 Published PR as canary version:
4.11.2--canary.687.8737546972.0
✨ Test out this PR locally via:
npm install @grafana/scenes@4.11.2--canary.687.8737546972.0 # or yarn add @grafana/scenes@4.11.2--canary.687.8737546972.0