Skip to content

Commit

Permalink
remove isLoading prop
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed Dec 10, 2024
1 parent b8c5361 commit 3431599
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 37 deletions.
50 changes: 23 additions & 27 deletions packages/dataviews/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The `@wordpress/dataviews` package

The DataViews package offers two React components and a few utilites to work with a list of data:
The DataViews package offers two React components and a few utilities to work with a list of data:

- `DataViews`: to render the dataset using different types of layouts (table, grid, list) and interaction capabilities (search, filters, sorting, etc.).
- `DataForm`: to edit the items of the dataset.
Expand All @@ -15,7 +15,7 @@ npm install @wordpress/dataviews --save

## `DataViews`

<div class="callout callout-info">At <a href="https://wordpress.github.io/gutenberg/">WordPress Gutenberg's Storybook</a> there's and <a href="https://wordpress.github.io/gutenberg/?path=/docs/dataviews-dataviews--docs">example implementation of the Dataviews component</a>.</div>
<div class="callout callout-info">At <a href="https://wordpress.github.io/gutenberg/">WordPress Gutenberg's Storybook</a> there's an <a href="https://wordpress.github.io/gutenberg/?path=/docs/dataviews-dataviews--docs">example implementation of the Dataviews component</a>.</div>

**Important note** If you're trying to use the `DataViews` component in a WordPress plugin or theme and you're building your scripts using the `@wordpress/scripts` package, you need to import the components from `@wordpress/dataviews/wp` instead of `@wordpress/dataviews`.

