File tree Expand file tree Collapse file tree 11 files changed +50
-2
lines changed
components/dataviews/stories Expand file tree Collapse file tree 11 files changed +50
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Next
4
4
5
+ - Implement the ` media ` field type definition and allow type definitions to provide a new default: ` enableSorting ` .
5
6
- Add new ` boolean ` field type definition and edit control. Field type definitions are able to define a default render function that will be used if the field doesn't define one.
6
7
- Pin the actions column on the table view when the width is insufficient.
7
8
- Bring changes from @wordpress/dataviews 4.19.0 (no updates in this version).
Original file line number Diff line number Diff line change @@ -633,6 +633,7 @@ export const fields: Field< SpaceObject >[] = [
633
633
{
634
634
label : 'Image' ,
635
635
id : 'image' ,
636
+ type : 'media' ,
636
637
header : (
637
638
< HStack spacing = { 1 } justify = "start" >
638
639
< Icon icon = { image } />
@@ -644,7 +645,6 @@ export const fields: Field< SpaceObject >[] = [
644
645
< img src = { item . image } alt = "" style = { { width : '100%' } } />
645
646
) ;
646
647
} ,
647
- enableSorting : false ,
648
648
} ,
649
649
{
650
650
label : 'Title' ,
Original file line number Diff line number Diff line change @@ -57,4 +57,5 @@ export default {
57
57
58
58
return null ;
59
59
} ,
60
+ enableSorting : true ,
60
61
} ;
Original file line number Diff line number Diff line change @@ -35,4 +35,5 @@ export default {
35
35
? renderFromElements ( { item, field } )
36
36
: field . getValue ( { item } ) ;
37
37
} ,
38
+ enableSorting : true ,
38
39
} ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import { default as integer } from './integer';
11
11
import { default as text } from './text' ;
12
12
import { default as datetime } from './datetime' ;
13
13
import { default as boolean } from './boolean' ;
14
+ import { default as media } from './media' ;
14
15
import { renderFromElements } from '../utils' ;
15
16
16
17
/**
@@ -36,6 +37,12 @@ export default function getFieldTypeDefinition< Item >( type?: FieldType ) {
36
37
return boolean ;
37
38
}
38
39
40
+ if ( 'media' === type ) {
41
+ return media ;
42
+ }
43
+
44
+ // This is a fallback for fields that don't provide a type.
45
+ // It can be removed when the field.type is mandatory.
39
46
return {
40
47
sort : ( a : any , b : any , direction : SortDirection ) => {
41
48
if ( typeof a === 'number' && typeof b === 'number' ) {
@@ -62,5 +69,6 @@ export default function getFieldTypeDefinition< Item >( type?: FieldType ) {
62
69
? renderFromElements ( { item, field } )
63
70
: field . getValue ( { item } ) ;
64
71
} ,
72
+ enableSorting : true ,
65
73
} ;
66
74
}
Original file line number Diff line number Diff line change @@ -41,4 +41,5 @@ export default {
41
41
? renderFromElements ( { item, field } )
42
42
: field . getValue ( { item } ) ;
43
43
} ,
44
+ enableSorting : true ,
44
45
} ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { SortDirection , ValidationContext } from '../types' ;
5
+
6
+ function sort ( a : any , b : any , direction : SortDirection ) {
7
+ return 0 ;
8
+ }
9
+
10
+ function isValid ( value : any , context ?: ValidationContext ) {
11
+ if ( context ?. elements ) {
12
+ const validValues = context ?. elements . map ( ( f ) => f . value ) ;
13
+ if ( ! validValues . includes ( value ) ) {
14
+ return false ;
15
+ }
16
+ }
17
+
18
+ return true ;
19
+ }
20
+
21
+ export default {
22
+ sort,
23
+ isValid,
24
+ Edit : ( ) => null ,
25
+ render : ( ) => null ,
26
+ enableSorting : false ,
27
+ } ;
Original file line number Diff line number Diff line change @@ -34,4 +34,5 @@ export default {
34
34
? renderFromElements ( { item, field } )
35
35
: field . getValue ( { item } ) ;
36
36
} ,
37
+ enableSorting : true ,
37
38
} ;
Original file line number Diff line number Diff line change @@ -77,7 +77,10 @@ export function normalizeFields< Item >(
77
77
isValid,
78
78
Edit,
79
79
enableHiding : field . enableHiding ?? true ,
80
- enableSorting : field . enableSorting ?? true ,
80
+ enableSorting :
81
+ field . enableSorting ??
82
+ fieldTypeDefinition . enableSorting ??
83
+ true ,
81
84
} ;
82
85
} ) ;
83
86
}
Original file line number Diff line number Diff line change @@ -76,6 +76,11 @@ export type FieldTypeDefinition< Item > = {
76
76
* Callback used to render the field.
77
77
*/
78
78
render : ComponentType < DataViewRenderFieldProps < Item > > ;
79
+
80
+ /**
81
+ * Whether the field is sortable.
82
+ */
83
+ enableSorting : boolean ;
79
84
} ;
80
85
81
86
/**
You can’t perform that action at this time.
0 commit comments