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

Fix JS docs (@typedef) #9752

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Fix JS docs (@typedef) #9752

wants to merge 2 commits into from

Conversation

erwanMarmelab
Copy link
Contributor

We have many components that have @typedef and @prop in their documentation.

They should only use param

Example

  * @typedef Props
  * @property {Object} record: The current resource record

To:

  * @param {Object} props
  * @param {Object} props.record The current resource record

@erwanMarmelab erwanMarmelab added the RFR Ready For Review label Apr 2, 2024
@fzaninotto
Copy link
Member

I don't agree. The second definition means the function has 2 params, which is wrong. What needs to be done is to set the param to the defined type, e.g.

  * @typedef Props
  * @property {Object} record: The current resource record
  *
  * @param {Props} 

@fzaninotto
Copy link
Member

What we actually need to do is to move the @param JSDoc annotations to the TypeScript Prop types definitions, as in

export interface ListControllerProps<RecordType extends RaRecord = any> {
/**
* The debounce delay for filter queries in milliseconds. Defaults to 500ms.
*
* @see https://marmelab.com/react-admin/List.html#debounce
* @example
* // wait 1 seconds instead of 500 milliseconds befoce calling the dataProvider
* const PostList = () => (
* <List debounce={1000}>
* ...
* </List>
* );
*/
debounce?: number;
/**
* Allow anonymous access to the list view. Defaults to false.
*
* @see https://marmelab.com/react-admin/List.html#disableauthentication
* @example
* import { List } from 'react-admin';
*
* const BoolkList = () => (
* <List disableAuthentication>
* ...
* </List>
* );
*/
disableAuthentication?: boolean;
/**
* Whether to disable the synchronization of the list parameters with the current location (URL search parameters)
*
* @see https://marmelab.com/react-admin/List.html#disablesyncwithlocation
* @example
* const Dashboard = () => (
* <div>
* // ...
* <ResourceContextProvider value="posts">
* <List disableSyncWithLocation>
* <SimpleList
* primaryText={record => record.title}
* secondaryText={record => `${record.views} views`}
* tertiaryText={record => new Date(record.published_at).toLocaleDateString()}
* />
* </List>
* </ResourceContextProvider>
* <ResourceContextProvider value="comments">
* <List disableSyncWithLocation>
* <SimpleList
* primaryText={record => record.title}
* secondaryText={record => `${record.views} views`}
* tertiaryText={record => new Date(record.published_at).toLocaleDateString()}
* />
* </List>
* </ResourceContextProvider>
* </div>
* )
*/
disableSyncWithLocation?: boolean;
/**
* The function called when a user exports the list
*
* @see https://marmelab.com/react-admin/List.html#exporter
* @example
* import { List, downloadCSV } from 'react-admin';
* import jsonExport from 'jsonexport/dist';
*
* const exporter = posts => {
* const postsForExport = posts.map(post => {
* const { backLinks, author, ...postForExport } = post; // omit backLinks and author
* postForExport.author_name = post.author.name; // add a field
* return postForExport;
* });
* jsonExport(postsForExport, {
* headers: ['id', 'title', 'author_name', 'body'] // order fields in the export
* }, (err, csv) => {
* downloadCSV(csv, 'posts'); // download as 'posts.csv` file
* });
* };
*
* const PostList = () => (
* <List exporter={exporter}>
* ...
* </List>
* )
*/
exporter?: Exporter | false;
/**
* Permanent filter applied to all getList queries, regardless of the user selected filters.
*
* @see https://marmelab.com/react-admin/List.html#filter
* @example
* export const PostList = () => (
* <List filter={{ is_published: true }}>
* ...
* </List>
* );
*/
filter?: FilterPayload;
/**
* The filter to apply when calling getList if the filter is empty.
*
* @see https://marmelab.com/react-admin/List.html#filterdefaultvalues
* @example
* const postFilters = [
* <TextInput label="Search" source="q" alwaysOn />,
* <BooleanInput source="is_published" alwaysOn />,
* <TextInput source="title" defaultValue="Hello, World!" />,
* ];
*
* export const PostList = () => (
* <List filters={postFilters} filterDefaultValues={{ is_published: true }}>
* ...
* </List>
* );
*/
filterDefaultValues?: object;
/**
* The number of results per page. Defaults to 10.
*
* @see https://marmelab.com/react-admin/List.html#perpage
* @example
* export const PostList = () => (
* <List perPage={25}>
* ...
* </List>
* );
*/
perPage?: number;
/**
* The options passed to react-query's useQuery when calling getList.
*
* @see https://marmelab.com/react-admin/List.html#queryoptions
* @example
* import { useNotify, useRedirect, List } from 'react-admin';
*
* const PostList = () => {
* const notify = useNotify();
* const redirect = useRedirect();
*
* const onError = (error) => {
* notify(`Could not load list: ${error.message}`, { type: 'error' });
* redirect('/dashboard');
* };
*
* return (
* <List queryOptions={{ onError }}>
* ...
* </List>
* );
* }
*/
queryOptions?: UseQueryOptions<{
data: RecordType[];
total?: number;
pageInfo?: {
hasNextPage?: boolean;
hasPreviousPage?: boolean;
};
}> & { meta?: any };
/**
* The resource name. Defaults to the resource from ResourceContext.
*
* @see https://marmelab.com/react-admin/List.html#resource
* @example
* import { List } from 'react-admin';
*
* const PostList = () => (
* <List resource="posts">
* ...
* </List>
* );
*/
resource?: string;
/**
* The default sort field and order. Defaults to { field: 'id', order: 'ASC' }.
*
* @see https://marmelab.com/react-admin/List.html#sort
* @example
* export const PostList = () => (
* <List sort={{ field: 'published_at', order: 'DESC' }}>
* ...
* </List>
* );
*/
sort?: SortPayload;
/**
* The key to use to store the current filter & sort. Pass false to disable.
*
* @see https://marmelab.com/react-admin/List.html#storekey
* @example
* const NewerBooks = () => (
* <List
* resource="books"
* storeKey="newerBooks"
* sort={{ field: 'year', order: 'DESC' }}
* >
* ...
* </List>
* );
*/
storeKey?: string | false;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants