Commit 0da4f8d
authored
[ZEPPELIN-6244] Handle Collection as defaultValue in GUI.select()
# [MINOR] Handle Collection as defaultValue in GUI.select()
## What is this PR for?
This PR improves the `GUI.select()` method to properly handle Collection objects passed as defaultValue. When a Collection is provided, the method now extracts the first element as the actual default value instead of using the Collection object itself.
## What type of PR is it?
Improvement
## What is the Jira issue?
N/A (Minor improvement)
## How should this be tested?
1. Run the test: `./mvnw test -pl zeppelin-interpreter -Dtest=GUITest`
2. Verify that the new test `testSelectWithCollectionDefault()` passes
3. The test verifies that:
- When a Collection containing `["2"]` is passed as defaultValue
- The select form uses `"2"` as the default value (not the Collection object)
## Questions:
* Does the license files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No
## Description
### Problem
Currently, when using `GUI.select()` with a Collection as the defaultValue parameter, the entire Collection object is used as the default value. This can cause issues since the select form expects a single value, not a Collection.
### Solution
Added logic to check if the defaultValue is a Collection (but not a String, since String implements CharSequence which is a Collection-like interface). If it is:
- Extract the first element from the Collection
- Use that element as the actual default value
- If the Collection is empty, use null
### Code Changes
```java
// Added to GUI.select() method
if (defaultValue instanceof Collection && !(defaultValue instanceof String)) {
Collection<?> values = (Collection<?>) defaultValue;
defaultValue = values.isEmpty() ? null : values.iterator().next();
}
```
### Test Coverage
Added `testSelectWithCollectionDefault()` test that verifies:
- A Collection containing `"2"` is properly converted to default value `"2"`
- The form's default value is correctly set to `"2"`
- The selected value matches the expected default
This change improves the API's flexibility and prevents potential issues when Collections are inadvertently passed as default values.
Closes #4973 from renechoi/fix-gui-select-collection-default.
Signed-off-by: Philipp Dallig <philipp.dallig@gmail.com>1 parent 4efa2a3 commit 0da4f8d
File tree
2 files changed
+52
-0
lines changed- zeppelin-interpreter/src
- main/java/org/apache/zeppelin/display
- test/java/org/apache/zeppelin/display
2 files changed
+52
-0
lines changedLines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
99 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
100 | 110 | | |
101 | 111 | | |
102 | 112 | | |
| |||
Lines changed: 42 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| |||
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
67 | 109 | | |
68 | 110 | | |
69 | 111 | | |
| |||
0 commit comments