diff --git a/packages/host/app/components/operator-mode/create-pr-modal.gts b/packages/host/app/components/operator-mode/create-pr-modal.gts index cf4dbb24dcd..4943676770e 100644 --- a/packages/host/app/components/operator-mode/create-pr-modal.gts +++ b/packages/host/app/components/operator-mode/create-pr-modal.gts @@ -4,18 +4,18 @@ import { service } from '@ember/service'; import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; -import { task } from 'ember-concurrency'; +import { restartableTask, task } from 'ember-concurrency'; import perform from 'ember-concurrency/helpers/perform'; import onKeyMod from 'ember-keyboard/modifiers/on-key'; -import { - Button, - FieldContainer, - RealmIcon, -} from '@cardstack/boxel-ui/components'; +import { Button, FieldContainer } from '@cardstack/boxel-ui/components'; + +import { chooseCard } from '@cardstack/runtime-common'; import CreateListingPRRequestCommand from '@cardstack/host/commands/bot-requests/create-listing-pr-request'; +import CardPill from '@cardstack/host/components/card-pill'; import ModalContainer from '@cardstack/host/components/modal-container'; +import { catalogRealm } from '@cardstack/host/lib/utils'; import type CommandService from '@cardstack/host/services/command-service'; import type OperatorModeStateService from '@cardstack/host/services/operator-mode-state-service'; @@ -31,6 +31,7 @@ export default class CreatePRModal extends Component { @service declare private realm: RealmService; @tracked private isSubmitted = false; + @tracked private selectedListingId?: string; private get payload() { return this.operatorModeStateService.createPRModalPayload; @@ -40,16 +41,19 @@ export default class CreatePRModal extends Component { return Boolean(this.payload); } - private get realmInfo() { - let payload = this.payload; - if (!payload) { + private get listingId() { + return this.selectedListingId ?? this.payload?.listingId; + } + + private get listingTitle(): string | undefined { + if (this.selectedListingId) { return undefined; } - return this.realm.info(payload.realm); + return this.payload?.listingName; } - private get listingName(): string { - return this.payload?.listingName ?? 'Listing'; + private get canChangeListing() { + return Boolean(catalogRealm); } private createPR = task(async () => { @@ -58,18 +62,44 @@ export default class CreatePRModal extends Component { throw new Error('Cannot create PR without a modal payload'); } + let currentListingId = this.listingId; + if (!currentListingId) { + throw new Error('Cannot create PR without a listing'); + } + + let realm = + this.realm.realmOfURL(new URL(currentListingId))?.href ?? payload.realm; + await new CreateListingPRRequestCommand( this.commandService.commandContext, ).execute({ - listingId: payload.listingId, - realm: payload.realm, + listingId: currentListingId, + realm, }); this.isSubmitted = true; }); + private changeListing = restartableTask(async () => { + if (!catalogRealm) { + throw new Error('Cannot find catalog realm'); + } + let listingId = await chooseCard({ + filter: { + type: { + module: `${catalogRealm.url}catalog-app/listing/listing`, + name: 'Listing', + }, + }, + }); + if (listingId) { + this.selectedListingId = listingId; + } + }); + @action private onClose() { this.isSubmitted = false; + this.selectedListingId = undefined; this.operatorModeStateService.dismissCreatePRModal(); } @@ -78,7 +108,7 @@ export default class CreatePRModal extends Component { { <:content> {{#if this.isSubmitted}} @@ -139,8 +176,7 @@ export default class CreatePRModal extends Component { {{else if this.createPR.isRunning}}