Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeScript] Fix SimpleList and other list components can't be used without context #6090

Merged
merged 1 commit into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/ra-ui-materialui/src/list/SimpleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
sanitizeListRestProps,
useListContext,
Record,
RecordMap,
Identifier,
} from 'ra-core';

Expand Down Expand Up @@ -186,7 +187,8 @@ export type FunctionToElement = (
id: Identifier
) => ReactElement | string;

export interface SimpleListProps extends Omit<ListProps, 'classes'> {
export interface SimpleListProps<RecordType extends Record = Record>
extends Omit<ListProps, 'classes'> {
className?: string;
classes?: ClassesOverride<typeof useStyles>;
hasBulkActions?: boolean;
Expand All @@ -199,6 +201,12 @@ export interface SimpleListProps extends Omit<ListProps, 'classes'> {
secondaryText?: FunctionToElement;
tertiaryText?: FunctionToElement;
rowStyle?: (record: Record, index: number) => any;
// can be injected when using the component without context
basePath?: string;
data?: RecordMap<RecordType>;
ids?: Identifier[];
loaded?: boolean;
total?: number;
}

const useLinkOrNotStyles = makeStyles(
Expand Down
12 changes: 10 additions & 2 deletions packages/ra-ui-materialui/src/list/SingleFieldList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
sanitizeListRestProps,
useListContext,
useResourceContext,
Record,
RecordMap,
Identifier,
} from 'ra-core';

import Link from '../Link';
Expand Down Expand Up @@ -129,19 +132,24 @@ SingleFieldList.propTypes = {
children: PropTypes.element.isRequired,
classes: PropTypes.object,
className: PropTypes.string,
data: PropTypes.object,
data: PropTypes.any,
ids: PropTypes.array,
// @ts-ignore
linkType: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
resource: PropTypes.string,
};

export interface SingleFieldListProps
export interface SingleFieldListProps<RecordType extends Record = Record>
extends HtmlHTMLAttributes<HTMLDivElement> {
className?: string;
classes?: ClassesOverride<typeof useStyles>;
linkType?: string | false;
children: React.ReactElement;
// can be injected when using the component without context
basePath?: string;
data?: RecordMap<RecordType>;
ids?: Identifier[];
loaded?: boolean;
}

export default SingleFieldList;
18 changes: 16 additions & 2 deletions packages/ra-ui-materialui/src/list/datagrid/Datagrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
useVersion,
Identifier,
Record,
RecordMap,
SortPayload,
} from 'ra-core';
import {
Checkbox,
Expand Down Expand Up @@ -337,7 +339,7 @@ Datagrid.propTypes = {
field: PropTypes.string,
order: PropTypes.string,
}),
data: PropTypes.object,
data: PropTypes.any,
// @ts-ignore
expand: PropTypes.oneOfType([PropTypes.element, PropTypes.elementType]),
hasBulkActions: PropTypes.bool,
Expand All @@ -356,7 +358,8 @@ Datagrid.propTypes = {
isRowSelectable: PropTypes.func,
};

export interface DatagridProps extends Omit<TableProps, 'size' | 'classes'> {
export interface DatagridProps<RecordType extends Record = Record>
extends Omit<TableProps, 'size' | 'classes' | 'onSelect'> {
body?: ReactElement;
classes?: ClassesOverride<typeof useDatagridStyles>;
className?: string;
Expand All @@ -375,6 +378,17 @@ export interface DatagridProps extends Omit<TableProps, 'size' | 'classes'> {
rowClick?: string | RowClickFunction;
rowStyle?: (record: Record, index: number) => any;
size?: 'medium' | 'small';
// can be injected when using the component without context
basePath?: string;
currentsort?: SortPayload;
data?: RecordMap<RecordType>;
ids?: Identifier[];
loaded?: boolean;
onSelect?: (ids: Identifier[]) => void;
onToggleItem?: (id: Identifier) => void;
setSort?: (sort: string, order?: string) => void;
selectedIds?: Identifier[];
total?: number;
}

export default Datagrid;