Skip to content

Commit

Permalink
update destructuration
Browse files Browse the repository at this point in the history
  • Loading branch information
pa-lem committed Feb 17, 2025
1 parent a0d94e7 commit 6e48b04
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions frontend/app/src/entities/events/ui/node-events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import { Link } from "@/shared/components/ui/link";
import { Spinner } from "@/shared/components/ui/spinner";
import { useParams } from "react-router";
import { useEvents } from "../api/get-events.query";
import { INFRAHUB_EVENT } from "../utils/constants";
import { Event, EventType } from "./event";
import { Event } from "./event";

const MAX_EVENTS = 5;

export const NodeEvents = () => {
const { objectid } = useParams();

const { isLoading, data, error } = useEvents({ ids: [objectid], limit: MAX_EVENTS });
const { isLoading, data, count, error } = useEvents({ ids: [objectid], limit: MAX_EVENTS });

if (isLoading) {
return (
Expand All @@ -27,21 +26,17 @@ export const NodeEvents = () => {
return <ErrorFallback error={error} />;
}

const activities: EventType[] = data?.data?.[INFRAHUB_EVENT]?.edges?.map((edge) => {
return edge.node;
});

if (!activities?.length) {
if (!data?.length) {
return <NoDataFound message="No activity found for this object." />;
}

return (
<div className="flex flex-col gap-2 p-2">
{activities?.map((activity) => (
{data?.map((activity) => (
<Event key={activity.id} {...activity} />
))}

{data?.data?.[INFRAHUB_EVENT]?.count > MAX_EVENTS && (
{count > MAX_EVENTS && (
<div className="flex items-center justify-center">
<Link to={constructPath("/activities")} className="p-1 text-sm text-gray-400 text-center">
More events...
Expand Down

0 comments on commit 6e48b04

Please sign in to comment.