|
@@ -1,11 +1,6 @@
|
|
|
-import { DataTable } from '@/framework/internal/data-table/data-table.js';
|
|
|
|
|
-import { getListQueryFields } from '@/framework/internal/document-introspection/get-document-structure.js';
|
|
|
|
|
-import { api } from '@/graphql/api.js';
|
|
|
|
|
|
|
+import { ListPage } from '@/framework/internal/page/list-page.js';
|
|
|
import { graphql } from '@/graphql/graphql.js';
|
|
import { graphql } from '@/graphql/graphql.js';
|
|
|
-import { useQuery } from '@tanstack/react-query';
|
|
|
|
|
import { createFileRoute } from '@tanstack/react-router';
|
|
import { createFileRoute } from '@tanstack/react-router';
|
|
|
-import { createColumnHelper } from '@tanstack/react-table';
|
|
|
|
|
-import { ResultOf } from 'gql.tada';
|
|
|
|
|
import React from 'react';
|
|
import React from 'react';
|
|
|
|
|
|
|
|
export const Route = createFileRoute('/_authenticated/products')({
|
|
export const Route = createFileRoute('/_authenticated/products')({
|
|
@@ -17,35 +12,24 @@ const productListDocument = graphql(`
|
|
|
products(options: $options) {
|
|
products(options: $options) {
|
|
|
items {
|
|
items {
|
|
|
id
|
|
id
|
|
|
- name
|
|
|
|
|
- slug
|
|
|
|
|
- enabled
|
|
|
|
|
|
|
+ createdAt
|
|
|
updatedAt
|
|
updatedAt
|
|
|
|
|
+ name
|
|
|
|
|
+ description
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
`);
|
|
`);
|
|
|
|
|
|
|
|
export function ProductListPage() {
|
|
export function ProductListPage() {
|
|
|
- const { data } = useQuery({
|
|
|
|
|
- queryFn: () =>
|
|
|
|
|
- api.query(productListDocument, {
|
|
|
|
|
- options: {
|
|
|
|
|
- take: 100,
|
|
|
|
|
- },
|
|
|
|
|
- }),
|
|
|
|
|
- queryKey: ['ProductList'],
|
|
|
|
|
- });
|
|
|
|
|
- const fields = getListQueryFields(productListDocument);
|
|
|
|
|
- const columnHelper =
|
|
|
|
|
- createColumnHelper<ResultOf<typeof productListDocument>['products']['items'][number]>();
|
|
|
|
|
-
|
|
|
|
|
- const columns = fields.map(field =>
|
|
|
|
|
- columnHelper.accessor(field.name as any, {
|
|
|
|
|
- header: field.name,
|
|
|
|
|
- meta: { type: field.type },
|
|
|
|
|
- }),
|
|
|
|
|
|
|
+ return (
|
|
|
|
|
+ <ListPage
|
|
|
|
|
+ title="Products"
|
|
|
|
|
+ listQuery={productListDocument}
|
|
|
|
|
+ customizeColumns={{
|
|
|
|
|
+ id: { header: 'ID' },
|
|
|
|
|
+ name: { header: 'Name' },
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
);
|
|
);
|
|
|
-
|
|
|
|
|
- return <DataTable columns={columns} data={data?.products.items ?? []}></DataTable>;
|
|
|
|
|
}
|
|
}
|