Fix some any in editable table
Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
@@ -53,6 +53,7 @@ export function AssetsTable(props: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<EditableTable
|
<EditableTable
|
||||||
|
pageSize={10}
|
||||||
connectionId={connectionId}
|
connectionId={connectionId}
|
||||||
pagination={pagination}
|
pagination={pagination}
|
||||||
items={assets}
|
items={assets}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { useToggle } from "@probo/hooks";
|
|||||||
import { useStateWithSchema } from "/hooks/useStateWithSchema.ts";
|
import { useStateWithSchema } from "/hooks/useStateWithSchema.ts";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { useMutationWithToasts } from "/hooks/useMutationWithToasts.ts";
|
import { useMutationWithToasts } from "/hooks/useMutationWithToasts.ts";
|
||||||
|
import { defaultPageSize } from "/components/table/SortableDataTable.tsx";
|
||||||
|
|
||||||
type ColumnDefinition = { label: string; field: string } | string;
|
type ColumnDefinition = { label: string; field: string } | string;
|
||||||
|
|
||||||
@@ -60,6 +61,7 @@ export function EditableTable<
|
|||||||
addLabel: string;
|
addLabel: string;
|
||||||
// Default value used when creating a new item
|
// Default value used when creating a new item
|
||||||
defaultValue: z.infer<S>;
|
defaultValue: z.infer<S>;
|
||||||
|
pageSize?: number;
|
||||||
}) {
|
}) {
|
||||||
const { update } = useMutateField(props.updateMutation);
|
const { update } = useMutateField(props.updateMutation);
|
||||||
const [showAdd, toggleAdd] = useToggle(false);
|
const [showAdd, toggleAdd] = useToggle(false);
|
||||||
@@ -71,6 +73,7 @@ export function EditableTable<
|
|||||||
hasNext={props.pagination.hasNext}
|
hasNext={props.pagination.hasNext}
|
||||||
isLoadingNext={props.pagination.isLoadingNext}
|
isLoadingNext={props.pagination.isLoadingNext}
|
||||||
loadNext={props.pagination.loadNext}
|
loadNext={props.pagination.loadNext}
|
||||||
|
pageSize={props.pageSize ?? defaultPageSize}
|
||||||
>
|
>
|
||||||
<Row>
|
<Row>
|
||||||
{props.columns.map((column, index) => (
|
{props.columns.map((column, index) => (
|
||||||
@@ -104,13 +107,13 @@ export function EditableTable<
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function NewItemRow<S extends z.ZodSchema>(props: {
|
function NewItemRow<T extends { id: string }, S extends z.ZodSchema>(props: {
|
||||||
schema: S;
|
schema: S;
|
||||||
defaultValue: z.infer<S>;
|
defaultValue: z.infer<S>;
|
||||||
connectionId: string;
|
connectionId: string;
|
||||||
mutation: GraphQLTaggedNode;
|
mutation: GraphQLTaggedNode;
|
||||||
onSuccess: () => void;
|
onSuccess: () => void;
|
||||||
row: (props: EditableTableRowProps<any, S>) => ReactNode;
|
row: (props: EditableTableRowProps<T, S>) => ReactNode;
|
||||||
}) {
|
}) {
|
||||||
const { update, errors, value } = useStateWithSchema(
|
const { update, errors, value } = useStateWithSchema(
|
||||||
props.schema,
|
props.schema,
|
||||||
|
|||||||
@@ -15,12 +15,16 @@ import {
|
|||||||
useContext,
|
useContext,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
|
import type { LoadMoreFn } from "react-relay";
|
||||||
|
import type { OperationType } from "relay-runtime";
|
||||||
|
|
||||||
type Order = {
|
type Order = {
|
||||||
direction: string;
|
direction: string;
|
||||||
field: string;
|
field: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const defaultPageSize = 50;
|
||||||
|
|
||||||
export const SortableContext = createContext({
|
export const SortableContext = createContext({
|
||||||
order: {
|
order: {
|
||||||
direction: "DESC",
|
direction: "DESC",
|
||||||
@@ -39,12 +43,14 @@ export function SortableDataTable({
|
|||||||
hasNext,
|
hasNext,
|
||||||
loadNext,
|
loadNext,
|
||||||
isLoadingNext,
|
isLoadingNext,
|
||||||
|
pageSize = defaultPageSize,
|
||||||
...props
|
...props
|
||||||
}: ComponentProps<typeof DataTable> & {
|
}: ComponentProps<typeof DataTable> & {
|
||||||
refetch: (o: { order: Order }) => void;
|
refetch: (o: { order: Order }) => void;
|
||||||
hasNext?: boolean;
|
hasNext?: boolean;
|
||||||
loadNext?: (...args: any[]) => void;
|
loadNext?: LoadMoreFn<OperationType>;
|
||||||
isLoadingNext?: boolean;
|
isLoadingNext?: boolean;
|
||||||
|
pageSize?: number;
|
||||||
}) {
|
}) {
|
||||||
const { __ } = useTranslate();
|
const { __ } = useTranslate();
|
||||||
const [order, setOrder] = useState(defaultOrder);
|
const [order, setOrder] = useState(defaultOrder);
|
||||||
@@ -61,7 +67,7 @@ export function SortableDataTable({
|
|||||||
{hasNext && loadNext && (
|
{hasNext && loadNext && (
|
||||||
<Button
|
<Button
|
||||||
variant="tertiary"
|
variant="tertiary"
|
||||||
onClick={() => loadNext()}
|
onClick={() => loadNext(pageSize)}
|
||||||
className="mt-3 mx-auto"
|
className="mt-3 mx-auto"
|
||||||
disabled={isLoadingNext}
|
disabled={isLoadingNext}
|
||||||
icon={isLoadingNext ? Spinner : IconChevronDown}
|
icon={isLoadingNext ? Spinner : IconChevronDown}
|
||||||
|
|||||||
Reference in New Issue
Block a user