From 4751e44ca3097e88665e42cffedae4380a8fe7ed Mon Sep 17 00:00:00 2001 From: yincong Date: Tue, 17 Dec 2024 16:02:52 +0800 Subject: [PATCH 1/2] current value --- .../scenes/src/variables/variants/MultiValueVariable.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/scenes/src/variables/variants/MultiValueVariable.ts b/packages/scenes/src/variables/variants/MultiValueVariable.ts index b0c4df801..d0783e7b7 100644 --- a/packages/scenes/src/variables/variants/MultiValueVariable.ts +++ b/packages/scenes/src/variables/variants/MultiValueVariable.ts @@ -325,13 +325,19 @@ export abstract class MultiValueVariable(this, state); } - public getOptionsForSelect(): VariableValueOption[] { + public getOptionsForSelectWithoutCurrentValue(): VariableValueOption[] { let options = this.state.options; if (this.state.includeAll) { options = [{ value: ALL_VARIABLE_VALUE, label: ALL_VARIABLE_TEXT }, ...options]; } + return options; + } + + public getOptionsForSelect(): VariableValueOption[] { + let options = this.getOptionsForSelectWithoutCurrentValue(); + if (!Array.isArray(this.state.value)) { const current = options.find((x) => x.value === this.state.value); if (!current) { From 5ab050c7b41bc9df4fd7b86ab2aec30249114e93 Mon Sep 17 00:00:00 2001 From: yincong Date: Thu, 19 Dec 2024 10:17:42 +0800 Subject: [PATCH 2/2] optimize --- .../src/variables/variants/MultiValueVariable.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/scenes/src/variables/variants/MultiValueVariable.ts b/packages/scenes/src/variables/variants/MultiValueVariable.ts index d0783e7b7..1745dfa61 100644 --- a/packages/scenes/src/variables/variants/MultiValueVariable.ts +++ b/packages/scenes/src/variables/variants/MultiValueVariable.ts @@ -325,20 +325,14 @@ export abstract class MultiValueVariable(this, state); } - public getOptionsForSelectWithoutCurrentValue(): VariableValueOption[] { + public getOptionsForSelect(includeCurrentValue = true): VariableValueOption[] { let options = this.state.options; if (this.state.includeAll) { options = [{ value: ALL_VARIABLE_VALUE, label: ALL_VARIABLE_TEXT }, ...options]; } - return options; - } - - public getOptionsForSelect(): VariableValueOption[] { - let options = this.getOptionsForSelectWithoutCurrentValue(); - - if (!Array.isArray(this.state.value)) { + if (includeCurrentValue && !Array.isArray(this.state.value)) { const current = options.find((x) => x.value === this.state.value); if (!current) { options = [{ value: this.state.value, label: String(this.state.text) }, ...options];