@wordpress/dataviews 4.1.0 → 4.3.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 +19 -0
- package/README.md +77 -29
- package/build/components/dataviews/index.js +10 -14
- package/build/components/dataviews/index.js.map +1 -1
- package/build/components/dataviews-bulk-actions/index.js +145 -141
- package/build/components/dataviews-bulk-actions/index.js.map +1 -1
- package/build/components/dataviews-filters/add-filter.js +4 -6
- package/build/components/dataviews-filters/add-filter.js.map +1 -1
- package/build/components/dataviews-filters/index.js +3 -0
- package/build/components/dataviews-filters/index.js.map +1 -1
- package/build/components/dataviews-filters/search-widget.js +30 -23
- package/build/components/dataviews-filters/search-widget.js.map +1 -1
- package/build/components/dataviews-footer/index.js +45 -0
- package/build/components/dataviews-footer/index.js.map +1 -0
- package/build/components/dataviews-item-actions/index.js +5 -8
- package/build/components/dataviews-item-actions/index.js.map +1 -1
- package/build/components/dataviews-pagination/index.js +27 -19
- package/build/components/dataviews-pagination/index.js.map +1 -1
- package/build/components/dataviews-view-config/index.js +197 -41
- package/build/components/dataviews-view-config/index.js.map +1 -1
- package/build/dataform-controls/datetime.js +49 -0
- package/build/dataform-controls/datetime.js.map +1 -0
- package/build/dataform-controls/index.js +50 -0
- package/build/dataform-controls/index.js.map +1 -0
- package/build/dataform-controls/integer.js +45 -0
- package/build/dataform-controls/integer.js.map +1 -0
- package/build/dataform-controls/radio.js +45 -0
- package/build/dataform-controls/radio.js.map +1 -0
- package/build/dataform-controls/select.js +58 -0
- package/build/dataform-controls/select.js.map +1 -0
- package/build/dataform-controls/text.js +45 -0
- package/build/dataform-controls/text.js.map +1 -0
- package/build/dataforms-layouts/panel/index.js +10 -4
- package/build/dataforms-layouts/panel/index.js.map +1 -1
- package/build/dataforms-layouts/regular/index.js +6 -3
- package/build/dataforms-layouts/regular/index.js.map +1 -1
- package/build/dataviews-layouts/grid/density-picker.js +23 -52
- package/build/dataviews-layouts/grid/density-picker.js.map +1 -1
- package/build/dataviews-layouts/grid/index.js +1 -1
- package/build/dataviews-layouts/grid/index.js.map +1 -1
- package/build/dataviews-layouts/index.js +48 -2
- package/build/dataviews-layouts/index.js.map +1 -1
- package/build/dataviews-layouts/list/index.js +124 -80
- package/build/dataviews-layouts/list/index.js.map +1 -1
- package/build/dataviews-layouts/table/column-header-menu.js +52 -57
- package/build/dataviews-layouts/table/column-header-menu.js.map +1 -1
- package/build/dataviews-layouts/table/index.js +7 -35
- package/build/dataviews-layouts/table/index.js.map +1 -1
- package/build/field-types/datetime.js +30 -0
- package/build/field-types/datetime.js.map +1 -0
- package/build/field-types/index.js +4 -0
- package/build/field-types/index.js.map +1 -1
- package/build/field-types/integer.js +1 -60
- package/build/field-types/integer.js.map +1 -1
- package/build/field-types/text.js +1 -60
- package/build/field-types/text.js.map +1 -1
- package/build/normalize-fields.js +10 -9
- package/build/normalize-fields.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build-module/components/dataviews/index.js +10 -14
- package/build-module/components/dataviews/index.js.map +1 -1
- package/build-module/components/dataviews-bulk-actions/index.js +145 -143
- package/build-module/components/dataviews-bulk-actions/index.js.map +1 -1
- package/build-module/components/dataviews-filters/add-filter.js +4 -6
- package/build-module/components/dataviews-filters/add-filter.js.map +1 -1
- package/build-module/components/dataviews-filters/index.js +3 -0
- package/build-module/components/dataviews-filters/index.js.map +1 -1
- package/build-module/components/dataviews-filters/search-widget.js +30 -23
- package/build-module/components/dataviews-filters/search-widget.js.map +1 -1
- package/build-module/components/dataviews-footer/index.js +38 -0
- package/build-module/components/dataviews-footer/index.js.map +1 -0
- package/build-module/components/dataviews-item-actions/index.js +5 -8
- package/build-module/components/dataviews-item-actions/index.js.map +1 -1
- package/build-module/components/dataviews-pagination/index.js +28 -20
- package/build-module/components/dataviews-pagination/index.js.map +1 -1
- package/build-module/components/dataviews-view-config/index.js +203 -47
- package/build-module/components/dataviews-view-config/index.js.map +1 -1
- package/build-module/dataform-controls/datetime.js +43 -0
- package/build-module/dataform-controls/datetime.js.map +1 -0
- package/build-module/dataform-controls/index.js +42 -0
- package/build-module/dataform-controls/index.js.map +1 -0
- package/build-module/dataform-controls/integer.js +38 -0
- package/build-module/dataform-controls/integer.js.map +1 -0
- package/build-module/dataform-controls/radio.js +38 -0
- package/build-module/dataform-controls/radio.js.map +1 -0
- package/build-module/dataform-controls/select.js +51 -0
- package/build-module/dataform-controls/select.js.map +1 -0
- package/build-module/dataform-controls/text.js +38 -0
- package/build-module/dataform-controls/text.js.map +1 -0
- package/build-module/dataforms-layouts/panel/index.js +10 -4
- package/build-module/dataforms-layouts/panel/index.js.map +1 -1
- package/build-module/dataforms-layouts/regular/index.js +6 -3
- package/build-module/dataforms-layouts/regular/index.js.map +1 -1
- package/build-module/dataviews-layouts/grid/density-picker.js +25 -56
- package/build-module/dataviews-layouts/grid/density-picker.js.map +1 -1
- package/build-module/dataviews-layouts/grid/index.js +1 -1
- package/build-module/dataviews-layouts/grid/index.js.map +1 -1
- package/build-module/dataviews-layouts/index.js +45 -1
- package/build-module/dataviews-layouts/index.js.map +1 -1
- package/build-module/dataviews-layouts/list/index.js +125 -80
- package/build-module/dataviews-layouts/list/index.js.map +1 -1
- package/build-module/dataviews-layouts/table/column-header-menu.js +52 -57
- package/build-module/dataviews-layouts/table/column-header-menu.js.map +1 -1
- package/build-module/dataviews-layouts/table/index.js +9 -37
- package/build-module/dataviews-layouts/table/index.js.map +1 -1
- package/build-module/field-types/datetime.js +24 -0
- package/build-module/field-types/datetime.js.map +1 -0
- package/build-module/field-types/index.js +4 -0
- package/build-module/field-types/index.js.map +1 -1
- package/build-module/field-types/integer.js +2 -60
- package/build-module/field-types/integer.js.map +1 -1
- package/build-module/field-types/text.js +2 -60
- package/build-module/field-types/text.js.map +1 -1
- package/build-module/normalize-fields.js +11 -9
- package/build-module/normalize-fields.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-style/style-rtl.css +93 -80
- package/build-style/style.css +93 -80
- package/build-types/components/dataform/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataviews/index.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/fixtures.d.ts +28 -113
- package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/index.story.d.ts +12 -44
- package/build-types/components/dataviews/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataviews-bulk-actions/index.d.ts +11 -1
- package/build-types/components/dataviews-bulk-actions/index.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/add-filter.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/index.d.ts +1 -1
- package/build-types/components/dataviews-filters/index.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/search-widget.d.ts.map +1 -1
- package/build-types/components/dataviews-footer/index.d.ts +2 -0
- package/build-types/components/dataviews-footer/index.d.ts.map +1 -0
- package/build-types/components/dataviews-item-actions/index.d.ts.map +1 -1
- package/build-types/components/dataviews-pagination/index.d.ts.map +1 -1
- package/build-types/components/dataviews-view-config/index.d.ts +4 -3
- package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
- package/build-types/dataform-controls/datetime.d.ts +6 -0
- package/build-types/dataform-controls/datetime.d.ts.map +1 -0
- package/build-types/dataform-controls/index.d.ts +11 -0
- package/build-types/dataform-controls/index.d.ts.map +1 -0
- package/build-types/dataform-controls/integer.d.ts +6 -0
- package/build-types/dataform-controls/integer.d.ts.map +1 -0
- package/build-types/dataform-controls/radio.d.ts +6 -0
- package/build-types/dataform-controls/radio.d.ts.map +1 -0
- package/build-types/dataform-controls/select.d.ts +6 -0
- package/build-types/dataform-controls/select.d.ts.map +1 -0
- package/build-types/dataform-controls/text.d.ts +6 -0
- package/build-types/dataform-controls/text.d.ts.map +1 -0
- package/build-types/dataforms-layouts/panel/index.d.ts.map +1 -1
- package/build-types/dataforms-layouts/regular/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/grid/density-picker.d.ts.map +1 -1
- package/build-types/dataviews-layouts/index.d.ts +4 -2
- package/build-types/dataviews-layouts/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/list/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/column-header-menu.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/index.d.ts.map +1 -1
- package/build-types/field-types/datetime.d.ts +13 -0
- package/build-types/field-types/datetime.d.ts.map +1 -0
- package/build-types/field-types/index.d.ts +1 -1
- package/build-types/field-types/index.d.ts.map +1 -1
- package/build-types/field-types/integer.d.ts +2 -3
- package/build-types/field-types/integer.d.ts.map +1 -1
- package/build-types/field-types/text.d.ts +2 -3
- package/build-types/field-types/text.d.ts.map +1 -1
- package/build-types/normalize-fields.d.ts.map +1 -1
- package/build-types/types.d.ts +43 -21
- package/build-types/types.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/components/dataform/stories/index.story.tsx +43 -2
- package/src/components/dataviews/index.tsx +14 -18
- package/src/components/dataviews/stories/fixtures.tsx +690 -0
- package/src/components/dataviews/stories/index.story.tsx +164 -0
- package/src/components/dataviews/style.scss +2 -12
- package/src/components/dataviews-bulk-actions/index.tsx +264 -213
- package/src/components/dataviews-bulk-actions/style.scss +9 -4
- package/src/components/dataviews-filters/add-filter.tsx +7 -11
- package/src/components/dataviews-filters/index.tsx +3 -0
- package/src/components/dataviews-filters/search-widget.tsx +46 -25
- package/src/components/dataviews-filters/style.scss +13 -3
- package/src/components/dataviews-footer/index.tsx +50 -0
- package/src/components/dataviews-footer/style.scss +40 -0
- package/src/components/dataviews-item-actions/index.tsx +8 -14
- package/src/components/dataviews-pagination/index.tsx +40 -21
- package/src/components/dataviews-pagination/style.scss +7 -21
- package/src/components/dataviews-view-config/index.tsx +297 -69
- package/src/components/dataviews-view-config/style.scss +25 -0
- package/src/dataform-controls/datetime.tsx +43 -0
- package/src/dataform-controls/index.tsx +61 -0
- package/src/dataform-controls/integer.tsx +38 -0
- package/src/dataform-controls/radio.tsx +42 -0
- package/src/dataform-controls/select.tsx +52 -0
- package/src/dataform-controls/style.scss +4 -0
- package/src/dataform-controls/text.tsx +40 -0
- package/src/dataforms-layouts/panel/index.tsx +8 -2
- package/src/dataforms-layouts/regular/index.tsx +6 -2
- package/src/dataviews-layouts/grid/density-picker.tsx +33 -67
- package/src/dataviews-layouts/grid/index.tsx +1 -1
- package/src/dataviews-layouts/grid/style.scss +1 -5
- package/src/dataviews-layouts/index.ts +63 -2
- package/src/dataviews-layouts/list/index.tsx +199 -123
- package/src/dataviews-layouts/list/style.scss +10 -4
- package/src/dataviews-layouts/table/column-header-menu.tsx +86 -90
- package/src/dataviews-layouts/table/index.tsx +8 -65
- package/src/dataviews-layouts/table/style.scss +0 -5
- package/src/field-types/datetime.tsx +28 -0
- package/src/field-types/index.tsx +5 -0
- package/src/field-types/integer.tsx +2 -71
- package/src/field-types/text.tsx +2 -70
- package/src/normalize-fields.ts +10 -10
- package/src/style.scss +2 -1
- package/src/test/filter-and-sort-data-view.js +28 -0
- package/src/types.ts +56 -32
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/dataviews-bulk-actions-toolbar/index.js +0 -207
- package/build/components/dataviews-bulk-actions-toolbar/index.js.map +0 -1
- package/build-module/components/dataviews-bulk-actions-toolbar/index.js +0 -201
- package/build-module/components/dataviews-bulk-actions-toolbar/index.js.map +0 -1
- package/build-types/components/dataviews-bulk-actions-toolbar/index.d.ts +0 -2
- package/build-types/components/dataviews-bulk-actions-toolbar/index.d.ts.map +0 -1
- package/src/components/dataviews/stories/fixtures.js +0 -222
- package/src/components/dataviews/stories/index.story.js +0 -65
- package/src/components/dataviews-bulk-actions-toolbar/index.tsx +0 -288
- package/src/components/dataviews-bulk-actions-toolbar/style.scss +0 -45
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_fieldTypes","_interopRequireDefault","require","normalizeFields","fields","map","field","_field$sort","_field$isValid","fieldTypeDefinition","getFieldTypeDefinition","type","getValue","item","id","sort","a","b","direction","isValid","context","Edit","
|
|
1
|
+
{"version":3,"names":["_fieldTypes","_interopRequireDefault","require","_dataformControls","normalizeFields","fields","map","field","_field$sort","_field$isValid","_field$enableHiding","_field$enableSorting","fieldTypeDefinition","getFieldTypeDefinition","type","getValue","item","id","sort","a","b","direction","isValid","context","Edit","getControl","renderFromElements","value","elements","find","element","label","render","header","enableHiding","enableSorting"],"sources":["@wordpress/dataviews/src/normalize-fields.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport getFieldTypeDefinition from './field-types';\nimport type { Field, NormalizedField } from './types';\nimport { getControl } from './dataform-controls';\n\n/**\n * Apply default values and normalize the fields config.\n *\n * @param fields Fields config.\n * @return Normalized fields config.\n */\nexport function normalizeFields< Item >(\n\tfields: Field< Item >[]\n): NormalizedField< Item >[] {\n\treturn fields.map( ( field ) => {\n\t\tconst fieldTypeDefinition = getFieldTypeDefinition( field.type );\n\n\t\tconst getValue =\n\t\t\tfield.getValue || ( ( { item } ) => ( item as any )[ field.id ] );\n\n\t\tconst sort =\n\t\t\tfield.sort ??\n\t\t\tfunction sort( a, b, direction ) {\n\t\t\t\treturn fieldTypeDefinition.sort(\n\t\t\t\t\tgetValue( { item: a } ),\n\t\t\t\t\tgetValue( { item: b } ),\n\t\t\t\t\tdirection\n\t\t\t\t);\n\t\t\t};\n\n\t\tconst isValid =\n\t\t\tfield.isValid ??\n\t\t\tfunction isValid( item, context ) {\n\t\t\t\treturn fieldTypeDefinition.isValid(\n\t\t\t\t\tgetValue( { item } ),\n\t\t\t\t\tcontext\n\t\t\t\t);\n\t\t\t};\n\n\t\tconst Edit = getControl( field, fieldTypeDefinition );\n\n\t\tconst renderFromElements = ( { item }: { item: Item } ) => {\n\t\t\tconst value = getValue( { item } );\n\t\t\treturn (\n\t\t\t\tfield?.elements?.find( ( element ) => element.value === value )\n\t\t\t\t\t?.label || getValue( { item } )\n\t\t\t);\n\t\t};\n\n\t\tconst render =\n\t\t\tfield.render || ( field.elements ? renderFromElements : getValue );\n\n\t\treturn {\n\t\t\t...field,\n\t\t\tlabel: field.label || field.id,\n\t\t\theader: field.header || field.label || field.id,\n\t\t\tgetValue,\n\t\t\trender,\n\t\t\tsort,\n\t\t\tisValid,\n\t\t\tEdit,\n\t\t\tenableHiding: field.enableHiding ?? true,\n\t\t\tenableSorting: field.enableSorting ?? true,\n\t\t};\n\t} );\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,iBAAA,GAAAD,OAAA;AALA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,eAAeA,CAC9BC,MAAuB,EACK;EAC5B,OAAOA,MAAM,CAACC,GAAG,CAAIC,KAAK,IAAM;IAAA,IAAAC,WAAA,EAAAC,cAAA,EAAAC,mBAAA,EAAAC,oBAAA;IAC/B,MAAMC,mBAAmB,GAAG,IAAAC,mBAAsB,EAAEN,KAAK,CAACO,IAAK,CAAC;IAEhE,MAAMC,QAAQ,GACbR,KAAK,CAACQ,QAAQ,KAAM,CAAE;MAAEC;IAAK,CAAC,KAAQA,IAAI,CAAWT,KAAK,CAACU,EAAE,CAAE,CAAE;IAElE,MAAMC,IAAI,IAAAV,WAAA,GACTD,KAAK,CAACW,IAAI,cAAAV,WAAA,cAAAA,WAAA,GACV,SAASU,IAAIA,CAAEC,CAAC,EAAEC,CAAC,EAAEC,SAAS,EAAG;MAChC,OAAOT,mBAAmB,CAACM,IAAI,CAC9BH,QAAQ,CAAE;QAAEC,IAAI,EAAEG;MAAE,CAAE,CAAC,EACvBJ,QAAQ,CAAE;QAAEC,IAAI,EAAEI;MAAE,CAAE,CAAC,EACvBC,SACD,CAAC;IACF,CAAC;IAEF,MAAMC,OAAO,IAAAb,cAAA,GACZF,KAAK,CAACe,OAAO,cAAAb,cAAA,cAAAA,cAAA,GACb,SAASa,OAAOA,CAAEN,IAAI,EAAEO,OAAO,EAAG;MACjC,OAAOX,mBAAmB,CAACU,OAAO,CACjCP,QAAQ,CAAE;QAAEC;MAAK,CAAE,CAAC,EACpBO,OACD,CAAC;IACF,CAAC;IAEF,MAAMC,IAAI,GAAG,IAAAC,4BAAU,EAAElB,KAAK,EAAEK,mBAAoB,CAAC;IAErD,MAAMc,kBAAkB,GAAGA,CAAE;MAAEV;IAAqB,CAAC,KAAM;MAC1D,MAAMW,KAAK,GAAGZ,QAAQ,CAAE;QAAEC;MAAK,CAAE,CAAC;MAClC,OACCT,KAAK,EAAEqB,QAAQ,EAAEC,IAAI,CAAIC,OAAO,IAAMA,OAAO,CAACH,KAAK,KAAKA,KAAM,CAAC,EAC5DI,KAAK,IAAIhB,QAAQ,CAAE;QAAEC;MAAK,CAAE,CAAC;IAElC,CAAC;IAED,MAAMgB,MAAM,GACXzB,KAAK,CAACyB,MAAM,KAAMzB,KAAK,CAACqB,QAAQ,GAAGF,kBAAkB,GAAGX,QAAQ,CAAE;IAEnE,OAAO;MACN,GAAGR,KAAK;MACRwB,KAAK,EAAExB,KAAK,CAACwB,KAAK,IAAIxB,KAAK,CAACU,EAAE;MAC9BgB,MAAM,EAAE1B,KAAK,CAAC0B,MAAM,IAAI1B,KAAK,CAACwB,KAAK,IAAIxB,KAAK,CAACU,EAAE;MAC/CF,QAAQ;MACRiB,MAAM;MACNd,IAAI;MACJI,OAAO;MACPE,IAAI;MACJU,YAAY,GAAAxB,mBAAA,GAAEH,KAAK,CAAC2B,YAAY,cAAAxB,mBAAA,cAAAA,mBAAA,GAAI,IAAI;MACxCyB,aAAa,GAAAxB,oBAAA,GAAEJ,KAAK,CAAC4B,aAAa,cAAAxB,oBAAA,cAAAA,oBAAA,GAAI;IACvC,CAAC;EACF,CAAE,CAAC;AACJ","ignoreList":[]}
|
package/build/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["@wordpress/dataviews/src/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type {\n\tReactElement,\n\tComponentType,\n\tDispatch,\n\tSetStateAction,\n} from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { SetSelection } from './private-types';\n\nexport type SortDirection = 'asc' | 'desc';\n\n/**\n * Generic option type.\n */\nexport interface Option< Value extends any = any > {\n\tvalue: Value;\n\tlabel: string;\n\tdescription?: string;\n}\n\ninterface FilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators?: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\nexport type Operator =\n\t| 'is'\n\t| 'isNot'\n\t| 'isAny'\n\t| 'isNone'\n\t| 'isAll'\n\t| 'isNotAll';\n\nexport type ItemRecord = Record< string, unknown >;\n\nexport type FieldType = 'text' | 'integer';\n\nexport type ValidationContext = {\n\telements?: Option[];\n};\n\n/**\n * A dataview field for a specific property of a data type.\n */\nexport type Field< Item > = {\n\t/**\n\t * Type of the fields.\n\t */\n\ttype?: FieldType;\n\n\t/**\n\t * The unique identifier of the field.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the field. Defaults to the id.\n\t */\n\tlabel?: string;\n\n\t/**\n\t * A description of the field.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Placeholder for the field.\n\t */\n\tplaceholder?: string;\n\n\t/**\n\t * Callback used to render the field. Defaults to `field.getValue`.\n\t */\n\trender?: ComponentType< { item: Item } >;\n\n\t/**\n\t * Callback used to render an edit control for the field.\n\t */\n\tEdit?: ComponentType< DataFormControlProps< Item > >;\n\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort?: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid?: ( item: Item, context?: ValidationContext ) => boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting?: boolean;\n\n\t/**\n\t * Whether the field is searchable.\n\t */\n\tenableGlobalSearch?: boolean;\n\n\t/**\n\t * Whether the field is filterable.\n\t */\n\tenableHiding?: boolean;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements?: Option[];\n\n\t/**\n\t * Filter config for the field.\n\t */\n\tfilterBy?: FilterByConfig | undefined;\n} & ( Item extends ItemRecord\n\t? {\n\t\t\t/**\n\t\t\t * Callback used to retrieve the value of the field from the item.\n\t\t\t * Defaults to `item[ field.id ]`.\n\t\t\t */\n\t\t\tgetValue?: ( args: { item: Item } ) => any;\n\t }\n\t: {\n\t\t\t/**\n\t\t\t * Callback used to retrieve the value of the field from the item.\n\t\t\t * Defaults to `item[ field.id ]`.\n\t\t\t */\n\t\t\tgetValue: ( args: { item: Item } ) => any;\n\t } );\n\nexport type NormalizedField< Item > = Field< Item > & {\n\tlabel: string;\n\tgetValue: ( args: { item: Item } ) => any;\n\trender: ComponentType< { item: Item } >;\n\tEdit: ComponentType< DataFormControlProps< Item > >;\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\tisValid: ( item: Item, context?: ValidationContext ) => boolean;\n};\n\n/**\n * A collection of dataview fields for a data type.\n */\nexport type Fields< Item > = Field< Item >[];\n\nexport type Data< Item > = Item[];\n\n/**\n * The form configuration.\n */\nexport type Form = {\n\ttype?: 'regular' | 'panel';\n\tfields?: string[];\n};\n\nexport type DataFormControlProps< Item > = {\n\tdata: Item;\n\tfield: NormalizedField< Item >;\n\tonChange: Dispatch< SetStateAction< Item > >;\n\thideLabelFromVision?: boolean;\n};\n\n/**\n * The filters applied to the dataset.\n */\nexport interface Filter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The operator to use.\n\t */\n\toperator: Operator;\n\n\t/**\n\t * The value to filter by.\n\t */\n\tvalue: any;\n}\n\nexport interface NormalizedFilter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The field name.\n\t */\n\tname: string;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements: Option[];\n\n\t/**\n\t * Is a single selection filter.\n\t */\n\tsingleSelection: boolean;\n\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether the filter is visible.\n\t */\n\tisVisible: boolean;\n\n\t/**\n\t * Whether it is a primary filter.\n\t */\n\tisPrimary: boolean;\n}\n\ninterface ViewBase {\n\t/**\n\t * The layout of the view.\n\t */\n\ttype: string;\n\n\t/**\n\t * The global search term.\n\t */\n\tsearch?: string;\n\n\t/**\n\t * The filters to apply.\n\t */\n\tfilters?: Filter[];\n\n\t/**\n\t * The sorting configuration.\n\t */\n\tsort?: {\n\t\t/**\n\t\t * The field to sort by.\n\t\t */\n\t\tfield: string;\n\n\t\t/**\n\t\t * The direction to sort by.\n\t\t */\n\t\tdirection: SortDirection;\n\t};\n\n\t/**\n\t * The active page\n\t */\n\tpage?: number;\n\n\t/**\n\t * The number of items per page\n\t */\n\tperPage?: number;\n\n\t/**\n\t * The fields to render\n\t */\n\tfields?: string[];\n}\n\nexport interface CombinedField {\n\tid: string;\n\n\tlabel: string;\n\n\t/**\n\t * The fields to use as columns.\n\t */\n\tchildren: string[];\n\n\t/**\n\t * The direction of the stack.\n\t */\n\tdirection: 'horizontal' | 'vertical';\n}\n\nexport interface ColumnStyle {\n\t/**\n\t * The width of the field column.\n\t */\n\twidth?: string | number;\n\n\t/**\n\t * The minimum width of the field column.\n\t */\n\tmaxWidth?: string | number;\n\n\t/**\n\t * The maximum width of the field column.\n\t */\n\tminWidth?: string | number;\n}\n\nexport interface ViewTable extends ViewBase {\n\ttype: 'table';\n\n\tlayout?: {\n\t\t/**\n\t\t * The field to use as the primary field.\n\t\t */\n\t\tprimaryField?: string;\n\n\t\t/**\n\t\t * The fields to use as columns.\n\t\t */\n\t\tcombinedFields?: CombinedField[];\n\n\t\t/**\n\t\t * The styles for the columns.\n\t\t */\n\t\tstyles?: Record< string, ColumnStyle >;\n\t};\n}\n\nexport interface ViewList extends ViewBase {\n\ttype: 'list';\n\n\tlayout?: {\n\t\t/**\n\t\t * The field to use as the primary field.\n\t\t */\n\t\tprimaryField?: string;\n\n\t\t/**\n\t\t * The field to use as the media field.\n\t\t */\n\t\tmediaField?: string;\n\t};\n}\n\nexport interface ViewGrid extends ViewBase {\n\ttype: 'grid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The field to use as the primary field.\n\t\t */\n\t\tprimaryField?: string;\n\n\t\t/**\n\t\t * The field to use as the media field.\n\t\t */\n\t\tmediaField?: string;\n\n\t\t/**\n\t\t * The fields to use as columns.\n\t\t */\n\t\tcolumnFields?: string[];\n\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\t};\n}\n\nexport type View = ViewList | ViewGrid | ViewTable;\n\ninterface ActionBase< Item > {\n\t/**\n\t * The unique identifier of the action.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the action.\n\t * In case we want to adjust the label based on the selected items,\n\t * a function can be provided.\n\t */\n\tlabel: string | ( ( items: Item[] ) => string );\n\n\t/**\n\t * The icon of the action. (Either a string or an SVG element)\n\t * This should be IconType from the components package\n\t * but that import is breaking typescript build for the moment.\n\t */\n\ticon?: any;\n\n\t/**\n\t * Whether the action is disabled.\n\t */\n\tdisabled?: boolean;\n\n\t/**\n\t * Whether the action is destructive.\n\t */\n\tisDestructive?: boolean;\n\n\t/**\n\t * Whether the action is a primary action.\n\t */\n\tisPrimary?: boolean;\n\n\t/**\n\t * Whether the item passed as an argument supports the current action.\n\t */\n\tisEligible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the action can be used as a bulk action.\n\t */\n\tsupportsBulk?: boolean;\n}\n\nexport interface ActionModal< Item > extends ActionBase< Item > {\n\t/**\n\t * Modal to render when the action is triggered.\n\t */\n\tRenderModal: ( {\n\t\titems,\n\t\tcloseModal,\n\t\tonActionPerformed,\n\t}: {\n\t\titems: Item[];\n\t\tcloseModal?: () => void;\n\t\tonActionPerformed?: ( items: Item[] ) => void;\n\t} ) => ReactElement;\n\n\t/**\n\t * Whether to hide the modal header.\n\t */\n\thideModalHeader?: boolean;\n\n\t/**\n\t * The header of the modal.\n\t */\n\tmodalHeader?: string;\n}\n\nexport interface ActionButton< Item > extends ActionBase< Item > {\n\t/**\n\t * The callback to execute when the action is triggered.\n\t */\n\tcallback: (\n\t\titems: Item[],\n\t\tcontext: {\n\t\t\tregistry: any;\n\t\t\tonActionPerformed?: ( items: Item[] ) => void;\n\t\t}\n\t) => void;\n}\n\nexport type Action< Item > = ActionModal< Item > | ActionButton< Item >;\n\nexport interface ViewBaseProps< Item > {\n\tactions: Action< Item >[];\n\tdata: Item[];\n\tfields: NormalizedField< Item >[];\n\tgetItemId: ( item: Item ) => string;\n\tisLoading?: boolean;\n\tonChangeView: ( view: View ) => void;\n\tonChangeSelection: SetSelection;\n\tselection: string[];\n\tsetOpenedFilter: ( fieldId: string ) => void;\n\tview: View;\n\tdensity: number;\n}\n\nexport interface ViewTableProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewTable;\n}\n\nexport interface ViewListProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewList;\n}\n\nexport interface ViewGridProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewGrid;\n}\n\nexport type ViewProps< Item > =\n\t| ViewTableProps< Item >\n\t| ViewGridProps< Item >\n\t| ViewListProps< Item >;\n\nexport interface SupportedLayouts {\n\tlist?: Omit< ViewList, 'type' >;\n\tgrid?: Omit< ViewGrid, 'type' >;\n\ttable?: Omit< ViewTable, 'type' >;\n}\n\nexport interface DataFormProps< Item > {\n\tdata: Item;\n\tfields: Field< Item >[];\n\tform: Form;\n\tonChange: Dispatch< SetStateAction< Item > >;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/dataviews/src/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ReactElement, ComponentType } from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { SetSelection } from './private-types';\n\nexport type SortDirection = 'asc' | 'desc';\n\n/**\n * Generic option type.\n */\nexport interface Option< Value extends any = any > {\n\tvalue: Value;\n\tlabel: string;\n\tdescription?: string;\n}\n\ninterface FilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators?: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\nexport type Operator =\n\t| 'is'\n\t| 'isNot'\n\t| 'isAny'\n\t| 'isNone'\n\t| 'isAll'\n\t| 'isNotAll';\n\nexport type FieldType = 'text' | 'integer' | 'datetime';\n\nexport type ValidationContext = {\n\telements?: Option[];\n};\n\n/**\n * An abstract interface for Field based on the field type.\n */\nexport type FieldTypeDefinition< Item > = {\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid: ( item: Item, context?: ValidationContext ) => boolean;\n\n\t/**\n\t * Callback used to render an edit control for the field or control name.\n\t */\n\tEdit: ComponentType< DataFormControlProps< Item > > | string;\n};\n\n/**\n * A dataview field for a specific property of a data type.\n */\nexport type Field< Item > = {\n\t/**\n\t * Type of the fields.\n\t */\n\ttype?: FieldType;\n\n\t/**\n\t * The unique identifier of the field.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the field. Defaults to the id.\n\t */\n\tlabel?: string;\n\n\t/**\n\t * The header of the field. Defaults to the label.\n\t * It allows the usage of a React Element to render the field labels.\n\t */\n\theader?: string | ReactElement;\n\n\t/**\n\t * A description of the field.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Placeholder for the field.\n\t */\n\tplaceholder?: string;\n\n\t/**\n\t * Callback used to render the field. Defaults to `field.getValue`.\n\t */\n\trender?: ComponentType< { item: Item } >;\n\n\t/**\n\t * Callback used to render an edit control for the field.\n\t */\n\tEdit?: ComponentType< DataFormControlProps< Item > > | string;\n\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort?: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid?: ( item: Item, context?: ValidationContext ) => boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting?: boolean;\n\n\t/**\n\t * Whether the field is searchable.\n\t */\n\tenableGlobalSearch?: boolean;\n\n\t/**\n\t * Whether the field is filterable.\n\t */\n\tenableHiding?: boolean;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements?: Option[];\n\n\t/**\n\t * Filter config for the field.\n\t */\n\tfilterBy?: FilterByConfig | undefined;\n\n\t/**\n\t * Callback used to retrieve the value of the field from the item.\n\t * Defaults to `item[ field.id ]`.\n\t */\n\tgetValue?: ( args: { item: Item } ) => any;\n};\n\nexport type NormalizedField< Item > = Field< Item > & {\n\tlabel: string;\n\theader: string | ReactElement;\n\tgetValue: ( args: { item: Item } ) => any;\n\trender: ComponentType< { item: Item } >;\n\tEdit: ComponentType< DataFormControlProps< Item > >;\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\tisValid: ( item: Item, context?: ValidationContext ) => boolean;\n\tenableHiding: boolean;\n\tenableSorting: boolean;\n};\n\n/**\n * A collection of dataview fields for a data type.\n */\nexport type Fields< Item > = Field< Item >[];\n\nexport type Data< Item > = Item[];\n\n/**\n * The form configuration.\n */\nexport type Form = {\n\ttype?: 'regular' | 'panel';\n\tfields?: string[];\n};\n\nexport type DataFormControlProps< Item > = {\n\tdata: Item;\n\tfield: NormalizedField< Item >;\n\tonChange: ( value: Record< string, any > ) => void;\n\thideLabelFromVision?: boolean;\n};\n\n/**\n * The filters applied to the dataset.\n */\nexport interface Filter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The operator to use.\n\t */\n\toperator: Operator;\n\n\t/**\n\t * The value to filter by.\n\t */\n\tvalue: any;\n}\n\nexport interface NormalizedFilter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The field name.\n\t */\n\tname: string;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements: Option[];\n\n\t/**\n\t * Is a single selection filter.\n\t */\n\tsingleSelection: boolean;\n\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether the filter is visible.\n\t */\n\tisVisible: boolean;\n\n\t/**\n\t * Whether it is a primary filter.\n\t */\n\tisPrimary: boolean;\n}\n\ninterface ViewBase {\n\t/**\n\t * The layout of the view.\n\t */\n\ttype: string;\n\n\t/**\n\t * The global search term.\n\t */\n\tsearch?: string;\n\n\t/**\n\t * The filters to apply.\n\t */\n\tfilters?: Filter[];\n\n\t/**\n\t * The sorting configuration.\n\t */\n\tsort?: {\n\t\t/**\n\t\t * The field to sort by.\n\t\t */\n\t\tfield: string;\n\n\t\t/**\n\t\t * The direction to sort by.\n\t\t */\n\t\tdirection: SortDirection;\n\t};\n\n\t/**\n\t * The active page\n\t */\n\tpage?: number;\n\n\t/**\n\t * The number of items per page\n\t */\n\tperPage?: number;\n\n\t/**\n\t * The fields to render\n\t */\n\tfields?: string[];\n}\n\nexport interface CombinedField {\n\tid: string;\n\n\tlabel: string;\n\n\theader?: string | ReactElement;\n\n\t/**\n\t * The fields to use as columns.\n\t */\n\tchildren: string[];\n\n\t/**\n\t * The direction of the stack.\n\t */\n\tdirection: 'horizontal' | 'vertical';\n}\n\nexport interface ColumnStyle {\n\t/**\n\t * The width of the field column.\n\t */\n\twidth?: string | number;\n\n\t/**\n\t * The minimum width of the field column.\n\t */\n\tmaxWidth?: string | number;\n\n\t/**\n\t * The maximum width of the field column.\n\t */\n\tminWidth?: string | number;\n}\n\nexport interface ViewTable extends ViewBase {\n\ttype: 'table';\n\n\tlayout?: {\n\t\t/**\n\t\t * The field to use as the primary field.\n\t\t */\n\t\tprimaryField?: string;\n\n\t\t/**\n\t\t * The fields to use as columns.\n\t\t */\n\t\tcombinedFields?: CombinedField[];\n\n\t\t/**\n\t\t * The styles for the columns.\n\t\t */\n\t\tstyles?: Record< string, ColumnStyle >;\n\t};\n}\n\nexport interface ViewList extends ViewBase {\n\ttype: 'list';\n\n\tlayout?: {\n\t\t/**\n\t\t * The field to use as the primary field.\n\t\t */\n\t\tprimaryField?: string;\n\n\t\t/**\n\t\t * The field to use as the media field.\n\t\t */\n\t\tmediaField?: string;\n\t};\n}\n\nexport interface ViewGrid extends ViewBase {\n\ttype: 'grid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The field to use as the primary field.\n\t\t */\n\t\tprimaryField?: string;\n\n\t\t/**\n\t\t * The field to use as the media field.\n\t\t */\n\t\tmediaField?: string;\n\n\t\t/**\n\t\t * The fields to use as columns.\n\t\t */\n\t\tcolumnFields?: string[];\n\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\t};\n}\n\nexport type View = ViewList | ViewGrid | ViewTable;\n\ninterface ActionBase< Item > {\n\t/**\n\t * The unique identifier of the action.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the action.\n\t * In case we want to adjust the label based on the selected items,\n\t * a function can be provided.\n\t */\n\tlabel: string | ( ( items: Item[] ) => string );\n\n\t/**\n\t * The icon of the action. (Either a string or an SVG element)\n\t * This should be IconType from the components package\n\t * but that import is breaking typescript build for the moment.\n\t */\n\ticon?: any;\n\n\t/**\n\t * Whether the action is disabled.\n\t */\n\tdisabled?: boolean;\n\n\t/**\n\t * Whether the action is destructive.\n\t */\n\tisDestructive?: boolean;\n\n\t/**\n\t * Whether the action is a primary action.\n\t */\n\tisPrimary?: boolean;\n\n\t/**\n\t * Whether the item passed as an argument supports the current action.\n\t */\n\tisEligible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the action can be used as a bulk action.\n\t */\n\tsupportsBulk?: boolean;\n\n\t/**\n\t * The context in which the action is visible.\n\t * This is only a \"meta\" information for now.\n\t */\n\tcontext?: 'list' | 'single';\n}\n\nexport interface RenderModalProps< Item > {\n\titems: Item[];\n\tcloseModal?: () => void;\n\tonActionPerformed?: ( items: Item[] ) => void;\n}\n\nexport interface ActionModal< Item > extends ActionBase< Item > {\n\t/**\n\t * Modal to render when the action is triggered.\n\t */\n\tRenderModal: ( {\n\t\titems,\n\t\tcloseModal,\n\t\tonActionPerformed,\n\t}: RenderModalProps< Item > ) => ReactElement;\n\n\t/**\n\t * Whether to hide the modal header.\n\t */\n\thideModalHeader?: boolean;\n\n\t/**\n\t * The header of the modal.\n\t */\n\tmodalHeader?: string;\n}\n\nexport interface ActionButton< Item > extends ActionBase< Item > {\n\t/**\n\t * The callback to execute when the action is triggered.\n\t */\n\tcallback: (\n\t\titems: Item[],\n\t\tcontext: {\n\t\t\tregistry: any;\n\t\t\tonActionPerformed?: ( items: Item[] ) => void;\n\t\t}\n\t) => void;\n}\n\nexport type Action< Item > = ActionModal< Item > | ActionButton< Item >;\n\nexport interface ViewBaseProps< Item > {\n\tactions: Action< Item >[];\n\tdata: Item[];\n\tfields: NormalizedField< Item >[];\n\tgetItemId: ( item: Item ) => string;\n\tisLoading?: boolean;\n\tonChangeView: ( view: View ) => void;\n\tonChangeSelection: SetSelection;\n\tselection: string[];\n\tsetOpenedFilter: ( fieldId: string ) => void;\n\tview: View;\n\tdensity: number;\n}\n\nexport interface ViewTableProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewTable;\n}\n\nexport interface ViewListProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewList;\n}\n\nexport interface ViewGridProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewGrid;\n}\n\nexport type ViewProps< Item > =\n\t| ViewTableProps< Item >\n\t| ViewGridProps< Item >\n\t| ViewListProps< Item >;\n\nexport interface SupportedLayouts {\n\tlist?: Omit< ViewList, 'type' >;\n\tgrid?: Omit< ViewGrid, 'type' >;\n\ttable?: Omit< ViewTable, 'type' >;\n}\n\nexport interface DataFormProps< Item > {\n\tdata: Item;\n\tfields: Field< Item >[];\n\tform: Form;\n\tonChange: ( value: Record< string, any > ) => void;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -11,17 +11,13 @@ import { useMemo, useState } from '@wordpress/element';
|
|
|
11
11
|
/**
|
|
12
12
|
* Internal dependencies
|
|
13
13
|
*/
|
|
14
|
-
import { default as DataViewsBulkActions } from '../dataviews-bulk-actions';
|
|
15
|
-
import DataViewsBulkActionsToolbar from '../dataviews-bulk-actions-toolbar';
|
|
16
14
|
import DataViewsContext from '../dataviews-context';
|
|
17
15
|
import { default as DataViewsFilters, useFilters, FilterVisibilityToggle } from '../dataviews-filters';
|
|
18
16
|
import DataViewsLayout from '../dataviews-layout';
|
|
19
|
-
import
|
|
17
|
+
import DataViewsFooter from '../dataviews-footer';
|
|
20
18
|
import DataViewsSearch from '../dataviews-search';
|
|
21
19
|
import DataViewsViewConfig from '../dataviews-view-config';
|
|
22
20
|
import { normalizeFields } from '../../normalize-fields';
|
|
23
|
-
import DensityPicker from '../../dataviews-layouts/grid/density-picker';
|
|
24
|
-
import { LAYOUT_GRID } from '../../constants';
|
|
25
21
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
26
22
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
27
23
|
const defaultGetItemId = item => item.id;
|
|
@@ -43,7 +39,6 @@ export default function DataViews({
|
|
|
43
39
|
}) {
|
|
44
40
|
const [selectionState, setSelectionState] = useState([]);
|
|
45
41
|
const [density, setDensity] = useState(0);
|
|
46
|
-
const [isShowingFilter, setIsShowingFilter] = useState(false);
|
|
47
42
|
const isUncontrolled = selectionProperty === undefined || onChangeSelection === undefined;
|
|
48
43
|
const selection = isUncontrolled ? selectionState : selectionProperty;
|
|
49
44
|
const [openedFilter, setOpenedFilter] = useState(null);
|
|
@@ -61,6 +56,7 @@ export default function DataViews({
|
|
|
61
56
|
return selection.filter(id => data.some(item => getItemId(item) === id));
|
|
62
57
|
}, [selection, data, getItemId]);
|
|
63
58
|
const filters = useFilters(_fields, view);
|
|
59
|
+
const [isShowingFilter, setIsShowingFilter] = useState(() => (filters || []).some(filter => filter.isPrimary));
|
|
64
60
|
return /*#__PURE__*/_jsx(DataViewsContext.Provider, {
|
|
65
61
|
value: {
|
|
66
62
|
view,
|
|
@@ -81,12 +77,13 @@ export default function DataViews({
|
|
|
81
77
|
className: "dataviews-wrapper",
|
|
82
78
|
children: [/*#__PURE__*/_jsxs(HStack, {
|
|
83
79
|
alignment: "top",
|
|
84
|
-
justify: "
|
|
80
|
+
justify: "space-between",
|
|
85
81
|
className: "dataviews__view-actions",
|
|
86
82
|
spacing: 1,
|
|
87
83
|
children: [/*#__PURE__*/_jsxs(HStack, {
|
|
88
84
|
justify: "start",
|
|
89
|
-
|
|
85
|
+
expanded: false,
|
|
86
|
+
className: "dataviews__search",
|
|
90
87
|
children: [search && /*#__PURE__*/_jsx(DataViewsSearch, {
|
|
91
88
|
label: searchLabel
|
|
92
89
|
}), /*#__PURE__*/_jsx(FilterVisibilityToggle, {
|
|
@@ -97,20 +94,19 @@ export default function DataViews({
|
|
|
97
94
|
setIsShowingFilter: setIsShowingFilter,
|
|
98
95
|
isShowingFilter: isShowingFilter
|
|
99
96
|
})]
|
|
100
|
-
}),
|
|
101
|
-
density: density,
|
|
102
|
-
setDensity: setDensity
|
|
103
|
-
}), /*#__PURE__*/_jsx(DataViewsBulkActions, {}), /*#__PURE__*/_jsxs(HStack, {
|
|
97
|
+
}), /*#__PURE__*/_jsxs(HStack, {
|
|
104
98
|
spacing: 1,
|
|
105
99
|
expanded: false,
|
|
106
100
|
style: {
|
|
107
101
|
flexShrink: 0
|
|
108
102
|
},
|
|
109
103
|
children: [/*#__PURE__*/_jsx(DataViewsViewConfig, {
|
|
110
|
-
defaultLayouts: defaultLayouts
|
|
104
|
+
defaultLayouts: defaultLayouts,
|
|
105
|
+
density: density,
|
|
106
|
+
setDensity: setDensity
|
|
111
107
|
}), header]
|
|
112
108
|
})]
|
|
113
|
-
}), isShowingFilter && /*#__PURE__*/_jsx(DataViewsFilters, {}), /*#__PURE__*/_jsx(DataViewsLayout, {}), /*#__PURE__*/_jsx(
|
|
109
|
+
}), isShowingFilter && /*#__PURE__*/_jsx(DataViewsFilters, {}), /*#__PURE__*/_jsx(DataViewsLayout, {}), /*#__PURE__*/_jsx(DataViewsFooter, {})]
|
|
114
110
|
})
|
|
115
111
|
});
|
|
116
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__experimentalHStack","HStack","useMemo","useState","
|
|
1
|
+
{"version":3,"names":["__experimentalHStack","HStack","useMemo","useState","DataViewsContext","default","DataViewsFilters","useFilters","FilterVisibilityToggle","DataViewsLayout","DataViewsFooter","DataViewsSearch","DataViewsViewConfig","normalizeFields","jsx","_jsx","jsxs","_jsxs","defaultGetItemId","item","id","DataViews","view","onChangeView","fields","search","searchLabel","undefined","actions","data","getItemId","isLoading","paginationInfo","defaultLayouts","selection","selectionProperty","onChangeSelection","header","selectionState","setSelectionState","density","setDensity","isUncontrolled","openedFilter","setOpenedFilter","setSelectionWithChange","value","newValue","_fields","_selection","filter","some","filters","isShowingFilter","setIsShowingFilter","isPrimary","Provider","children","className","alignment","justify","spacing","expanded","label","style","flexShrink"],"sources":["@wordpress/dataviews/src/components/dataviews/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ReactNode } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { __experimentalHStack as HStack } from '@wordpress/components';\nimport { useMemo, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../dataviews-context';\nimport {\n\tdefault as DataViewsFilters,\n\tuseFilters,\n\tFilterVisibilityToggle,\n} from '../dataviews-filters';\nimport DataViewsLayout from '../dataviews-layout';\nimport DataViewsFooter from '../dataviews-footer';\nimport DataViewsSearch from '../dataviews-search';\nimport DataViewsViewConfig from '../dataviews-view-config';\nimport { normalizeFields } from '../../normalize-fields';\nimport type { Action, Field, View, SupportedLayouts } from '../../types';\nimport type { SelectionOrUpdater } from '../../private-types';\n\ntype ItemWithId = { id: string };\n\ntype DataViewsProps< Item > = {\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n\tfields: Field< Item >[];\n\tsearch?: boolean;\n\tsearchLabel?: string;\n\tactions?: Action< Item >[];\n\tdata: Item[];\n\tisLoading?: boolean;\n\tpaginationInfo: {\n\t\ttotalItems: number;\n\t\ttotalPages: number;\n\t};\n\tdefaultLayouts: SupportedLayouts;\n\tselection?: string[];\n\tonChangeSelection?: ( items: string[] ) => void;\n\theader?: ReactNode;\n} & ( Item extends ItemWithId\n\t? { getItemId?: ( item: Item ) => string }\n\t: { getItemId: ( item: Item ) => string } );\n\nconst defaultGetItemId = ( item: ItemWithId ) => item.id;\n\nexport default function DataViews< Item >( {\n\tview,\n\tonChangeView,\n\tfields,\n\tsearch = true,\n\tsearchLabel = undefined,\n\tactions = [],\n\tdata,\n\tgetItemId = defaultGetItemId,\n\tisLoading = false,\n\tpaginationInfo,\n\tdefaultLayouts,\n\tselection: selectionProperty,\n\tonChangeSelection,\n\theader,\n}: DataViewsProps< Item > ) {\n\tconst [ selectionState, setSelectionState ] = useState< string[] >( [] );\n\tconst [ density, setDensity ] = useState< number >( 0 );\n\tconst isUncontrolled =\n\t\tselectionProperty === undefined || onChangeSelection === undefined;\n\tconst selection = isUncontrolled ? selectionState : selectionProperty;\n\tconst [ openedFilter, setOpenedFilter ] = useState< string | null >( null );\n\tfunction setSelectionWithChange( value: SelectionOrUpdater ) {\n\t\tconst newValue =\n\t\t\ttypeof value === 'function' ? value( selection ) : value;\n\t\tif ( isUncontrolled ) {\n\t\t\tsetSelectionState( newValue );\n\t\t}\n\t\tif ( onChangeSelection ) {\n\t\t\tonChangeSelection( newValue );\n\t\t}\n\t}\n\tconst _fields = useMemo( () => normalizeFields( fields ), [ fields ] );\n\tconst _selection = useMemo( () => {\n\t\treturn selection.filter( ( id ) =>\n\t\t\tdata.some( ( item ) => getItemId( item ) === id )\n\t\t);\n\t}, [ selection, data, getItemId ] );\n\n\tconst filters = useFilters( _fields, view );\n\tconst [ isShowingFilter, setIsShowingFilter ] = useState< boolean >( () =>\n\t\t( filters || [] ).some( ( filter ) => filter.isPrimary )\n\t);\n\n\treturn (\n\t\t<DataViewsContext.Provider\n\t\t\tvalue={ {\n\t\t\t\tview,\n\t\t\t\tonChangeView,\n\t\t\t\tfields: _fields,\n\t\t\t\tactions,\n\t\t\t\tdata,\n\t\t\t\tisLoading,\n\t\t\t\tpaginationInfo,\n\t\t\t\tselection: _selection,\n\t\t\t\tonChangeSelection: setSelectionWithChange,\n\t\t\t\topenedFilter,\n\t\t\t\tsetOpenedFilter,\n\t\t\t\tgetItemId,\n\t\t\t\tdensity,\n\t\t\t} }\n\t\t>\n\t\t\t<div className=\"dataviews-wrapper\">\n\t\t\t\t<HStack\n\t\t\t\t\talignment=\"top\"\n\t\t\t\t\tjustify=\"space-between\"\n\t\t\t\t\tclassName=\"dataviews__view-actions\"\n\t\t\t\t\tspacing={ 1 }\n\t\t\t\t>\n\t\t\t\t\t<HStack\n\t\t\t\t\t\tjustify=\"start\"\n\t\t\t\t\t\texpanded={ false }\n\t\t\t\t\t\tclassName=\"dataviews__search\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ search && <DataViewsSearch label={ searchLabel } /> }\n\t\t\t\t\t\t<FilterVisibilityToggle\n\t\t\t\t\t\t\tfilters={ filters }\n\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\t\t\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t\t\t\t\tsetIsShowingFilter={ setIsShowingFilter }\n\t\t\t\t\t\t\tisShowingFilter={ isShowingFilter }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</HStack>\n\t\t\t\t\t<HStack\n\t\t\t\t\t\tspacing={ 1 }\n\t\t\t\t\t\texpanded={ false }\n\t\t\t\t\t\tstyle={ { flexShrink: 0 } }\n\t\t\t\t\t>\n\t\t\t\t\t\t<DataViewsViewConfig\n\t\t\t\t\t\t\tdefaultLayouts={ defaultLayouts }\n\t\t\t\t\t\t\tdensity={ density }\n\t\t\t\t\t\t\tsetDensity={ setDensity }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ header }\n\t\t\t\t\t</HStack>\n\t\t\t\t</HStack>\n\t\t\t\t{ isShowingFilter && <DataViewsFilters /> }\n\t\t\t\t<DataViewsLayout />\n\t\t\t\t<DataViewsFooter />\n\t\t\t</div>\n\t\t</DataViewsContext.Provider>\n\t);\n}\n"],"mappings":"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","ignoreList":[]}
|
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { Button, CheckboxControl, __experimentalHStack as HStack } from '@wordpress/components';
|
|
5
5
|
import { __, sprintf, _n } from '@wordpress/i18n';
|
|
6
|
-
import { useMemo, useState,
|
|
6
|
+
import { useMemo, useState, useRef, useContext } from '@wordpress/element';
|
|
7
7
|
import { useRegistry } from '@wordpress/data';
|
|
8
|
+
import { closeSmall } from '@wordpress/icons';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Internal dependencies
|
|
11
12
|
*/
|
|
12
13
|
import DataViewsContext from '../dataviews-context';
|
|
13
|
-
import {
|
|
14
|
-
import { unlock } from '../../lock-unlock';
|
|
14
|
+
import { ActionWithModal } from '../dataviews-item-actions';
|
|
15
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
|
-
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
17
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
|
-
const {
|
|
19
|
-
DropdownMenuV2: DropdownMenu,
|
|
20
|
-
DropdownMenuGroupV2: DropdownMenuGroup,
|
|
21
|
-
DropdownMenuItemV2: DropdownMenuItem,
|
|
22
|
-
DropdownMenuSeparatorV2: DropdownMenuSeparator
|
|
23
|
-
} = unlock(componentsPrivateApis);
|
|
24
17
|
export function useHasAPossibleBulkAction(actions, item) {
|
|
25
18
|
return useMemo(() => {
|
|
26
19
|
return actions.some(action => {
|
|
@@ -37,166 +30,175 @@ export function useSomeItemHasAPossibleBulkAction(actions, data) {
|
|
|
37
30
|
});
|
|
38
31
|
}, [actions, data]);
|
|
39
32
|
}
|
|
40
|
-
function
|
|
33
|
+
export function BulkSelectionCheckbox({
|
|
34
|
+
selection,
|
|
35
|
+
onChangeSelection,
|
|
36
|
+
data,
|
|
37
|
+
actions,
|
|
38
|
+
getItemId
|
|
39
|
+
}) {
|
|
40
|
+
const selectableItems = useMemo(() => {
|
|
41
|
+
return data.filter(item => {
|
|
42
|
+
return actions.some(action => action.supportsBulk && (!action.isEligible || action.isEligible(item)));
|
|
43
|
+
});
|
|
44
|
+
}, [data, actions]);
|
|
45
|
+
const selectedItems = data.filter(item => selection.includes(getItemId(item)) && selectableItems.includes(item));
|
|
46
|
+
const areAllSelected = selectedItems.length === selectableItems.length;
|
|
47
|
+
return /*#__PURE__*/_jsx(CheckboxControl, {
|
|
48
|
+
className: "dataviews-view-table-selection-checkbox",
|
|
49
|
+
__nextHasNoMarginBottom: true,
|
|
50
|
+
checked: areAllSelected,
|
|
51
|
+
indeterminate: !areAllSelected && !!selectedItems.length,
|
|
52
|
+
onChange: () => {
|
|
53
|
+
if (areAllSelected) {
|
|
54
|
+
onChangeSelection([]);
|
|
55
|
+
} else {
|
|
56
|
+
onChangeSelection(selectableItems.map(item => getItemId(item)));
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"aria-label": areAllSelected ? __('Deselect all') : __('Select all')
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function ActionTrigger({
|
|
41
63
|
action,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
64
|
+
onClick,
|
|
65
|
+
isBusy,
|
|
66
|
+
items
|
|
45
67
|
}) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
const label = typeof action.label === 'string' ? action.label : action.label(selectedItems);
|
|
60
|
-
return /*#__PURE__*/_jsx(Modal, {
|
|
61
|
-
title: !hideModalHeader ? label : undefined,
|
|
62
|
-
__experimentalHideHeader: !!hideModalHeader,
|
|
63
|
-
onRequestClose: onCloseModal,
|
|
64
|
-
overlayClassName: "dataviews-bulk-actions__modal",
|
|
65
|
-
children: /*#__PURE__*/_jsx(RenderModal, {
|
|
66
|
-
items: eligibleItems,
|
|
67
|
-
closeModal: onCloseModal,
|
|
68
|
-
onActionPerformed: () => onMenuOpenChange(false)
|
|
69
|
-
})
|
|
68
|
+
const label = typeof action.label === 'string' ? action.label : action.label(items);
|
|
69
|
+
return /*#__PURE__*/_jsx(Button, {
|
|
70
|
+
disabled: isBusy,
|
|
71
|
+
accessibleWhenDisabled: true,
|
|
72
|
+
label: label,
|
|
73
|
+
icon: action.icon,
|
|
74
|
+
isDestructive: action.isDestructive,
|
|
75
|
+
size: "compact",
|
|
76
|
+
onClick: onClick,
|
|
77
|
+
isBusy: isBusy,
|
|
78
|
+
tooltipPosition: "top"
|
|
70
79
|
});
|
|
71
80
|
}
|
|
72
|
-
|
|
81
|
+
const EMPTY_ARRAY = [];
|
|
82
|
+
function ActionButton({
|
|
73
83
|
action,
|
|
74
84
|
selectedItems,
|
|
75
|
-
|
|
85
|
+
actionInProgress,
|
|
86
|
+
setActionInProgress
|
|
76
87
|
}) {
|
|
77
88
|
const registry = useRegistry();
|
|
78
|
-
const
|
|
79
|
-
return selectedItems.filter(item =>
|
|
89
|
+
const selectedEligibleItems = useMemo(() => {
|
|
90
|
+
return selectedItems.filter(item => {
|
|
91
|
+
return !action.isEligible || action.isEligible(item);
|
|
92
|
+
});
|
|
80
93
|
}, [action, selectedItems]);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
94
|
+
if ('RenderModal' in action) {
|
|
95
|
+
return /*#__PURE__*/_jsx(ActionWithModal, {
|
|
96
|
+
action: action,
|
|
97
|
+
items: selectedEligibleItems,
|
|
98
|
+
ActionTrigger: ActionTrigger
|
|
99
|
+
}, action.id);
|
|
100
|
+
}
|
|
101
|
+
return /*#__PURE__*/_jsx(ActionTrigger, {
|
|
102
|
+
action: action,
|
|
84
103
|
onClick: async () => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
});
|
|
91
|
-
}
|
|
104
|
+
setActionInProgress(action.id);
|
|
105
|
+
await action.callback(selectedItems, {
|
|
106
|
+
registry
|
|
107
|
+
});
|
|
108
|
+
setActionInProgress(null);
|
|
92
109
|
},
|
|
93
|
-
|
|
94
|
-
|
|
110
|
+
items: selectedEligibleItems,
|
|
111
|
+
isBusy: actionInProgress === action.id
|
|
95
112
|
}, action.id);
|
|
96
113
|
}
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
selectedItems,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
function renderFooterContent(data, actions, getItemId, selection, actionsToShow, selectedItems, actionInProgress, setActionInProgress, onChangeSelection) {
|
|
115
|
+
const message = selectedItems.length > 0 ? sprintf( /* translators: %d: number of items. */
|
|
116
|
+
_n('%d Item selected', '%d Items selected', selectedItems.length), selectedItems.length) : sprintf( /* translators: %d: number of items. */
|
|
117
|
+
_n('%d Item', '%d Items', data.length), data.length);
|
|
118
|
+
return /*#__PURE__*/_jsxs(HStack, {
|
|
119
|
+
expanded: false,
|
|
120
|
+
className: "dataviews-bulk-actions-footer__container",
|
|
121
|
+
spacing: 3,
|
|
122
|
+
children: [/*#__PURE__*/_jsx(BulkSelectionCheckbox, {
|
|
123
|
+
selection: selection,
|
|
124
|
+
onChangeSelection: onChangeSelection,
|
|
125
|
+
data: data,
|
|
126
|
+
actions: actions,
|
|
127
|
+
getItemId: getItemId
|
|
128
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
129
|
+
className: "dataviews-bulk-actions-footer__item-count",
|
|
130
|
+
children: message
|
|
131
|
+
}), /*#__PURE__*/_jsxs(HStack, {
|
|
132
|
+
className: "dataviews-bulk-actions-footer__action-buttons",
|
|
133
|
+
expanded: false,
|
|
134
|
+
spacing: 1,
|
|
135
|
+
children: [actionsToShow.map(action => {
|
|
136
|
+
return /*#__PURE__*/_jsx(ActionButton, {
|
|
137
|
+
action: action,
|
|
138
|
+
selectedItems: selectedItems,
|
|
139
|
+
actionInProgress: actionInProgress,
|
|
140
|
+
setActionInProgress: setActionInProgress
|
|
141
|
+
}, action.id);
|
|
142
|
+
}), selectedItems.length > 0 && /*#__PURE__*/_jsx(Button, {
|
|
143
|
+
icon: closeSmall,
|
|
144
|
+
showTooltip: true,
|
|
145
|
+
tooltipPosition: "top",
|
|
146
|
+
size: "compact",
|
|
147
|
+
label: __('Cancel'),
|
|
148
|
+
disabled: !!actionInProgress,
|
|
149
|
+
accessibleWhenDisabled: false,
|
|
150
|
+
onClick: () => {
|
|
151
|
+
onChangeSelection(EMPTY_ARRAY);
|
|
152
|
+
}
|
|
153
|
+
})]
|
|
154
|
+
})]
|
|
118
155
|
});
|
|
119
156
|
}
|
|
120
|
-
function
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
157
|
+
function FooterContent({
|
|
158
|
+
selection,
|
|
159
|
+
actions,
|
|
160
|
+
onChangeSelection,
|
|
161
|
+
data,
|
|
162
|
+
getItemId
|
|
163
|
+
}) {
|
|
164
|
+
const [actionInProgress, setActionInProgress] = useState(null);
|
|
165
|
+
const footerContent = useRef(null);
|
|
128
166
|
const bulkActions = useMemo(() => actions.filter(action => action.supportsBulk), [actions]);
|
|
129
|
-
const [isMenuOpen, onMenuOpenChange] = useState(false);
|
|
130
|
-
const [actionWithModal, setActionWithModal] = useState();
|
|
131
167
|
const selectableItems = useMemo(() => {
|
|
132
168
|
return data.filter(item => {
|
|
133
169
|
return bulkActions.some(action => !action.isEligible || action.isEligible(item));
|
|
134
170
|
});
|
|
135
171
|
}, [data, bulkActions]);
|
|
136
|
-
const numberSelectableItems = selectableItems.length;
|
|
137
172
|
const selectedItems = useMemo(() => {
|
|
138
173
|
return data.filter(item => selection.includes(getItemId(item)) && selectableItems.includes(item));
|
|
139
174
|
}, [selection, data, getItemId, selectableItems]);
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
175
|
+
const actionsToShow = useMemo(() => actions.filter(action => {
|
|
176
|
+
return action.supportsBulk && action.icon && selectedItems.some(item => !action.isEligible || action.isEligible(item));
|
|
177
|
+
}), [actions, selectedItems]);
|
|
178
|
+
if (!actionInProgress) {
|
|
179
|
+
if (footerContent.current) {
|
|
180
|
+
footerContent.current = null;
|
|
181
|
+
}
|
|
182
|
+
return renderFooterContent(data, actions, getItemId, selection, actionsToShow, selectedItems, actionInProgress, setActionInProgress, onChangeSelection);
|
|
183
|
+
} else if (!footerContent.current) {
|
|
184
|
+
footerContent.current = renderFooterContent(data, actions, getItemId, selection, actionsToShow, selectedItems, actionInProgress, setActionInProgress, onChangeSelection);
|
|
143
185
|
}
|
|
144
|
-
return
|
|
145
|
-
children: [/*#__PURE__*/_jsxs(DropdownMenu, {
|
|
146
|
-
open: isMenuOpen,
|
|
147
|
-
onOpenChange: onMenuOpenChange,
|
|
148
|
-
label: __('Bulk actions'),
|
|
149
|
-
style: {
|
|
150
|
-
minWidth: '240px'
|
|
151
|
-
},
|
|
152
|
-
trigger: /*#__PURE__*/_jsx(Button, {
|
|
153
|
-
className: "dataviews-bulk-actions__edit-button",
|
|
154
|
-
__next40pxDefaultSize: true,
|
|
155
|
-
variant: "tertiary",
|
|
156
|
-
size: "compact",
|
|
157
|
-
children: selectedItems.length ? sprintf( /* translators: %d: Number of items. */
|
|
158
|
-
_n('Edit %d item', 'Edit %d items', selectedItems.length), selectedItems.length) : __('Bulk edit')
|
|
159
|
-
}),
|
|
160
|
-
children: [/*#__PURE__*/_jsx(ActionsMenuGroup, {
|
|
161
|
-
actions: bulkActions,
|
|
162
|
-
setActionWithModal: setActionWithModal,
|
|
163
|
-
selectedItems: selectedItems
|
|
164
|
-
}), /*#__PURE__*/_jsxs(DropdownMenuGroup, {
|
|
165
|
-
children: [/*#__PURE__*/_jsx(DropdownMenuItem, {
|
|
166
|
-
disabled: areAllSelected,
|
|
167
|
-
hideOnClick: false,
|
|
168
|
-
onClick: () => {
|
|
169
|
-
onChangeSelection(selectableItems.map(item => getItemId(item)));
|
|
170
|
-
},
|
|
171
|
-
suffix: numberSelectableItems,
|
|
172
|
-
children: __('Select all')
|
|
173
|
-
}), /*#__PURE__*/_jsx(DropdownMenuItem, {
|
|
174
|
-
disabled: selection.length === 0,
|
|
175
|
-
hideOnClick: false,
|
|
176
|
-
onClick: () => {
|
|
177
|
-
onChangeSelection([]);
|
|
178
|
-
},
|
|
179
|
-
children: __('Deselect')
|
|
180
|
-
})]
|
|
181
|
-
})]
|
|
182
|
-
}), actionWithModal && /*#__PURE__*/_jsx(ActionWithModal, {
|
|
183
|
-
action: actionWithModal,
|
|
184
|
-
selectedItems: selectedItems,
|
|
185
|
-
setActionWithModal: setActionWithModal,
|
|
186
|
-
onMenuOpenChange: onMenuOpenChange
|
|
187
|
-
})]
|
|
188
|
-
});
|
|
186
|
+
return footerContent.current;
|
|
189
187
|
}
|
|
190
|
-
export
|
|
188
|
+
export function BulkActionsFooter() {
|
|
191
189
|
const {
|
|
192
190
|
data,
|
|
193
|
-
|
|
194
|
-
|
|
191
|
+
selection,
|
|
192
|
+
actions = EMPTY_ARRAY,
|
|
193
|
+
onChangeSelection,
|
|
194
|
+
getItemId
|
|
195
195
|
} = useContext(DataViewsContext);
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
196
|
+
return /*#__PURE__*/_jsx(FooterContent, {
|
|
197
|
+
selection: selection,
|
|
198
|
+
onChangeSelection: onChangeSelection,
|
|
199
|
+
data: data,
|
|
200
|
+
actions: actions,
|
|
201
|
+
getItemId: getItemId
|
|
202
|
+
});
|
|
201
203
|
}
|
|
202
204
|
//# sourceMappingURL=index.js.map
|