Skip to content

Commit 62fed46

Browse files
pa-lembilalabbad
andauthored
Activities cleanup and UI updates (#5937)
* start upate get events functions * wip * fix lint * remove duplicate * rename for consistency * moved file around * Styled changes on attributes * improving UI node event * extracted event details popover * more simplification * move standard events * move filters * move node events component * rename file * nowrap * update branch events * update group event * update standard event * fix group event in node details view * fix wrap * fix wrap title * fix event attributes * fix sub activities * update media query * wrap items on small screens * fix grow * update tests * update test --------- Co-authored-by: bilalabbad <[email protected]>
1 parent dee4f4e commit 62fed46

37 files changed

+276
-452
lines changed

backend/infrahub/menu/menu.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,6 @@ def _extract_node_icon(model: MainSchemaTypes) -> str:
185185
section=MenuSection.INTERNAL,
186186
order_weight=3500,
187187
),
188-
MenuItemDefinition(
189-
namespace="Builtin",
190-
name="ActivityLogs",
191-
label="Activity Logs",
192-
path="/activities",
193-
icon="mdi:format-list-bulleted",
194-
protected=True,
195-
section=MenuSection.INTERNAL,
196-
order_weight=4000,
197-
),
198188
],
199189
),
200190
MenuItemDefinition(

frontend/app/src/entities/events/api/get-event-details-from-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { EventType } from "@/entities/events/types";
12
import graphqlClient from "@/shared/api/graphql/graphqlClientApollo";
23
import { gql } from "@apollo/client";
3-
import { EventType } from "../ui/event";
4-
import { INFRAHUB_EVENT } from "../utils/constants";
4+
import { INFRAHUB_EVENT } from "../constants";
55

66
export type EventDetailsFilters = {
77
id: string;

frontend/app/src/entities/events/api/get-events-from-api.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1+
import { Get_ActivitiesQuery } from "@/shared/api/graphql/generated/graphql";
12
import graphqlClient from "@/shared/api/graphql/graphqlClientApollo";
2-
import { ContextParams } from "@/shared/api/types";
3+
import { ContextParams, PaginationParams } from "@/shared/api/types";
34
import { gql } from "@apollo/client";
4-
import { EventType } from "../ui/event";
5-
import { INFRAHUB_EVENT } from "../utils/constants";
6-
7-
export const OBJECTS_PER_PAGE = 40;
85

96
export type GlobalEventsFilters = {
107
hasChildren?: boolean;
@@ -20,6 +17,10 @@ export type GlobalEventsFilters = {
2017
limit?: number;
2118
};
2219

20+
export type GetEventsParams = ContextParams & PaginationParams & { filters: GlobalEventsFilters };
21+
22+
export const OBJECTS_PER_PAGE = 40;
23+
2324
const EVENTS_QUERY = gql`
2425
query GET_ACTIVITIES(
2526
$hasChildren: Boolean
@@ -126,9 +127,9 @@ export async function getEventsFromApi({
126127
limit = OBJECTS_PER_PAGE,
127128
branchName,
128129
atDate,
129-
...filters
130-
}: GlobalEventsFilters & ContextParams) {
131-
const { data } = await graphqlClient.query({
130+
filters,
131+
}: GetEventsParams) {
132+
return graphqlClient.query<Get_ActivitiesQuery>({
132133
query: EVENTS_QUERY,
133134
variables: {
134135
limit,
@@ -139,10 +140,4 @@ export async function getEventsFromApi({
139140
date: atDate,
140141
},
141142
});
142-
143-
const activities: EventType[] = data?.[INFRAHUB_EVENT]?.edges?.map((edge) => {
144-
return edge.node;
145-
});
146-
147-
return activities;
148143
}
Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
import { useCurrentBranch } from "@/entities/branches/ui/branches-provider";
22
import { ContextParams } from "@/shared/api/types";
3-
import { datetimeAtom } from "@/shared/stores/time.atom";
43
import { infiniteQueryOptions, useInfiniteQuery } from "@tanstack/react-query";
5-
import { useAtomValue } from "jotai";
6-
import { GlobalEventsFilters, OBJECTS_PER_PAGE, getEventsFromApi } from "./get-events-from-api";
4+
import { getEvents } from "../domain/get-events";
5+
import { GlobalEventsFilters, OBJECTS_PER_PAGE } from "./get-events-from-api";
76

87
export function getEventsQueryOptions({
98
filters,
109
branchName,
11-
atDate,
1210
}: { filters: GlobalEventsFilters } & ContextParams) {
1311
return infiniteQueryOptions({
14-
queryKey: [branchName, atDate, "events", filters],
15-
queryFn: ({ pageParam }) => {
16-
return getEventsFromApi({
17-
...filters,
12+
queryKey: [branchName, "events", filters],
13+
queryFn: ({ pageParam }) =>
14+
getEvents({
15+
filters,
1816
offset: pageParam,
1917
branchName,
20-
atDate,
21-
});
22-
},
18+
}),
2319
initialPageParam: 0,
2420
getNextPageParam: (lastPage, _, lastPageParam) => {
2521
if (lastPage?.length < OBJECTS_PER_PAGE) {
@@ -32,9 +28,6 @@ export function getEventsQueryOptions({
3228

3329
export const useEvents = ({ filters }: { filters: GlobalEventsFilters }) => {
3430
const { currentBranch } = useCurrentBranch();
35-
const timeMachineDate = useAtomValue(datetimeAtom);
3631

37-
return useInfiniteQuery(
38-
getEventsQueryOptions({ filters, branchName: currentBranch.name, atDate: timeMachineDate })
39-
);
32+
return useInfiniteQuery(getEventsQueryOptions({ filters, branchName: currentBranch.name }));
4033
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { EventType } from "@/entities/events/types";
2+
import { GetEventsParams, getEventsFromApi } from "../api/get-events-from-api";
3+
import { INFRAHUB_EVENT } from "../constants";
4+
5+
export type GetEvents = (params: GetEventsParams) => Promise<Array<EventType>>;
6+
7+
export const getEvents: GetEvents = async (params) => {
8+
const { data } = await getEventsFromApi(params);
9+
10+
return data[INFRAHUB_EVENT].edges.map((edge) => {
11+
return edge.node as EventType;
12+
});
13+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
BRANCH_CREATED_EVENT,
3+
BRANCH_DELETED_EVENT,
4+
BRANCH_REBASEDED_EVENT,
5+
NODE_MUTATED_EVENT,
6+
} from "@/entities/events/constants";
7+
import {
8+
EventNodeInterface,
9+
GroupEvent,
10+
NodeMutatedEvent,
11+
} from "@/shared/api/graphql/generated/graphql";
12+
13+
export type BranchEventType = EventNodeInterface & {
14+
__typename:
15+
| typeof BRANCH_DELETED_EVENT
16+
| typeof BRANCH_CREATED_EVENT
17+
| typeof BRANCH_REBASEDED_EVENT;
18+
};
19+
20+
export type NodeEventType = NodeMutatedEvent & {
21+
__typename: typeof NODE_MUTATED_EVENT;
22+
};
23+
24+
export type EventType = BranchEventType | NodeEventType | GroupEvent;

frontend/app/src/entities/events/ui/branch-event.tsx renamed to frontend/app/src/entities/events/ui/branch-events/branch-event-title.tsx

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,41 @@ import { ReactNode } from "react";
55

66
export const BRANCH_EVENTS_MAPPING: Record<string, (props: EventNodeInterface) => ReactNode> = {
77
"infrahub.branch.created": (props) => (
8-
<div>
8+
<div className="text-gray-500">
99
created the branch{" "}
10-
<Link to={`/branches/${props.created_branch}`} className="text-black font-semibold">
10+
<Link to={`/branches/${props.created_branch}`} className="text-black">
1111
{props.created_branch ?? "-"}
1212
</Link>
1313
</div>
1414
),
1515
"infrahub.branch.rebased": (props) => (
16-
<div>
16+
<div className="text-gray-500">
1717
rebased the branch{" "}
18-
<Link to={`/branches/${props.rebased_branch}`} className="text-black font-semibold">
18+
<Link to={`/branches/${props.rebased_branch}`} className="text-black">
1919
{props.rebased_branch ?? "-"}
2020
</Link>
2121
</div>
2222
),
2323
"infrahub.branch.merged": (props) => (
24-
<div>
25-
merged the branch{" "}
26-
<span className="text-black font-semibold">{props.source_branch ?? "-"}</span>
24+
<div className="text-gray-500">
25+
merged the branch <span className="text-black">{props.source_branch ?? "-"}</span>
2726
</div>
2827
),
2928
"infrahub.branch.deleted": (props) => (
30-
<div>
31-
deleted the branch{" "}
32-
<span className="text-black font-semibold">{props.deleted_branch ?? "-"}</span>
29+
<div className="text-gray-500">
30+
deleted the branch <span className="text-black">{props.deleted_branch ?? "-"}</span>
3331
</div>
3432
),
3533
};
3634

37-
export const BranchEvent = (props: EventNodeInterface) => {
35+
export const BranchEventTitle = (props: EventNodeInterface) => {
3836
const { event, account_id } = props;
3937

4038
return (
41-
<>
42-
<div className="flex items-center justify-between">
43-
<div className="flex items-center gap-2 text-sm">
44-
<div className="text-gray-500">
45-
<div className="font-semibold">
46-
<NodeLabel id={account_id} />
47-
</div>
39+
<div className="flex items-center flex-wrap gap-2 text-sm">
40+
<NodeLabel id={account_id} />
4841

49-
{BRANCH_EVENTS_MAPPING[event] && BRANCH_EVENTS_MAPPING[event](props)}
50-
</div>
51-
</div>
52-
</div>
53-
</>
42+
{BRANCH_EVENTS_MAPPING[event] && BRANCH_EVENTS_MAPPING[event](props)}
43+
</div>
5444
);
5545
};

frontend/app/src/entities/events/ui/event.tsx renamed to frontend/app/src/entities/events/ui/event-card.tsx

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,22 @@
1-
import {
2-
EventNodeInterface,
3-
GroupEvent,
4-
NodeMutatedEvent,
5-
} from "@/shared/api/graphql/generated/graphql";
61
import { DateDisplay } from "@/shared/components/display/date-display";
72

83
import { ACCOUNT_OBJECT } from "@/config/constants";
94
import { QSP } from "@/config/qsp";
5+
import { EventType } from "@/entities/events/types";
6+
import { EventDetailsPopover } from "@/entities/events/ui/event-details-popover";
7+
108
import { NodeLabel } from "@/entities/nodes/object/ui/node-label";
119
import { PropertyRow } from "@/entities/schema/ui/styled";
1210
import { constructPath } from "@/shared/api/rest/fetch";
1311
import { CopyToClipboard } from "@/shared/components/buttons/copy-to-clipboard";
1412
import { Link } from "@/shared/components/ui/link";
15-
import { Popover, PopoverContent, PopoverTrigger } from "@/shared/components/ui/popover";
1613
import { TimelineBorder } from "@/shared/components/ui/timeline-border";
17-
import {
18-
BRANCH_CREATED_EVENT,
19-
BRANCH_DELETED_EVENT,
20-
BRANCH_EVENTS,
21-
BRANCH_REBASEDED_EVENT,
22-
NODE_MUTATED_EVENT,
23-
STANDARD_EVENTS,
24-
} from "../utils/constants";
25-
import { BranchEvent } from "./branch-event";
26-
import { EventAttributes, NodeEvent } from "./node-event";
27-
import { StandardEvent } from "./standard-event";
28-
29-
export type BranchEventType = EventNodeInterface & {
30-
__typename:
31-
| typeof BRANCH_DELETED_EVENT
32-
| typeof BRANCH_CREATED_EVENT
33-
| typeof BRANCH_REBASEDED_EVENT;
34-
};
35-
36-
export type NodeEventType = NodeMutatedEvent & {
37-
__typename: typeof NODE_MUTATED_EVENT;
38-
};
39-
40-
export type EventType = BranchEventType | NodeEventType | GroupEvent;
14+
import { BRANCH_EVENTS, GROUP_EVENTS, STANDARD_EVENTS } from "../constants";
15+
import { BranchEventTitle } from "./branch-events/branch-event-title";
16+
import { GroupEventTitle } from "./group-events/group-event-title";
17+
import { EventAttributes } from "./node-events/event-attributes";
18+
import { NodeEventTitle } from "./node-events/node-event-title";
19+
import { StandardEventTitle } from "./standard-events/standard-event-title";
4120

4221
export const EventDetails = ({
4322
id,
@@ -162,38 +141,27 @@ export const EventDetails = ({
162141
);
163142
};
164143

165-
export const Event = ({ __typename, ...props }: EventType) => {
144+
export const EventCard = (props: EventType) => {
166145
return (
167146
<div className="flex gap-2">
168147
<TimelineBorder />
169148

170149
<div className="flex flex-grow gap-3 p-2 rounded-md shadow-sm border bg-white">
171150
<div className="flex flex-col gap-2 grow">
172-
{"attributes" in props && <NodeEvent {...props} />}
151+
{"attributes" in props && <NodeEventTitle {...props} />}
173152

174153
{"attributes" in props && <EventAttributes attributes={props.attributes} />}
175154

176-
{BRANCH_EVENTS.includes(__typename) && <BranchEvent {...props} />}
155+
{BRANCH_EVENTS.includes(props.__typename) && <BranchEventTitle {...props} />}
177156

178-
{STANDARD_EVENTS.includes(__typename) && <StandardEvent {...props} />}
157+
{STANDARD_EVENTS.includes(props.__typename) && <StandardEventTitle {...props} />}
179158

180-
<div className="flex justify-between">
181-
<div className="text-xs font-medium text-gray-500 dark:text-neutral-400">
182-
<DateDisplay date={props.occurred_at} />
183-
</div>
159+
{GROUP_EVENTS.includes(props.__typename) && <GroupEventTitle {...props} />}
160+
161+
<div className="flex justify-between text-gray-500">
162+
<DateDisplay date={props.occurred_at} />
184163

185-
<Popover>
186-
<PopoverTrigger>
187-
<div className="flex flex-grow justify-end">
188-
<p className="text-sm underline text-gray-600 dark:text-neutral-400 mb-1">
189-
View more.
190-
</p>
191-
</div>
192-
</PopoverTrigger>
193-
<PopoverContent className="w-full">
194-
<EventDetails {...props} />
195-
</PopoverContent>
196-
</Popover>
164+
<EventDetailsPopover {...props} />
197165
</div>
198166
</div>
199167
</div>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { EventType } from "@/entities/events/types";
2+
import { EventDetails } from "@/entities/events/ui/event-card";
3+
import { Popover, PopoverContent, PopoverTrigger } from "@/shared/components/ui/popover";
4+
import { InfoIcon } from "lucide-react";
5+
6+
export function EventDetailsPopover(props: EventType) {
7+
return (
8+
<Popover>
9+
<PopoverTrigger className="flex items-center gap-1 text-xs text-gray-600">
10+
View all <InfoIcon className="size-3" />
11+
</PopoverTrigger>
12+
13+
<PopoverContent className="w-full">
14+
<EventDetails {...props} />
15+
</PopoverContent>
16+
</Popover>
17+
);
18+
}

0 commit comments

Comments
 (0)