@@ -54,9 +54,10 @@ app.action("open-modal-button", async ({ ack, body, client, logger }) => {
54
54
55
55
if ( dbId == undefined ) {
56
56
const dbs = await cache . getDatabases ( )
57
- const metaData = {
57
+ const metaData : MetaData = {
58
58
channel_id : body . channel . id ,
59
59
thread_ts : body . message . thread_ts ,
60
+ filter_values : [ ] ,
60
61
}
61
62
await client . views . open ( {
62
63
trigger_id : body . trigger_id ,
@@ -70,6 +71,7 @@ app.action("open-modal-button", async ({ ack, body, client, logger }) => {
70
71
thread_ts : body . message . thread_ts ,
71
72
selected_db_id : dbId ,
72
73
selected_db_name : dbTitle ,
74
+ filter_values : [ ] ,
73
75
}
74
76
75
77
const res = await notion . client . databases . query ( {
@@ -152,18 +154,32 @@ app.action("title_search_input-action", async ({ ack, body, client, logger }) =>
152
154
153
155
// Set search string to metaData
154
156
metaData . search_string = body . actions [ 0 ] . value
155
-
157
+ metaData . filters = null
158
+ if ( metaData . search_string ) {
159
+ const titlePropName = await notion . getDbPropNameByType ( metaData . selected_db_id , "title" )
160
+ metaData . filters = {
161
+ and : [
162
+ {
163
+ property : titlePropName ,
164
+ title : {
165
+ contains : metaData . search_string ,
166
+ } ,
167
+ } ,
168
+ ] ,
169
+ }
170
+ }
156
171
const params = {
157
172
database_id : metaData . selected_db_id ,
158
173
page_size : 10 ,
159
174
}
160
175
if ( metaData . filters != null ) {
161
176
params [ "filter" ] = metaData . filters as QueryDatabaseParameters [ "filter" ]
162
177
}
178
+ console . dir ( params , { depth : null } )
163
179
const res = await notion . client . databases . query ( params )
164
180
const urls = await notion . getPageUrls ( res , metaData . search_string )
165
181
if ( urls . length == 0 ) {
166
- urls . push ( "該当するページはありませんでした " )
182
+ urls . push ( "No Results " )
167
183
}
168
184
metaData . next_cursor = res . has_more ? res . next_cursor : ""
169
185
@@ -364,7 +380,7 @@ app.action("select_prop_value-action", async ({ ack, body, client, logger }) =>
364
380
} )
365
381
const urls = await notion . getPageUrls ( res , metaData . search_string )
366
382
if ( urls . length == 0 ) {
367
- urls . push ( "該当するページはありませんでした " )
383
+ urls . push ( "No Results " )
368
384
}
369
385
metaData . next_cursor = res . has_more ? res . next_cursor : ""
370
386
@@ -414,7 +430,7 @@ app.action("select_prop_value_input-action", async ({ ack, body, client, logger
414
430
} )
415
431
const urls = await notion . getPageUrls ( res , metaData . search_string )
416
432
if ( urls . length == 0 ) {
417
- urls . push ( "該当するページはありませんでした " )
433
+ urls . push ( "No Results " )
418
434
}
419
435
420
436
// プロパティ設定用モーダルに更新
@@ -434,13 +450,14 @@ app.view("set-filter-property", async ({ ack, view, client, logger }) => {
434
450
} )
435
451
436
452
app . action ( "clear_filter-action" , async ( { ack, body, client, logger } ) => {
437
- logger . info ( "add_filter action called" )
453
+ logger . info ( "clear_filter action called" )
438
454
ack ( )
439
455
440
456
try {
441
457
const metaData = JSON . parse ( body . view . private_metadata ) as MetaData
442
458
console . dir ( { metaData } , { depth : null } )
443
459
460
+ // Clear filters
444
461
metaData . filter_values = [ ]
445
462
metaData . filters = null
446
463
metaData . search_string = null
@@ -503,7 +520,7 @@ app.action("filter-remove-action", async ({ ack, body, client, logger }) => {
503
520
const res = await notion . client . databases . query ( params )
504
521
const urls = await notion . getPageUrls ( res , metaData . search_string )
505
522
if ( urls . length == 0 ) {
506
- urls . push ( "該当するページはありませんでした " )
523
+ urls . push ( "No Results " )
507
524
}
508
525
metaData . next_cursor = res . has_more ? res . next_cursor : ""
509
526
@@ -536,7 +553,7 @@ app.action("next_result-action", async ({ ack, body, client, logger }) => {
536
553
const res = await notion . client . databases . query ( params )
537
554
const urls = await notion . getPageUrls ( res , metaData . search_string )
538
555
if ( urls . length == 0 ) {
539
- urls . push ( "該当するページはありませんでした " )
556
+ urls . push ( "No Results " )
540
557
}
541
558
const nextCursor = res . has_more ? res . next_cursor : ""
542
559
metaData . next_cursor = nextCursor
@@ -567,7 +584,7 @@ app.view("search-db-modal", async ({ ack, view, client, logger }) => {
567
584
} )
568
585
const urls = await notion . getPageUrls ( res )
569
586
if ( urls . length == 0 ) {
570
- urls . push ( "該当するページはありませんでした " )
587
+ urls . push ( "No Results " )
571
588
}
572
589
573
590
// Reply result
0 commit comments