@@ -21,8 +21,8 @@ import {
21
21
chooseFile ,
22
22
} from ' @cardstack/runtime-common' ;
23
23
24
- import Pill from ' @cardstack/host/components/pill' ;
25
-
24
+ import CardPill from ' @cardstack/host/components/card- pill' ;
25
+ import FilePill from ' @cardstack/host/components/file-pill ' ;
26
26
import ENV from ' @cardstack/host/config/environment' ;
27
27
28
28
import { type CardDef } from ' https://cardstack.com/base/card-api' ;
@@ -34,8 +34,8 @@ interface Signature {
34
34
Element: HTMLDivElement ;
35
35
Args: {
36
36
autoAttachedCards? : TrackedSet <CardDef >;
37
- autoAttachedFiles? : FileDef [];
38
37
cardsToAttach: CardDef [] | undefined ;
38
+ autoAttachedFile? : FileDef ;
39
39
filesToAttach: FileDef [] | undefined ;
40
40
chooseCard: (card : CardDef ) => void ;
41
41
removeCard: (card : CardDef ) => void ;
@@ -53,30 +53,51 @@ export default class AiAssistantAttachmentPicker extends Component<Signature> {
53
53
<template >
54
54
<div class =' item-picker' >
55
55
{{#each this . itemsToDisplay as | item | }}
56
- {{#if ( this.isAutoAttached item ) }}
57
- <Tooltip @ placement =' top' >
58
- <: trigger >
59
- <Pill
60
- @ item ={{item }}
61
- @ isAutoAttached ={{ true }}
62
- @ remove ={{this .removeItem }}
63
- />
64
- </: trigger >
56
+ {{#if ( this.isCard item ) }}
57
+ {{#if ( this.isAutoAttachedCard item ) }}
58
+ <Tooltip @ placement =' top' >
59
+ <: trigger >
60
+ <CardPill
61
+ @ card ={{item }}
62
+ @ isAutoAttachedCard ={{ true }}
63
+ @ removeCard ={{@ removeCard }}
64
+ />
65
+ </: trigger >
65
66
66
- <: content >
67
- {{#if ( this.isAutoAttached item ) }}
68
- Topmost
69
- {{if ( this.isCard item ) ' card' ' file' }}
70
- is shared automatically
71
- {{/if }}
72
- </: content >
73
- </Tooltip >
67
+ <: content >
68
+ {{#if ( this.isAutoAttachedCard item ) }}
69
+ Topmost card is shared automatically
70
+ {{/if }}
71
+ </: content >
72
+ </Tooltip >
73
+ {{else }}
74
+ <CardPill
75
+ @ card ={{item }}
76
+ @ isAutoAttachedCard ={{ false }}
77
+ @ removeCard ={{@ removeCard }}
78
+ />
79
+ {{/if }}
74
80
{{else }}
75
- <Pill
76
- @ item ={{item }}
77
- @ isAutoAttached ={{ false }}
78
- @ remove ={{this .removeItem }}
79
- />
81
+ {{#if ( this.isAutoAttachedFile item ) }}
82
+ <Tooltip @ placement =' top' >
83
+ <: trigger >
84
+ <FilePill
85
+ @ file ={{item }}
86
+ @ isAutoAttachedFile ={{ true }}
87
+ @ removeFile ={{@ removeFile }}
88
+ />
89
+ </: trigger >
90
+ <: content >
91
+ Currently opened file is shared automatically
92
+ </: content >
93
+ </Tooltip >
94
+ {{else }}
95
+ <FilePill
96
+ @ file ={{item }}
97
+ @ isAutoAttachedFile ={{ false }}
98
+ @ removeFile ={{@ removeFile }}
99
+ />
100
+ {{/if }}
80
101
{{/if }}
81
102
{{/each }}
82
103
{{#if
@@ -170,37 +191,29 @@ export default class AiAssistantAttachmentPicker extends Component<Signature> {
170
191
};
171
192
172
193
private isAutoAttachedCard = (card : CardDef ) => {
173
- if (this .args .autoAttachedCards === undefined ) {
174
- return false ;
175
- }
176
- return this .args .autoAttachedCards .has (card );
194
+ return this .args .autoAttachedCards ?.has (card );
177
195
};
178
196
179
197
private isAutoAttachedFile = (file : FileDef ) => {
180
- if (this .args .autoAttachedFiles === undefined ) {
181
- return false ;
182
- }
183
- return this .args .autoAttachedFiles .includes (file );
184
- };
185
-
186
- private isAutoAttached = (item : CardDef | FileDef ) => {
187
- return this .isCard (item )
188
- ? this .isAutoAttachedCard (item )
189
- : this .isAutoAttachedFile (item );
198
+ return this .args .autoAttachedFile ?.sourceUrl === file .sourceUrl ;
190
199
};
191
200
192
201
private get items() {
193
202
let cards = this .args .cardsToAttach ?? [];
194
- let files = this . args . filesToAttach ?? [];
203
+
195
204
if (this .args .autoAttachedCards ) {
196
205
cards = [... new Set ([... this .args .autoAttachedCards , ... cards ])];
197
206
}
198
207
199
208
cards = cards .filter ((card ) => card .id ); // Dont show new unsaved cards
200
-
201
- if (this .args .autoAttachedFiles ) {
202
- files = [... new Set ([... this .args .autoAttachedFiles , ... files ])];
209
+ let files : FileDef [] = [];
210
+ if (this .args .autoAttachedFile ) {
211
+ files = [... new Set ([this .args .autoAttachedFile ])];
203
212
}
213
+ if (this .args .filesToAttach ) {
214
+ files = [... files , ... this .args .filesToAttach ];
215
+ }
216
+
204
217
return [... cards , ... files ];
205
218
}
206
219
@@ -244,13 +257,4 @@ export default class AiAssistantAttachmentPicker extends Component<Signature> {
244
257
let chosenFile: FileDef | undefined = await chooseFile ();
245
258
return chosenFile ;
246
259
});
247
-
248
- @action
249
- private removeItem(item : CardDef | FileDef ) {
250
- if (isCardInstance (item )) {
251
- this .args .removeCard (item );
252
- } else {
253
- this .args .removeFile (item );
254
- }
255
- }
256
260
}
0 commit comments