1- import { AdminForthPlugin , Filters } from "adminforth" ;
1+ import { AdminForthFilterOperators , AdminForthPlugin , Filters } from "adminforth" ;
22import type { IAdminForth , IHttpServer , AdminForthComponentDeclaration , AdminForthResource } from "adminforth" ;
33import { suggestIfTypo } from "adminforth" ;
44import type { PluginOptions } from './types.js' ;
@@ -601,7 +601,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
601601 isFieldsForAnalizePlain : this . options . fillPlainFields ? Object . keys ( this . options . fillPlainFields ) . length > 0 : false ,
602602 isImageGeneration : this . options . generateImages ? Object . keys ( this . options . generateImages ) . length > 0 : false ,
603603 isAttachFiles : this . options . attachFiles ? true : false ,
604- disabledWhenNoCheckboxes : true ,
604+ disabledWhenNoCheckboxes : this . options . recordSelector === 'filtered' ? false : true ,
605605 refreshRates : {
606606 fillFieldsFromImages : this . options . refreshRates ?. fillFieldsFromImages || 2_000 ,
607607 fillPlainFields : this . options . refreshRates ?. fillPlainFields || 1_000 ,
@@ -610,6 +610,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
610610 } ,
611611 askConfirmationBeforeGenerating : this . options . askConfirmationBeforeGenerating || false ,
612612 concurrencyLimit : this . options . concurrencyLimit || 10 ,
613+ recordSelector : this . options . recordSelector || 'checkbox' ,
613614 generationPrompts : {
614615 plainFieldsPrompts : this . options . fillPlainFields || { } ,
615616 imageFieldsPrompts : this . options . fillFieldsFromImages || { } ,
@@ -1034,5 +1035,44 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
10341035 }
10351036 }
10361037 } ) ;
1038+
1039+ server . endpoint ( {
1040+ method : 'POST' ,
1041+ path : `/plugin/${ this . pluginInstanceId } /get_filtered_ids` ,
1042+ handler : async ( { body, adminUser, headers } ) => {
1043+ const filters = body . filters ;
1044+
1045+ const normalizedFilters = { operator : AdminForthFilterOperators . AND , subFilters : [ ] } ;
1046+ if ( filters ) {
1047+ if ( typeof filters !== 'object' ) {
1048+ throw new Error ( `Filter should be an array or an object` ) ;
1049+ }
1050+ if ( Array . isArray ( filters ) ) {
1051+ // if filters are an array, they will be connected with "AND" operator by default
1052+ normalizedFilters . subFilters = filters ;
1053+ } else if ( filters . field ) {
1054+ // assume filter is a SingleFilter
1055+ normalizedFilters . subFilters = [ filters ] ;
1056+ } else if ( filters . subFilters ) {
1057+ // assume filter is a AndOr filter
1058+ normalizedFilters . operator = filters . operator ;
1059+ normalizedFilters . subFilters = filters . subFilters ;
1060+ } else {
1061+ // wrong filter
1062+ throw new Error ( `Wrong filter object value: ${ JSON . stringify ( filters ) } ` ) ;
1063+ }
1064+ }
1065+
1066+ const records = await this . adminforth . resource ( this . resourceConfig . resourceId ) . list ( normalizedFilters ) ;
1067+ if ( ! records ) {
1068+ return { ok : true , recordIds : [ ] } ;
1069+ }
1070+ const primaryKeyColumn = this . resourceConfig . columns . find ( ( col ) => col . primaryKey ) ;
1071+
1072+ const recordIds = records . map ( record => record [ primaryKeyColumn . name ] ) ;
1073+
1074+ return { ok : true , recordIds }
1075+ }
1076+ } ) ;
10371077 }
10381078}
0 commit comments