feat: add executions page
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
ab82134b88
commit
2218ffd790
@@ -29,7 +29,7 @@ const cache = new InMemoryCache({
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
|
70
packages/web/src/graphql/pagination.ts
Normal file
70
packages/web/src/graphql/pagination.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import type { FieldPolicy, Reference } from '@apollo/client';
|
||||
|
||||
type KeyArgs = FieldPolicy<unknown>["keyArgs"];
|
||||
|
||||
export type TEdge<TNode> = {
|
||||
node: TNode;
|
||||
} | Reference;
|
||||
|
||||
export type TPageInfo = {
|
||||
currentPage: number;
|
||||
totalPages: number;
|
||||
};
|
||||
|
||||
export type TExisting<TNode> = Readonly<{
|
||||
edges: TEdge<TNode>[];
|
||||
pageInfo: TPageInfo;
|
||||
}>;
|
||||
|
||||
export type TIncoming<TNode> = {
|
||||
edges: TEdge<TNode>[];
|
||||
pageInfo: TPageInfo;
|
||||
};
|
||||
|
||||
export type CustomFieldPolicy<TNode> = FieldPolicy<
|
||||
TExisting<TNode> | null,
|
||||
TIncoming<TNode> | null,
|
||||
TIncoming<TNode> | null
|
||||
>;
|
||||
|
||||
|
||||
const makeEmptyData = <TNode>(): TExisting<TNode> => {
|
||||
return {
|
||||
edges: [],
|
||||
pageInfo: {
|
||||
currentPage: 1,
|
||||
totalPages: 1,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
function offsetLimitPagination<TNode = Reference>(
|
||||
keyArgs: KeyArgs = false
|
||||
): CustomFieldPolicy<TNode> {
|
||||
return {
|
||||
keyArgs,
|
||||
merge(existing, incoming, { args }) {
|
||||
if (!existing) {
|
||||
existing = makeEmptyData<TNode>();
|
||||
}
|
||||
|
||||
if (!incoming || incoming === null) return existing;
|
||||
|
||||
const existingEdges = existing?.edges || [];
|
||||
const incomingEdges = incoming.edges || []
|
||||
|
||||
|
||||
if (args) {
|
||||
const newEdges = [...existingEdges, ...incomingEdges];
|
||||
return {
|
||||
pageInfo: incoming.pageInfo,
|
||||
edges: newEdges,
|
||||
};
|
||||
} else {
|
||||
return existing;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default offsetLimitPagination;
|
25
packages/web/src/graphql/queries/get-executions.ts
Normal file
25
packages/web/src/graphql/queries/get-executions.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const GET_EXECUTIONS = gql`
|
||||
query GetExecutions($limit: Int!, $offset: Int!) {
|
||||
getExecutions(limit: $limit, offset: $offset) {
|
||||
pageInfo {
|
||||
currentPage
|
||||
totalPages
|
||||
}
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
testRun
|
||||
createdAt
|
||||
updatedAt
|
||||
flow {
|
||||
id
|
||||
name
|
||||
active
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
Reference in New Issue
Block a user