@@ -41,6 +41,7 @@ import { EmptyState } from '../../../../admin-ui/components/EmptyState'
4141import { GraphQLErrorNotice } from '../../../../admin-ui/components/GraphQLErrorNotice'
4242import { PageContainer } from '../../../../admin-ui/components/PageContainer'
4343import { useList } from '../../../../admin-ui/context'
44+ import { serializeActionData } from '../../../../admin-ui/utils/actionData'
4445import { useSearchFilter } from '../../../../fields/types/relationship/views/useFilter'
4546import type { ActionMeta , FieldMeta , JSONValue , ListMeta } from '../../../../types'
4647import {
@@ -343,10 +344,14 @@ function ListPage({ listKey }: ListPageProps) {
343344 ( ) => columns . map ( fieldKey => list . fields [ fieldKey ] ) . filter ( Boolean ) ,
344345 [ columns , list . fields ]
345346 )
347+
346348 const queriedFields = useMemo (
347349 ( ) => [
348350 ...new Set ( [
349351 ...shownFields ,
352+ ...list . actions
353+ . filter ( action => action . listView . actionMode === 'enabled' )
354+ . flatMap ( action => action . graphql . fields ) ,
350355 ...getQueriedFieldKeysForActions ( columns , list . actions , 'listView' )
351356 . map ( fieldKey => list . fields [ fieldKey ] )
352357 . filter ( Boolean ) ,
@@ -397,7 +402,7 @@ function ListPage({ listKey }: ListPageProps) {
397402 count: ${ list . graphql . names . listQueryCountName } (where: $where)
398403 }
399404 `
400- } , [ list , shownFields ] ) ,
405+ } , [ list , queriedFields ] ) ,
401406 {
402407 fetchPolicy : 'cache-and-network' ,
403408 errorPolicy : 'all' ,
@@ -462,6 +467,7 @@ function ListPage({ listKey }: ListPageProps) {
462467 label : 'Delete' ,
463468 icon : 'trash2Icon' ,
464469 graphql : {
470+ fields : [ ] ,
465471 names : {
466472 one : list . graphql . names . deleteMutationName ,
467473 many : list . graphql . names . deleteManyMutationName ,
@@ -703,6 +709,7 @@ function ListPage({ listKey }: ListPageProps) {
703709 return (
704710 < ActionItemsDialog
705711 itemIds = { selectedItemIds }
712+ items = { data ?. items ?? [ ] }
706713 action = { action }
707714 list = { list }
708715 onSuccess = { remaining => {
@@ -830,27 +837,47 @@ type ActionErrorResult = {
830837function ActionItemsDialog ( {
831838 list,
832839 itemIds,
840+ items,
833841 onSuccess,
834842 onErrors,
835843 action,
836844} : {
837845 list : ListMeta
838846 itemIds : string [ ]
847+ items : Record < string , unknown > [ ]
839848 onSuccess : ( remaining : Set < string > ) => void
840849 onErrors : ( result : ActionErrorResult ) => void
841850 action : ActionMeta
842851} ) {
843- const [ actionOnItems ] = useMutation < { results ?: ( { id : string } | null ) [ ] } > (
844- gql `mutation($where: [${ list . graphql . names . whereUniqueInputName } !]!) {
852+ const actionMutation =
853+ action . key === 'delete'
854+ ? gql `mutation($where: [${ list . graphql . names . whereUniqueInputName } !]!) {
845855 results: ${ action . graphql . names . many } (where: $where) {
846856 id
847857 }
848- }` ,
849- {
850- variables : { where : itemIds . map ( id => ( { id } ) ) } ,
851- errorPolicy : 'all' ,
852- }
853- )
858+ }`
859+ : gql `mutation($data: [${ action . graphql . names . one [ 0 ] . toUpperCase ( ) } ${ action . graphql . names . one . slice ( 1 ) } Args!]!) {
860+ results: ${ action . graphql . names . many } (data: $data) {
861+ id
862+ }
863+ }`
864+ const [ actionOnItems ] = useMutation < { results ?: ( { id : string } | null ) [ ] } > ( actionMutation , {
865+ variables :
866+ action . key === 'delete'
867+ ? { where : itemIds . map ( id => ( { id } ) ) }
868+ : {
869+ data : itemIds . flatMap ( id => {
870+ const row = items . find ( item => String ( item . id ) === id )
871+ if ( ! row ) {
872+ return [ ]
873+ }
874+ const deserialized = deserializeItemToValue ( list . fields , row )
875+ const data = serializeActionData ( list , action , deserialized , deserialized )
876+ return Object . keys ( data ) . length ? { where : { id } , data } : { where : { id } }
877+ } ) ,
878+ } ,
879+ errorPolicy : 'all' ,
880+ } )
854881 const { messages : m } = action
855882
856883 async function onTryAction ( ) {
0 commit comments