Skip to content

Commit

Permalink
Correct final displays in notification inbox page
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymond Negron authored and Raymond Negron committed Apr 4, 2023
1 parent d13aa7b commit 6ab6550
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 26 deletions.
10 changes: 5 additions & 5 deletions estela-api/api/serializers/cronjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,21 @@ def update(self, instance, validated_data):
if "schedule" in validated_data:
instance.schedule = schedule
update_schedule(name, schedule)
message = f"changed the schedule of scheduled-job {instance.cjid}"
message = f"changed the schedule of scheduled-job {instance.cjid}."
if "status" in validated_data:
instance.status = status
if status == SpiderCronJob.ACTIVE_STATUS:
enable_cronjob(name)
message = f"enabled scheduled-job {instance.cjid}"
message = f"enabled scheduled-job {instance.cjid}."
elif status == SpiderCronJob.DISABLED_STATUS:
disable_cronjob(name)
message = f"disabled scheduled-job {instance.cjid}"
message = f"disabled scheduled-job {instance.cjid}."
if "unique_collection" in validated_data:
instance.unique_collection = unique_collection
if "data_status" in validated_data:
if data_status == SpiderCronJob.PERSISTENT_STATUS:
instance.data_status = SpiderCronJob.PERSISTENT_STATUS
message = f"changed data persistence of scheduled-job {instance.cjid} to Persistent"
message = f"changed data persistence of scheduled-job {instance.cjid} to Persistent."
elif data_status == SpiderCronJob.PENDING_STATUS:
instance.data_status = SpiderCronJob.PENDING_STATUS
if data_expiry_days < 1:
Expand All @@ -161,7 +161,7 @@ def update(self, instance, validated_data):
)
else:
instance.data_expiry_days = data_expiry_days
message = "changed data persistence of scheduled-job {} to {} days".format(
message = "changed data persistence of scheduled-job {} to {} days.".format(
instance.cjid, data_expiry_days
)
else:
Expand Down
8 changes: 2 additions & 6 deletions estela-api/api/serializers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ class ProjectDetailSerializer(serializers.ModelSerializer):
pid = serializers.UUIDField(
read_only=True, help_text="A UUID identifying this project."
)
name = serializers.CharField(
read_only=True, help_text="Project name."
)
name = serializers.CharField(read_only=True, help_text="Project name.")

class Meta:
model = Project
Expand Down Expand Up @@ -117,9 +115,7 @@ class ProjectUpdateSerializer(serializers.ModelSerializer):
pid = serializers.UUIDField(
read_only=True, help_text="A UUID identifying this project."
)
name = serializers.CharField(
required=False, help_text="Project name."
)
name = serializers.CharField(required=False, help_text="Project name.")
users = UserDetailSerializer(many=True, required=False, help_text="Afected users.")
user = serializers.EmailField(
write_only=True, required=False, help_text="User email address."
Expand Down
2 changes: 1 addition & 1 deletion estela-api/api/views/cronjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def create(self, request, *args, **kwargs):
project = get_object_or_404(Project, pid=self.kwargs["pid"])
self.save_notification(
user=request.user,
message=f"scheduled a new scheduled-job in {spider.name} spider",
message=f"scheduled a new scheduled-job in {spider.name} spider.",
project=project,
)

Expand Down
4 changes: 2 additions & 2 deletions estela-api/api/views/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def create(self, request, *args, **kwargs):
# Send action notification
self.save_notification(
user=user,
message=f"deployed a new spider in Deploy {serializer.data['did']}",
message=f"deployed a new spider in Deploy {serializer.data['did']}.",
project=project,
)

Expand Down Expand Up @@ -103,7 +103,7 @@ def update(self, request, *args, **kwargs):
project = get_object_or_404(Project, pid=self.kwargs["pid"])
self.save_notification(
user=instance.user,
message=f"updated a spider in Deploy {instance.did}",
message=f"updated a spider in Deploy {instance.did}.",
project=project,
)

Expand Down
8 changes: 6 additions & 2 deletions estela-api/api/views/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from api.mixins import BaseViewSet
from core.models import Notification, Project

from api.serializers.notification import NotificationSerializer
from api.serializers.notification import (
NotificationSerializer,
)


class NotificationViewSet(BaseViewSet, viewsets.ReadOnlyModelViewSet):
Expand All @@ -15,7 +17,9 @@ class NotificationViewSet(BaseViewSet, viewsets.ReadOnlyModelViewSet):
def get_queryset(self):
if self.request is None:
return Notification.objects.none()
projects = Project.objects.filter(users__in=[self.request.user.id], deleted=False)
projects = Project.objects.filter(
users__in=[self.request.user.id], deleted=False
)
return (
super(NotificationViewSet, self).get_queryset().filter(project__in=projects)
)
9 changes: 5 additions & 4 deletions estela-web/src/components/NotificationsInboxPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ export class NotificationsInboxPage extends Component<unknown, NotificationInbox
};

changeNotificationStatus(nid: number | undefined): void {
// this.apiService.apiNotificationsUpdate(nid, { seen: true }).then((response) => {
// console.log(response);
// });
const notifications = this.state.notifications;
const index = notifications.findIndex((notification) => notification.nid == nid);
notifications[index].seen = true;
Expand Down Expand Up @@ -82,7 +79,11 @@ export class NotificationsInboxPage extends Component<unknown, NotificationInbox
: notification.user.username}
</span>
{AuthService.getUserEmail() == notification.user.email ? " have " : " has "}
{notification.message}
{notification.message}&nbsp;In&nbsp;
<span className="font-semibold text-estela-black-full">
{notification.project.name}&apos;
</span>
s project.
<p className="text-xs text-estela-black-low">
{notification.createdAt?.toDateString()}
</p>
Expand Down
38 changes: 32 additions & 6 deletions estela-web/src/shared/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class CustomHeader extends Component<unknown, HeaderState> {
notifications: [],
loaded: false,
path: "",
news: true,
news: false,
};

async componentDidMount() {
Expand Down Expand Up @@ -63,9 +63,14 @@ export class CustomHeader extends Component<unknown, HeaderState> {
pageSize: 3,
};
this.apiService.apiNotificationsList(requestParams).then((response) => {
if (response.results[0].seen && response.results[1].seen && response.results[2].seen) {
this.setState({ news: false });
if (response.count === 0) {
this.setState({ news: false, loaded: true });
return;
}
response.results.find((notification) => {
notification.seen === false;
this.setState({ news: true });
});
this.setState({ notifications: response.results, loaded: true });
});
};
Expand Down Expand Up @@ -209,11 +214,25 @@ export class CustomHeader extends Component<unknown, HeaderState> {
},
];

noNotifications = (): MenuProps["items"] => [
{
key: "1",
label: (
<Content className="w-[320px] rounded-md p-2 hover:bg-estela-blue-low m-0">
<p className="text-sm text-estela-blue-full font-medium">
You don&apos;t have any notifications yet.
</p>
</Content>
),
style: { backgroundColor: "white" },
},
];

render(): JSX.Element {
const { loaded, path } = this.state;
const { path, loaded, notifications } = this.state;
return (
<>
{loaded && (
{loaded ? (
<Header className="bg-white h-[72px]">
<Row justify="center" align="middle" className="flex justify-center">
<Col flex={1} className="my-1">
Expand All @@ -222,7 +241,12 @@ export class CustomHeader extends Component<unknown, HeaderState> {
</Link>
</Col>
<Col flex={0.06}>
<Dropdown menu={{ items: this.notificationItems() }} trigger={["click"]}>
<Dropdown
menu={{
items: notifications.length ? this.notificationItems() : this.noNotifications(),
}}
trigger={["click"]}
>
{this.renderNotificationIcon(path === "/notifications/inbox")}
</Dropdown>
</Col>
Expand All @@ -246,6 +270,8 @@ export class CustomHeader extends Component<unknown, HeaderState> {
</Col>
</Row>
</Header>
) : (
<></>
)}
</>
);
Expand Down

0 comments on commit 6ab6550

Please sign in to comment.