From 80cde4a2a3c0a9e7af32c84595bba9e95b145721 Mon Sep 17 00:00:00 2001 From: Yashgupta9330 Date: Thu, 10 Apr 2025 22:45:37 +0530 Subject: [PATCH 1/9] added --- backend/apps/owasp/graphql/nodes/snapshot.py | 5 +++ backend/apps/owasp/models/snapshot.py | 31 +++++++++++++++++++ frontend/src/components/SnapshotCard.tsx | 9 +++++- .../src/server/queries/snapshotQueries.ts | 1 + frontend/src/types/card.ts | 1 + frontend/src/types/snapshot.ts | 1 + 6 files changed, 47 insertions(+), 1 deletion(-) diff --git a/backend/apps/owasp/graphql/nodes/snapshot.py b/backend/apps/owasp/graphql/nodes/snapshot.py index 53c15fd78..0f9f6371e 100644 --- a/backend/apps/owasp/graphql/nodes/snapshot.py +++ b/backend/apps/owasp/graphql/nodes/snapshot.py @@ -22,6 +22,7 @@ class SnapshotNode(GenericEntityNode): new_projects = graphene.List(ProjectNode) new_releases = graphene.List(ReleaseNode) new_users = graphene.List(UserNode) + summary = graphene.String() class Meta: model = Snapshot @@ -55,3 +56,7 @@ def resolve_new_releases(self, info): def resolve_new_users(self, info): """Resolve recent new users.""" return self.new_users.order_by("-created_at") + + def resolve_summary(self, info): + """Resolve summary of the snapshot.""" + return self.generate_summary() diff --git a/backend/apps/owasp/models/snapshot.py b/backend/apps/owasp/models/snapshot.py index 6b4edf7ac..a08b0446c 100644 --- a/backend/apps/owasp/models/snapshot.py +++ b/backend/apps/owasp/models/snapshot.py @@ -51,3 +51,34 @@ def save(self, *args, **kwargs): self.key = now().strftime("%Y-%m") super().save(*args, **kwargs) + + def generate_summary(self, max_examples=2): + """Generate a snapshot summary with counts and examples.""" + summary_parts = [] + + def summarize(queryset, label, example_attr): + count = queryset.count() + if count == 0: + return None + examples = list(queryset.values_list(example_attr, flat=True)[:max_examples]) + example_str = ", ".join(str(e) for e in examples) + return f"{count} {label}{'s' if count != 1 else ''} (e.g., {example_str})" + + entities = [ + (self.new_users, "user", "login"), + (self.new_projects, "project", "name"), + (self.new_chapters, "chapter", "name"), + (self.new_issues, "issue", "title"), + (self.new_releases, "release", "tag_name"), + ] + + for queryset, label, attr in entities: + part = summarize(queryset, label, attr) + if part: + summary_parts.append(part) + + return ( + "Snapshot Summary: " + "; ".join(summary_parts) + if summary_parts + else "No new entities were added." + ) diff --git a/frontend/src/components/SnapshotCard.tsx b/frontend/src/components/SnapshotCard.tsx index 78da8c999..2dbf74558 100644 --- a/frontend/src/components/SnapshotCard.tsx +++ b/frontend/src/components/SnapshotCard.tsx @@ -4,12 +4,19 @@ import { Button } from '@heroui/button' import { SnapshotCardProps } from 'types/card' import { formatDate } from 'utils/dateFormatter' -const SnapshotCard = ({ title, button, startAt, endAt }: SnapshotCardProps) => { +const SnapshotCard = ({ title, button, startAt, endAt, summary }: SnapshotCardProps) => { + return (