@wordpress/dataviews 2.2.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +23 -8
- package/build/components/dataform/index.js +78 -0
- package/build/components/dataform/index.js.map +1 -0
- package/build/components/dataviews/index.js +115 -0
- package/build/components/dataviews/index.js.map +1 -0
- package/build/{bulk-actions.js → components/dataviews-bulk-actions/index.js} +39 -16
- package/build/components/dataviews-bulk-actions/index.js.map +1 -0
- package/build/{bulk-actions-toolbar.js → components/dataviews-bulk-actions-toolbar/index.js} +36 -20
- package/build/components/dataviews-bulk-actions-toolbar/index.js.map +1 -0
- package/build/components/dataviews-context/index.js +36 -0
- package/build/components/dataviews-context/index.js.map +1 -0
- package/build/{add-filter.js → components/dataviews-filters/add-filter.js} +3 -3
- package/build/components/dataviews-filters/add-filter.js.map +1 -0
- package/build/{filter-summary.js → components/dataviews-filters/filter-summary.js} +15 -14
- package/build/components/dataviews-filters/filter-summary.js.map +1 -0
- package/build/{filters.js → components/dataviews-filters/index.js} +15 -16
- package/build/components/dataviews-filters/index.js.map +1 -0
- package/build/{reset-filters.js → components/dataviews-filters/reset-filters.js} +1 -1
- package/build/components/dataviews-filters/reset-filters.js.map +1 -0
- package/build/{search-widget.js → components/dataviews-filters/search-widget.js} +21 -19
- package/build/components/dataviews-filters/search-widget.js.map +1 -0
- package/build/{item-actions.js → components/dataviews-item-actions/index.js} +3 -3
- package/build/components/dataviews-item-actions/index.js.map +1 -0
- package/build/components/dataviews-layout/index.js +53 -0
- package/build/components/dataviews-layout/index.js.map +1 -0
- package/build/{pagination.js → components/dataviews-pagination/index.js} +18 -15
- package/build/components/dataviews-pagination/index.js.map +1 -0
- package/build/{search.js → components/dataviews-search/index.js} +10 -6
- package/build/components/dataviews-search/index.js.map +1 -0
- package/build/components/dataviews-selection-checkbox/index.js +52 -0
- package/build/components/dataviews-selection-checkbox/index.js.map +1 -0
- package/build/{view-actions.js → components/dataviews-view-config/index.js} +94 -80
- package/build/components/dataviews-view-config/index.js.map +1 -0
- package/build/filter-and-sort-data-view.js +4 -1
- package/build/filter-and-sort-data-view.js.map +1 -1
- package/build/index.js +8 -1
- package/build/index.js.map +1 -1
- package/build/layouts/grid/density-picker.js +143 -0
- package/build/layouts/grid/density-picker.js.map +1 -0
- package/build/{view-grid.js → layouts/grid/index.js} +40 -53
- package/build/layouts/grid/index.js.map +1 -0
- package/build/layouts/index.js +52 -0
- package/build/layouts/index.js.map +1 -0
- package/build/{view-list.js → layouts/list/index.js} +31 -27
- package/build/layouts/list/index.js.map +1 -0
- package/build/layouts/table/column-header-menu.js +196 -0
- package/build/layouts/table/column-header-menu.js.map +1 -0
- package/build/layouts/table/index.js +350 -0
- package/build/layouts/table/index.js.map +1 -0
- package/build/normalize-fields.js +1 -1
- package/build/normalize-fields.js.map +1 -1
- package/build/private-types.js +6 -0
- package/build/private-types.js.map +1 -0
- package/build/types.js.map +1 -1
- package/build/utils.js.map +1 -1
- package/build-module/components/dataform/index.js +72 -0
- package/build-module/components/dataform/index.js.map +1 -0
- package/build-module/components/dataviews/index.js +108 -0
- package/build-module/components/dataviews/index.js.map +1 -0
- package/build-module/{bulk-actions.js → components/dataviews-bulk-actions/index.js} +39 -17
- package/build-module/components/dataviews-bulk-actions/index.js.map +1 -0
- package/build-module/{bulk-actions-toolbar.js → components/dataviews-bulk-actions-toolbar/index.js} +35 -20
- package/build-module/components/dataviews-bulk-actions-toolbar/index.js.map +1 -0
- package/build-module/components/dataviews-context/index.js +30 -0
- package/build-module/components/dataviews-context/index.js.map +1 -0
- package/build-module/{add-filter.js → components/dataviews-filters/add-filter.js} +3 -3
- package/build-module/components/dataviews-filters/add-filter.js.map +1 -0
- package/build-module/{filter-summary.js → components/dataviews-filters/filter-summary.js} +15 -14
- package/build-module/components/dataviews-filters/filter-summary.js.map +1 -0
- package/build-module/{filters.js → components/dataviews-filters/index.js} +16 -17
- package/build-module/components/dataviews-filters/index.js.map +1 -0
- package/build-module/{reset-filters.js → components/dataviews-filters/reset-filters.js} +1 -1
- package/build-module/components/dataviews-filters/reset-filters.js.map +1 -0
- package/build-module/{search-widget.js → components/dataviews-filters/search-widget.js} +21 -19
- package/build-module/components/dataviews-filters/search-widget.js.map +1 -0
- package/build-module/{item-actions.js → components/dataviews-item-actions/index.js} +3 -3
- package/build-module/components/dataviews-item-actions/index.js.map +1 -0
- package/build-module/components/dataviews-layout/index.js +45 -0
- package/build-module/components/dataviews-layout/index.js.map +1 -0
- package/build-module/{pagination.js → components/dataviews-pagination/index.js} +19 -17
- package/build-module/components/dataviews-pagination/index.js.map +1 -0
- package/build-module/{search.js → components/dataviews-search/index.js} +10 -7
- package/build-module/components/dataviews-search/index.js.map +1 -0
- package/build-module/components/dataviews-selection-checkbox/index.js +45 -0
- package/build-module/components/dataviews-selection-checkbox/index.js.map +1 -0
- package/build-module/{view-actions.js → components/dataviews-view-config/index.js} +98 -84
- package/build-module/components/dataviews-view-config/index.js.map +1 -0
- package/build-module/filter-and-sort-data-view.js +4 -1
- package/build-module/filter-and-sort-data-view.js.map +1 -1
- package/build-module/index.js +2 -1
- package/build-module/index.js.map +1 -1
- package/build-module/layouts/grid/density-picker.js +138 -0
- package/build-module/layouts/grid/density-picker.js.map +1 -0
- package/build-module/{view-grid.js → layouts/grid/index.js} +37 -50
- package/build-module/layouts/grid/index.js.map +1 -0
- package/build-module/layouts/index.js +43 -0
- package/build-module/layouts/index.js.map +1 -0
- package/build-module/{view-list.js → layouts/list/index.js} +29 -25
- package/build-module/layouts/list/index.js.map +1 -0
- package/build-module/layouts/table/column-header-menu.js +190 -0
- package/build-module/layouts/table/column-header-menu.js.map +1 -0
- package/build-module/layouts/table/index.js +344 -0
- package/build-module/layouts/table/index.js.map +1 -0
- package/build-module/normalize-fields.js +1 -1
- package/build-module/normalize-fields.js.map +1 -1
- package/build-module/private-types.js +2 -0
- package/build-module/private-types.js.map +1 -0
- package/build-module/types.js.map +1 -1
- package/build-module/utils.js.map +1 -1
- package/build-style/style-rtl.css +607 -561
- package/build-style/style.css +607 -561
- package/build-types/components/dataform/index.d.ts +17 -0
- package/build-types/components/dataform/index.d.ts.map +1 -0
- package/build-types/components/dataform/stories/index.story.d.ts +11 -0
- package/build-types/components/dataform/stories/index.story.d.ts.map +1 -0
- package/build-types/components/dataviews/index.d.ts +33 -0
- package/build-types/components/dataviews/index.d.ts.map +1 -0
- package/build-types/{stories → components/dataviews/stories}/fixtures.d.ts +18 -17
- package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -0
- package/build-types/components/dataviews/stories/index.story.d.ts +46 -0
- package/build-types/components/dataviews/stories/index.story.d.ts.map +1 -0
- package/build-types/components/dataviews-bulk-actions/index.d.ts +5 -0
- package/build-types/components/dataviews-bulk-actions/index.d.ts.map +1 -0
- package/build-types/components/dataviews-bulk-actions-toolbar/index.d.ts +2 -0
- package/build-types/components/dataviews-bulk-actions-toolbar/index.d.ts.map +1 -0
- package/build-types/components/dataviews-context/index.d.ts +26 -0
- package/build-types/components/dataviews-context/index.d.ts.map +1 -0
- package/build-types/{add-filter.d.ts → components/dataviews-filters/add-filter.d.ts} +1 -2
- package/build-types/components/dataviews-filters/add-filter.d.ts.map +1 -0
- package/build-types/{filter-summary.d.ts → components/dataviews-filters/filter-summary.d.ts} +1 -1
- package/build-types/components/dataviews-filters/filter-summary.d.ts.map +1 -0
- package/build-types/components/dataviews-filters/index.d.ts +4 -0
- package/build-types/components/dataviews-filters/index.d.ts.map +1 -0
- package/build-types/{reset-filters.d.ts → components/dataviews-filters/reset-filters.d.ts} +1 -2
- package/build-types/components/dataviews-filters/reset-filters.d.ts.map +1 -0
- package/build-types/{search-widget.d.ts → components/dataviews-filters/search-widget.d.ts} +1 -2
- package/build-types/components/dataviews-filters/search-widget.d.ts.map +1 -0
- package/build-types/components/dataviews-item-actions/index.d.ts +35 -0
- package/build-types/components/dataviews-item-actions/index.d.ts.map +1 -0
- package/build-types/components/dataviews-layout/index.d.ts +2 -0
- package/build-types/components/dataviews-layout/index.d.ts.map +1 -0
- package/build-types/components/dataviews-pagination/index.d.ts +4 -0
- package/build-types/components/dataviews-pagination/index.d.ts.map +1 -0
- package/build-types/components/dataviews-search/index.d.ts +6 -0
- package/build-types/components/dataviews-search/index.d.ts.map +1 -0
- package/build-types/components/dataviews-selection-checkbox/index.d.ts +16 -0
- package/build-types/components/dataviews-selection-checkbox/index.d.ts.map +1 -0
- package/build-types/components/dataviews-view-config/index.d.ts +8 -0
- package/build-types/components/dataviews-view-config/index.d.ts.map +1 -0
- package/build-types/filter-and-sort-data-view.d.ts +2 -2
- package/build-types/filter-and-sort-data-view.d.ts.map +1 -1
- package/build-types/index.d.ts +2 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/layouts/grid/density-picker.d.ts +5 -0
- package/build-types/layouts/grid/density-picker.d.ts.map +1 -0
- package/build-types/layouts/grid/index.d.ts +3 -0
- package/build-types/layouts/grid/index.d.ts.map +1 -0
- package/build-types/{layouts.d.ts → layouts/index.d.ts} +6 -5
- package/build-types/layouts/index.d.ts.map +1 -0
- package/build-types/layouts/list/index.d.ts +3 -0
- package/build-types/layouts/list/index.d.ts.map +1 -0
- package/build-types/layouts/table/column-header-menu.d.ts +17 -0
- package/build-types/layouts/table/column-header-menu.d.ts.map +1 -0
- package/build-types/layouts/table/index.d.ts +4 -0
- package/build-types/layouts/table/index.d.ts.map +1 -0
- package/build-types/normalize-fields.d.ts +2 -2
- package/build-types/normalize-fields.d.ts.map +1 -1
- package/build-types/private-types.d.ts +3 -0
- package/build-types/private-types.d.ts.map +1 -0
- package/build-types/types.d.ts +106 -46
- package/build-types/types.d.ts.map +1 -1
- package/build-types/utils.d.ts +2 -2
- package/build-types/utils.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/components/dataform/index.tsx +106 -0
- package/src/components/dataform/stories/index.story.tsx +42 -0
- package/src/components/dataviews/index.tsx +149 -0
- package/src/{stories → components/dataviews/stories}/fixtures.js +23 -11
- package/src/components/dataviews/stories/index.story.js +65 -0
- package/src/components/dataviews/style.scss +97 -0
- package/src/{bulk-actions.tsx → components/dataviews-bulk-actions/index.tsx} +58 -36
- package/src/components/dataviews-bulk-actions/style.scss +7 -0
- package/src/{bulk-actions-toolbar.tsx → components/dataviews-bulk-actions-toolbar/index.tsx} +48 -36
- package/src/components/dataviews-bulk-actions-toolbar/style.scss +45 -0
- package/src/components/dataviews-context/index.ts +49 -0
- package/src/{add-filter.tsx → components/dataviews-filters/add-filter.tsx} +4 -4
- package/src/{filter-summary.tsx → components/dataviews-filters/filter-summary.tsx} +36 -22
- package/src/{filters.tsx → components/dataviews-filters/index.tsx} +11 -25
- package/src/{reset-filters.tsx → components/dataviews-filters/reset-filters.tsx} +2 -2
- package/src/{search-widget.tsx → components/dataviews-filters/search-widget.tsx} +20 -20
- package/src/components/dataviews-filters/style.scss +252 -0
- package/src/{item-actions.tsx → components/dataviews-item-actions/index.tsx} +16 -17
- package/src/components/dataviews-item-actions/style.scss +3 -0
- package/src/components/dataviews-layout/index.tsx +51 -0
- package/src/{pagination.tsx → components/dataviews-pagination/index.tsx} +15 -23
- package/src/components/dataviews-pagination/style.scss +26 -0
- package/src/{search.tsx → components/dataviews-search/index.tsx} +5 -10
- package/src/components/dataviews-selection-checkbox/index.tsx +65 -0
- package/src/components/dataviews-selection-checkbox/style.scss +14 -0
- package/src/{view-actions.tsx → components/dataviews-view-config/index.tsx} +116 -119
- package/src/filter-and-sort-data-view.ts +13 -3
- package/src/index.ts +2 -1
- package/src/layouts/grid/density-picker.tsx +136 -0
- package/src/{view-grid.tsx → layouts/grid/index.tsx} +45 -63
- package/src/layouts/grid/style.scss +140 -0
- package/src/layouts/index.ts +66 -0
- package/src/{view-list.tsx → layouts/list/index.tsx} +40 -30
- package/src/layouts/list/style.scss +189 -0
- package/src/layouts/table/column-header-menu.tsx +268 -0
- package/src/layouts/table/index.tsx +471 -0
- package/src/layouts/table/style.scss +201 -0
- package/src/normalize-fields.ts +6 -4
- package/src/private-types.tsx +2 -0
- package/src/style.scss +11 -919
- package/src/test/filter-and-sort-data-view.js +17 -2
- package/src/types.ts +113 -55
- package/src/utils.ts +2 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/build/add-filter.js.map +0 -1
- package/build/bulk-actions-toolbar.js.map +0 -1
- package/build/bulk-actions.js.map +0 -1
- package/build/dataviews.js +0 -136
- package/build/dataviews.js.map +0 -1
- package/build/filter-summary.js.map +0 -1
- package/build/filters.js.map +0 -1
- package/build/item-actions.js.map +0 -1
- package/build/layouts.js +0 -38
- package/build/layouts.js.map +0 -1
- package/build/pagination.js.map +0 -1
- package/build/reset-filters.js.map +0 -1
- package/build/search-widget.js.map +0 -1
- package/build/search.js.map +0 -1
- package/build/single-selection-checkbox.js +0 -63
- package/build/single-selection-checkbox.js.map +0 -1
- package/build/view-actions.js.map +0 -1
- package/build/view-grid.js.map +0 -1
- package/build/view-list.js.map +0 -1
- package/build/view-table.js +0 -409
- package/build/view-table.js.map +0 -1
- package/build-module/add-filter.js.map +0 -1
- package/build-module/bulk-actions-toolbar.js.map +0 -1
- package/build-module/bulk-actions.js.map +0 -1
- package/build-module/dataviews.js +0 -129
- package/build-module/dataviews.js.map +0 -1
- package/build-module/filter-summary.js.map +0 -1
- package/build-module/filters.js.map +0 -1
- package/build-module/item-actions.js.map +0 -1
- package/build-module/layouts.js +0 -30
- package/build-module/layouts.js.map +0 -1
- package/build-module/pagination.js.map +0 -1
- package/build-module/reset-filters.js.map +0 -1
- package/build-module/search-widget.js.map +0 -1
- package/build-module/search.js.map +0 -1
- package/build-module/single-selection-checkbox.js +0 -56
- package/build-module/single-selection-checkbox.js.map +0 -1
- package/build-module/view-actions.js.map +0 -1
- package/build-module/view-grid.js.map +0 -1
- package/build-module/view-list.js.map +0 -1
- package/build-module/view-table.js +0 -402
- package/build-module/view-table.js.map +0 -1
- package/build-types/add-filter.d.ts.map +0 -1
- package/build-types/bulk-actions-toolbar.d.ts +0 -12
- package/build-types/bulk-actions-toolbar.d.ts.map +0 -1
- package/build-types/bulk-actions.d.ts +0 -14
- package/build-types/bulk-actions.d.ts.map +0 -1
- package/build-types/dataviews.d.ts +0 -24
- package/build-types/dataviews.d.ts.map +0 -1
- package/build-types/filter-summary.d.ts.map +0 -1
- package/build-types/filters.d.ts +0 -13
- package/build-types/filters.d.ts.map +0 -1
- package/build-types/item-actions.d.ts +0 -35
- package/build-types/item-actions.d.ts.map +0 -1
- package/build-types/layouts.d.ts.map +0 -1
- package/build-types/pagination.d.ts +0 -16
- package/build-types/pagination.d.ts.map +0 -1
- package/build-types/reset-filters.d.ts.map +0 -1
- package/build-types/search-widget.d.ts.map +0 -1
- package/build-types/search.d.ts +0 -13
- package/build-types/search.d.ts.map +0 -1
- package/build-types/single-selection-checkbox.d.ts +0 -17
- package/build-types/single-selection-checkbox.d.ts.map +0 -1
- package/build-types/stories/fixtures.d.ts.map +0 -1
- package/build-types/stories/index.story.d.ts +0 -15
- package/build-types/stories/index.story.d.ts.map +0 -1
- package/build-types/view-actions.d.ts +0 -12
- package/build-types/view-actions.d.ts.map +0 -1
- package/build-types/view-grid.d.ts +0 -4
- package/build-types/view-grid.d.ts.map +0 -1
- package/build-types/view-list.d.ts +0 -4
- package/build-types/view-list.d.ts.map +0 -1
- package/build-types/view-table.d.ts +0 -5
- package/build-types/view-table.d.ts.map +0 -1
- package/src/dataviews.tsx +0 -189
- package/src/layouts.ts +0 -39
- package/src/single-selection-checkbox.tsx +0 -80
- package/src/stories/index.story.js +0 -64
- package/src/view-table.tsx +0 -603
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { filterSortAndPaginate } from '../filter-and-sort-data-view';
|
|
5
|
-
import { data, fields } from '../stories/fixtures';
|
|
5
|
+
import { data, fields } from '../components/dataviews/stories/fixtures';
|
|
6
6
|
|
|
7
7
|
describe( 'filters', () => {
|
|
8
8
|
it( 'should return empty if the data is empty', () => {
|
|
@@ -233,7 +233,7 @@ describe( 'filters', () => {
|
|
|
233
233
|
} );
|
|
234
234
|
|
|
235
235
|
describe( 'sorting', () => {
|
|
236
|
-
it( 'should sort', () => {
|
|
236
|
+
it( 'should sort by string', () => {
|
|
237
237
|
const { data: result } = filterSortAndPaginate(
|
|
238
238
|
data,
|
|
239
239
|
{
|
|
@@ -252,6 +252,21 @@ describe( 'sorting', () => {
|
|
|
252
252
|
expect( result[ 0 ].title ).toBe( 'Uranus' );
|
|
253
253
|
expect( result[ 1 ].title ).toBe( 'Neptune' );
|
|
254
254
|
} );
|
|
255
|
+
|
|
256
|
+
it( 'should sort by number', () => {
|
|
257
|
+
const { data: result } = filterSortAndPaginate(
|
|
258
|
+
data,
|
|
259
|
+
{
|
|
260
|
+
sort: { field: 'satellites', direction: 'desc' },
|
|
261
|
+
},
|
|
262
|
+
fields
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
expect( result ).toHaveLength( 11 );
|
|
266
|
+
expect( result[ 0 ].title ).toBe( 'Saturn' );
|
|
267
|
+
expect( result[ 1 ].title ).toBe( 'Jupiter' );
|
|
268
|
+
expect( result[ 2 ].title ).toBe( 'Uranus' );
|
|
269
|
+
} );
|
|
255
270
|
} );
|
|
256
271
|
|
|
257
272
|
describe( 'pagination', () => {
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import type { ReactElement,
|
|
4
|
+
import type { ReactElement, ComponentType } from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import type { SetSelection } from './private-types';
|
|
5
10
|
|
|
6
11
|
export type SortDirection = 'asc' | 'desc';
|
|
7
12
|
|
|
@@ -37,12 +42,19 @@ export type Operator =
|
|
|
37
42
|
| 'isAll'
|
|
38
43
|
| 'isNotAll';
|
|
39
44
|
|
|
40
|
-
export type
|
|
45
|
+
export type ItemRecord = Record< string, unknown >;
|
|
46
|
+
|
|
47
|
+
export type FieldType = 'text';
|
|
41
48
|
|
|
42
49
|
/**
|
|
43
50
|
* A dataview field for a specific property of a data type.
|
|
44
51
|
*/
|
|
45
|
-
export
|
|
52
|
+
export type Field< Item > = {
|
|
53
|
+
/**
|
|
54
|
+
* Type of the fields.
|
|
55
|
+
*/
|
|
56
|
+
type?: FieldType;
|
|
57
|
+
|
|
46
58
|
/**
|
|
47
59
|
* The unique identifier of the field.
|
|
48
60
|
*/
|
|
@@ -51,33 +63,17 @@ export interface Field< Item extends AnyItem > {
|
|
|
51
63
|
/**
|
|
52
64
|
* The label of the field. Defaults to the id.
|
|
53
65
|
*/
|
|
54
|
-
|
|
66
|
+
label?: string;
|
|
55
67
|
|
|
56
68
|
/**
|
|
57
|
-
*
|
|
58
|
-
* Defaults to `item[ field.id ]`.
|
|
69
|
+
* Placeholder for the field.
|
|
59
70
|
*/
|
|
60
|
-
|
|
71
|
+
placeholder?: string;
|
|
61
72
|
|
|
62
73
|
/**
|
|
63
74
|
* Callback used to render the field. Defaults to `field.getValue`.
|
|
64
75
|
*/
|
|
65
|
-
render?:
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* The width of the field column.
|
|
69
|
-
*/
|
|
70
|
-
width?: string | number;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* The minimum width of the field column.
|
|
74
|
-
*/
|
|
75
|
-
maxWidth?: string | number;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* The maximum width of the field column.
|
|
79
|
-
*/
|
|
80
|
-
minWidth?: string | number;
|
|
76
|
+
render?: ComponentType< { item: Item } >;
|
|
81
77
|
|
|
82
78
|
/**
|
|
83
79
|
* Whether the field is sortable.
|
|
@@ -103,17 +99,41 @@ export interface Field< Item extends AnyItem > {
|
|
|
103
99
|
* Filter config for the field.
|
|
104
100
|
*/
|
|
105
101
|
filterBy?: FilterByConfig | undefined;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
102
|
+
} & ( Item extends ItemRecord
|
|
103
|
+
? {
|
|
104
|
+
/**
|
|
105
|
+
* Callback used to retrieve the value of the field from the item.
|
|
106
|
+
* Defaults to `item[ field.id ]`.
|
|
107
|
+
*/
|
|
108
|
+
getValue?: ( args: { item: Item } ) => any;
|
|
109
|
+
}
|
|
110
|
+
: {
|
|
111
|
+
/**
|
|
112
|
+
* Callback used to retrieve the value of the field from the item.
|
|
113
|
+
* Defaults to `item[ field.id ]`.
|
|
114
|
+
*/
|
|
115
|
+
getValue: ( args: { item: Item } ) => any;
|
|
116
|
+
} );
|
|
117
|
+
|
|
118
|
+
export type NormalizedField< Item > = Field< Item > & {
|
|
119
|
+
label: string;
|
|
120
|
+
getValue: ( args: { item: Item } ) => any;
|
|
121
|
+
render: ComponentType< { item: Item } >;
|
|
122
|
+
};
|
|
110
123
|
|
|
111
124
|
/**
|
|
112
125
|
* A collection of dataview fields for a data type.
|
|
113
126
|
*/
|
|
114
|
-
export type Fields< Item
|
|
127
|
+
export type Fields< Item > = Field< Item >[];
|
|
128
|
+
|
|
129
|
+
export type Data< Item > = Item[];
|
|
115
130
|
|
|
116
|
-
|
|
131
|
+
/**
|
|
132
|
+
* The form configuration.
|
|
133
|
+
*/
|
|
134
|
+
export type Form = {
|
|
135
|
+
visibleFields?: string[];
|
|
136
|
+
};
|
|
117
137
|
|
|
118
138
|
/**
|
|
119
139
|
* The filters applied to the dataset.
|
|
@@ -186,7 +206,7 @@ interface ViewBase {
|
|
|
186
206
|
/**
|
|
187
207
|
* The filters to apply.
|
|
188
208
|
*/
|
|
189
|
-
filters
|
|
209
|
+
filters?: Filter[];
|
|
190
210
|
|
|
191
211
|
/**
|
|
192
212
|
* The sorting configuration.
|
|
@@ -214,31 +234,69 @@ interface ViewBase {
|
|
|
214
234
|
perPage?: number;
|
|
215
235
|
|
|
216
236
|
/**
|
|
217
|
-
* The
|
|
237
|
+
* The fields to render
|
|
218
238
|
*/
|
|
219
|
-
|
|
239
|
+
fields?: string[];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface CombinedField {
|
|
243
|
+
id: string;
|
|
244
|
+
|
|
245
|
+
label: string;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* The fields to use as columns.
|
|
249
|
+
*/
|
|
250
|
+
children: string[];
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* The direction of the stack.
|
|
254
|
+
*/
|
|
255
|
+
direction: 'horizontal' | 'vertical';
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export interface ColumnStyle {
|
|
259
|
+
/**
|
|
260
|
+
* The width of the field column.
|
|
261
|
+
*/
|
|
262
|
+
width?: string | number;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The minimum width of the field column.
|
|
266
|
+
*/
|
|
267
|
+
maxWidth?: string | number;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* The maximum width of the field column.
|
|
271
|
+
*/
|
|
272
|
+
minWidth?: string | number;
|
|
220
273
|
}
|
|
221
274
|
|
|
222
275
|
export interface ViewTable extends ViewBase {
|
|
223
276
|
type: 'table';
|
|
224
277
|
|
|
225
|
-
layout
|
|
278
|
+
layout?: {
|
|
226
279
|
/**
|
|
227
280
|
* The field to use as the primary field.
|
|
228
281
|
*/
|
|
229
282
|
primaryField?: string;
|
|
230
283
|
|
|
231
284
|
/**
|
|
232
|
-
* The
|
|
285
|
+
* The fields to use as columns.
|
|
233
286
|
*/
|
|
234
|
-
|
|
287
|
+
combinedFields?: CombinedField[];
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* The styles for the columns.
|
|
291
|
+
*/
|
|
292
|
+
styles?: Record< string, ColumnStyle >;
|
|
235
293
|
};
|
|
236
294
|
}
|
|
237
295
|
|
|
238
296
|
export interface ViewList extends ViewBase {
|
|
239
297
|
type: 'list';
|
|
240
298
|
|
|
241
|
-
layout
|
|
299
|
+
layout?: {
|
|
242
300
|
/**
|
|
243
301
|
* The field to use as the primary field.
|
|
244
302
|
*/
|
|
@@ -254,7 +312,7 @@ export interface ViewList extends ViewBase {
|
|
|
254
312
|
export interface ViewGrid extends ViewBase {
|
|
255
313
|
type: 'grid';
|
|
256
314
|
|
|
257
|
-
layout
|
|
315
|
+
layout?: {
|
|
258
316
|
/**
|
|
259
317
|
* The field to use as the primary field.
|
|
260
318
|
*/
|
|
@@ -279,7 +337,7 @@ export interface ViewGrid extends ViewBase {
|
|
|
279
337
|
|
|
280
338
|
export type View = ViewList | ViewGrid | ViewTable;
|
|
281
339
|
|
|
282
|
-
interface ActionBase< Item
|
|
340
|
+
interface ActionBase< Item > {
|
|
283
341
|
/**
|
|
284
342
|
* The unique identifier of the action.
|
|
285
343
|
*/
|
|
@@ -325,8 +383,7 @@ interface ActionBase< Item extends AnyItem > {
|
|
|
325
383
|
supportsBulk?: boolean;
|
|
326
384
|
}
|
|
327
385
|
|
|
328
|
-
export interface ActionModal< Item extends
|
|
329
|
-
extends ActionBase< Item > {
|
|
386
|
+
export interface ActionModal< Item > extends ActionBase< Item > {
|
|
330
387
|
/**
|
|
331
388
|
* Modal to render when the action is triggered.
|
|
332
389
|
*/
|
|
@@ -351,8 +408,7 @@ export interface ActionModal< Item extends AnyItem >
|
|
|
351
408
|
modalHeader?: string;
|
|
352
409
|
}
|
|
353
410
|
|
|
354
|
-
export interface ActionButton< Item extends
|
|
355
|
-
extends ActionBase< AnyItem > {
|
|
411
|
+
export interface ActionButton< Item > extends ActionBase< Item > {
|
|
356
412
|
/**
|
|
357
413
|
* The callback to execute when the action is triggered.
|
|
358
414
|
*/
|
|
@@ -365,39 +421,41 @@ export interface ActionButton< Item extends AnyItem >
|
|
|
365
421
|
) => void;
|
|
366
422
|
}
|
|
367
423
|
|
|
368
|
-
export type Action< Item
|
|
369
|
-
| ActionModal< Item >
|
|
370
|
-
| ActionButton< Item >;
|
|
424
|
+
export type Action< Item > = ActionModal< Item > | ActionButton< Item >;
|
|
371
425
|
|
|
372
|
-
export interface ViewBaseProps< Item
|
|
426
|
+
export interface ViewBaseProps< Item > {
|
|
373
427
|
actions: Action< Item >[];
|
|
374
428
|
data: Item[];
|
|
375
429
|
fields: NormalizedField< Item >[];
|
|
376
430
|
getItemId: ( item: Item ) => string;
|
|
377
431
|
isLoading?: boolean;
|
|
378
|
-
onChangeView( view: View )
|
|
379
|
-
|
|
432
|
+
onChangeView: ( view: View ) => void;
|
|
433
|
+
onChangeSelection: SetSelection;
|
|
380
434
|
selection: string[];
|
|
381
435
|
setOpenedFilter: ( fieldId: string ) => void;
|
|
382
436
|
view: View;
|
|
437
|
+
density: number;
|
|
383
438
|
}
|
|
384
439
|
|
|
385
|
-
export interface ViewTableProps< Item extends
|
|
386
|
-
extends ViewBaseProps< Item > {
|
|
440
|
+
export interface ViewTableProps< Item > extends ViewBaseProps< Item > {
|
|
387
441
|
view: ViewTable;
|
|
388
442
|
}
|
|
389
443
|
|
|
390
|
-
export interface ViewListProps< Item extends
|
|
391
|
-
extends ViewBaseProps< Item > {
|
|
444
|
+
export interface ViewListProps< Item > extends ViewBaseProps< Item > {
|
|
392
445
|
view: ViewList;
|
|
393
446
|
}
|
|
394
447
|
|
|
395
|
-
export interface ViewGridProps< Item extends
|
|
396
|
-
extends ViewBaseProps< Item > {
|
|
448
|
+
export interface ViewGridProps< Item > extends ViewBaseProps< Item > {
|
|
397
449
|
view: ViewGrid;
|
|
398
450
|
}
|
|
399
451
|
|
|
400
|
-
export type ViewProps< Item
|
|
452
|
+
export type ViewProps< Item > =
|
|
401
453
|
| ViewTableProps< Item >
|
|
402
454
|
| ViewGridProps< Item >
|
|
403
455
|
| ViewListProps< Item >;
|
|
456
|
+
|
|
457
|
+
export interface SupportedLayouts {
|
|
458
|
+
list?: Omit< ViewList, 'type' >;
|
|
459
|
+
grid?: Omit< ViewGrid, 'type' >;
|
|
460
|
+
table?: Omit< ViewTable, 'type' >;
|
|
461
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -8,11 +8,9 @@ import {
|
|
|
8
8
|
OPERATOR_IS_ANY,
|
|
9
9
|
OPERATOR_IS_NONE,
|
|
10
10
|
} from './constants';
|
|
11
|
-
import type {
|
|
11
|
+
import type { NormalizedField } from './types';
|
|
12
12
|
|
|
13
|
-
export function sanitizeOperators< Item
|
|
14
|
-
field: NormalizedField< Item >
|
|
15
|
-
) {
|
|
13
|
+
export function sanitizeOperators< Item >( field: NormalizedField< Item > ) {
|
|
16
14
|
let operators = field.filterBy?.operators;
|
|
17
15
|
|
|
18
16
|
// Assign default values.
|