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

Add nodes activities in the details view #5708

Merged
merged 34 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1695fd3
start add activities structure
pa-lem Feb 6, 2025
3b71bbd
Merge branch 'develop' of github.com:opsmill/infrahub into ple-acitiv…
pa-lem Feb 7, 2025
e45d75a
add main structure
pa-lem Feb 7, 2025
786ca82
add display label component to query value from id
pa-lem Feb 7, 2025
a67cdb0
add attributes
pa-lem Feb 7, 2025
8e6e932
switch display label to tanstack query
pa-lem Feb 7, 2025
cb9fa94
start add new routes and pages
pa-lem Feb 7, 2025
24f4af0
start add more details
pa-lem Feb 7, 2025
b3c4d2e
Merge branch 'develop' of github.com:opsmill/infrahub into ple-acitiv…
pa-lem Feb 10, 2025
561ef1f
update queries to get param
pa-lem Feb 10, 2025
c809c0e
add param
pa-lem Feb 10, 2025
0151279
update constants
pa-lem Feb 10, 2025
eeeb11d
update ui
pa-lem Feb 10, 2025
b553add
update timeline style
pa-lem Feb 10, 2025
8dc9153
handle multiple activities
pa-lem Feb 10, 2025
a7c63df
add responsive
pa-lem Feb 10, 2025
e4e99e6
update default param
pa-lem Feb 10, 2025
8ff7f66
update ui
pa-lem Feb 10, 2025
78469b2
add fragment
pa-lem Feb 10, 2025
1f1c293
lint
pa-lem Feb 10, 2025
94c5cde
fix test
pa-lem Feb 12, 2025
66a8a63
update tests
pa-lem Feb 12, 2025
7bf4015
update and rename files
pa-lem Feb 12, 2025
387b027
split components
pa-lem Feb 12, 2025
abed484
improve ui
pa-lem Feb 12, 2025
2038d4b
rename + update key
pa-lem Feb 12, 2025
baf9f64
update tests
pa-lem Feb 12, 2025
1c4b66a
fix test
pa-lem Feb 12, 2025
a5897bc
fix test
pa-lem Feb 12, 2025
3ba25e1
fix test
pa-lem Feb 13, 2025
c10b272
Merge branch 'develop' of github.com:opsmill/infrahub into ple-acitiv…
pa-lem Feb 13, 2025
eb91b20
update test and add empty state screen
pa-lem Feb 13, 2025
e26ffb1
fix test
pa-lem Feb 13, 2025
bb21626
fix empty state
pa-lem Feb 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/+activities.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add activities logs in the nodes details view
32 changes: 32 additions & 0 deletions frontend/app/src/app/router.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ARTIFACT_OBJECT, NODE_OBJECT, PROPOSED_CHANGES_OBJECT } from "@/config/constants";
import { RequireAuth } from "@/entities/authentication/ui/useAuth";
import { BranchesProvider } from "@/entities/branches/ui/branches-provider";
import { INFRAHUB_EVENT } from "@/entities/events/utils/constants";
import { constructPathForIpam } from "@/entities/ipam/common/utils";
import { IPAM_ROUTE, IP_ADDRESS_GENERIC, IP_PREFIX_GENERIC } from "@/entities/ipam/constants";
import { RESOURCE_GENERIC_KIND } from "@/entities/resource-manager/constants";
Expand Down Expand Up @@ -73,6 +74,37 @@ export const router = createBrowserRouter([
},
],
},
{
path: "/activities",
handle: {
breadcrumb: () => {
return {
type: "link",
label: "Activities",
to: constructPath("/activities"),
};
},
},
children: [
{
index: true,
lazy: () => import("@/pages/activities"),
},
{
path: ":activityid",
lazy: () => import("@/pages/activities/details"),
handle: {
breadcrumb: (match: UIMatch) => {
return {
type: "select",
value: match.params.activityid,
kind: INFRAHUB_EVENT,
};
},
},
},
],
},
{
path: `/objects/${ARTIFACT_OBJECT}/:objectid`,
handle: {
Expand Down
25 changes: 25 additions & 0 deletions frontend/app/src/entities/events/api/get-events.query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { getCurrentBranchName } from "@/entities/branches/domain/get-current-branch";
import { store } from "@/shared/stores";
import { datetimeAtom } from "@/shared/stores/time.atom";
import { queryOptions, useQuery } from "@tanstack/react-query";
import { getEventsFromApi } from "./get-events";

export function getEventsQueryOptions({ ids }: { ids?: Array<string | undefined> }) {
const currentBranchName = getCurrentBranchName();
const timeMachineDate = store.get(datetimeAtom);

return queryOptions({
queryKey: ["events", ids],
queryFn: () => {
return getEventsFromApi({
ids,
branchName: currentBranchName,
atDate: timeMachineDate,
});
},
});
}

export const useEvents = ({ ids = [] }: { ids?: Array<string | undefined> }) => {
return useQuery(getEventsQueryOptions({ ids }));
};
54 changes: 54 additions & 0 deletions frontend/app/src/entities/events/api/get-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import graphqlClient from "@/shared/api/graphql/graphqlClientApollo";
import { gql } from "@apollo/client";
import { jsonToGraphQLQuery } from "json-to-graphql-query";
import { INFRAHUB_EVENT, NODE_MUTATED_EVENT } from "../utils/constants";

const getEventsQuery = ({ ids }: { ids?: Array<string | undefined> }) => {
const request = {
query: {
__name: "GET_EVENTS",
[INFRAHUB_EVENT]: {
__args: {
related_node__ids: ids,
},
count: true,
edges: {
node: {
id: true,
event: true,
branch: true,
account_id: true,
occurred_at: true,
__on: {
__typeName: NODE_MUTATED_EVENT,
attributes: {
action: true,
kind: true,
name: true,
value: true,
value_previous: true,
},
payload: true,
},
},
},
},
},
};

return jsonToGraphQLQuery(request);
};

export function getEventsFromApi({
ids,
branchName,
atDate,
}: { ids?: Array<string | undefined>; branchName: string; atDate: Date | null }) {
return graphqlClient.query({
query: gql(getEventsQuery({ ids })),
context: {
branch: branchName,
date: atDate,
},
});
}
40 changes: 40 additions & 0 deletions frontend/app/src/entities/events/ui/branch-event.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { EventNodeInterface } from "@/shared/api/graphql/generated/graphql";
import { DateDisplay } from "@/shared/components/display/date-display";
import { ReactElement } from "react";

export const BRANCH_EVENTS_MAPPING: Record<string, (param: string) => ReactElement> = {
"infrahub.branch.created": (branch) => (
<div>
Branch <span className="text-black font-semibold">{branch}</span> created
</div>
),
"infrahub.branch.rebased": (branch) => (
<div>
Branch <span className="text-black font-semibold">{branch}</span> rebased
</div>
),
"infrahub.branch.deleted": (branch) => (
<div>
Branch <span className="text-black font-semibold">{branch}</span> deleted
</div>
),
};

export const BranchEvent = (props: EventNodeInterface) => {
const { event, occurred_at, branch } = props;

return (
<>
<div className="flex items-center justify-between">
<div className="flex items-center gap-2 text-sm">
<div className="text-gray-500">
{branch && BRANCH_EVENTS_MAPPING[event] && BRANCH_EVENTS_MAPPING[event](branch)}
</div>
</div>
<div className="text-xs font-medium text-gray-500 dark:text-neutral-400">
<DateDisplay date={occurred_at} />
</div>
</div>
</>
);
};
3 changes: 3 additions & 0 deletions frontend/app/src/entities/events/ui/event-details.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const EventDetails = () => {
return <div>DETAILS</div>;
};
86 changes: 86 additions & 0 deletions frontend/app/src/entities/events/ui/event.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { EventNodeInterface, NodeMutatedEvent } from "@/shared/api/graphql/generated/graphql";
import { DateDisplay } from "@/shared/components/display/date-display";

import { DisplayLabel } from "@/entities/nodes/object/ui/display-label";
import { PropertyRow } from "@/entities/schema/ui/styled";
import { CopyToClipboard } from "@/shared/components/buttons/copy-to-clipboard";
import { Popover, PopoverContent, PopoverTrigger } from "@/shared/components/ui/popover";
import { TimelineBorder } from "@/shared/components/ui/timeline-border";
import {
BRANCH_CREATED_EVENT,
BRANCH_DELETED_EVENT,
BRANCH_EVENTS,
BRANCH_REBASEDED_EVENT,
NODE_MUTATED_EVENT,
} from "../utils/constants";
import { BranchEvent } from "./branch-event";
import { EventAttributes, NodeEvent } from "./node-event";

export type BranchEventType = EventNodeInterface & {
__typename:
| typeof BRANCH_DELETED_EVENT
| typeof BRANCH_CREATED_EVENT
| typeof BRANCH_REBASEDED_EVENT;
};

export type NodeEventType = NodeMutatedEvent & {
__typename: typeof NODE_MUTATED_EVENT;
};

export type EventType = BranchEventType | NodeEventType;

const EventDetails = ({ id, event, occurred_at, account_id, ...props }: EventType) => {
return (
<div className="divide-y">
<PropertyRow
title="ID"
value={
<div className="flex items-center gap-2">
{id} <CopyToClipboard text={id} />
</div>
}
/>
<PropertyRow title="Event" value={event} />
<PropertyRow title="Occured at" value={<DateDisplay date={occurred_at} />} />
{account_id && <PropertyRow title="Account" value={<DisplayLabel id={account_id} />} />}
{"attributes" in props && (
<PropertyRow title="Changes" value={<EventAttributes attributes={props.attributes} />} />
)}
</div>
);
};

export const Event = ({ __typename, ...props }: EventType) => {
return (
<div className="flex gap-2">
<TimelineBorder />

<div className="flex flex-grow gap-3 p-2 rounded-md shadow-sm border">
<div className="flex flex-col gap-2 grow">
{__typename === NODE_MUTATED_EVENT && <NodeEvent {...props} />}

{BRANCH_EVENTS.includes(__typename) && <BranchEvent {...props} />}

<div className="flex justify-between">
<div className="text-xs font-medium text-gray-500 dark:text-neutral-400">
<DateDisplay date={props.occurred_at} />
</div>

<Popover>
<PopoverTrigger>
<div className="flex flex-grow justify-end">
<p className="text-sm underline text-gray-600 dark:text-neutral-400 mb-1">
View more.
</p>
</div>
</PopoverTrigger>
<PopoverContent className="w-full">
<EventDetails {...props} />
</PopoverContent>
</Popover>
</div>
</div>
</div>
</div>
);
};
Loading
Loading