Skip to content

Commit c04ce8e

Browse files
committed
update lnksToType to addCardFilter
1 parent f835e56 commit c04ce8e

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed

packages/base/card-api.gts

+10-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
type CardResourceMeta,
4545
CodeRef,
4646
CommandContext,
47+
type Filter,
4748
} from '@cardstack/runtime-common';
4849
import type { ComponentLike } from '@glint/template';
4950
import { initSharedState } from './shared-state';
@@ -1090,7 +1091,13 @@ class LinksTo<CardT extends CardDefConstructor> implements Field<CardT> {
10901091
}
10911092
return class LinksToComponent extends GlimmerComponent<{
10921093
Element: HTMLElement;
1093-
Args: { Named: { format?: Format; displayContainer?: boolean } };
1094+
Args: {
1095+
Named: {
1096+
format?: Format;
1097+
displayContainer?: boolean;
1098+
addCardFilter?: Filter;
1099+
};
1100+
};
10941101
Blocks: {};
10951102
}> {
10961103
<template>
@@ -1099,6 +1106,7 @@ class LinksTo<CardT extends CardDefConstructor> implements Field<CardT> {
10991106
<LinksToEditor
11001107
@model={{(getInnerModel)}}
11011108
@field={{linksToField}}
1109+
@addCardFilter={{@addCardFilter}}
11021110
...attributes
11031111
/>
11041112
{{else}}
@@ -1812,7 +1820,7 @@ export type BaseDefComponent = ComponentLike<{
18121820
fieldName: string | undefined;
18131821
context?: CardContext;
18141822
canEdit?: boolean;
1815-
linksToType?: CodeRef;
1823+
addCardFilter?: Filter;
18161824
};
18171825
}>;
18181826

packages/base/catalog-entry.gts

+12-2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ export class CatalogEntry extends CardDef {
131131
}
132132
});
133133

134+
get addCardFilter() {
135+
return { type: this.args.model.ref };
136+
}
137+
134138
<template>
135139
<div class='container'>
136140
<div class='header'>
@@ -171,7 +175,7 @@ export class CatalogEntry extends CardDef {
171175
{{#if (eq @model.specType 'field')}}
172176
<@fields.containedExamples />
173177
{{else}}
174-
<@fields.linkedExamples @linksToType={{@model.ref}} />
178+
<@fields.linkedExamples @addCardFilter={{@model.ref}} />
175179
{{/if}}
176180
</div>
177181
<div class='module section'>
@@ -341,8 +345,14 @@ export class CatalogEntry extends CardDef {
341345
let url = new URL(this.args.model.id);
342346
return codeRefWithAbsoluteURL(this.args.model.ref, url);
343347
}
348+
349+
get addCardFilter() {
350+
return {
351+
type: this.absoluteRef,
352+
};
353+
}
344354
<template>
345-
<@fields.linkedExamples @linksToType={{this.absoluteRef}} />
355+
<@fields.linkedExamples @addCardFilter={{this.addCardFilter}} />
346356
</template>
347357
};
348358
}

packages/base/field-component.gts

+6-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
Loader,
2222
type CodeRef,
2323
type Permissions,
24+
type Filter,
2425
} from '@cardstack/runtime-common';
2526
import type { ComponentLike } from '@glint/template';
2627
import { CardContainer } from '@cardstack/boxel-ui/components';
@@ -37,7 +38,7 @@ export interface BoxComponentSignature {
3738
Named: {
3839
format?: Format;
3940
displayContainer?: boolean;
40-
linksToType?: CodeRef;
41+
addCardFilter?: Filter;
4142
};
4243
};
4344
Blocks: {};
@@ -194,7 +195,7 @@ export function getBoxComponent(
194195
Args: {
195196
format?: Format;
196197
displayContainer?: boolean;
197-
linksToType?: CodeRef;
198+
addCardFilter?: Filter;
198199
};
199200
}> = <template>
200201
<CardContextConsumer as |context|>
@@ -248,7 +249,7 @@ export function getBoxComponent(
248249
(not field.computeVia)
249250
permissions.canWrite
250251
}}
251-
@linksToType={{@linksToType}}
252+
@addCardFilter={{@addCardFilter}}
252253
/>
253254
</CardContainer>
254255
</DefaultFormatsProvider>
@@ -276,7 +277,7 @@ export function getBoxComponent(
276277
(not field.computeVia)
277278
permissions.canWrite
278279
}}
279-
@linksToType={{@linksToType}}
280+
@addCardFilter={{@addCardFilter}}
280281
/>
281282
</div>
282283
</DefaultFormatsProvider>
@@ -293,7 +294,7 @@ export function getBoxComponent(
293294
@fieldName={{model.name}}
294295
@context={{context}}
295296
@canEdit={{and (not field.computeVia) permissions.canWrite}}
296-
@linksToType={{@linksToType}}
297+
@addCardFilter={{@addCardFilter}}
297298
...attributes
298299
/>
299300
</DefaultFormatsProvider>

packages/base/links-to-editor.gts

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
identifyCard,
2323
CardContextName,
2424
RealmURLContextName,
25+
type Filter,
2526
} from '@cardstack/runtime-common';
2627
import { AddButton, IconButton } from '@cardstack/boxel-ui/components';
2728
import { IconMinusCircle } from '@cardstack/boxel-ui/icons';
@@ -33,6 +34,7 @@ interface Signature {
3334
Args: {
3435
model: Box<CardDef | null>;
3536
field: Field<typeof CardDef>;
37+
addCardFilter?: Filter;
3638
};
3739
}
3840

packages/base/links-to-many-component.gts

+9-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
getPlural,
3030
CardContextName,
3131
RealmURLContextName,
32-
type CodeRef,
32+
type Filter,
3333
} from '@cardstack/runtime-common';
3434
import { IconMinusCircle, IconX, FourLines } from '@cardstack/boxel-ui/icons';
3535
import { eq } from '@cardstack/boxel-ui/helpers';
@@ -48,7 +48,7 @@ interface Signature {
4848
model: Box<CardDef[]>;
4949
field: Field<typeof CardDef>;
5050
childFormat: 'atom' | 'fitted';
51-
linksToType?: CodeRef;
51+
addCardFilter?: Filter;
5252
};
5353
}
5454

@@ -87,12 +87,13 @@ class LinksToManyEditor extends GlimmerComponent<Signature> {
8787
let selectedCardsQuery =
8888
selectedCards?.map((card: any) => ({ not: { eq: { id: card.id } } })) ??
8989
[];
90-
let type =
91-
this.args.linksToType ??
92-
identifyCard(this.args.field.card) ??
93-
baseCardRef;
90+
let type = identifyCard(this.args.field.card) ?? baseCardRef;
9491
let filter = {
95-
every: [{ type }, ...selectedCardsQuery],
92+
every: [
93+
{ type },
94+
...selectedCardsQuery,
95+
...(this.args.addCardFilter ? [this.args.addCardFilter] : []),
96+
],
9697
};
9798
let chosenCard: CardDef | undefined = await chooseCard(
9899
{ filter },
@@ -385,7 +386,7 @@ export function getLinksToManyComponent({
385386
defaultFormats.cardDef
386387
model
387388
}}
388-
@linksToType={{@linksToType}}
389+
@addCardFilter={{@addCardFilter}}
389390
...attributes
390391
/>
391392
{{else}}

0 commit comments

Comments
 (0)