@@ -2,7 +2,7 @@ import type { IFilter } from '$comp/faceted-filter';
22import type { PersistentEventKnownTypes } from '$features/events/models' ;
33import type { StackStatus } from '$features/stacks/models' ;
44
5- import { quoteIfSpecialCharacters } from './helpers' ;
5+ import { quoteIfSpecialCharacters } from './helpers.svelte ' ;
66
77export class BooleanFilter implements IFilter {
88 public id : string = crypto . randomUUID ( ) ;
@@ -20,6 +20,12 @@ export class BooleanFilter implements IFilter {
2020 this . value = value ;
2121 }
2222
23+ public clone ( ) : IFilter {
24+ const filter = new BooleanFilter ( this . term , this . value ) ;
25+ filter . id = this . id ;
26+ return filter ;
27+ }
28+
2329 public toFilter ( ) : string {
2430 if ( this . term === undefined ) {
2531 return '' ;
@@ -31,14 +37,6 @@ export class BooleanFilter implements IFilter {
3137
3238 return `${ this . term } :${ this . value } ` ;
3339 }
34-
35- public toJSON ( ) {
36- return {
37- term : this . term ,
38- type : this . type ,
39- value : this . value
40- } ;
41- }
4240}
4341
4442export class DateFilter implements IFilter {
@@ -57,6 +55,12 @@ export class DateFilter implements IFilter {
5755 this . value = value ;
5856 }
5957
58+ public clone ( ) : IFilter {
59+ const filter = new DateFilter ( this . term , this . value ) ;
60+ filter . id = this . id ;
61+ return filter ;
62+ }
63+
6064 public toFilter ( ) : string {
6165 if ( this . term === undefined ) {
6266 return '' ;
@@ -69,14 +73,6 @@ export class DateFilter implements IFilter {
6973 const date = this . value instanceof Date ? this . value . toISOString ( ) : this . value ;
7074 return `${ this . term } :${ quoteIfSpecialCharacters ( date ) } ` ;
7175 }
72-
73- public toJSON ( ) {
74- return {
75- term : this . term ,
76- type : this . type ,
77- value : this . value
78- } ;
79- }
8076}
8177
8278export class KeywordFilter implements IFilter {
@@ -93,20 +89,19 @@ export class KeywordFilter implements IFilter {
9389 this . value = value ;
9490 }
9591
92+ public clone ( ) : IFilter {
93+ const filter = new KeywordFilter ( this . value ) ;
94+ filter . id = this . id ;
95+ return filter ;
96+ }
97+
9698 public toFilter ( ) : string {
9799 if ( ! this . value ?. trim ( ) ) {
98100 return '' ;
99101 }
100102
101103 return this . value ! . trim ( ) ;
102104 }
103-
104- public toJSON ( ) {
105- return {
106- type : this . type ,
107- value : this . value
108- } ;
109- }
110105}
111106
112107export class NumberFilter implements IFilter {
@@ -125,6 +120,12 @@ export class NumberFilter implements IFilter {
125120 this . value = value ;
126121 }
127122
123+ public clone ( ) : IFilter {
124+ const filter = new NumberFilter ( this . term , this . value ) ;
125+ filter . id = this . id ;
126+ return filter ;
127+ }
128+
128129 public toFilter ( ) : string {
129130 if ( this . term === undefined ) {
130131 return '' ;
@@ -136,14 +137,6 @@ export class NumberFilter implements IFilter {
136137
137138 return `${ this . term } :${ this . value } ` ;
138139 }
139-
140- public toJSON ( ) {
141- return {
142- term : this . term ,
143- type : this . type ,
144- value : this . value
145- } ;
146- }
147140}
148141
149142export class ProjectFilter implements IFilter {
@@ -160,6 +153,12 @@ export class ProjectFilter implements IFilter {
160153 this . value = value ;
161154 }
162155
156+ public clone ( ) : IFilter {
157+ const filter = new ProjectFilter ( this . value ) ;
158+ filter . id = this . id ;
159+ return filter ;
160+ }
161+
163162 public toFilter ( ) : string {
164163 if ( this . value . length == 0 ) {
165164 return '' ;
@@ -171,13 +170,6 @@ export class ProjectFilter implements IFilter {
171170
172171 return `(${ this . value . map ( ( val ) => `project:${ val } ` ) . join ( ' OR ' ) } )` ;
173172 }
174-
175- public toJSON ( ) {
176- return {
177- type : this . type ,
178- value : this . value
179- } ;
180- }
181173}
182174
183175export class ReferenceFilter implements IFilter {
@@ -194,20 +186,19 @@ export class ReferenceFilter implements IFilter {
194186 this . value = value ;
195187 }
196188
189+ public clone ( ) : IFilter {
190+ const filter = new ReferenceFilter ( this . value ) ;
191+ filter . id = this . id ;
192+ return filter ;
193+ }
194+
197195 public toFilter ( ) : string {
198196 if ( ! this . value ?. trim ( ) ) {
199197 return '' ;
200198 }
201199
202200 return `reference:${ quoteIfSpecialCharacters ( this . value ) } ` ;
203201 }
204-
205- public toJSON ( ) {
206- return {
207- type : this . type ,
208- value : this . value
209- } ;
210- }
211202}
212203
213204export class SessionFilter implements IFilter {
@@ -224,6 +215,12 @@ export class SessionFilter implements IFilter {
224215 this . value = value ;
225216 }
226217
218+ public clone ( ) : IFilter {
219+ const filter = new SessionFilter ( this . value ) ;
220+ filter . id = this . id ;
221+ return filter ;
222+ }
223+
227224 public toFilter ( ) : string {
228225 if ( ! this . value ?. trim ( ) ) {
229226 return '' ;
@@ -232,13 +229,6 @@ export class SessionFilter implements IFilter {
232229 const session = quoteIfSpecialCharacters ( this . value ) ;
233230 return `(reference:${ session } OR ref.session:${ session } )` ;
234231 }
235-
236- public toJSON ( ) {
237- return {
238- type : this . type ,
239- value : this . value
240- } ;
241- }
242232}
243233
244234export class StatusFilter implements IFilter {
@@ -255,6 +245,12 @@ export class StatusFilter implements IFilter {
255245 this . value = value ;
256246 }
257247
248+ public clone ( ) : IFilter {
249+ const filter = new StatusFilter ( this . value ) ;
250+ filter . id = this . id ;
251+ return filter ;
252+ }
253+
258254 public toFilter ( ) : string {
259255 if ( this . value . length == 0 ) {
260256 return '' ;
@@ -266,13 +262,6 @@ export class StatusFilter implements IFilter {
266262
267263 return `(${ this . value . map ( ( val ) => `status:${ val } ` ) . join ( ' OR ' ) } )` ;
268264 }
269-
270- public toJSON ( ) {
271- return {
272- type : this . type ,
273- value : this . value
274- } ;
275- }
276265}
277266
278267export class StringFilter implements IFilter {
@@ -291,6 +280,12 @@ export class StringFilter implements IFilter {
291280 this . value = value ;
292281 }
293282
283+ public clone ( ) : IFilter {
284+ const filter = new StringFilter ( this . term , this . value ) ;
285+ filter . id = this . id ;
286+ return filter ;
287+ }
288+
294289 public toFilter ( ) : string {
295290 if ( this . term === undefined ) {
296291 return '' ;
@@ -302,14 +297,6 @@ export class StringFilter implements IFilter {
302297
303298 return `${ this . term } :${ quoteIfSpecialCharacters ( this . value ) } ` ;
304299 }
305-
306- public toJSON ( ) {
307- return {
308- term : this . term ,
309- type : this . type ,
310- value : this . value
311- } ;
312- }
313300}
314301
315302export class TypeFilter implements IFilter {
@@ -326,6 +313,12 @@ export class TypeFilter implements IFilter {
326313 this . value = value ;
327314 }
328315
316+ public clone ( ) : IFilter {
317+ const filter = new TypeFilter ( this . value ) ;
318+ filter . id = this . id ;
319+ return filter ;
320+ }
321+
329322 public toFilter ( ) : string {
330323 if ( this . value . length == 0 ) {
331324 return '' ;
@@ -337,13 +330,6 @@ export class TypeFilter implements IFilter {
337330
338331 return `(${ this . value . map ( ( val ) => `type:${ val } ` ) . join ( ' OR ' ) } )` ;
339332 }
340-
341- public toJSON ( ) {
342- return {
343- type : this . type ,
344- value : this . value
345- } ;
346- }
347333}
348334
349335export class VersionFilter implements IFilter {
@@ -362,6 +348,12 @@ export class VersionFilter implements IFilter {
362348 this . value = value ;
363349 }
364350
351+ public clone ( ) : IFilter {
352+ const filter = new VersionFilter ( this . term , this . value ) ;
353+ filter . id = this . id ;
354+ return filter ;
355+ }
356+
365357 public toFilter ( ) : string {
366358 if ( this . term === undefined ) {
367359 return '' ;
@@ -373,12 +365,4 @@ export class VersionFilter implements IFilter {
373365
374366 return `${ this . term } :${ quoteIfSpecialCharacters ( this . value ) } ` ;
375367 }
376-
377- public toJSON ( ) {
378- return {
379- term : this . term ,
380- type : this . type ,
381- value : this . value
382- } ;
383- }
384368}
0 commit comments