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

singlefieldlist-component #6036

Merged
merged 1 commit into from
Mar 15, 2021
Merged
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
21 changes: 16 additions & 5 deletions packages/ra-ui-materialui/src/list/SingleFieldList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import * as React from 'react';
import { cloneElement, Children, HtmlHTMLAttributes, FC } from 'react';
import {
cloneElement,
Children,
HtmlHTMLAttributes,
FC,
ComponentType,
} from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import LinearProgress from '@material-ui/core/LinearProgress';
Expand All @@ -10,6 +16,7 @@ import {
useListContext,
useResourceContext,
RecordContextProvider,
ComponentPropType,
} from 'ra-core';

import Link from '../Link';
Expand Down Expand Up @@ -74,19 +81,21 @@ const SingleFieldList: FC<SingleFieldListProps> = props => {
className,
children,
linkType = 'edit',
component = 'div',
...rest
} = props;
const { ids, data, loaded, basePath } = useListContext(props);
const resource = useResourceContext(props);

const classes = useStyles(props);
const Component = component;

if (loaded === false) {
return <LinearProgress />;
}

return (
<div
<Component
className={classnames(classes.root, className)}
{...sanitizeListRestProps(rest)}
>
Expand All @@ -97,7 +106,7 @@ const SingleFieldList: FC<SingleFieldListProps> = props => {

if (resourceLinkPath) {
return (
<RecordContextProvider value={data[id]}>
<RecordContextProvider value={data[id]} key={id}>
<Link
className={classes.link}
key={id}
Expand All @@ -117,7 +126,7 @@ const SingleFieldList: FC<SingleFieldListProps> = props => {
}

return (
<RecordContextProvider value={data[id]}>
<RecordContextProvider value={data[id]} key={id}>
{cloneElement(Children.only(children), {
key: id,
record: data[id],
Expand All @@ -127,7 +136,7 @@ const SingleFieldList: FC<SingleFieldListProps> = props => {
</RecordContextProvider>
);
})}
</div>
</Component>
);
};

Expand All @@ -136,6 +145,7 @@ SingleFieldList.propTypes = {
children: PropTypes.element.isRequired,
classes: PropTypes.object,
className: PropTypes.string,
component: ComponentPropType,
data: PropTypes.object,
ids: PropTypes.array,
// @ts-ignore
Expand All @@ -147,6 +157,7 @@ export interface SingleFieldListProps
extends HtmlHTMLAttributes<HTMLDivElement> {
className?: string;
classes?: ClassesOverride<typeof useStyles>;
component?: ComponentType<any>;
linkType?: string | false;
children: React.ReactElement;
}
Expand Down