feat: add executions page

This commit is contained in:
Ali BARIN
2022-03-11 14:30:43 +01:00
committed by Ömer Faruk Aydın
parent ab82134b88
commit 2218ffd790
15 changed files with 260 additions and 10 deletions

View File

@@ -29,7 +29,7 @@ const cache = new InMemoryCache({
}
}
}
}
},
}
});

View 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;

View 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
}
}
}
}
}
`;