-
Notifications
You must be signed in to change notification settings - Fork 21
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
Changes from 12 commits
6f86b6d
fa76749
c06b727
e977f59
5d1fc4e
c25441a
d437a0e
728b903
ef201e3
5cc0411
e700a9a
dc3a0c3
7dba5ad
61693c9
dfc1e7a
5ce642d
a330a2b
132da8a
c0e7c51
b8ff623
23e4a50
1e6455b
8502da1
c4882e1
dd22357
e07cc16
9f3b626
3c95578
a0d94e7
6e48b04
106546d
e5be26a
1e69b45
bc1f849
a5de78f
3b31890
2505db1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,45 @@ | ||
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); | ||
}; | ||
const EVENTS_QUERY = ` | ||
query GET_ACTIVITIES($ids: [String], $limit: Int) { | ||
InfrahubEvent(related_node__ids: $ids, limit: $limit) { | ||
count | ||
edges { | ||
node { | ||
id | ||
event | ||
branch | ||
occurred_at | ||
__typename | ||
... on NodeMutatedEvent { | ||
attributes { | ||
action | ||
kind | ||
name | ||
value | ||
value_previous | ||
} | ||
payload | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export function getEventsFromApi({ | ||
ids, | ||
limit, | ||
branchName, | ||
atDate, | ||
}: { ids?: Array<string | undefined>; branchName: string; atDate: Date | null }) { | ||
}: { ids?: Array<string | undefined>; limit?: number; branchName: string; atDate: Date | null }) { | ||
return graphqlClient.query({ | ||
query: gql(getEventsQuery({ ids })), | ||
query: gql(EVENTS_QUERY), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gql should be part of EVENTS_QUERY |
||
variables: { | ||
ids, | ||
limit, | ||
}, | ||
context: { | ||
branch: branchName, | ||
date: atDate, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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 { getGlobalEventsFromApi } from "./get-global-events"; | ||
|
||
export function getEventsQueryOptions() { | ||
const currentBranchName = getCurrentBranchName(); | ||
const timeMachineDate = store.get(datetimeAtom); | ||
|
||
return queryOptions({ | ||
queryKey: ["global-events"], | ||
queryFn: () => { | ||
return getGlobalEventsFromApi({ | ||
branchName: currentBranchName, | ||
atDate: timeMachineDate, | ||
}); | ||
}, | ||
}); | ||
} | ||
|
||
export const useGlobalEvents = () => { | ||
return useQuery(getEventsQueryOptions()); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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 getGlobalEventsQuery = () => { | ||
const request = { | ||
query: { | ||
__name: "GET_GLOBAL_EVENTS", | ||
[INFRAHUB_EVENT]: { | ||
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 getGlobalEventsFromApi({ | ||
branchName, | ||
atDate, | ||
}: { branchName: string; atDate: Date | null }) { | ||
return graphqlClient.query({ | ||
query: gql(getGlobalEventsQuery()), | ||
context: { | ||
branch: branchName, | ||
date: atDate, | ||
}, | ||
}); | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same condition |
||
|
||
{BRANCH_EVENTS.includes(__typename) && <BranchEvent {...props} />} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
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 ( | ||
<> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fragment is useless no? |
||
<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> | ||
</> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file name should be
get-events-from-api.ts