Skip to content
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

feat: DH-16737 Add ObjectManager, useWidget hook #2030

Merged
merged 8 commits into from
Jun 4, 2024

Conversation

mofojed
Copy link
Member

@mofojed mofojed commented May 24, 2024

  • Hook for loading a widget that makes it easy to use
  • ObjectManager context allows for implementation to handle loading the object
    • On Core side, we have a very simple ObjectManager, as we just have one connection
    • On Enterprise side, the ObjectManager provided to the context manager will need to handle fetching from queries, and will be able to handle more scenarios (such as when a query is restarting)
  • Use with feat: Use useWidget hook to load widgets deephaven-plugins#502

@mofojed mofojed changed the title feat: Add ObjectManager, useWidget hook Add ObjectManager, useWidget hook May 27, 2024
@mofojed mofojed changed the title Add ObjectManager, useWidget hook feat: Add ObjectManager, useWidget hook May 27, 2024
mofojed added 5 commits May 30, 2024 16:36
- Just allows for subscribing to an object, which will allow refetching when necessary
- Cleaned up the useObjectFetch tests as well
- Still not using the useWidget hook, will use from deephaven-plugin-ui
@mofojed mofojed requested a review from mattrunyon May 30, 2024 20:40
@mofojed mofojed changed the title feat: Add ObjectManager, useWidget hook feat: DH-16737 Add ObjectManager, useWidget hook May 30, 2024
@mofojed mofojed self-assigned this May 30, 2024
@mofojed mofojed marked this pull request as ready for review May 30, 2024 20:41
Copy link
Collaborator

@mattrunyon mattrunyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we deprecate/remove useObjectFetcher with this? We still use it in at least 1 place internally and I'm not sure if that should be replaced with this

packages/jsapi-bootstrap/src/useObjectFetch.ts Outdated Show resolved Hide resolved
packages/jsapi-bootstrap/src/useObjectFetch.ts Outdated Show resolved Hide resolved
packages/jsapi-bootstrap/src/useObjectFetch.ts Outdated Show resolved Hide resolved
packages/jsapi-bootstrap/src/useObjectFetch.ts Outdated Show resolved Hide resolved
Comment on lines 84 to 88
// Signal that we're still loading
setCurrentUpdate({
fetch: null,
error: null,
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary since the state is already set to this initially? I guess it would be if objectFetchManager changed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I guess technically I could check if the old update is still fetch: null; error: null... it would technically matter if you are just looking at the object instead of destructuring it right away, as it's a new object...
I guess there's no real reason to fallback to the objectFetcher either. I should just take that out.

packages/jsapi-bootstrap/src/useObjectFetch.ts Outdated Show resolved Hide resolved
Comment on lines 70 to 81
if (objectFetchManager == null) {
if (objectFetcher == null) {
setCurrentUpdate({
fetch: null,
error: new Error('No ObjectFetchManager available in context'),
});
} else {
setCurrentUpdate({
fetch: () => objectFetcher(descriptor),
error: null,
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to be able to fetch without the object manager?

The error in the first block says no manager available, but that's true in both blocks

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also makes me wonder if these 2 should be part of the same context. Is there a case where someone should be getting just the object fetcher and not using the object fetch manager?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yea they could be combined... ObjectFetcher would be if you just want to fetch an object once, not subscribe to it and listen for updates... though not sure when you actually would want to do that.

packages/jsapi-bootstrap/src/useWidget.ts Outdated Show resolved Hide resolved
};

/**
* Retrieve a widget for the given variable descriptor. Note that if the widget is successfully fetched, ownership of the widget is passed to the consumer and will need to close the object as well.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there frequently cases where we wouldn't want to just close this when useWidget unmounts? Wondering if the norm should be we clean it up automatically and provide a config option to not clean it up automatically if you have a good reason.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, with a widget you can get updates that include new exported objects (like we do with deephaven.ui), those need to be cleaned up as well; or you may want to re-export exported objects rather than fetch them, I don't think we want to automatically close things here as it's not clear if the objects were actually fetched by the consumer or not.

packages/jsapi-bootstrap/src/useWidget.ts Outdated Show resolved Hide resolved
@mofojed mofojed changed the base branch from main to release/v0.78 May 31, 2024 13:22
@mofojed mofojed requested a review from mattrunyon May 31, 2024 17:14
@mattrunyon
Copy link
Collaborator

I think the status messages are fine (as long as they're constants). I've used tanstack query some which has each state as a boolean value in the returned object. When I was using it, it seemed to be a fine pattern as well. In the case of tanstack query it's ajax/browser fetch requests with optional refetch intervals/events.

https://tanstack.com/query/latest/docs/framework/react/reference/useQuery

- Some docs changes
- Allow other types other than just `dh.Widget` to be used
@mofojed mofojed requested a review from mattrunyon June 3, 2024 15:31
- Remove type as it's already inferred
- Add case to check if table is closed if unmounted before fetched
@mofojed mofojed requested a review from mattrunyon June 4, 2024 19:28
@mofojed mofojed merged commit 207a470 into deephaven:release/v0.78 Jun 4, 2024
10 checks passed
@mofojed mofojed deleted the object-manager branch June 4, 2024 19:31
@github-actions github-actions bot locked and limited conversation to collaborators Jun 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants