1
1
import GlimmerComponent from ' @glimmer/component' ;
2
2
import { cached , tracked } from ' @glimmer/tracking' ;
3
- import { array } from ' @ember/helper' ;
4
3
import { on } from ' @ember/modifier' ;
5
4
import { action } from ' @ember/object' ;
5
+ import { Button , FieldContainer } from ' @cardstack/boxel-ui/components' ;
6
+ import { eq } from ' @cardstack/boxel-ui/helpers' ;
6
7
import {
7
- BoxelDropdown ,
8
- Button ,
9
- FieldContainer ,
10
- Header ,
11
- IconButton ,
12
- Menu ,
13
- } from ' @cardstack/boxel-ui/components' ;
14
- import { eq , menuItem } from ' @cardstack/boxel-ui/helpers' ;
15
- import {
16
- ArrowLeft ,
17
8
IconMinusCircle ,
18
9
IconPlus ,
19
10
IconSearchThick ,
20
- ThreeDotsHorizontal ,
21
11
} from ' @cardstack/boxel-ui/icons' ;
22
- import { getCard } from ' @cardstack/runtime-common' ;
12
+ import { getCard , primitive } from ' @cardstack/runtime-common' ;
23
13
import {
24
14
BaseDef ,
25
15
CardDef ,
@@ -30,8 +20,8 @@ import {
30
20
field ,
31
21
type CardContext ,
32
22
type Format ,
23
+ FieldDef ,
33
24
} from ' ./card-api' ;
34
- import { CommandObjectField } from ' ./command' ;
35
25
36
26
type AttachedCardResource = {
37
27
card: CardDef | undefined ;
@@ -48,6 +38,10 @@ interface ResourceListSignature {
48
38
context? : CardContext ;
49
39
}
50
40
41
+ export class JsonField extends FieldDef {
42
+ static [primitive ]: Record <string , any >;
43
+ }
44
+
51
45
class ResourceList extends GlimmerComponent <ResourceListSignature > {
52
46
<template >
53
47
<ol class =' result-list {{@ format }} ' data-test-result-list >
@@ -117,7 +111,9 @@ class ResourceList extends GlimmerComponent<ResourceListSignature> {
117
111
</template >
118
112
}
119
113
120
- class CommandResultEmbeddedView extends Component <typeof CommandResult > {
114
+ class SearchCardsResultEmbeddedView extends Component <
115
+ typeof SearchCardsResult
116
+ > {
121
117
@tracked showAllResults = false ;
122
118
123
119
@cached
@@ -181,74 +177,25 @@ class CommandResultEmbeddedView extends Component<typeof CommandResult> {
181
177
}
182
178
183
179
<template >
184
- <div class =' command-result' data-test-command-result >
185
- <Header
186
- @ title =' Search Results'
187
- @ subtitle =' {{this .numberOfCards }} {{if
188
- ( eq this . numberOfCards 1 )
189
- " Result"
190
- " Results"
191
- }} '
192
- @ hasBottomBorder ={{ true }}
193
- class =' header'
194
- data-test-command-result-header
195
- >
196
- <: icon >
197
- <div class =' search-icon-container' >
198
- <IconSearchThick width =' 16' height =' 16' />
199
- </div >
200
- </: icon >
201
- <: actions >
202
- <BoxelDropdown >
203
- <: trigger as | bindings | >
204
- <IconButton
205
- @ icon ={{ThreeDotsHorizontal }}
206
- @ width =' 20px'
207
- @ height =' 20px'
208
- class =' icon-button'
209
- aria-label =' Options'
210
- data-test-more-options-button
211
- {{bindings }}
212
- />
213
- </: trigger >
214
- <: content as | dd | >
215
- <Menu
216
- class =' options-menu'
217
- @ items ={{array
218
- ( menuItem
219
- ' Copy to Workspace' this . copyToWorkspace icon =ArrowLeft
220
- )
221
- }}
222
- @ closeMenu ={{dd.close }}
223
- />
224
- </: content >
225
- </BoxelDropdown >
226
- </: actions >
227
- </Header >
228
- <div class =' body' >
229
- <ResourceList @ resources ={{this .attachedResources }} @ format =' atom' />
230
- <div class =' footer' >
231
- {{#if this . numberOfCardsGreaterThanPaginateSize }}
232
- <Button
233
- @ size =' small'
234
- class =' toggle-show'
235
- {{on ' click' this . toggleShow}}
236
- data-test-toggle-show-button
237
- >
238
- {{#if this . showAllResults }}
239
- <IconMinusCircle
240
- width =' 11px'
241
- height =' 11px'
242
- role =' presentation'
243
- />
244
- {{else }}
245
- <IconPlus width =' 11px' height =' 11px' role =' presentation' />
246
- {{/if }}
180
+ <div class =' command-result' >
181
+ <ResourceList @ resources ={{this .attachedResources }} @ format =' atom' />
182
+ <div class =' footer' >
183
+ {{#if this . numberOfCardsGreaterThanPaginateSize }}
184
+ <Button
185
+ @ size =' small'
186
+ class =' toggle-show'
187
+ {{on ' click' this . toggleShow}}
188
+ data-test-toggle-show-button
189
+ >
190
+ {{#if this . showAllResults }}
191
+ <IconMinusCircle width =' 11px' height =' 11px' role =' presentation' />
192
+ {{else }}
193
+ <IconPlus width =' 11px' height =' 11px' role =' presentation' />
194
+ {{/if }}
247
195
248
- {{this .toggleShowText }}
249
- </Button >
250
- {{/if }}
251
- </div >
196
+ {{this .toggleShowText }}
197
+ </Button >
198
+ {{/if }}
252
199
</div >
253
200
</div >
254
201
<style scoped >
@@ -257,36 +204,6 @@ class CommandResultEmbeddedView extends Component<typeof CommandResult> {
257
204
background-color : var (--boxel-light );
258
205
border-radius : var (--boxel-border-radius );
259
206
--left-padding : var (--boxel-sp-xs );
260
- }
261
- .search-icon-container {
262
- background-color : var (--boxel-border-color );
263
- display : flex ;
264
- padding : var (--boxel-sp-xxxs );
265
- border-radius : var (--boxel-border-radius-sm );
266
- }
267
- .header {
268
- --boxel-label-color : var (--boxel-450 );
269
- --boxel-label-font : 600 var (--boxel-font-xs );
270
- --boxel-header-padding : var (--boxel-sp-xxxs ) var (--boxel-sp-xxxs ) 0
271
- var (--left-padding );
272
- }
273
- .header :deep(.content ) {
274
- gap : 0 ;
275
- }
276
- .icon-button {
277
- --icon-color : var (--boxel-dark );
278
- }
279
- .icon-button :hover {
280
- --icon-color : var (--boxel-highlight );
281
- }
282
- .options-menu :deep(.boxel-menu__item__content ) {
283
- padding-right : var (--boxel-sp-xxs );
284
- padding-left : var (--boxel-sp-xxs );
285
- }
286
- .options-menu :deep(.check-icon ) {
287
- display : none ;
288
- }
289
- .body {
290
207
display : flex ;
291
208
flex-direction : column ;
292
209
font-weight : 600 ;
@@ -322,22 +239,9 @@ class CommandResultEmbeddedView extends Component<typeof CommandResult> {
322
239
}
323
240
< /style >
324
241
</template >
325
-
326
- @action async copyToWorkspace() {
327
- let newCard = await this .args .context ?.actions ?.copyCard ?.(
328
- this .args .model as CardDef ,
329
- );
330
- if (! newCard ) {
331
- console .error (' Could not copy card to workspace.' );
332
- return ;
333
- }
334
- this .args .context ?.actions ?.viewCard (newCard , ' isolated' , {
335
- openCardInRightMostStack: true ,
336
- });
337
- }
338
242
}
339
243
340
- class CommandResultIsolated extends CommandResultEmbeddedView {
244
+ class SearchCardsResultIsolatedView extends SearchCardsResultEmbeddedView {
341
245
<template >
342
246
<section class =' command-result' data-test-command-result-isolated >
343
247
<header >
@@ -351,9 +255,6 @@ class CommandResultIsolated extends CommandResultEmbeddedView {
351
255
<FieldContainer @ label =' Description' >
352
256
{{@ model.description }}
353
257
</FieldContainer >
354
- <FieldContainer @ label =' Filter' >
355
- <pre >{{this .filterString }} </pre >
356
- </FieldContainer >
357
258
<FieldContainer @ label =' Results' class =' results' >
358
259
<ResourceList
359
260
@ resources ={{this .attachedResources }}
@@ -393,38 +294,17 @@ class CommandResultIsolated extends CommandResultEmbeddedView {
393
294
</template >
394
295
395
296
@tracked showAllResults = true ;
396
-
397
- get filterString() {
398
- if (! this .args .model .toolCallArgs ?.attributes .filter ) {
399
- return ;
400
- }
401
- return JSON .stringify (
402
- this .args .model .toolCallArgs .attributes .filter ,
403
- null ,
404
- 2 ,
405
- );
406
- }
407
297
}
408
298
409
- export class CommandResult extends CardDef {
410
- static displayName = ' Command Result' ;
411
- @field toolCallName = contains (StringField );
412
- @field toolCallId = contains (StringField );
413
- @field toolCallArgs = contains (CommandObjectField );
299
+ export class SearchCardsResult extends CardDef {
300
+ static displayName = ' Search Results' ;
301
+ static icon = IconSearchThick ;
414
302
@field cardIds = containsMany (StringField );
303
+ static embedded = SearchCardsResultEmbeddedView ;
304
+ static isolated = SearchCardsResultIsolatedView ;
415
305
@field title = contains (StringField , {
416
- computeVia : function (this : CommandResult ) {
417
- return this .toolCallName === ' searchCard'
418
- ? ' Search Results'
419
- : ' Command Result' ;
306
+ computeVia : function (this : SearchCardsResult ) {
307
+ return ' Search Results' ;
420
308
},
421
309
});
422
- @field description = contains (StringField , {
423
- computeVia : function (this : CommandResult ) {
424
- return this .toolCallArgs ?.description ;
425
- },
426
- });
427
-
428
- static embedded = CommandResultEmbeddedView ;
429
- static isolated = CommandResultIsolated ;
430
310
}
0 commit comments