@@ -42,6 +42,37 @@ const PAGED_OPERATIONS = [
4242 */
4343const NEXT_LINK_OPERATIONS = [ ...PAGED_OPERATIONS , 'list_service_principal_app_role_assignments' ]
4444
45+ /** Operations that own the shared `filter` and `search` fields. */
46+ const SHARED_FILTER_OPERATIONS = [ 'list_users' , 'list_groups' ]
47+
48+ /**
49+ * The subBlock each operation reads its OData `$filter` from.
50+ *
51+ * A subBlock keeps its value after the operation changes, so the filter is resolved by
52+ * ownership rather than by letting later assignments overwrite earlier ones. Otherwise a clause
53+ * written for `/users` would still be sent when the block is switched to `/auditLogs/signIns` or
54+ * `/devices`, where it is invalid.
55+ */
56+ const FILTER_FIELD_BY_OPERATION : Record < string , string > = {
57+ list_users : 'filter' ,
58+ list_groups : 'filter' ,
59+ list_sign_ins : 'signInFilter' ,
60+ list_directory_audits : 'auditFilter' ,
61+ list_user_app_role_assignments : 'appRoleFilter' ,
62+ list_service_principal_app_role_assignments : 'appRoleFilter' ,
63+ list_service_principals : 'servicePrincipalFilter' ,
64+ list_devices : 'deviceFilter' ,
65+ list_conditional_access_policies : 'policyFilter' ,
66+ }
67+
68+ /** The subBlock each operation reads its `$search` term from. */
69+ const SEARCH_FIELD_BY_OPERATION : Record < string , string > = {
70+ list_users : 'search' ,
71+ list_groups : 'search' ,
72+ list_service_principals : 'servicePrincipalSearch' ,
73+ list_devices : 'deviceSearch' ,
74+ }
75+
4576/** Operations that act on a single device object. */
4677const DEVICE_ID_OPERATIONS = [ 'get_device' ]
4778
@@ -355,15 +386,15 @@ export const MicrosoftAdBlock: BlockConfig<MicrosoftAdResponse> = {
355386 title : 'Filter' ,
356387 type : 'short-input' ,
357388 placeholder : "e.g., department eq 'Sales'" ,
358- condition : { field : 'operation' , value : [ 'list_users' , 'list_groups' ] } ,
389+ condition : { field : 'operation' , value : SHARED_FILTER_OPERATIONS } ,
359390 mode : 'advanced' ,
360391 } ,
361392 {
362393 id : 'search' ,
363394 title : 'Search' ,
364395 type : 'short-input' ,
365396 placeholder : 'Search by name or email' ,
366- condition : { field : 'operation' , value : [ 'list_users' , 'list_groups' ] } ,
397+ condition : { field : 'operation' , value : SHARED_FILTER_OPERATIONS } ,
367398 mode : 'advanced' ,
368399 } ,
369400 {
@@ -756,17 +787,12 @@ export const MicrosoftAdBlock: BlockConfig<MicrosoftAdResponse> = {
756787 params : ( params ) => {
757788 const result : Record < string , unknown > = { }
758789 if ( params . top ) result . top = Number ( params . top )
759- if ( params . filter ) result . filter = params . filter
760- if ( params . search ) result . search = params . search
761790 if ( params . nextLink ) result . nextLink = params . nextLink
762- if ( params . signInFilter ) result . filter = params . signInFilter
763- if ( params . auditFilter ) result . filter = params . auditFilter
764- if ( params . appRoleFilter ) result . filter = params . appRoleFilter
765- if ( params . servicePrincipalFilter ) result . filter = params . servicePrincipalFilter
766- if ( params . servicePrincipalSearch ) result . search = params . servicePrincipalSearch
767- if ( params . deviceFilter ) result . filter = params . deviceFilter
768- if ( params . deviceSearch ) result . search = params . deviceSearch
769- if ( params . policyFilter ) result . filter = params . policyFilter
791+ const values = params as Record < string , unknown >
792+ const filter = values [ FILTER_FIELD_BY_OPERATION [ params . operation ] ]
793+ if ( filter ) result . filter = filter
794+ const search = values [ SEARCH_FIELD_BY_OPERATION [ params . operation ] ]
795+ if ( search ) result . search = search
770796 if ( params . operation === 'set_password' ) {
771797 result . forceChangePasswordNextSignIn = params . forceChangePasswordNextSignIn !== 'false'
772798 if ( params . forceChangePasswordNextSignInWithMfa )
0 commit comments