Skip to content

Commit f835e56

Browse files
committed
new arg to filter catalog entry type
1 parent d3518d1 commit f835e56

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

packages/base/card-api.gts

+1
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,7 @@ export type BaseDefComponent = ComponentLike<{
18121812
fieldName: string | undefined;
18131813
context?: CardContext;
18141814
canEdit?: boolean;
1815+
linksToType?: CodeRef;
18151816
};
18161817
}>;
18171818

packages/base/catalog-entry.gts

+19-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import CodeRef from './code-ref';
1515
import MarkdownField from './markdown';
1616
import { restartableTask } from 'ember-concurrency';
1717
import { LoadingIndicator } from '@cardstack/boxel-ui/components';
18-
import { loadCard, Loader } from '@cardstack/runtime-common';
18+
import {
19+
codeRefWithAbsoluteURL,
20+
loadCard,
21+
Loader,
22+
} from '@cardstack/runtime-common';
1923
import { eq } from '@cardstack/boxel-ui/helpers';
2024

2125
import GlimmerComponent from '@glimmer/component';
@@ -167,7 +171,7 @@ export class CatalogEntry extends CardDef {
167171
{{#if (eq @model.specType 'field')}}
168172
<@fields.containedExamples />
169173
{{else}}
170-
<@fields.linkedExamples />
174+
<@fields.linkedExamples @linksToType={{@model.ref}} />
171175
{{/if}}
172176
</div>
173177
<div class='module section'>
@@ -328,6 +332,19 @@ export class CatalogEntry extends CardDef {
328332
</style>
329333
</template>
330334
};
335+
336+
static edit = class Edit extends Component<typeof this> {
337+
get absoluteRef() {
338+
if (!this.args.model.ref || !this.args.model.id) {
339+
return undefined;
340+
}
341+
let url = new URL(this.args.model.id);
342+
return codeRefWithAbsoluteURL(this.args.model.ref, url);
343+
}
344+
<template>
345+
<@fields.linkedExamples @linksToType={{this.absoluteRef}} />
346+
</template>
347+
};
331348
}
332349

333350
interface Signature {

packages/base/field-component.gts

+15-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ import Component from '@glimmer/component';
3333

3434
export interface BoxComponentSignature {
3535
Element: HTMLElement; // This may not be true for some field components, but it's true more often than not
36-
Args: { Named: { format?: Format; displayContainer?: boolean } };
36+
Args: {
37+
Named: {
38+
format?: Format;
39+
displayContainer?: boolean;
40+
linksToType?: CodeRef;
41+
};
42+
};
3743
Blocks: {};
3844
}
3945

@@ -185,7 +191,11 @@ export function getBoxComponent(
185191

186192
let component: TemplateOnlyComponent<{
187193
Element: HTMLElement;
188-
Args: { format?: Format; displayContainer?: boolean };
194+
Args: {
195+
format?: Format;
196+
displayContainer?: boolean;
197+
linksToType?: CodeRef;
198+
};
189199
}> = <template>
190200
<CardContextConsumer as |context|>
191201
<PermissionsConsumer as |permissions|>
@@ -238,6 +248,7 @@ export function getBoxComponent(
238248
(not field.computeVia)
239249
permissions.canWrite
240250
}}
251+
@linksToType={{@linksToType}}
241252
/>
242253
</CardContainer>
243254
</DefaultFormatsProvider>
@@ -265,6 +276,7 @@ export function getBoxComponent(
265276
(not field.computeVia)
266277
permissions.canWrite
267278
}}
279+
@linksToType={{@linksToType}}
268280
/>
269281
</div>
270282
</DefaultFormatsProvider>
@@ -281,6 +293,7 @@ export function getBoxComponent(
281293
@fieldName={{model.name}}
282294
@context={{context}}
283295
@canEdit={{and (not field.computeVia) permissions.canWrite}}
296+
@linksToType={{@linksToType}}
284297
...attributes
285298
/>
286299
</DefaultFormatsProvider>

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
getPlural,
3030
CardContextName,
3131
RealmURLContextName,
32+
type CodeRef,
3233
} from '@cardstack/runtime-common';
3334
import { IconMinusCircle, IconX, FourLines } from '@cardstack/boxel-ui/icons';
3435
import { eq } from '@cardstack/boxel-ui/helpers';
@@ -47,6 +48,7 @@ interface Signature {
4748
model: Box<CardDef[]>;
4849
field: Field<typeof CardDef>;
4950
childFormat: 'atom' | 'fitted';
51+
linksToType?: CodeRef;
5052
};
5153
}
5254

@@ -85,8 +87,13 @@ class LinksToManyEditor extends GlimmerComponent<Signature> {
8587
let selectedCardsQuery =
8688
selectedCards?.map((card: any) => ({ not: { eq: { id: card.id } } })) ??
8789
[];
88-
let type = identifyCard(this.args.field.card) ?? baseCardRef;
89-
let filter = { every: [{ type }, ...selectedCardsQuery] };
90+
let type =
91+
this.args.linksToType ??
92+
identifyCard(this.args.field.card) ??
93+
baseCardRef;
94+
let filter = {
95+
every: [{ type }, ...selectedCardsQuery],
96+
};
9097
let chosenCard: CardDef | undefined = await chooseCard(
9198
{ filter },
9299
{
@@ -378,6 +385,7 @@ export function getLinksToManyComponent({
378385
defaultFormats.cardDef
379386
model
380387
}}
388+
@linksToType={{@linksToType}}
381389
...attributes
382390
/>
383391
{{else}}

0 commit comments

Comments
 (0)