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: improve notifications html #8106

Merged
merged 9 commits into from
Oct 2, 2023
5 changes: 1 addition & 4 deletions packages/syft/src/syft/client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,7 @@ def __getitem__(self, key: Union[str, int]) -> Any:
def _repr_html_(self) -> Any:
if not hasattr(self, "get_all"):
return NotImplementedError
if hasattr(self, "get_all_unread"):
results = self.get_all_unread()
else:
results = self.get_all()
results = self.get_all()
return results._repr_html_()


Expand Down
20 changes: 10 additions & 10 deletions packages/syft/src/syft/service/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from result import Err
from result import Ok
from result import Result
from syft.service.user.roles import Roles

# relative
from ...serde.serializable import serializable
Expand Down Expand Up @@ -154,11 +155,7 @@ def _repr_html_(self) -> Any:
# relative
from ...service.action.action_object import ActionObject

uploaded_by_line = "n/a"
if len(self.contributors) > 0:
uploaded_by_line = (
f"<p><strong>Uploaded by: </strong>{self.uploader.name}</p>"
)
uploaded_by_line = f"<p><strong>Uploaded by: </strong>{self.uploader.name} ({self.uploader.email})</p>" if self.uploader else ""
if isinstance(self.data, ActionObject):
data_table_line = itables.to_html_datatable(
df=self.data.syft_action_data, css=itables_css
Expand Down Expand Up @@ -336,6 +333,8 @@ def add_contributor(
name=name, role=_role_str, email=email, phone=phone, note=note
)
self.contributors.append(contributor)
if _role_str == Roles.UPLOADER.value:
self.uploader = contributor
return SyftSuccess(
message=f"Contributor '{name}' added to '{self.name}' Asset."
)
Expand Down Expand Up @@ -451,12 +450,11 @@ def _coll_repr_(self) -> Dict[str, Any]:
}

def _repr_html_(self) -> Any:
uploaded_by_line = "n/a"
if len(self.contributors) > 0:
uploaded_by_line = (
uploaded_by_line = (
"<p class='paragraph-sm'><strong>"
+ f"<span class='pr-8'>Uploaded by:</span></strong>{self.uploader.name}</p>"
)
+ f"<span class='pr-8'>Uploaded by:</span></strong>{self.uploader.name} ({self.uploader.email})</p>"
) if self.uploader else ""

return f"""
<style>
{fonts_css}
Expand Down Expand Up @@ -620,6 +618,8 @@ def add_contributor(
name=name, role=_role_str, email=email, phone=phone, note=note
)
self.contributors.append(contributor)
if _role_str == Roles.UPLOADER.value:
self.uploader = contributor
return SyftSuccess(
message=f"Contributor '{name}' added to '{self.name}' Dataset."
)
Expand Down
18 changes: 18 additions & 0 deletions packages/syft/src/syft/service/notification/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from ...types.transforms import generate_id
from ...types.transforms import transform
from ...types.uid import UID
from ...util import options
from ...util.colors import SURFACE


@serializable()
Expand Down Expand Up @@ -67,6 +69,22 @@ class Notification(SyftObject):
]
__repr_attrs__ = ["subject", "status", "created_at", "linked_obj"]

def _repr_html_(self) -> str:
return f"""
<style>
.syft-request {{color: {SURFACE[options.color_theme]}; line-height: 1;}}
</style>
<div class='syft-request'>
<h3>Notification</h3>
<p><strong>ID: </strong>{self.id}</p>
<p><strong>Subject: </strong>{self.subject}</p>
<p><strong>Status: </strong>{self.status.name}</p>
<p><strong>Created at: </strong>{self.created_at}</p>
<p><strong>Linked object: </strong>{self.linked_obj}</p>
<p>
</div>
"""

@property
def link(self) -> Optional[SyftObject]:
if self.linked_obj:
Expand Down
5 changes: 4 additions & 1 deletion packages/syft/src/syft/store/linked_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ class LinkedObject(SyftObject):
object_uid: UID

def __str__(self) -> str:
return f"<{self.object_type}: {self.object_uid}@<Node: {self.node_uid}>"
resolved_obj_type = (
type(self.resolve) if self.object_type is None else self.object_type
)
return f"{resolved_obj_type.__name__}: {self.object_uid} @ Node {self.node_uid}"

@property
def resolve(self) -> SyftObject:
Expand Down