Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved deno deploy UX #18

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions src/client/components/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { customElement, property } from 'lit/decorators.js'
import '@vscode/webview-ui-toolkit/dist/button/index'

import { getContext } from '../utils'
import { Deployment } from '../../utils/deno/api_types'
import { Deployment, Project } from '../../utils/deno/api_types'
import { ClientMessages } from '../../constants'
import type { ClientMessage } from '../../types'

Expand Down Expand Up @@ -51,8 +51,8 @@ export class DenoOutput extends LitElement {
// Declare reactive properties
@property({ type: Boolean })
deployed = false
@property({ type: String })
project?: string
@property({ type: Object })
project?: Project
@property({ type: Object })
deployments?: Deployment[]

Expand All @@ -63,6 +63,10 @@ export class DenoOutput extends LitElement {
return html`Deploying to Deno...`
}

const project = this.project!
const prodDomainMapping = project.productionDeployment?.domainMappings.reduce((acc, curr) =>
// oldest is prod domain mapping
acc?.createdAt > curr.createdAt ? curr : acc)
const deployment = this.deployments[0]
return html`<section>
<img src="https://www.svgrepo.com/show/378789/deno.svg">
Expand All @@ -74,16 +78,17 @@ export class DenoOutput extends LitElement {
</vscode-link>
` : html`Pending` }
<h4>Project</h4>
<vscode-link href="https://dash.deno.com/projects/${this.project}/deployments">${this.project}</vscode-link>
<vscode-link href="https://dash.deno.com/projects/${project.name}/deployments">
${project.name}
</vscode-link>
</div>
<div>
<h4>Created At</h4>
${this.deployed ? (new Date(deployment.createdAt)).toString() : 'Pending' }
<h4>Status</h4>
${this.deployed
? 'Ready'
: html`Deploying <vscode-spinner />`}

${this.deployed
? ((supportsMessaging && this.#promoted) ? 'Production' : 'Preview')
: html`Deploying <vscode-spinner />`}
${when(this.deployed && supportsMessaging && !this.#promoted, () => html`
<vscode-button
class="btnPromote"
Expand All @@ -93,10 +98,11 @@ export class DenoOutput extends LitElement {
🚀 ${this.#isPromoting ? 'Promoting...' : 'Promote to Production'}
</vscode-button>
`)}
${when(this.deployed && supportsMessaging && this.#promoted, () => html`
${when(this.deployed && supportsMessaging && this.#promoted && project.hasProductionDeployment, () => html`
<p>
Promoted to production: <vscode-link href="https://${deployment.domainMappings[0].domain}">
${deployment.domainMappings[0].domain}
Promoted to 🚀:
<vscode-link href="https://${prodDomainMapping?.domain}">
${prodDomainMapping?.domain}
</vscode-link>
</p>
`)}
Expand Down
2 changes: 1 addition & 1 deletion src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const activate: ActivationFunction = (context: RendererContext<void>) =>
const deno = payload.output as CellOutput<OutputType.deno>['output'] || {}
const denoElem = document.createElement('deno-output')
deno.deployed && denoElem.setAttribute('deployed', deno.deployed.toString())
deno.project && denoElem.setAttribute('project', deno.project)
deno.project && denoElem.setAttribute('project', JSON.stringify(deno.project))
denoElem.setAttribute('deployments', JSON.stringify(deno.deployments))
element.appendChild(denoElem)
break
Expand Down
1 change: 1 addition & 0 deletions src/extension/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import os from 'node:os'

export const PLATFORM_OS = os.platform()
export const DENO_ACCESS_TOKEN_KEY = 'DENO_ACCESS_TOKEN'
export const DENO_PROJECT_NAME_KEY = 'DENO_PROJECT_NAME'

export const DEFAULT_ENV = {
RUNME_TASK: 'true',
Expand Down
9 changes: 6 additions & 3 deletions src/extension/executors/deno/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NotebookCellOutput, NotebookCellOutputItem, NotebookCellExecution } fro

import { renderError } from '../utils'
import { OutputType, ClientMessages } from '../../../constants'
import { ENV_STORE, DENO_ACCESS_TOKEN_KEY } from '../../constants'
import { ENV_STORE, DENO_ACCESS_TOKEN_KEY, DENO_PROJECT_NAME_KEY } from '../../constants'
import { API } from '../../../utils/deno/api'
import type { Kernel } from '../../kernel'
import type { CellOutput, ClientMessage } from '../../../types'
Expand All @@ -12,6 +12,7 @@ export async function deploy (
exec: NotebookCellExecution,
): Promise<boolean> {
let token = ENV_STORE.get(DENO_ACCESS_TOKEN_KEY)
const pname = ENV_STORE.get(DENO_PROJECT_NAME_KEY)

const cancel = new Promise<void>((_, reject) =>
exec.token.onCancellationRequested(() =>
Expand Down Expand Up @@ -41,7 +42,9 @@ export async function deploy (
let iteration = 0
let created = start
while (created <= start && iteration < 30) {
const deployments = await denoAPI.getDeployments(projects![0].id)
// lookup project name if not available use most recent
const project = projects?.find(p => p.name === pname) || projects![0]
const deployments = await denoAPI.getDeployments(project.id)
if ((deployments || []).length > 0) {
created = new Date(deployments![0].createdAt) ?? start
}
Expand All @@ -52,7 +55,7 @@ export async function deploy (
output: {
deployed,
deployments,
project: projects![0].name
project
}
})

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface CellOutput<T extends OutputType> {

interface DenoPayload {
deployed?: boolean
project?: string
project?: any
deployments?: any[]
}

Expand Down