Skip to content

Commit

Permalink
Rewire autosave (#1077)
Browse files Browse the repository at this point in the history
* Remove persistence experiment

* Fix autosave status

* Fix share button status and stop generating sessions when disabled

* Respect configured settings for auto-save

* Rewire auto-save and output persistence

* Prevent sign in badge, separate auto-save from output persistence

* Prevent output persistence if auto-save is disabled

* Add saveExecution test
  • Loading branch information
degrammer authored Jan 29, 2024
1 parent fd3047d commit 14325b0
Show file tree
Hide file tree
Showing 17 changed files with 578 additions and 50 deletions.
9 changes: 8 additions & 1 deletion __mocks__/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export class Uri extends URI {
static parse = vi.fn(super.parse)

static joinPath = vi.fn((uri: Uri, ...paths: string[]) => {
/**
* Allow testing against http endpoints
*/
if (uri.authority?.includes('.runme.dev')) {
return `https://testing.runme.dev${path.join(...paths)}`
}
return super.file(path.join(uri.fsPath, ...paths))
})
}
Expand Down Expand Up @@ -280,7 +286,8 @@ export enum TaskScope {
export const ShellExecution = vi.fn()
export const Task = vi.fn()
export const authentication = {
getSession: vi.fn()
getSession: vi.fn(),
onDidChangeSessions: vi.fn()
}

export class WorkspaceEdit {
Expand Down
166 changes: 166 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@
"title": "Reset Session including Environment Variables",
"icon": "$(search-refresh)",
"shortTitle": "Reset Session"
},
{
"command": "runme.resetLoginPrompt",
"category": "Runme",
"title": "Reset login prompt when asking to Signin with GitHub"
}
],
"menus": {
Expand Down Expand Up @@ -339,7 +344,7 @@
},
{
"command": "runme.resetRunnerSession",
"when": "notebookType == runme && notebookHasRunmeOutputs",
"when": "notebookType == runme",
"group": "navigation"
},
{
Expand Down Expand Up @@ -460,12 +465,6 @@
"default": true,
"markdownDescription": "If set to `true`, the extension will bring up the GRPC server."
},
"runme.experiments.outputPersistence": {
"type": "boolean",
"scope": "window",
"default": false,
"markdownDescription": "If set to `true`, the notebook's outputs are stored inside a full copy of the original file per session."
},
"runme.checkout.projectDir": {
"type": "string",
"scope": "machine",
Expand Down Expand Up @@ -673,6 +672,12 @@
],
"default": "no",
"markdownDescription": "Automatically save cell execution output"
},
"runme.app.sessionOutputs": {
"type": "boolean",
"scope": "window",
"default": true,
"markdownDescription": "If set to `true`, the notebook's outputs are stored inside a full copy of the original file per session."
}
}
}
Expand Down Expand Up @@ -924,6 +929,7 @@
"expect-webdriverio": "^4.2.7",
"fork-ts-checker-webpack-plugin": "^9.0.0",
"husky": "^8.0.3",
"msw": "^2.1.5",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.4",
"runme": "^3.1.0",
Expand Down
23 changes: 20 additions & 3 deletions src/client/components/terminal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,15 @@ export class TerminalView extends LitElement {
if (e.output.hasErrors) {
return postClientMessage(ctx, ClientMessages.errorMessage, e.output.data)
}

if (
e.output.data.hasOwnProperty('displayShare') &&
e.output.data.displayShare === false
) {
this.shareText = this.saveText
return
}

const { data } = e.output.data
if (data.createCellExecution) {
const {
Expand Down Expand Up @@ -515,7 +524,7 @@ export class TerminalView extends LitElement {
return
}
this.shareText = this.isAutoSaveEnabled ? this.shareEnabledText : this.saveText
return this.#shareCellOutput()
return this.#shareCellOutput(false)
}
}
}),
Expand Down Expand Up @@ -717,7 +726,14 @@ export class TerminalView extends LitElement {
})
}

async #shareCellOutput(): Promise<boolean | void | undefined> {
async #triggerShareCellOutput(): Promise<boolean | void | undefined> {
return this.#shareCellOutput(true)
}

/**
* @param isUserAction Indicates if the user clicked the save button directly
*/
async #shareCellOutput(isUserAction: boolean): Promise<boolean | void | undefined> {
const ctx = getContext()
if (!ctx.postMessage) {
return
Expand All @@ -744,6 +760,7 @@ export class TerminalView extends LitElement {
await postClientMessage(ctx, ClientMessages.cloudApiRequest, {
data: {
stdout: contentWithAnsi,
isUserAction,
},
id: this.id!,
method: APIMethod.CreateCellExecution,
Expand Down Expand Up @@ -788,7 +805,7 @@ export class TerminalView extends LitElement {
?disabled=${this.isCloudApiLoading}
?displayShareIcon=${this.isShareReady}
shareText="${this.isCloudApiLoading ? 'Saving ...' : this.shareText}"
@onShare="${this.#shareCellOutput}"
@onShare="${this.#triggerShareCellOutput}"
>
</share-cell>`,
() => html``,
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1069,3 +1069,5 @@ export enum WebViews {
export const CATEGORY_SEPARATOR = ','
export const EXECUTION_CELL_STORAGE_KEY = 'executionCell'
export const EXECUTION_CELL_CREATION_DATE_STORAGE_KEY = 'executionCellCreationDate'
export const SAVE_CELL_LOGIN_CONSENT_STORAGE_KEY = 'loginConsent'
export const CLOUD_USER_SIGNED_IN = 'userSignedIn'
Loading

0 comments on commit 14325b0

Please sign in to comment.