Skip to content

Commit

Permalink
[current.card.components] card component refresh
Browse files Browse the repository at this point in the history
- added interface to MetaflowCardComponent for making it REALTIME_UPDATABLE
- add realtime component rendering capabiity.
- Changed ville's abstraction of CardComponents to CardComponentManager
- introduced the `current.card.components` / `current.card['abc'].components` interface
- `current.card.components` interface helps access/remove components
  • Loading branch information
valayDave committed Sep 26, 2023
1 parent 2566019 commit bc4064a
Show file tree
Hide file tree
Showing 2 changed files with 318 additions and 52 deletions.
25 changes: 25 additions & 0 deletions metaflow/plugins/cards/card_modules/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,31 @@ def reload_content_token(self, task, data):


class MetaflowCardComponent(object):

# Setting REALTIME_UPDATABLE as True will make the card component
# updatable via the `current.card.update` method for realtime updates
REALTIME_UPDATABLE = False

_component_id = None

@property
def id(self):
return self._component_id

@id.setter
def id(self, value):
if not isinstance(value, str):
raise TypeError("id must be a string")
self._component_id = value

def update(self, *args, **kwargs):
"""
Gets called when the user calls `current.card.update(id="abc", data, myval=123)`.
The logic of the update method will be component specific. Some components may
update the contents of the component, while others can just append to the data.
"""
raise NotImplementedError()

def render(self):
"""
`render` returns a string or dictionary. This class can be called on the client side to dynamically add components to the `MetaflowCard`
Expand Down
Loading

0 comments on commit bc4064a

Please sign in to comment.