Skip to main content

ListPage

ListPage

Auto-generates a list page with columns generated based on the provided query document fields.

Example

import {
Button,
DashboardRouteDefinition,
ListPage,
PageActionBarRight,
DetailPageButton,
} from '@vendure/dashboard';
import { Link } from '@tanstack/react-router';
import { PlusIcon } from 'lucide-react';

// This function is generated for you by the `vendureDashboardPlugin` in your Vite config.
// It uses gql-tada to generate TypeScript types which give you type safety as you write
// your queries and mutations.
import { graphql } from '@/gql';

// The fields you select here will be automatically used to generate the appropriate columns in the
// data table below.
const getArticleList = graphql(`
query GetArticles($options: ArticleListOptions) {
articles(options: $options) {
items {
id
createdAt
updatedAt
isPublished
title
slug
body
customFields
}
}
}
`);

const deleteArticleDocument = graphql(`
mutation DeleteArticle($id: ID!) {
deleteArticle(id: $id) {
result
}
}
`);

export const articleList: DashboardRouteDefinition = {
navMenuItem: {
sectionId: 'catalog',
id: 'articles',
url: '/articles',
title: 'CMS Articles',
},
path: '/articles',
loader: () => ({
breadcrumb: 'Articles',
}),
component: route => (
<ListPage
pageId="article-list"
title="Articles"
listQuery={getArticleList}
deleteMutation={deleteArticleDocument}
route={route}
customizeColumns={{
title: {
cell: ({ row }) => {
const post = row.original;
return <DetailPageButton id={post.id} label={post.title} />;
},
},
}}
>
<PageActionBarRight>
<Button asChild>
<Link to="./new">
<PlusIcon className="mr-2 h-4 w-4" />
New article
</Link>
</Button>
</PageActionBarRight>
</ListPage>
),
};
Signature
function ListPage<T extends TypedDocumentNode<U, V>, U extends Record<string, any> = any, V extends ListQueryOptionsShape = ListQueryOptionsShape, AC extends AdditionalColumns<T> = AdditionalColumns<T>>(props: Readonly<ListPageProps<T, U, V, AC>>): void

Parameters

props

parameter
Readonly<ListPageProps<T, U, V, AC>>

ListPageProps

Props to configure the ListPage component.

Signature
interface ListPageProps<T extends TypedDocumentNode<U, V>, U extends ListQueryShape, V extends ListQueryOptionsShape, AC extends AdditionalColumns<T>> {
pageId?: string;
route: AnyRoute | (() => AnyRoute);
title: string | React.ReactElement;
listQuery: T;
deleteMutation?: TypedDocumentNode<any, { id: string }>;
transformVariables?: (variables: V) => V;
onSearchTermChange?: (searchTerm: string) => NonNullable<V['options']>['filter'];
customizeColumns?: CustomizeColumnConfig<T>;
additionalColumns?: AC;
defaultColumnOrder?: (keyof ListQueryFields<T> | keyof AC | CustomFieldKeysOfItem<ListQueryFields<T>>)[];
defaultSort?: SortingState;
defaultVisibility?: Partial<
Record<keyof ListQueryFields<T> | keyof AC | CustomFieldKeysOfItem<ListQueryFields<T>>, boolean>
>;
children?: React.ReactNode;
facetedFilters?: FacetedFilterConfig<T>;
rowActions?: RowAction<ListQueryFields<T>>[];
transformData?: (data: any[]) => any[];
setTableOptions?: (table: TableOptions<any>) => TableOptions<any>;
bulkActions?: BulkAction[];
registerRefresher?: PaginatedListRefresherRegisterFn;
}

pageId

property
string

route

property
AnyRoute | (() => AnyRoute)

title

property
string | React.ReactElement

listQuery

property
T

deleteMutation

property
TypedDocumentNode<any, { id: string }>

transformVariables

property
(variables: V) => V

onSearchTermChange

property
(searchTerm: string) => NonNullable<V['options']>['filter']

customizeColumns

property
CustomizeColumnConfig<T>

additionalColumns

property
AC

defaultColumnOrder

property
(keyof ListQueryFields<T> | keyof AC | CustomFieldKeysOfItem<ListQueryFields<T>>)[]

defaultSort

property
SortingState

defaultVisibility

property
Partial< Record<keyof ListQueryFields<T> | keyof AC | CustomFieldKeysOfItem<ListQueryFields<T>>, boolean> >

children

property
React.ReactNode

facetedFilters

property
FacetedFilterConfig<T>

rowActions

property
RowAction<ListQueryFields<T>>[]

transformData

property
(data: any[]) => any[]

setTableOptions

property
(table: TableOptions<any>) => TableOptions<any>

bulkActions

property

registerRefresher

property
PaginatedListRefresherRegisterFn

Register a function that allows you to assign a refresh function for this list. The function can be assigned to a ref and then called when the list needs to be refreshed.