Skip to content

Commit

Permalink
UI-searchable API methods/attributes (#3384)
Browse files Browse the repository at this point in the history
* user-api method/attr filtering in plugin tray
* changelog entry
* force expansion arrow to stay near top
  • Loading branch information
kecnry authored Jan 13, 2025
1 parent d019ae4 commit 1ad5fb0
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ New Features
methods to change active selection to all table items or clear all selected
items without clearing the table. [#3381]

- Plugin API methods and attributes are now searchable from the plugin tray (and visible when API hints are enabled). [#3384]

Cubeviz
^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2848,6 +2848,7 @@ def compose_viewer_area(viewer_area_items):
'name': name,
'label': tray_item_label,
'tray_item_description': tray_item_description,
'api_methods': tray_item_instance.api_methods,
'is_relevant': len(tray_item_instance.irrelevant_msg) == 0,
'widget': "IPY_MODEL_" + tray_item_instance.model_id
})
Expand Down
16 changes: 14 additions & 2 deletions jdaviz/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@
<v-list-item-subtitle v-if="state.show_api_hints" style="white-space: normal; font-size: 8pt; padding-top: 4px; padding-bottom: 4px" class="api-hint">
<span class="api-hint" :style="state.tray_items_open.includes(index) ? 'font-weight: bold' : null">plg = {{ config }}.plugins['{{ trayItem.label }}']</span>
</v-list-item-subtitle>
<v-list-item-subtitle v-if="state.show_api_hints && state.tray_items_filter.length" v-for="api_method in trayItemMethodMatch(trayItem, state.tray_items_filter)" style="white-space: normal; font-size: 8pt; padding-top: 4px; padding-bottom: 4px" class="api-hint">
<span class="api-hint">plg.{{ api_method }}</span>
</v-list-item-subtitle>
<v-list-item-subtitle style="white-space: normal; font-size: 8pt">
{{ trayItem.tray_item_description }}
</v-list-item-subtitle>
Expand Down Expand Up @@ -194,8 +197,17 @@ export default {
if (tray_items_filter === null || tray_items_filter.length == 0) {
return true
}
// simple exact text search match on the plugin title for now.
return trayItem.label.toLowerCase().indexOf(tray_items_filter.toLowerCase()) !== -1 || trayItem.tray_item_description.toLowerCase().indexOf(tray_items_filter.toLowerCase()) !== -1
// simple exact text search match on the plugin title/description for now.
return trayItem.label.toLowerCase().includes(tray_items_filter.toLowerCase()) || trayItem.tray_item_description.toLowerCase().includes(tray_items_filter.toLowerCase()) || this.trayItemMethodMatch(trayItem, tray_items_filter).length > 0
},
trayItemMethodMatch(trayItem, tray_items_filter ) {
if (tray_items_filter === null) {
return []
}
if (tray_items_filter === '.') {
return trayItem.api_methods
}
return trayItem.api_methods.filter((item) => ("."+item.toLowerCase()).includes(tray_items_filter.toLowerCase()))
},
onLayoutChange() {
/* Workaround for #1677, can be removed when bqplot/bqplot#1531 is released */
Expand Down
10 changes: 10 additions & 0 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import bqplot
from contextlib import contextmanager
import numpy as np
import inspect
import logging
import os
import threading
Expand Down Expand Up @@ -419,6 +420,7 @@ class PluginTemplateMixin(TemplateMixin):
previews_temp_disabled = Bool(False).tag(sync=True) # noqa use along-side @with_temp_disable() and <plugin-previews-temp-disabled :previews_temp_disabled.sync="previews_temp_disabled" :previews_last_time="previews_last_time" :show_live_preview.sync="show_live_preview"/>
previews_last_time = Float(0).tag(sync=True)
supports_auto_update = Bool(False).tag(sync=True) # noqa whether this plugin supports auto-updating plugin results (requires __call__ method)
api_methods = List([]).tag(sync=True) # noqa list of methods exposed to the user API, searchable

def __init__(self, app, tray_instance=False, **kwargs):
self._plugin_name = kwargs.pop('plugin_name', None)
Expand Down Expand Up @@ -465,6 +467,14 @@ def __init__(self, app, tray_instance=False, **kwargs):

super().__init__(app=app, **kwargs)

# set user-API methods
def get_api_text(name, obj):
if type(obj).__name__ == 'method':
return f"{name}{inspect.signature(obj)}"
return name
self.api_methods = sorted([get_api_text(name, obj)
for name, obj in inspect.getmembers(self.user_api)])

def new(self):
new = self.__class__(app=self.app)
new._plugin_name = self._plugin_name
Expand Down
9 changes: 9 additions & 0 deletions jdaviz/main_styles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ div.output_wrapper {
padding: 0px;
}
.plugin-header {
/* ensure dropdown arrow aligns to the top for tall headers */
align-items: start !important;
}
.plugin-header .v-expansion-panel-header__icon {
margin-top: 4px;
}
.plugin-expansion-panel-content .row {
/* override -12px margins */
margin-left: 0px;
Expand Down

0 comments on commit 1ad5fb0

Please sign in to comment.