@@ -4,18 +4,18 @@ import { service } from '@ember/service';
44import Component from ' @glimmer/component' ;
55import { tracked } from ' @glimmer/tracking' ;
66
7- import { task } from ' ember-concurrency' ;
7+ import { restartableTask , task } from ' ember-concurrency' ;
88import perform from ' ember-concurrency/helpers/perform' ;
99import onKeyMod from ' ember-keyboard/modifiers/on-key' ;
1010
11- import {
12- Button ,
13- FieldContainer ,
14- RealmIcon ,
15- } from ' @cardstack/boxel-ui/components' ;
11+ import { Button , FieldContainer } from ' @cardstack/boxel-ui/components' ;
12+
13+ import { chooseCard } from ' @cardstack/runtime-common' ;
1614
1715import CreateListingPRRequestCommand from ' @cardstack/host/commands/bot-requests/create-listing-pr-request' ;
16+ import CardPill from ' @cardstack/host/components/card-pill' ;
1817import ModalContainer from ' @cardstack/host/components/modal-container' ;
18+ import { catalogRealm } from ' @cardstack/host/lib/utils' ;
1919
2020import type CommandService from ' @cardstack/host/services/command-service' ;
2121import type OperatorModeStateService from ' @cardstack/host/services/operator-mode-state-service' ;
@@ -31,6 +31,7 @@ export default class CreatePRModal extends Component<Signature> {
3131 @service declare private realm: RealmService ;
3232
3333 @tracked private isSubmitted = false ;
34+ @tracked private selectedListingId? : string ;
3435
3536 private get payload() {
3637 return this .operatorModeStateService .createPRModalPayload ;
@@ -40,16 +41,19 @@ export default class CreatePRModal extends Component<Signature> {
4041 return Boolean (this .payload );
4142 }
4243
43- private get realmInfo() {
44- let payload = this .payload ;
45- if (! payload ) {
44+ private get listingId() {
45+ return this .selectedListingId ?? this .payload ?.listingId ;
46+ }
47+
48+ private get listingTitle(): string | undefined {
49+ if (this .selectedListingId ) {
4650 return undefined ;
4751 }
48- return this .realm . info ( payload . realm ) ;
52+ return this .payload ?. listingName ;
4953 }
5054
51- private get listingName() : string {
52- return this . payload ?. listingName ?? ' Listing ' ;
55+ private get canChangeListing() {
56+ return Boolean ( catalogRealm ) ;
5357 }
5458
5559 private createPR = task (async () => {
@@ -58,18 +62,44 @@ export default class CreatePRModal extends Component<Signature> {
5862 throw new Error (' Cannot create PR without a modal payload' );
5963 }
6064
65+ let currentListingId = this .listingId ;
66+ if (! currentListingId ) {
67+ throw new Error (' Cannot create PR without a listing' );
68+ }
69+
70+ let realm =
71+ this .realm .realmOfURL (new URL (currentListingId ))?.href ?? payload .realm ;
72+
6173 await new CreateListingPRRequestCommand (
6274 this .commandService .commandContext ,
6375 ).execute ({
64- listingId: payload . listingId ,
65- realm: payload . realm ,
76+ listingId: currentListingId ,
77+ realm ,
6678 });
6779
6880 this .isSubmitted = true ;
6981 });
7082
83+ private changeListing = restartableTask (async () => {
84+ if (! catalogRealm ) {
85+ throw new Error (' Cannot find catalog realm' );
86+ }
87+ let listingId = await chooseCard ({
88+ filter: {
89+ type: {
90+ module: ` ${catalogRealm .url }catalog-app/listing/listing ` ,
91+ name: ' Listing' ,
92+ },
93+ },
94+ });
95+ if (listingId ) {
96+ this .selectedListingId = listingId ;
97+ }
98+ });
99+
71100 @action private onClose() {
72101 this .isSubmitted = false ;
102+ this .selectedListingId = undefined ;
73103 this .operatorModeStateService .dismissCreatePRModal ();
74104 }
75105
@@ -78,7 +108,7 @@ export default class CreatePRModal extends Component<Signature> {
78108 <ModalContainer
79109 class =' create-pr-modal'
80110 @ cardContainerClass =' create-pr'
81- @ title ={{if this . isSubmitted ' Listing Submitted 🎉 ! ' ' Make a PR' }}
111+ @ title ={{if this . isSubmitted ' Listing Submitted 🎉! ' ' Make a PR' }}
82112 @ size =' small'
83113 @ isOpen ={{this .isModalOpen }}
84114 @ onClose ={{this .onClose }}
@@ -87,12 +117,10 @@ export default class CreatePRModal extends Component<Signature> {
87117 <: content >
88118 {{#if this . isSubmitted }}
89119 <div class =' submitted-container' data-test-create-pr-success >
90- <p class =' submitted-message' >
91- Your listing
92- <strong >{{this .listingName }} </strong >
93- has been submitted for review. A PR will be created on GitHub
94- and you will be notified once it is approved.
95- </p >
120+ <div class =' submitted-message' >
121+ Your listing has been submitted for review. A PR will be created
122+ on GitHub and you will be notified once it is approved.
123+ </div >
96124 <Button
97125 @ as =' anchor'
98126 @ kind =' secondary'
@@ -111,15 +139,24 @@ export default class CreatePRModal extends Component<Signature> {
111139 </p >
112140 <FieldContainer @ label =' Listing' class =' field' >
113141 <div class =' field-contents' data-test-create-pr-listing-name >
114- <span >{{this .listingName }} </span >
115- </div >
116- </FieldContainer >
117-
118- <FieldContainer @ label =' Realm' @ tag =' label' class =' field' >
119- <div class =' field-contents' data-test-create-pr-realm >
120- {{#if this . realmInfo }}
121- <RealmIcon class =' realm-icon' @ realmInfo ={{this .realmInfo }} />
122- <span >{{this .realmInfo.name }} </span >
142+ {{#if this . listingId }}
143+ <CardPill
144+ @ cardId ={{this .listingId }}
145+ @ urlForRealmLookup ={{this .listingId }}
146+ @ displayTitle ={{this .listingTitle }}
147+ class =' listing-pill'
148+ />
149+ {{/if }}
150+ {{#if this . canChangeListing }}
151+ <Button
152+ @ kind =' text-only'
153+ @ size =' small'
154+ @ disabled ={{this .createPR.isRunning }}
155+ {{on ' click' ( perform this . changeListing) }}
156+ data-test-create-pr-change-listing-button
157+ >
158+ Change
159+ </Button >
123160 {{/if }}
124161 </div >
125162 </FieldContainer >
@@ -139,8 +176,7 @@ export default class CreatePRModal extends Component<Signature> {
139176 </Button >
140177 {{else if this . createPR.isRunning }}
141178 <p class =' footer-loading-message' data-test-create-pr-loading >
142- Submitting
143- <strong >{{this .listingName }} </strong >. This may take a moment...
179+ Submitting your listing. This may take a moment...
144180 </p >
145181 <Button
146182 @ kind =' primary'
@@ -243,10 +279,11 @@ export default class CreatePRModal extends Component<Signature> {
243279 .field-contents {
244280 display : flex ;
245281 align-items : center ;
282+ justify-content : space-between ;
246283 gap : var (--horizontal-gap );
247284 }
248- .realm- icon {
249- --boxel-realm-icon-size : 1 rem ;
285+ .listing-pill :deep( figure . icon:last-child ) {
286+ display : none ;
250287 }
251288 .footer-buttons {
252289 display : flex ;
0 commit comments