@wordpress/dataviews 1.2.0 → 2.0.1
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 +16 -0
- package/README.md +33 -30
- package/build/add-filter.js +30 -22
- package/build/add-filter.js.map +1 -1
- package/build/bulk-actions-toolbar.js +74 -69
- package/build/bulk-actions-toolbar.js.map +1 -1
- package/build/bulk-actions.js +69 -56
- package/build/bulk-actions.js.map +1 -1
- package/build/constants.js +17 -10
- package/build/constants.js.map +1 -1
- package/build/dataviews.js +63 -56
- package/build/dataviews.js.map +1 -1
- package/build/filter-summary.js +105 -95
- package/build/filter-summary.js.map +1 -1
- package/build/filters.js +18 -17
- package/build/filters.js.map +1 -1
- package/build/index.js.map +1 -1
- package/build/item-actions.js +79 -65
- package/build/item-actions.js.map +1 -1
- package/build/layouts.js.map +1 -1
- package/build/pagination.js +60 -57
- package/build/pagination.js.map +1 -1
- package/build/reset-filters.js +9 -4
- package/build/reset-filters.js.map +1 -1
- package/build/search-widget.js +108 -89
- package/build/search-widget.js.map +1 -1
- package/build/search.js +13 -6
- package/build/search.js.map +1 -1
- package/build/single-selection-checkbox.js +2 -2
- package/build/single-selection-checkbox.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build/utils.js +3 -15
- package/build/utils.js.map +1 -1
- package/build/view-actions.js +168 -120
- package/build/view-actions.js.map +1 -1
- package/build/view-grid.js +113 -99
- package/build/view-grid.js.map +1 -1
- package/build/view-list.js +154 -132
- package/build/view-list.js.map +1 -1
- package/build/view-table.js +220 -192
- package/build/view-table.js.map +1 -1
- package/build-module/add-filter.js +30 -22
- package/build-module/add-filter.js.map +1 -1
- package/build-module/bulk-actions-toolbar.js +76 -69
- package/build-module/bulk-actions-toolbar.js.map +1 -1
- package/build-module/bulk-actions.js +71 -56
- package/build-module/bulk-actions.js.map +1 -1
- package/build-module/constants.js +16 -9
- package/build-module/constants.js.map +1 -1
- package/build-module/dataviews.js +64 -56
- package/build-module/dataviews.js.map +1 -1
- package/build-module/filter-summary.js +106 -96
- package/build-module/filter-summary.js.map +1 -1
- package/build-module/filters.js +18 -17
- package/build-module/filters.js.map +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/item-actions.js +81 -65
- package/build-module/item-actions.js.map +1 -1
- package/build-module/layouts.js.map +1 -1
- package/build-module/pagination.js +61 -58
- package/build-module/pagination.js.map +1 -1
- package/build-module/reset-filters.js +9 -4
- package/build-module/reset-filters.js.map +1 -1
- package/build-module/search-widget.js +109 -89
- package/build-module/search-widget.js.map +1 -1
- package/build-module/search.js +13 -6
- package/build-module/search.js.map +1 -1
- package/build-module/single-selection-checkbox.js +2 -3
- package/build-module/single-selection-checkbox.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-module/utils.js +2 -13
- package/build-module/utils.js.map +1 -1
- package/build-module/view-actions.js +170 -121
- package/build-module/view-actions.js.map +1 -1
- package/build-module/view-grid.js +115 -99
- package/build-module/view-grid.js.map +1 -1
- package/build-module/view-list.js +155 -132
- package/build-module/view-list.js.map +1 -1
- package/build-module/view-table.js +223 -194
- package/build-module/view-table.js.map +1 -1
- package/build-style/style-rtl.css +115 -22
- package/build-style/style.css +115 -22
- package/build-types/add-filter.d.ts +9 -6
- package/build-types/add-filter.d.ts.map +1 -1
- package/build-types/bulk-actions-toolbar.d.ts +11 -7
- package/build-types/bulk-actions-toolbar.d.ts.map +1 -1
- package/build-types/bulk-actions.d.ts.map +1 -1
- package/build-types/constants.d.ts +19 -32
- package/build-types/constants.d.ts.map +1 -1
- package/build-types/dataviews.d.ts +21 -14
- package/build-types/dataviews.d.ts.map +1 -1
- package/build-types/filter-summary.d.ts +13 -5
- package/build-types/filter-summary.d.ts.map +1 -1
- package/build-types/filters.d.ts +11 -1
- package/build-types/filters.d.ts.map +1 -1
- package/build-types/index.d.ts +3 -3
- package/build-types/index.d.ts.map +1 -1
- package/build-types/item-actions.d.ts +5 -7
- package/build-types/item-actions.d.ts.map +1 -1
- package/build-types/layouts.d.ts +8 -4
- package/build-types/layouts.d.ts.map +1 -1
- package/build-types/reset-filters.d.ts +12 -5
- package/build-types/reset-filters.d.ts.map +1 -1
- package/build-types/search-widget.d.ts +9 -1
- package/build-types/search-widget.d.ts.map +1 -1
- package/build-types/search.d.ts +11 -1
- package/build-types/search.d.ts.map +1 -1
- package/build-types/types.d.ts +78 -10
- package/build-types/types.d.ts.map +1 -1
- package/build-types/utils.d.ts +2 -1
- package/build-types/utils.d.ts.map +1 -1
- package/build-types/view-actions.d.ts +10 -1
- package/build-types/view-actions.d.ts.map +1 -1
- package/build-types/view-grid.d.ts +1 -12
- package/build-types/view-grid.d.ts.map +1 -1
- package/build-types/view-list.d.ts +2 -14
- package/build-types/view-list.d.ts.map +1 -1
- package/build-types/view-table.d.ts +3 -12
- package/build-types/view-table.d.ts.map +1 -1
- package/package.json +11 -12
- package/src/{add-filter.js → add-filter.tsx} +17 -1
- package/src/{bulk-actions-toolbar.js → bulk-actions-toolbar.tsx} +68 -40
- package/src/bulk-actions.tsx +5 -1
- package/src/constants.ts +12 -5
- package/src/{dataviews.js → dataviews.tsx} +41 -12
- package/src/{filter-summary.js → filter-summary.tsx} +35 -6
- package/src/{filters.js → filters.tsx} +18 -6
- package/src/item-actions.tsx +21 -15
- package/src/pagination.tsx +1 -1
- package/src/{reset-filters.js → reset-filters.tsx} +17 -2
- package/src/{search-widget.js → search-widget.tsx} +27 -7
- package/src/{search.js → search.tsx} +22 -5
- package/src/style.scss +102 -25
- package/src/types.ts +105 -10
- package/src/{utils.js → utils.ts} +5 -13
- package/src/{view-actions.js → view-actions.tsx} +105 -49
- package/src/view-grid.tsx +4 -20
- package/src/view-list.tsx +13 -23
- package/src/{view-table.js → view-table.tsx} +91 -32
- package/tsconfig.json +0 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/build/dropdown-menu-helper.js +0 -71
- package/build/dropdown-menu-helper.js.map +0 -1
- package/build-module/dropdown-menu-helper.js +0 -64
- package/build-module/dropdown-menu-helper.js.map +0 -1
- package/build-types/dropdown-menu-helper.d.ts +0 -6
- package/build-types/dropdown-menu-helper.d.ts.map +0 -1
- package/src/dropdown-menu-helper.js +0 -61
- /package/src/{index.js → index.ts} +0 -0
- /package/src/{layouts.js → layouts.ts} +0 -0
package/src/style.scss
CHANGED
|
@@ -3,15 +3,20 @@
|
|
|
3
3
|
overflow: auto;
|
|
4
4
|
box-sizing: border-box;
|
|
5
5
|
scroll-padding-bottom: $grid-unit-80;
|
|
6
|
+
/* stylelint-disable-next-line property-no-unknown -- '@container' not globally permitted */
|
|
7
|
+
container: dataviews-wrapper / inline-size;
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: column;
|
|
6
10
|
}
|
|
7
11
|
|
|
8
12
|
.dataviews-filters__view-actions {
|
|
9
13
|
box-sizing: border-box;
|
|
10
|
-
padding: $grid-unit-
|
|
11
|
-
margin-bottom: $grid-unit-15;
|
|
14
|
+
padding: $grid-unit-20 $grid-unit-60;
|
|
12
15
|
flex-shrink: 0;
|
|
13
16
|
position: sticky;
|
|
14
17
|
left: 0;
|
|
18
|
+
transition: padding ease-out 0.1s;
|
|
19
|
+
@include reduce-motion("transition");
|
|
15
20
|
|
|
16
21
|
.components-search-control {
|
|
17
22
|
.components-base-control__field {
|
|
@@ -21,8 +26,6 @@
|
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
.dataviews-filters__container {
|
|
24
|
-
padding-right: $grid-unit-40;
|
|
25
|
-
|
|
26
29
|
.dataviews-filters__reset-button[aria-disabled="true"] {
|
|
27
30
|
&,
|
|
28
31
|
&:hover {
|
|
@@ -44,10 +47,12 @@
|
|
|
44
47
|
bottom: 0;
|
|
45
48
|
left: 0;
|
|
46
49
|
background-color: $white;
|
|
47
|
-
padding: $grid-unit-15 $grid-unit-
|
|
50
|
+
padding: $grid-unit-15 $grid-unit-60;
|
|
48
51
|
border-top: $border-width solid $gray-100;
|
|
49
52
|
color: $gray-700;
|
|
50
53
|
flex-shrink: 0;
|
|
54
|
+
transition: padding ease-out 0.1s;
|
|
55
|
+
@include reduce-motion("transition");
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
.dataviews-pagination__page-selection {
|
|
@@ -68,6 +73,7 @@
|
|
|
68
73
|
border-collapse: collapse;
|
|
69
74
|
position: relative;
|
|
70
75
|
color: $gray-700;
|
|
76
|
+
margin-bottom: auto;
|
|
71
77
|
|
|
72
78
|
a {
|
|
73
79
|
text-decoration: none;
|
|
@@ -100,9 +106,18 @@
|
|
|
100
106
|
gap: $grid-unit-05;
|
|
101
107
|
}
|
|
102
108
|
|
|
109
|
+
th,
|
|
110
|
+
td {
|
|
111
|
+
&:first-child,
|
|
112
|
+
&:last-child {
|
|
113
|
+
transition: padding ease-out 0.1s;
|
|
114
|
+
@include reduce-motion("transition");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
103
118
|
td:first-child,
|
|
104
119
|
th:first-child {
|
|
105
|
-
padding-left: $grid-unit-
|
|
120
|
+
padding-left: $grid-unit-60;
|
|
106
121
|
|
|
107
122
|
.dataviews-view-table-header-button,
|
|
108
123
|
.dataviews-view-table-header {
|
|
@@ -112,7 +127,7 @@
|
|
|
112
127
|
|
|
113
128
|
td:last-child,
|
|
114
129
|
th:last-child {
|
|
115
|
-
padding-right: $grid-unit-
|
|
130
|
+
padding-right: $grid-unit-60;
|
|
116
131
|
}
|
|
117
132
|
|
|
118
133
|
&:last-child {
|
|
@@ -278,10 +293,16 @@
|
|
|
278
293
|
}
|
|
279
294
|
|
|
280
295
|
.dataviews-view-grid {
|
|
281
|
-
margin-bottom:
|
|
282
|
-
grid-template-columns: repeat(
|
|
296
|
+
margin-bottom: auto;
|
|
297
|
+
grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
|
|
283
298
|
grid-template-rows: max-content;
|
|
284
|
-
padding: 0 $grid-unit-
|
|
299
|
+
padding: 0 $grid-unit-60 $grid-unit-30;
|
|
300
|
+
transition: padding ease-out 0.1s;
|
|
301
|
+
@include reduce-motion("transition");
|
|
302
|
+
|
|
303
|
+
@include break-mobile() {
|
|
304
|
+
grid-template-columns: repeat(2, minmax(0, 1fr)) !important; // Todo: eliminate !important dependency
|
|
305
|
+
}
|
|
285
306
|
|
|
286
307
|
@include break-xlarge() {
|
|
287
308
|
grid-template-columns: repeat(3, minmax(0, 1fr)) !important; // Todo: eliminate !important dependency
|
|
@@ -396,7 +417,7 @@
|
|
|
396
417
|
}
|
|
397
418
|
|
|
398
419
|
.dataviews-view-list {
|
|
399
|
-
margin: 0;
|
|
420
|
+
margin: 0 0 auto;
|
|
400
421
|
|
|
401
422
|
li {
|
|
402
423
|
margin: 0;
|
|
@@ -412,15 +433,28 @@
|
|
|
412
433
|
}
|
|
413
434
|
}
|
|
414
435
|
|
|
415
|
-
.dataviews-view-list__item-actions
|
|
416
|
-
|
|
436
|
+
.dataviews-view-list__item-actions {
|
|
437
|
+
.components-button {
|
|
438
|
+
opacity: 0;
|
|
439
|
+
position: fixed;
|
|
440
|
+
right: 0;
|
|
441
|
+
}
|
|
417
442
|
}
|
|
418
443
|
|
|
419
444
|
&.is-selected,
|
|
420
445
|
&.is-hovered,
|
|
421
446
|
&:focus-within {
|
|
422
|
-
.dataviews-view-list__item-actions
|
|
423
|
-
|
|
447
|
+
.dataviews-view-list__item-actions {
|
|
448
|
+
padding-right: $grid-unit-40;
|
|
449
|
+
|
|
450
|
+
.components-button {
|
|
451
|
+
opacity: 1;
|
|
452
|
+
position: static;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
.dataviews-view-list__item {
|
|
457
|
+
padding-right: 0;
|
|
424
458
|
}
|
|
425
459
|
}
|
|
426
460
|
|
|
@@ -449,15 +483,14 @@
|
|
|
449
483
|
color: $gray-900;
|
|
450
484
|
|
|
451
485
|
.dataviews-view-list__primary-field,
|
|
452
|
-
.dataviews-view-list__fields
|
|
453
|
-
.components-button {
|
|
486
|
+
.dataviews-view-list__fields {
|
|
454
487
|
color: var(--wp-admin-theme-color);
|
|
455
488
|
}
|
|
456
489
|
}
|
|
457
490
|
}
|
|
458
491
|
|
|
459
492
|
.dataviews-view-list__item {
|
|
460
|
-
padding: $grid-unit-20 0 $grid-unit-20 $grid-unit-
|
|
493
|
+
padding: $grid-unit-20 0 $grid-unit-20 $grid-unit-30;
|
|
461
494
|
width: 100%;
|
|
462
495
|
scroll-margin: $grid-unit-10 0;
|
|
463
496
|
|
|
@@ -475,6 +508,7 @@
|
|
|
475
508
|
}
|
|
476
509
|
.dataviews-view-list__primary-field {
|
|
477
510
|
min-height: $grid-unit-05 * 5;
|
|
511
|
+
line-height: $grid-unit-05 * 5;
|
|
478
512
|
overflow: hidden;
|
|
479
513
|
}
|
|
480
514
|
}
|
|
@@ -518,18 +552,20 @@
|
|
|
518
552
|
gap: $grid-unit-10;
|
|
519
553
|
flex-wrap: wrap;
|
|
520
554
|
font-size: 12px;
|
|
521
|
-
line-height: $grid-unit-20;
|
|
522
555
|
|
|
523
556
|
.dataviews-view-list__field {
|
|
524
557
|
&:has(.dataviews-view-list__field-value:empty) {
|
|
525
558
|
display: none;
|
|
526
559
|
}
|
|
527
560
|
}
|
|
528
|
-
}
|
|
529
561
|
|
|
562
|
+
.dataviews-view-list__field-value {
|
|
563
|
+
line-height: $grid-unit-05 * 5;
|
|
564
|
+
display: inline-flex;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
530
567
|
.dataviews-view-list__item-actions {
|
|
531
|
-
padding-
|
|
532
|
-
padding-right: $grid-unit-40;
|
|
568
|
+
padding-right: $grid-unit-30;
|
|
533
569
|
}
|
|
534
570
|
|
|
535
571
|
& + .dataviews-pagination {
|
|
@@ -544,11 +580,13 @@
|
|
|
544
580
|
|
|
545
581
|
.dataviews-no-results,
|
|
546
582
|
.dataviews-loading {
|
|
547
|
-
padding: 0 $grid-unit-
|
|
583
|
+
padding: 0 $grid-unit-60;
|
|
548
584
|
flex-grow: 1;
|
|
549
585
|
display: flex;
|
|
550
586
|
align-items: center;
|
|
551
587
|
justify-content: center;
|
|
588
|
+
transition: padding ease-out 0.1s;
|
|
589
|
+
@include reduce-motion("transition");
|
|
552
590
|
}
|
|
553
591
|
|
|
554
592
|
.dataviews-view-table-selection-checkbox {
|
|
@@ -559,6 +597,11 @@
|
|
|
559
597
|
}
|
|
560
598
|
|
|
561
599
|
line-height: 0;
|
|
600
|
+
flex-shrink: 0;
|
|
601
|
+
|
|
602
|
+
.components-checkbox-control__input-container {
|
|
603
|
+
margin: 0;
|
|
604
|
+
}
|
|
562
605
|
}
|
|
563
606
|
|
|
564
607
|
.dataviews-filters__custom-menu-radio-item-prefix {
|
|
@@ -802,6 +845,38 @@
|
|
|
802
845
|
}
|
|
803
846
|
}
|
|
804
847
|
|
|
848
|
+
/* stylelint-disable-next-line scss/at-rule-no-unknown -- '@container' not globally permitted */
|
|
849
|
+
@container (max-width: 430px) {
|
|
850
|
+
.dataviews-pagination,
|
|
851
|
+
.dataviews-filters__view-actions {
|
|
852
|
+
padding: $grid-unit-15 $grid-unit-30;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
.dataviews-filters__view-actions {
|
|
856
|
+
.components-search-control {
|
|
857
|
+
.components-base-control__field {
|
|
858
|
+
max-width: 112px;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
.dataviews-view-table tr td:first-child,
|
|
864
|
+
.dataviews-view-table tr th:first-child {
|
|
865
|
+
padding-left: $grid-unit-30;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
.dataviews-view-table tr td:last-child,
|
|
869
|
+
.dataviews-view-table tr th:last-child {
|
|
870
|
+
padding-right: $grid-unit-30;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
.dataviews-view-grid,
|
|
874
|
+
.dataviews-no-results,
|
|
875
|
+
.dataviews-loading {
|
|
876
|
+
padding-left: $grid-unit-30;
|
|
877
|
+
padding-right: $grid-unit-30;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
805
880
|
|
|
806
881
|
.dataviews-bulk-actions-toolbar-wrapper {
|
|
807
882
|
display: flex;
|
|
@@ -818,12 +893,14 @@
|
|
|
818
893
|
}
|
|
819
894
|
|
|
820
895
|
.dataviews-bulk-actions {
|
|
821
|
-
position:
|
|
896
|
+
position: sticky;
|
|
822
897
|
display: flex;
|
|
823
898
|
flex-direction: column;
|
|
824
899
|
align-content: center;
|
|
825
900
|
flex-wrap: wrap;
|
|
826
|
-
width:
|
|
901
|
+
width: fit-content;
|
|
902
|
+
margin-left: auto;
|
|
903
|
+
margin-right: auto;
|
|
827
904
|
bottom: $grid-unit-30;
|
|
828
905
|
z-index: z-index(".dataviews-bulk-actions");
|
|
829
906
|
|
package/src/types.ts
CHANGED
|
@@ -8,9 +8,10 @@ export type SortDirection = 'asc' | 'desc';
|
|
|
8
8
|
/**
|
|
9
9
|
* Generic option type.
|
|
10
10
|
*/
|
|
11
|
-
interface Option< Value extends any = any > {
|
|
11
|
+
export interface Option< Value extends any = any > {
|
|
12
12
|
value: Value;
|
|
13
13
|
label: string;
|
|
14
|
+
description?: string;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
interface FilterByConfig {
|
|
@@ -28,7 +29,13 @@ interface FilterByConfig {
|
|
|
28
29
|
isPrimary?: boolean;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
type Operator =
|
|
32
|
+
export type Operator =
|
|
33
|
+
| 'is'
|
|
34
|
+
| 'isNot'
|
|
35
|
+
| 'isAny'
|
|
36
|
+
| 'isNone'
|
|
37
|
+
| 'isAll'
|
|
38
|
+
| 'isNotAll';
|
|
32
39
|
|
|
33
40
|
export type AnyItem = Record< string, any >;
|
|
34
41
|
|
|
@@ -128,6 +135,43 @@ export interface Filter {
|
|
|
128
135
|
value: any;
|
|
129
136
|
}
|
|
130
137
|
|
|
138
|
+
export interface NormalizedFilter {
|
|
139
|
+
/**
|
|
140
|
+
* The field to filter by.
|
|
141
|
+
*/
|
|
142
|
+
field: string;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The field name.
|
|
146
|
+
*/
|
|
147
|
+
name: string;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The list of options to pick from when using the field as a filter.
|
|
151
|
+
*/
|
|
152
|
+
elements: Option[];
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Is a single selection filter.
|
|
156
|
+
*/
|
|
157
|
+
singleSelection: boolean;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The list of operators supported by the field.
|
|
161
|
+
*/
|
|
162
|
+
operators: Operator[];
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Whether the filter is visible.
|
|
166
|
+
*/
|
|
167
|
+
isVisible: boolean;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Whether it is a primary filter.
|
|
171
|
+
*/
|
|
172
|
+
isPrimary: boolean;
|
|
173
|
+
}
|
|
174
|
+
|
|
131
175
|
interface ViewBase {
|
|
132
176
|
/**
|
|
133
177
|
* The layout of the view.
|
|
@@ -175,6 +219,22 @@ interface ViewBase {
|
|
|
175
219
|
hiddenFields: string[];
|
|
176
220
|
}
|
|
177
221
|
|
|
222
|
+
export interface ViewTable extends ViewBase {
|
|
223
|
+
type: 'table';
|
|
224
|
+
|
|
225
|
+
layout: {
|
|
226
|
+
/**
|
|
227
|
+
* The field to use as the primary field.
|
|
228
|
+
*/
|
|
229
|
+
primaryField?: string;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The field to use as the media field.
|
|
233
|
+
*/
|
|
234
|
+
mediaField?: string;
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
178
238
|
export interface ViewList extends ViewBase {
|
|
179
239
|
type: 'list';
|
|
180
240
|
|
|
@@ -182,12 +242,12 @@ export interface ViewList extends ViewBase {
|
|
|
182
242
|
/**
|
|
183
243
|
* The field to use as the primary field.
|
|
184
244
|
*/
|
|
185
|
-
primaryField
|
|
245
|
+
primaryField?: string;
|
|
186
246
|
|
|
187
247
|
/**
|
|
188
248
|
* The field to use as the media field.
|
|
189
249
|
*/
|
|
190
|
-
mediaField
|
|
250
|
+
mediaField?: string;
|
|
191
251
|
};
|
|
192
252
|
}
|
|
193
253
|
|
|
@@ -198,26 +258,26 @@ export interface ViewGrid extends ViewBase {
|
|
|
198
258
|
/**
|
|
199
259
|
* The field to use as the primary field.
|
|
200
260
|
*/
|
|
201
|
-
primaryField
|
|
261
|
+
primaryField?: string;
|
|
202
262
|
|
|
203
263
|
/**
|
|
204
264
|
* The field to use as the media field.
|
|
205
265
|
*/
|
|
206
|
-
mediaField
|
|
266
|
+
mediaField?: string;
|
|
207
267
|
|
|
208
268
|
/**
|
|
209
269
|
* The fields to use as columns.
|
|
210
270
|
*/
|
|
211
|
-
columnFields
|
|
271
|
+
columnFields?: string[];
|
|
212
272
|
|
|
213
273
|
/**
|
|
214
274
|
* The fields to use as badge fields.
|
|
215
275
|
*/
|
|
216
|
-
badgeFields
|
|
276
|
+
badgeFields?: string[];
|
|
217
277
|
};
|
|
218
278
|
}
|
|
219
279
|
|
|
220
|
-
export type View = ViewList | ViewGrid |
|
|
280
|
+
export type View = ViewList | ViewGrid | ViewTable;
|
|
221
281
|
|
|
222
282
|
interface ActionBase< Item extends AnyItem > {
|
|
223
283
|
/**
|
|
@@ -227,8 +287,10 @@ interface ActionBase< Item extends AnyItem > {
|
|
|
227
287
|
|
|
228
288
|
/**
|
|
229
289
|
* The label of the action.
|
|
290
|
+
* In case we want to adjust the label based on the selected items,
|
|
291
|
+
* a function can be provided.
|
|
230
292
|
*/
|
|
231
|
-
label: string;
|
|
293
|
+
label: string | ( ( items: Item[] ) => string );
|
|
232
294
|
|
|
233
295
|
/**
|
|
234
296
|
* The icon of the action. (Either a string or an SVG element)
|
|
@@ -312,3 +374,36 @@ export interface ActionButton< Item extends AnyItem >
|
|
|
312
374
|
export type Action< Item extends AnyItem > =
|
|
313
375
|
| ActionModal< Item >
|
|
314
376
|
| ActionButton< Item >;
|
|
377
|
+
|
|
378
|
+
export interface ViewBaseProps< Item extends AnyItem > {
|
|
379
|
+
actions: Action< Item >[];
|
|
380
|
+
data: Item[];
|
|
381
|
+
fields: NormalizedField< Item >[];
|
|
382
|
+
getItemId: ( item: Item ) => string;
|
|
383
|
+
isLoading?: boolean;
|
|
384
|
+
onChangeView( view: View ): void;
|
|
385
|
+
onSelectionChange: ( items: Item[] ) => void;
|
|
386
|
+
selection: string[];
|
|
387
|
+
setOpenedFilter: ( fieldId: string ) => void;
|
|
388
|
+
view: View;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export interface ViewTableProps< Item extends AnyItem >
|
|
392
|
+
extends ViewBaseProps< Item > {
|
|
393
|
+
view: ViewTable;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export interface ViewListProps< Item extends AnyItem >
|
|
397
|
+
extends ViewBaseProps< Item > {
|
|
398
|
+
view: ViewList;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export interface ViewGridProps< Item extends AnyItem >
|
|
402
|
+
extends ViewBaseProps< Item > {
|
|
403
|
+
view: ViewGrid;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export type ViewProps< Item extends AnyItem > =
|
|
407
|
+
| ViewTableProps< Item >
|
|
408
|
+
| ViewGridProps< Item >
|
|
409
|
+
| ViewListProps< Item >;
|
|
@@ -8,8 +8,11 @@ import {
|
|
|
8
8
|
OPERATOR_IS_ANY,
|
|
9
9
|
OPERATOR_IS_NONE,
|
|
10
10
|
} from './constants';
|
|
11
|
+
import type { AnyItem, NormalizedField } from './types';
|
|
11
12
|
|
|
12
|
-
export
|
|
13
|
+
export function sanitizeOperators< Item extends AnyItem >(
|
|
14
|
+
field: NormalizedField< Item >
|
|
15
|
+
) {
|
|
13
16
|
let operators = field.filterBy?.operators;
|
|
14
17
|
|
|
15
18
|
// Assign default values.
|
|
@@ -17,17 +20,6 @@ export const sanitizeOperators = ( field ) => {
|
|
|
17
20
|
operators = [ OPERATOR_IS_ANY, OPERATOR_IS_NONE ];
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
// Transform legacy in, notIn operators to is, isNot.
|
|
21
|
-
// To be removed in the future.
|
|
22
|
-
if ( operators.includes( 'in' ) ) {
|
|
23
|
-
operators = operators.filter( ( operator ) => operator !== 'is' );
|
|
24
|
-
operators.push( 'is' );
|
|
25
|
-
}
|
|
26
|
-
if ( operators.includes( 'notIn' ) ) {
|
|
27
|
-
operators = operators.filter( ( operator ) => operator !== 'notIn' );
|
|
28
|
-
operators.push( 'isNot' );
|
|
29
|
-
}
|
|
30
|
-
|
|
31
23
|
// Make sure only valid operators are used.
|
|
32
24
|
operators = operators.filter( ( operator ) =>
|
|
33
25
|
ALL_OPERATORS.includes( operator )
|
|
@@ -45,4 +37,4 @@ export const sanitizeOperators = ( field ) => {
|
|
|
45
37
|
}
|
|
46
38
|
|
|
47
39
|
return operators;
|
|
48
|
-
}
|
|
40
|
+
}
|