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

Improve node activities and add first draft for global activities #5747

Merged
merged 37 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6f86b6d
add global activities
pa-lem Feb 13, 2025
fa76749
Merge branch 'ple-acitivites' of github.com:opsmill/infrahub into ple…
pa-lem Feb 13, 2025
c06b727
Merge branch 'develop' of github.com:opsmill/infrahub into ple-global…
pa-lem Feb 13, 2025
e977f59
update style
pa-lem Feb 13, 2025
5d1fc4e
switch to classic gql, add limit, refetch on object update
pa-lem Feb 13, 2025
c25441a
update reftech key
pa-lem Feb 13, 2025
d437a0e
retry activities query
pa-lem Feb 13, 2025
728b903
Merge branch 'develop' of github.com:opsmill/infrahub into ple-global…
pa-lem Feb 14, 2025
ef201e3
prevent card grow
pa-lem Feb 14, 2025
5cc0411
lint
pa-lem Feb 14, 2025
e700a9a
Merge branch 'develop' of github.com:opsmill/infrahub into ple-global…
pa-lem Feb 14, 2025
dc3a0c3
remove details page from router
pa-lem Feb 14, 2025
7dba5ad
add empty state
pa-lem Feb 14, 2025
61693c9
remove duplicates
pa-lem Feb 14, 2025
dfc1e7a
update query
pa-lem Feb 14, 2025
5ce642d
use regular query
pa-lem Feb 14, 2025
a330a2b
add group events
pa-lem Feb 14, 2025
132da8a
add pagination
pa-lem Feb 14, 2025
c0e7c51
update type
pa-lem Feb 14, 2025
b8ff623
add search
pa-lem Feb 14, 2025
23e4a50
add search hook
pa-lem Feb 14, 2025
1e6455b
update global filters
pa-lem Feb 14, 2025
8502da1
Merge branch 'develop' of github.com:opsmill/infrahub into ple-global…
pa-lem Feb 17, 2025
c4882e1
fix on update
pa-lem Feb 17, 2025
dd22357
rename file
pa-lem Feb 17, 2025
e07cc16
destructure
pa-lem Feb 17, 2025
9f3b626
lint
pa-lem Feb 17, 2025
3c95578
types
pa-lem Feb 17, 2025
a0d94e7
update export
pa-lem Feb 17, 2025
6e48b04
update destructuration
pa-lem Feb 17, 2025
106546d
fix import
pa-lem Feb 18, 2025
e5be26a
Merge branch 'develop' into ple-global-activities
pa-lem Feb 18, 2025
1e69b45
Merge branch 'develop' of github.com:opsmill/infrahub into ple-global…
pa-lem Feb 19, 2025
bc1f849
fix import
pa-lem Feb 19, 2025
a5de78f
Merge branch 'ple-global-activities' of github.com:opsmill/infrahub i…
pa-lem Feb 19, 2025
3b31890
fix query
pa-lem Feb 19, 2025
2505db1
fix query
pa-lem Feb 19, 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
12 changes: 11 additions & 1 deletion backend/infrahub/menu/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _extract_node_icon(model: MainSchemaTypes) -> str:
icon=_extract_node_icon(infrahub_schema.get(InfrahubKind.CHECKDEFINITION)),
protected=True,
section=MenuSection.INTERNAL,
order_weight=3000,
order_weight=2000,
),
MenuItemDefinition(
namespace="Builtin",
Expand All @@ -176,6 +176,16 @@ def _extract_node_icon(model: MainSchemaTypes) -> str:
section=MenuSection.INTERNAL,
order_weight=3000,
),
MenuItemDefinition(
namespace="Builtin",
name="ActivityLogs",
label="Activity Logs",
path="/activities",
icon="mdi:format-list-bulleted",
protected=True,
section=MenuSection.INTERNAL,
order_weight=4000,
),
],
),
MenuItemDefinition(
Expand Down
14 changes: 0 additions & 14 deletions frontend/app/src/app/router.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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 @@ -90,19 +89,6 @@ export const router = createBrowserRouter([
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,
};
},
},
},
],
},
{
Expand Down
65 changes: 65 additions & 0 deletions frontend/app/src/entities/events/api/get-events-from-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import graphqlClient from "@/shared/api/graphql/graphqlClientApollo";
import { gql } from "@apollo/client";

const EVENTS_QUERY = gql`
query GET_ACTIVITIES($ids: [String!], $offset: Int, $limit: Int) {
InfrahubEvent(related_node__ids: $ids, offset: $offset, limit: $limit) {
count
edges {
node {
id
event
branch
occurred_at
level
account_id
primary_node {
id
kind
}
__typename
... on NodeMutatedEvent {
attributes {
action
kind
name
value
value_previous
}
payload
}
}
}
}
}
`;

export function getEventsFromApi({
ids,
offset,
limit,
search,
branchName,
atDate,
}: {
ids?: Array<string | undefined>;
offset?: number;
limit?: number;
search?: string;
branchName: string;
atDate: Date | null;
}) {
return graphqlClient.query({
query: EVENTS_QUERY,
variables: {
ids,
offset,
limit,
search,
},
context: {
branch: branchName,
date: atDate,
},
});
}
37 changes: 32 additions & 5 deletions frontend/app/src/entities/events/api/get-events.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,51 @@ import { getCurrentBranchName } from "@/entities/branches/domain/get-current-bra
import { store } from "@/shared/stores";
import { datetimeAtom } from "@/shared/stores/time.atom";
import { queryOptions, useQuery } from "@tanstack/react-query";
import { getEventsFromApi } from "./get-events";
import { EventType } from "../ui/event";
import { INFRAHUB_EVENT } from "../utils/constants";
import { getEventsFromApi } from "./get-events-from-api";

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

return queryOptions({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally, it should be an infiniteQueryOptions

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

export const useEvents = ({ ids = [] }: { ids?: Array<string | undefined> }) => {
return useQuery(getEventsQueryOptions({ ids }));
export const useEvents = ({
ids = [],
offset,
limit,
search,
}: { ids?: Array<string | undefined>; offset?: number; limit?: number; search?: string }) => {
const { data } = useQuery(getEventsQueryOptions({ ids, offset, limit, search }));

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

const count = data?.data?.[INFRAHUB_EVENT]?.count;

return {
...useQuery(getEventsQueryOptions({ ids, offset, limit, search })),
data: activities,
count,
};
};
54 changes: 0 additions & 54 deletions frontend/app/src/entities/events/api/get-events.ts

This file was deleted.

10 changes: 3 additions & 7 deletions frontend/app/src/entities/events/ui/branch-event.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { EventNodeInterface } from "@/shared/api/graphql/generated/graphql";
import { DateDisplay } from "@/shared/components/display/date-display";
import { ReactElement } from "react";
import { ReactNode } from "react";

export const BRANCH_EVENTS_MAPPING: Record<string, (param: string) => ReactElement> = {
export const BRANCH_EVENTS_MAPPING: Record<string, (param: string) => ReactNode> = {
"infrahub.branch.created": (branch) => (
<div>
Branch <span className="text-black font-semibold">{branch}</span> created
Expand All @@ -21,7 +20,7 @@ export const BRANCH_EVENTS_MAPPING: Record<string, (param: string) => ReactEleme
};

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

return (
<>
Expand All @@ -31,9 +30,6 @@ export const BranchEvent = (props: EventNodeInterface) => {
{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>
</>
);
Expand Down
3 changes: 0 additions & 3 deletions frontend/app/src/entities/events/ui/event-details.tsx

This file was deleted.

6 changes: 4 additions & 2 deletions frontend/app/src/entities/events/ui/event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type NodeEventType = NodeMutatedEvent & {

export type EventType = BranchEventType | NodeEventType;

const EventDetails = ({ id, event, occurred_at, account_id, ...props }: EventType) => {
export const EventDetails = ({ id, event, occurred_at, account_id, ...props }: EventType) => {
return (
<div className="divide-y">
<PropertyRow
Expand Down Expand Up @@ -57,7 +57,9 @@ export const Event = ({ __typename, ...props }: EventType) => {

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

{"attributes" in props && <EventAttributes attributes={props.attributes} />}
Comment on lines +60 to +62
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same condition


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

Expand Down
17 changes: 17 additions & 0 deletions frontend/app/src/entities/events/ui/global-branch-event.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { EventNodeInterface } from "@/shared/api/graphql/generated/graphql";
import { Icon } from "@iconify-icon/react";
import { BRANCH_EVENTS_MAPPING } from "./branch-event";

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

return (
<div className="flex items-center justify-between">
<div className="flex items-center gap-2 text-sm text-gray-500">
<Icon icon="mdi:source-branch" className="text-gray-400" />

{branch && BRANCH_EVENTS_MAPPING[event] && BRANCH_EVENTS_MAPPING[event](branch)}
</div>
</div>
);
};
Loading
Loading