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

Dataviews: Extract to dedicated bundled package #56721

Merged
merged 5 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,12 @@
"markdown_source": "../packages/data/README.md",
"parent": "packages"
},
{
"title": "@wordpress/dataviews",
"slug": "packages-dataviews",
"markdown_source": "../packages/dataviews/README.md",
"parent": "packages"
},
{
"title": "@wordpress/date",
"slug": "packages-date",
Expand Down
49 changes: 47 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@wordpress/customize-widgets": "file:packages/customize-widgets",
"@wordpress/data": "file:packages/data",
"@wordpress/data-controls": "file:packages/data-controls",
"@wordpress/dataviews": "file:packages/dataviews",
"@wordpress/date": "file:packages/date",
"@wordpress/deprecated": "file:packages/deprecated",
"@wordpress/dom": "file:packages/dom",
Expand Down
1 change: 1 addition & 0 deletions packages/dataviews/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
3 changes: 3 additions & 0 deletions packages/dataviews/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. -->

## Unreleased
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# DataView
# DataViews

This file documents the DataViews UI component, which provides an API to render datasets using different view types (table, grid, etc.).
DataViews is a component that provides an API to render datasets using different types of layouts (table, grid, list, etc.).

## Installation

Install the module

```bash
npm install @wordpress/dataviews --save
```

## Usage

```js
<DataViews
Expand Down Expand Up @@ -189,3 +199,11 @@ Array of operations that can be performed upon each record. Each action is an ob
- `callback`: function, required unless `RenderModal` is provided. Callback function that takes the record as input and performs the required action.
- `RenderModal`: ReactElement, optional. If an action requires that some UI be rendered in a modal, it can provide a component which takes as props the record as `item` and a `closeModal` function. When this prop is provided, the `callback` property is ignored.
- `hideModalHeader`: boolean, optional. This property is used in combination with `RenderModal` and controls the visibility of the modal's header. If the action renders a modal and doesn't hide the header, the action's label is going to be used in the modal's header.

## Contributing to this package

This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.

To find out more about contributing to this package or Gutenberg as a whole, please read the project's main [contributor guide](https://github.com/WordPress/gutenberg/tree/HEAD/CONTRIBUTING.md).

<br /><br /><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
48 changes: 48 additions & 0 deletions packages/dataviews/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "@wordpress/dataviews",
"version": "0.1.0",
"description": "DataViews is a component that provides an API to render datasets using different types of layouts (table, grid, list, etc.).",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
"keywords": [
"wordpress",
"gutenberg",
"dataviews"
],
"homepage": "https://github.com/WordPress/gutenberg/tree/HEAD/packages/dataviews/README.md",
"repository": {
"type": "git",
"url": "https://github.com/WordPress/gutenberg.git",
"directory": "packages/dataviews"
},
"bugs": {
"url": "https://github.com/WordPress/gutenberg/issues"
},
"engines": {
"node": ">=12"
},
"main": "build/index.js",
"module": "build-module/index.js",
"react-native": "src/index",
"types": "build-types",
"sideEffects": false,
"dependencies": {
"@babel/runtime": "^7.16.0",
"@tanstack/react-table": "^8.10.3",
"@wordpress/a11y": "file:../a11y",
"@wordpress/components": "file:../components",
"@wordpress/compose": "file:../compose",
"@wordpress/element": "file:../element",
"@wordpress/i18n": "file:../i18n",
"@wordpress/icons": "file:../icons",
"@wordpress/private-apis": "file:../private-apis",
"classnames": "^2.3.1",
"remove-accents": "^0.5.0"
},
"peerDependencies": {
"react": "^18.0.0"
},
"publishConfig": {
"access": "public"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';
import { unlock } from './lock-unlock';
import { ENUMERATION_TYPE, OPERATOR_IN } from './constants';

const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { __, sprintf } from '@wordpress/i18n';
* Internal dependencies
*/
import { OPERATOR_IN } from './constants';
import { unlock } from '../../lock-unlock';
import { unlock } from './lock-unlock';

const {
DropdownMenuV2: DropdownMenu,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { moreVertical } from '@wordpress/icons';
/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';
import { unlock } from './lock-unlock';

const {
DropdownMenuV2Ariakit: DropdownMenu,
Expand Down
10 changes: 10 additions & 0 deletions packages/dataviews/src/lock-unlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* WordPress dependencies
*/
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';

export const { lock, unlock } =
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.',
'@wordpress/dataviews'
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SearchControl } from '@wordpress/components';
/**
* Internal dependencies
*/
import useDebouncedInput from '../../utils/use-debounced-input';
import useDebouncedInput from './utils/use-debounced-input';

export default function Search( { label, view, onChangeView } ) {
const [ search, setSearch, debouncedSearch ] = useDebouncedInput(
Expand Down
18 changes: 18 additions & 0 deletions packages/dataviews/src/utils/use-debounced-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* WordPress dependencies
*/
import { useEffect, useState } from '@wordpress/element';
import { useDebounce } from '@wordpress/compose';

export default function useDebouncedInput( defaultValue = '' ) {
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
const [ input, setInput ] = useState( defaultValue );
const [ debouncedInput, setDebouncedState ] = useState( defaultValue );

const setDebouncedInput = useDebounce( setDebouncedState, 250 );

useEffect( () => {
setDebouncedInput( input );
}, [ input ] );

return [ input, setInput, debouncedInput ];
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking this PR as opportunity to organize the code a bit. What would you think of the following src tree?

  • actions
    • view.js
    • item.js
  • filters
    • index.js (was filters.js before)
    • add.js
    • reset.js
    • summary.js
  • layouts
    • grid.js
    • list.js
    • table.js
  • utils
    • use-debounced-input.js
  • constants.js
  • dataviews.js
  • index.js
  • pagination.js
  • search.js
  • style.scss

Copy link
Contributor Author

@ntsekouras ntsekouras Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm planning to reorganise, but in the follow ups because of the many iterations right now. Is that a blocker for you in this PR?

Copy link
Member

@oandregal oandregal Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a blocker for you in this PR?

Not at all! Just thought it'd be nice given the situation, but I understand your concern about this PR's velocity. Let's revisit after merging if you feel this would take a bit longer to agree upon.

import { unlock } from './lock-unlock';
import { VIEW_LAYOUTS, LAYOUT_TABLE } from './constants';

const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { useMemo, Children, Fragment } from '@wordpress/element';
/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';
import { unlock } from './lock-unlock';
import ItemActions from './item-actions';
import { ENUMERATION_TYPE, OPERATOR_IN } from './constants';

Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"react-native": "src/index",
"dependencies": {
"@babel/runtime": "^7.16.0",
"@tanstack/react-table": "^8.10.3",
"@wordpress/a11y": "file:../a11y",
"@wordpress/api-fetch": "file:../api-fetch",
"@wordpress/blob": "file:../blob",
Expand All @@ -40,6 +39,7 @@
"@wordpress/core-commands": "file:../core-commands",
"@wordpress/core-data": "file:../core-data",
"@wordpress/data": "file:../data",
"@wordpress/dataviews": "file:../dataviews",
"@wordpress/date": "file:../date",
"@wordpress/deprecated": "file:../deprecated",
"@wordpress/dom": "file:../dom",
Expand Down
16 changes: 8 additions & 8 deletions packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ import { useState, useMemo, useCallback, useEffect } from '@wordpress/element';
import { dateI18n, getDate, getSettings } from '@wordpress/date';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { useSelect, useDispatch } from '@wordpress/data';
import {
DataViews,
ENUMERATION_TYPE,
VIEW_LAYOUTS,
OPERATOR_IN,
LAYOUT_GRID,
LAYOUT_TABLE,
} from '@wordpress/dataviews';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'm not a big fan of exporting constants from package but I can live with it for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few things here:


/**
* Internal dependencies
*/
import Page from '../page';
import Link from '../routes/link';
import {
DataViews,
VIEW_LAYOUTS,
ENUMERATION_TYPE,
LAYOUT_GRID,
LAYOUT_TABLE,
OPERATOR_IN,
} from '../dataviews';
import { default as DEFAULT_VIEWS } from '../sidebar-dataviews/default-views';
import {
trashPostAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ import {
BlockPreview,
privateApis as blockEditorPrivateApis,
} from '@wordpress/block-editor';
import {
DataViews,
ENUMERATION_TYPE,
OPERATOR_IN,
LAYOUT_GRID,
LAYOUT_TABLE,
} from '@wordpress/dataviews';

/**
* Internal dependencies
Expand All @@ -31,13 +38,6 @@ import Page from '../page';
import Link from '../routes/link';
import { useAddedBy, AvatarImage } from '../list/added-by';
import { TEMPLATE_POST_TYPE } from '../../utils/constants';
import {
DataViews,
ENUMERATION_TYPE,
OPERATOR_IN,
LAYOUT_GRID,
LAYOUT_TABLE,
} from '../dataviews';
import {
useResetTemplateAction,
deleteTemplateAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import classnames from 'classnames';
*/
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { __experimentalHStack as HStack } from '@wordpress/components';
import { VIEW_LAYOUTS } from '@wordpress/dataviews';

/**
* Internal dependencies
*/
import { useLink } from '../routes/link';
import SidebarNavigationItem from '../sidebar-navigation-item';
import { unlock } from '../../lock-unlock';
import { VIEW_LAYOUTS } from '../dataviews';
const { useLocation } = unlock( routerPrivateApis );

export default function DataViewItem( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
*/
import { __ } from '@wordpress/i18n';
import { trash } from '@wordpress/icons';

/**
* Internal dependencies
*/
import { LAYOUT_TABLE, OPERATOR_IN } from '../dataviews';
import { LAYOUT_TABLE, OPERATOR_IN } from '@wordpress/dataviews';

const DEFAULT_PAGE_BASE = {
type: LAYOUT_TABLE,
Expand Down
Loading
Loading