-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Playground panel accordion item (#2098)
* cs-7927 display playground-panel when clicked on card-def * add instance chooser * update getCards and add tests * lint fix * rename getter for clarity
- Loading branch information
1 parent
68873c5
commit 593f8cf
Showing
8 changed files
with
364 additions
and
14 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+118 Bytes
packages/host/app/components/operator-mode/code-submode/playground-background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
169 changes: 169 additions & 0 deletions
169
packages/host/app/components/operator-mode/code-submode/playground-panel.gts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
import type { TemplateOnlyComponent } from '@ember/component/template-only'; | ||
import { action } from '@ember/object'; | ||
import { service } from '@ember/service'; | ||
import Component from '@glimmer/component'; | ||
import { cached, tracked } from '@glimmer/tracking'; | ||
|
||
import { LoadingIndicator, BoxelSelect } from '@cardstack/boxel-ui/components'; | ||
|
||
import { getCards, type ResolvedCodeRef } from '@cardstack/runtime-common'; | ||
|
||
import { getCodeRef, type CardType } from '@cardstack/host/resources/card-type'; | ||
import { ModuleContentsResource } from '@cardstack/host/resources/module-contents'; | ||
|
||
import type RealmServerService from '@cardstack/host/services/realm-server'; | ||
|
||
import type { CardDef } from 'https://cardstack.com/base/card-api'; | ||
|
||
const getItemTitle = (item: CardDef, displayName?: string) => { | ||
if (!item) { | ||
return; | ||
} | ||
if (item.title) { | ||
return item.title; | ||
} | ||
let fallbackName = displayName ?? item.constructor.displayName ?? 'Card'; | ||
return `Untitled ${fallbackName}`; | ||
}; | ||
|
||
const SelectedItem: TemplateOnlyComponent<{ Args: { title?: string } }> = | ||
<template> | ||
<div class='selected-item'> | ||
Instance: | ||
<span class='title' data-test-selected-item> | ||
{{@title}} | ||
</span> | ||
</div> | ||
<style scoped> | ||
.selected-item { | ||
display: flex; | ||
align-items: center; | ||
gap: var(--boxel-sp-xs); | ||
overflow: hidden; | ||
font: 600 var(--boxel-font-xs); | ||
letter-spacing: var(--boxel-lsp-sm); | ||
} | ||
.title { | ||
display: -webkit-box; | ||
-webkit-box-orient: vertical; | ||
-webkit-line-clamp: 2; | ||
} | ||
</style> | ||
</template>; | ||
|
||
interface PlaygroundContentSignature { | ||
Args: { | ||
codeRef: ResolvedCodeRef; | ||
displayName?: string; | ||
}; | ||
} | ||
class PlaygroundPanelContent extends Component<PlaygroundContentSignature> { | ||
<template> | ||
<BoxelSelect | ||
class='instance-chooser' | ||
@options={{this.instances}} | ||
@selected={{this.selectedItem}} | ||
@selectedItemComponent={{if | ||
this.selectedItem | ||
(component | ||
SelectedItem title=(getItemTitle this.selectedItem @displayName) | ||
) | ||
}} | ||
@onChange={{this.onSelect}} | ||
@placeholder='Please Select' | ||
data-test-instance-chooser | ||
as |item| | ||
> | ||
{{getItemTitle item @displayName}} | ||
</BoxelSelect> | ||
<style scoped> | ||
.instance-chooser { | ||
color: var(--boxel-dark); | ||
height: var(--boxel-form-control-height); | ||
} | ||
</style> | ||
</template> | ||
|
||
@service private declare realmServer: RealmServerService; | ||
@tracked private selectedItem?: CardDef; | ||
|
||
private options = getCards( | ||
() => ({ | ||
filter: { type: this.args.codeRef }, | ||
sort: [{ by: 'createdAt', direction: 'desc' }], | ||
}), | ||
() => this.realmServer.availableRealmURLs, | ||
); | ||
|
||
@cached | ||
private get instances() { | ||
if (this.options?.isLoading) { | ||
return undefined; | ||
} | ||
return this.options.instances; | ||
} | ||
|
||
@action private onSelect(item: CardDef) { | ||
this.selectedItem = item; | ||
} | ||
} | ||
|
||
interface Signature { | ||
Args: { | ||
moduleContentsResource: ModuleContentsResource; | ||
cardType?: CardType; | ||
}; | ||
Element: HTMLElement; | ||
} | ||
export default class PlaygroundPanel extends Component<Signature> { | ||
<template> | ||
<section class='playground-panel' data-test-playground-panel> | ||
{{#if this.isLoading}} | ||
<LoadingIndicator class='loading-icon' /> | ||
Loading... | ||
{{else if @cardType.type}} | ||
{{#let (getCodeRef @cardType.type) as |codeRef|}} | ||
{{#if codeRef}} | ||
<PlaygroundPanelContent | ||
@codeRef={{codeRef}} | ||
@displayName={{@cardType.type.displayName}} | ||
/> | ||
{{else}} | ||
Error: Playground could not be loaded. | ||
{{/if}} | ||
{{/let}} | ||
{{else}} | ||
{{! TODO: error state }} | ||
Error: Playground could not be loaded. | ||
{{/if}} | ||
</section> | ||
<style scoped> | ||
.playground-panel { | ||
background-image: url('./playground-background.png'); | ||
background-position: left top; | ||
background-repeat: repeat; | ||
background-size: 22.5px; | ||
height: 100%; | ||
width: 100%; | ||
padding: var(--boxel-sp); | ||
background-color: var(--boxel-dark); | ||
color: var(--boxel-light); | ||
font: var(--boxel-font-sm); | ||
letter-spacing: var(--boxel-lsp-xs); | ||
overflow: auto; | ||
} | ||
.loading-icon { | ||
display: inline-block; | ||
margin-right: var(--boxel-sp-xxxs); | ||
vertical-align: middle; | ||
} | ||
</style> | ||
</template> | ||
|
||
get isLoading() { | ||
return ( | ||
this.args.moduleContentsResource.isLoadingNewModule || | ||
this.args.cardType?.isLoading | ||
); | ||
} | ||
} |
Oops, something went wrong.