Expand Down Expand Up @@ -68,13 +68,13 @@ const data = [
];
```

The data can come from anywhere, from a static JSON file to a dynamic source like a HTTP Request. It's the consumer's responsiblity to query the data source appropiately and update the dataset based on the user's choices for sorting, filtering, etc.
The data can come from anywhere, from a static JSON file to a dynamic source like an HTTP Request. It's the consumer's responsibility to query the data source appropriately and update the dataset based on the user's choices for sorting, filtering, etc.

Each record should have an `id` that identifies them uniquely. If they don't, the consumer should provide the `getItemId` property to `DataViews`: a function that returns an unique identifier for the record.

#### `getItemId`: `function`

Function that receives an item and returns an unique identifier for it.
A function that receives an item and returns a unique identifier for it.

It's optional. The field will get a default implementation by `DataViews` that returns the value of the `item[ id ]`.

Expand Down Expand Up @@ -185,9 +185,9 @@ Properties:
- `field`: the field used for sorting the dataset.
- `direction`: the direction to use for sorting, one of `asc` or `desc`.
- `titleField`: The id of the field reprensenting the title of the record.
- `mediaField`: The id of the field reprensenting the media of the record.
- `descriptionField`: The id of field the reprensenting the description of the record.
- `titleField`: The id of the field representing the title of the record.
- `mediaField`: The id of the field representing the media of the record.
- `descriptionField`: The id of the field representing the description of the record.
- `showTitle`: Whether the title should be shown in the UI. `true` by default.
- `showMedia`: Whether the media should be shown in the UI. `true` by default.
- `showDescription`: Whether the description should be shown in the UI. `true` by default.
Expand All @@ -205,7 +205,7 @@ Properties:

Callback executed when the view has changed. It receives the new view object as a parameter.

The view is a representation of the visible state of the dataset: what type of layout is used to display it (table, grid, etc.), how the dataset is filtered, how it is sorted or paginated. It's the consumer's responsibility to use the view config to query the data provider and make sure the user decisions (sort, pagination, filters, etc.) are respected.
The view is a representation of the visible state of the dataset: what type of layout is used to display it (table, grid, etc.), how the dataset is filtered, and how it is sorted or paginated. The consumer is responsible for using the view config to query the data provider and ensure the user decisions (sort, pagination, filters, etc.) are respected.

The following example shows how a view object is used to query the WordPress REST API via the entities abstraction. The same can be done with any other data provider.

Expand Down Expand Up @@ -337,7 +337,7 @@ Whether the data is loading. `false` by default.
#### `defaultLayouts`: `Record< string, view >`
This property provides layout information about the view types that are active. If empty, enables all layout types (see "Layout Types") with empty layout data.
This property provides layout information about active view types. If empty, this enables all layout types (see "Layout Types") with empty layout data.
For example, this is how you'd enable only the table view type:
Expand All @@ -358,17 +358,17 @@ The `defaultLayouts` property should be an object that includes properties named
The list of selected items' ids.
If `selection` and `onChangeSelection` are provided, the `DataViews` component behaves as a controlled component, otherwise, it behaves like an uncontrolled component.
If `selection` and `onChangeSelection` are provided, the `DataViews` component behaves like a controlled component. Otherwise, it behaves like an uncontrolled component.
#### `onChangeSelection`: `function`

Callback that signals the user selected one of more items. It receives the list of selected items' ids as a parameter.
Callback that signals the user selected one of more items. It receives the list of selected items' IDs as a parameter.

If `selection` and `onChangeSelection` are provided, the `DataViews` component behaves as a controlled component, otherwise, it behaves like an uncontrolled component.
If `selection` and `onChangeSelection` are provided, the `DataViews` component behaves like a controlled component. Otherwise, it behaves like an uncontrolled component.

### `isItemClickable`: `function`

A function that determines if a media field or a primary field are clickable. It receives an item as an argument and returns a boolean value indicating whether the item can be clicked.
A function that determines if a media field or a primary field is clickable. It receives an item as an argument and returns a boolean value indicating whether the item can be clicked.

### `onClickItem`: `function`

Expand Down Expand Up @@ -405,7 +405,7 @@ const Example = () => {
A single item to be edited.
It can be think of as a single record coming from the `data` property of `DataViews` — though it doesn't need to be. It can be totally separated or a mix of records if your app supports bulk editing.
It can be thought of as a single record coming from the `data` property of `DataViews` — though it doesn't need to be. It can be totally separated or a mix of records if your app supports bulk editing.
#### `fields`: `Object[]`
Expand Down Expand Up @@ -442,10 +442,6 @@ const fields = [
- `type`: either `regular` or `panel`.
- `fields`: a list of fields ids that should be rendered.
#### `isLoading`: `boolean`
Whether the data is loading. `false` by default.
#### `onChange`: `function`

Callback function that receives an object with the edits done by the user.
Expand Down Expand Up @@ -504,7 +500,7 @@ Returns an object containing:
### `isItemValid`
Utility to determine whether or not the given item's value is valid according to the current fields and form config.
Utility is used to determine whether or not the given item's value is valid according to the current fields and form configuration.
Parameters:
Expand All @@ -524,7 +520,7 @@ The unique identifier of the action.
- Required
- Example: `move-to-trash`
### `label`
### `label`
The user facing description of the action.
Expand Down Expand Up @@ -691,7 +687,7 @@ Example:
Field type. One of `text`, `integer`, `datetime`.
If a field declares a `type`, it gets default implementations for the `sort`, `isValid`, and `Edit` functions. They will overriden if the field provides its own.
If a field declares a `type`, it gets default implementations for the `sort`, `isValid`, and `Edit` functions if no other values are specified.
- Type: `string`.
- Optional.
Expand Down Expand Up @@ -736,7 +732,7 @@ Example:
### `getValue`
React component that returns the value of a field. This value is used in sorting the fields, or when filtering.
React component that returns the value of a field. This value is used to sort or filter the fields.
- Type: React component.
- Optional.
Expand Down Expand Up @@ -981,13 +977,13 @@ Example:
### `elements`
List of valid values for a field. If provided, it creates a DataViews' filter for the field. DataForm's edit control will use these values as well (see `Edit` field property).
List of valid values for a field. If provided, it creates a DataViews' filter for the field. DataForm's edit control will also use these values. (See `Edit` field property.)
- Type: `array` of objects.
- Optional.
- Each object can have the following properties:
- `value`: required, the value to match against the field's value.
- `label`: required, the name to display to users.
- `value`: the value to match against the field's value. (Required)
- `label`: the name to display to users. (Required)
- `description`: optional, a longer description of the item.
Example:
Expand All @@ -1010,7 +1006,7 @@ Configuration of the filters.
- Type: `object`.
- Optional.
- Properties:
- `operators`: the list of operators supported by the field. See "operators" below. By default, a filter will support the `isAny` and `isNone` multi-selection operators.
- `operators`: the list of operators supported by the field. See "operators" below. A filter will support the `isAny` and `isNone` multi-selection operators by default.
- `isPrimary`: boolean, optional. Indicates if the filter is primary. A primary filter is always visible and is not listed in the "Add filter" component, except for the list layout where it behaves like a secondary filter.
Operators:
Expand All @@ -1024,7 +1020,7 @@ Operators:
| `isAll` | Multiple items | `AND`. The item's field has all of the values in the list. | Category is all: Book, Review, Science Fiction |
| `isNotAll` | Multiple items | `NOT AND`. The item's field doesn't have all of the values in the list. | Category is not all: Book, Review, Science Fiction |
`is` and `isNot` are single-selection operators, while `isAny`, `isNone`, `isAll`, and `isNotALl` are multi-selection. By default, a filter with no operators declared will support the `isAny` and `isNone` multi-selection operators. A filter cannot mix single-selection & multi-selection operators; if a single-selection operator is present in the list of valid operators, the multi-selection ones will be discarded and the filter won't allow selecting more than one item.
`is` and `isNot` are single-selection operators, while `isAny`, `isNone`, `isAll`, and `isNotALl` are multi-selection. A filter with no operators declared will support the `isAny` and `isNone` multi-selection operators by default. A filter cannot mix single-selection & multi-selection operators; if a single-selection operator is present in the list of valid operators, the multi-selection ones will be discarded, and the filter won't allow selecting more than one item.
Example:
Expand Down
3 changes: 1 addition & 2 deletions packages/dataviews/src/components/dataform/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ export default function DataForm< Item >( {
form,
fields,
onChange,
isLoading = false,
}: DataFormProps< Item > ) {
const normalizedFields = useMemo(
() => normalizeFields( fields ),
[ fields ]
);

if ( ! form.fields || isLoading ) {
if ( ! form.fields ) {
return null;
}

Expand Down
1 change: 0 additions & 1 deletion packages/dataviews/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ export interface DataFormProps< Item > {
fields: Field< Item >[];
form: Form;
onChange: ( value: Record< string, any > ) => void;
isLoading?: boolean;
}

export interface FieldLayoutProps< Item > {
Expand Down
16 changes: 9 additions & 7 deletions packages/edit-site/src/components/post-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ function PostEditForm( { postType, postId } ) {
return (
<VStack spacing={ 4 }>
<PostEditHeader postType={ postType } postId={ postId } />
<DataForm
data={ ids.length === 1 ? record : multiEdits }
isLoading={ ! hasFinishedResolution }
fields={ fieldsWithDependency }
form={ form }
onChange={ onChange }
/>
{ hasFinishedResolution && (
<DataForm
data={ ids.length === 1 ? record : multiEdits }
isLoading={ ! hasFinishedResolution }
fields={ fieldsWithDependency }
form={ form }
onChange={ onChange }
/>
) }
</VStack>
);
}
Expand Down

0 comments on commit 3431599

Please sign in to comment.