@@ -51,6 +51,96 @@ To delete a filter:
5151await sdk .filters .delete (filterId );
5252```
5353
54+ ### Getting the Current Filter
55+
56+ To get the currently selected filter:
57+
58+ ``` ts
59+ const currentFilter = sdk .filters .getCurrentFilter ();
60+ ```
61+
62+ Returns the currently selected filter, or ` undefined ` if no filter is selected.
63+
64+ ### Subscribing to Filter Changes
65+
66+ To subscribe to changes in the currently selected filter:
67+
68+ ``` ts
69+ const handler = sdk .filters .onCurrentFilterChange ((event ) => {
70+ console .log (` Filter ${event .filterId } got selected! ` );
71+ });
72+
73+ // Later, stop listening
74+ handler .stop ();
75+ ```
76+
77+ The callback receives an event object with a ` filterId ` property that contains the ID of the newly selected filter, or ` undefined ` if no filter is selected.
78+
79+ ::: info
80+ The subscription handler returns an object with a ` stop() ` method that can be called to unsubscribe from filter changes.
81+ :::
82+
83+ ## Adding Components to Filter Slots
84+
85+ You can add custom components to filter slots to extend the Filters page UI. Available slots are:
86+
87+ - ` FilterSlot.CreateHeader ` - The header area of the preset form create component
88+ - ` FilterSlot.UpdateHeader ` - The header area of the preset form update component
89+
90+ ### Adding a Button to a Slot
91+
92+ Add a button with a label, icon, and click handler:
93+
94+ ``` ts
95+ import { FilterSlot } from " @caido/sdk-frontend" ;
96+
97+ sdk .filters .addToSlot (FilterSlot .UpdateHeader , {
98+ type: " Button" ,
99+ label: " My Button" ,
100+ icon: " my-icon" ,
101+ onClick : () => {
102+ console .log (" Button clicked" );
103+ },
104+ });
105+ ```
106+
107+ ### Adding a Command to a Slot
108+
109+ Add a button that triggers a registered command:
110+
111+ ``` ts
112+ import { FilterSlot } from " @caido/sdk-frontend" ;
113+
114+ // First register the command
115+ sdk .commands .register (" my-command" , {
116+ name: " My Command" ,
117+ run : () => {
118+ sdk .window .showToast (" Command executed" , { variant: " info" });
119+ },
120+ });
121+
122+ // Then add to slot
123+ sdk .filters .addToSlot (FilterSlot .UpdateHeader , {
124+ type: " Command" ,
125+ commandId: " my-command" ,
126+ icon: " my-icon" ,
127+ });
128+ ```
129+
130+ ### Adding a Custom Component to a Slot
131+
132+ Add a custom Vue component:
133+
134+ ``` ts
135+ import { FilterSlot } from " @caido/sdk-frontend" ;
136+ import MyComponent from " ./MyComponent.vue" ;
137+
138+ sdk .filters .addToSlot (FilterSlot .CreateHeader , {
139+ type: " Custom" ,
140+ definition: MyComponent ,
141+ });
142+ ```
143+
54144## Setting HTTPQL Queries on Pages
55145
56146### HTTP History
@@ -206,3 +296,64 @@ const filter = await sdk.filters.create({
206296// Use the filter in a query
207297sdk .httpHistory .setQuery (" preset:success-get" );
208298```
299+
300+ ### Tracking Current Filter Changes
301+
302+ This example subscribes to filter selection changes and logs information about the currently selected filter whenever it changes.
303+
304+ ``` ts
305+ import type { Caido } from " @caido/sdk-frontend" ;
306+
307+ export type CaidoSDK = Caido ;
308+
309+ export const init = (sdk : CaidoSDK ) => {
310+ const handler = sdk .filters .onCurrentFilterChange ((event ) => {
311+ if (event .filterId ) {
312+ const filter = sdk .filters .getCurrentFilter ();
313+ if (filter ) {
314+ sdk .log .info (` Filter selected: ${filter .name } (${filter .alias }) ` );
315+ sdk .log .info (` Query: ${filter .query } ` );
316+ }
317+ } else {
318+ sdk .log .info (" No filter selected" );
319+ }
320+ });
321+
322+ // Store handler for cleanup if needed
323+ // handler.stop();
324+ };
325+ ```
326+
327+ ### Adding Custom Actions to Filter Slots
328+
329+ This example adds a custom button to the filter update header that duplicates the current filter when clicked.
330+
331+ ``` ts
332+ import type { Caido } from " @caido/sdk-frontend" ;
333+ import { FilterSlot } from " @caido/sdk-frontend" ;
334+
335+ export type CaidoSDK = Caido ;
336+
337+ export const init = (sdk : CaidoSDK ) => {
338+ sdk .filters .addToSlot (FilterSlot .UpdateHeader , {
339+ type: " Button" ,
340+ label: " Duplicate Filter" ,
341+ icon: " fas fa-copy" ,
342+ onClick : async () => {
343+ const currentFilter = sdk .filters .getCurrentFilter ();
344+ if (currentFilter ) {
345+ const duplicated = await sdk .filters .create ({
346+ name: ` ${currentFilter .name } (Copy) ` ,
347+ alias: ` ${currentFilter .alias }-copy ` ,
348+ query: currentFilter .query ,
349+ });
350+ sdk .window .showToast (` Filter "${duplicated .name }" created ` , {
351+ variant: " success" ,
352+ });
353+ } else {
354+ sdk .window .showToast (" No filter selected" , { variant: " warning" });
355+ }
356+ },
357+ });
358+ };
359+ ```
0 commit comments