-
Notifications
You must be signed in to change notification settings - Fork 17
feat: Add ui.resolve to support URIs in dh.ui #1215
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
Changes from 13 commits
57d4ca7
daa7f03
b8b6931
cebf312
6db5dd2
ffffec6
a91fd15
fce3136
cab41be
9b5fdb9
2572afa
7b73bda
9f816fa
67c90fe
5499230
26be31b
6efa116
3359aff
cb01562
86538ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,74 @@ | ||||||
| # URI | ||||||
|
|
||||||
| URIs are a way to reference Deephaven resources, such as tables or figures, from another instance. Deephaven UI has its own `ui.resolve` method that does not require any server to server communication. Instead, the web client will communicate directly with the appropriate server to get the resource. | ||||||
|
|
||||||
| ## Usage | ||||||
|
|
||||||
| Deephaven UI provides a `resolve` method (not to be confused with `resolve` method from the Deephaven URI package) that allows you to reference Deephaven resources from other instances. Unlike the Deephaven URI package, `ui.resolve` does not resolve the URI to its resource on the server, so you cannot apply operations to the resource. | ||||||
mattrunyon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
mattrunyon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| > [!NOTE] | ||||||
| > The only valid URIs for deephaven UI at the moment are for Deephaven Enterprise persistent queries. | ||||||
mattrunyon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| > See the [Deephaven Enterprise documentation](/enterprise/docs/deephaven-database/remote-tables-python/#uris) for more information on persistent query URIs. The optional parameters are ignored by `ui.resolve`. | ||||||
mattrunyon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| ### Plain references | ||||||
|
|
||||||
| One way to use `ui.resolve` is to assign the reference to a variable which will be opened by the web UI just like you created the resource in the first place. This can be useful if you want to display tables from multiple sources in a single dashboard. | ||||||
mattrunyon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| One way to use `ui.resolve` is to assign the reference to a variable which will be opened by the web UI just like you created the resource in the first place. This can be useful if you want to display tables from multiple sources in a single dashboard. | |
| One way to use `ui.resolve` is to assign the reference to a variable which will be opened by the web UI just like you created the resource in the first place. This can be useful if you want to display tables from multiple sources in a single dashboard, without the worker defining the dashboard having to pull those resources in. |
Maybe we should just have a diagram in Mermaid, showing how it goes. Something like it going from Worker B -> Worker A -> Client to just Worker B -> Client (but make it a pretty diagram).
mattrunyon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
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.
Mixed feelings here... should we be explaining this on the Core side? Or on the Enterprise side? We really should have a utility method that accepts the query name and object name to make the URI for you, with proper encoding, ui.query_resolve or something, e.g. ui.query_resolve(query="MyQueryName", widget="MyWidget"). Technically it'd be Core+ only, but I wouldn't feel terrible about putting it in Core anyways...
As for this part - "If your URI contains any special characters" - moreso should be "You can construct a URI with any query name. If your query name contains special characters, such as spaces or slashes, you must encode the name first to avoid mangling the URL". (But nicer)
mattrunyon marked this conversation as resolved.
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"file":"components/uri.md","objects":{"t":{"type":"deephaven.ui.Element","data":{"document":{"__dhElemName":"deephaven.ui.elements.UITable","props":{"table":{"__dhElemName":"deephaven.ui.elements.UriElement","props":{"uri":"pq://MyPersistentQuery/scope/table"}},"format_":{"cols":"A","background_color":"salmon"},"showQuickFilters":false,"showGroupingColumn":true,"showSearch":false,"reverse":false}},"state":"{}"}},"picker":{"type":"deephaven.ui.Element","data":{"document":{"__dhElemName":"deephaven.ui.components.Picker","props":{"align":"start","direction":"bottom","shouldFlip":true,"label":"Picker Table","labelPosition":"top","children":{"__dhElemName":"deephaven.ui.elements.UriElement","props":{"uri":"pq://MyPersistentQuery/scope/picker_table"}}}},"state":"{}"}},"list_view":{"type":"deephaven.ui.Element","data":{"document":{"__dhElemName":"deephaven.ui.components.ListView","props":{"density":"COMPACT","overflowMode":"truncate","selectionMode":"MULTIPLE","labelColumn":"Labels","keyColumn":"Keys","children":{"__dhElemName":"deephaven.ui.elements.UriElement","props":{"uri":"pq://MyPersistentQuery/scope/list_view_table"}}}},"state":"{}"}}}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"file":"components/uri.md","objects":{"t":{"type":"deephaven.ui.Element","data":{"document":{"__dhElemName":"deephaven.ui.elements.UriElement","props":{"uri":"pq://MyPersistentQuery/scope/table"}},"state":"{}"}},"p":{"type":"deephaven.ui.Element","data":{"document":{"__dhElemName":"deephaven.ui.elements.UriElement","props":{"uri":"pq://MyPersistentQuery/scope/plot"}},"state":"{}"}},"my_dashboard":{"type":"deephaven.ui.Dashboard","data":{"document":{"__dhElemName":"deephaven.ui.components.Dashboard","props":{"children":{"__dhElemName":"__main__.basic_dashboard","props":{"children":{"__dhElemName":"deephaven.ui.components.Panel","props":{"title":"Table and Plot","direction":"column","alignItems":"start","gap":"size-100","overflow":"auto","padding":"size-100","children":{"__dhElemName":"deephaven.ui.components.Flex","props":{"gap":"size-100","flex":"auto","children":[{"__dhElemName":"deephaven.ui.elements.UriElement","props":{"uri":"pq://MyPersistentQuery/scope/table"}},{"__dhElemName":"deephaven.ui.elements.UriElement","props":{"uri":"pq://MyPersistentQuery/scope/plot"}}]}}}}}}}},"state":"{}"}}}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"file":"components/uri.md","objects":{"t":{"type":"deephaven.ui.Element","data":{"document":{"__dhElemName":"deephaven.ui.elements.UriElement","props":{"uri":"pq://My%20PQ%2Fwith%20spaces%21/scope/table"}},"state":"{}"}}}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from .Element import Element, PropsType | ||
| from .._internal import RenderContext | ||
|
|
||
|
|
||
| class UriElement(Element): | ||
| """ | ||
| Represents a remote object to be fetched by the client. | ||
|
|
||
| Args: | ||
| uri: The URI to fetch. | ||
| key: An optional key for the element. | ||
| """ | ||
|
|
||
| _uri: str | ||
|
|
||
| _key: str | None = None | ||
|
|
||
| def __init__(self, uri: str, key: str | None = None): | ||
| self._uri = uri | ||
| self._key = key | ||
|
|
||
| @property | ||
| def name(self) -> str: | ||
| return "deephaven.ui.elements.UriElement" | ||
|
|
||
| @property | ||
| def key(self) -> str | None: | ||
| return self._key | ||
|
|
||
| def render(self, context: RenderContext) -> PropsType: | ||
| return {"uri": self._uri} | ||
|
|
||
| def __eq__(self, other: object) -> bool: | ||
| if not isinstance(other, UriElement): | ||
| return False | ||
| return self._uri == other._uri and self._key == other._key | ||
|
|
||
|
|
||
| def resolve(uri: str) -> UriElement: | ||
| """ | ||
| Resolve a URI to a UriNode which can be used to fetch an object on the client from another query. | ||
|
|
||
| Args: | ||
| uri: The URI to resolve. | ||
|
|
||
| Returns: | ||
| A UriNode with the given URI. | ||
| """ | ||
| return UriElement(uri) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,14 +8,18 @@ import { | |
| ComboBoxProps as DHComboBoxJSApiProps, | ||
| } from '@deephaven/jsapi-components'; | ||
| import { isElementOfType } from '@deephaven/react-hooks'; | ||
| import type { dh } from '@deephaven/jsapi-types'; | ||
| import { ApiContext } from '@deephaven/jsapi-bootstrap'; | ||
| import { getSettings, RootState } from '@deephaven/redux'; | ||
| import { | ||
| SerializedPickerProps, | ||
| usePickerProps, | ||
| WrappedDHPickerJSApiProps, | ||
| } from './hooks/usePickerProps'; | ||
| import ObjectView from './ObjectView'; | ||
| import { useReExportedTable } from './hooks/useReExportedTable'; | ||
| import { useObjectViewObject } from './hooks/useObjectViewObject'; | ||
| import UriObjectView from './UriObjectView'; | ||
| import WidgetErrorView from '../widget/WidgetErrorView'; | ||
|
|
||
| export function ComboBox( | ||
| props: SerializedPickerProps< | ||
|
|
@@ -25,15 +29,33 @@ export function ComboBox( | |
| const settings = useSelector(getSettings<RootState>); | ||
| const { children, ...pickerProps } = usePickerProps(props); | ||
|
|
||
| const isObjectView = isElementOfType(children, ObjectView); | ||
| const table = useReExportedTable(children); | ||
| const isObjectView = | ||
| isElementOfType(children, ObjectView) || | ||
| isElementOfType(children, UriObjectView); | ||
| const { | ||
| widget: table, | ||
| api, | ||
| isLoading, | ||
| error, | ||
| } = useObjectViewObject<dh.Table>(children); | ||
|
|
||
| if (isObjectView) { | ||
| return ( | ||
| table && ( | ||
| if (error != null) { | ||
| return <WidgetErrorView error={error} />; | ||
| } | ||
| if (isLoading || table == null || api == null) { | ||
| return ( | ||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||
| <DHComboBox loadingState="loading" {...pickerProps}> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When does this state actually occur? And I was thinking we'd want something similar for the error state too, rather than the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is somewhat visible when loading from a PQ sometimes (especially first fetch) It's possibly more visible when loading via name because the check has been modified to ensure the serial doesn't exist in |
||
| {[]} | ||
| </DHComboBox> | ||
| ); | ||
| } | ||
| return ( | ||
| <ApiContext.Provider value={api}> | ||
| {/* eslint-disable-next-line react/jsx-props-no-spreading */} | ||
| <DHComboBoxJSApi {...pickerProps} table={table} settings={settings} /> | ||
| ) | ||
| </ApiContext.Provider> | ||
| ); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.