Skip to content

Commit

Permalink
Add frontend change RPCs
Browse files Browse the repository at this point in the history
Update submodule

update submodule

Revert submodule
  • Loading branch information
wesm committed Feb 26, 2024
1 parent dcca086 commit 8cd668b
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 23 deletions.
7 changes: 0 additions & 7 deletions positron/comms/data_explorer-backend-openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,6 @@
}
}
},
"column_formatted_data": {
"type": "array",
"description": "Column values formatted as strings",
"items": {
"type": "string"
}
},
"column_filter": {
"type": "object",
"description": "Specifies a table row filter based on a column's values",
Expand Down
29 changes: 29 additions & 0 deletions positron/comms/data_explorer-frontend-openrpc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"openrpc": "1.3.0",
"info": {
"title": "Data Explorer Frontend",
"version": "1.0.0"
},
"methods": [
{
"name": "schema_update",
"summary": "Reset after a schema change",
"description": "Fully reset and redraw the data explorer after a schema change.",
"params": [
{
"name": "discard_state",
"description": "If true, the UI should discard the filter/sort state.",
"schema": {
"type": "boolean"
}
}
]
},
{
"name": "data_update",
"summary": "Clear cache and request fresh data",
"description": "Triggered when there is any data change detected, clearing cache data and triggering a refresh/redraw.",
"params": []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,12 @@ export abstract class DataGridInstance extends Disposable {
/**
* Gets or sets the first column index.
*/
private _firstColumnIndex = 0;
protected _firstColumnIndex = 0;

/**
* Gets or sets the first row index.
*/
private _firstRowIndex = 0;
protected _firstRowIndex = 0;

/**
* Gets or sets the cursor column index.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* Copyright (C) 2023-2024 Posit Software, PBC. All rights reserved.
*--------------------------------------------------------------------------------------------*/

import { Event } from 'vs/base/common/event';
import { Emitter, Event } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import { generateUuid } from 'vs/base/common/uuid';
import { IRuntimeClientInstance } from 'vs/workbench/services/languageRuntime/common/languageRuntimeClientInstance';
import { ColumnSortKey, PositronDataExplorerComm, TableData, TableSchema } from 'vs/workbench/services/languageRuntime/common/positronDataExplorerComm';
import { ColumnSortKey, PositronDataExplorerComm, SchemaUpdateEvent, TableData, TableSchema } from 'vs/workbench/services/languageRuntime/common/positronDataExplorerComm';

/**
* A data explorer client instance.
Expand Down Expand Up @@ -40,8 +40,22 @@ export class DataExplorerClientInstance extends Disposable {
this._positronDataExplorerComm = new PositronDataExplorerComm(client);
this._register(this._positronDataExplorerComm);

// Setup events.
// Close emitter
this.onDidClose = this._positronDataExplorerComm.onDidClose;

// Connect schema update emitter
this.onDidSchemaUpdate = this._schemaUpdateEmitter.event;

// Connect data update emitter
this.onDidDataUpdate = this._dataUpdateEmitter.event;

this._positronDataExplorerComm.onDidSchemaUpdate(async (e: SchemaUpdateEvent) => {
this._schemaUpdateEmitter.fire(e);
});

this._positronDataExplorerComm.onDidDataUpdate(async (_evt) => {
this._dataUpdateEmitter.fire();
});
}

//#endregion Constructor & Dispose
Expand Down Expand Up @@ -95,10 +109,24 @@ export class DataExplorerClientInstance extends Disposable {

//#region Public Events


/**
* The onDidClose event.
* Event that fires when the data explorer is closed on the runtime side, as a result of
* a dataset being deallocated or overwritten with a non-dataset.
*/
onDidClose: Event<void>;

/**
* Event that fires when the schema has been updated.
*/
onDidSchemaUpdate: Event<SchemaUpdateEvent>;
private readonly _schemaUpdateEmitter = new Emitter<SchemaUpdateEvent>();

/**
* Event that fires when the data has been updated.
*/
onDidDataUpdate: Event<void>;
private readonly _dataUpdateEmitter = new Emitter<void>();

//#endregion Public Events
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// AUTO-GENERATED from data_explorer.json; do not edit.
//

import { Event } from 'vs/base/common/event';
import { PositronBaseComm } from 'vs/workbench/services/languageRuntime/common/positronBaseComm';
import { IRuntimeClientInstance } from 'vs/workbench/services/languageRuntime/common/languageRuntimeClientInstance';

Expand Down Expand Up @@ -342,13 +343,32 @@ export enum ColumnFilterSearchType {
}

/**
* Column values formatted as strings
* Event: Reset after a schema change
*/
export type ColumnFormattedData = Array<string>;
export interface SchemaUpdateEvent {
/**
* If true, the UI should discard the filter/sort state.
*/
discard_state: boolean;

}

/**
* Event: Clear cache and request fresh data
*/
export interface DataUpdateEvent {
}

export enum DataExplorerFrontendEvent {
SchemaUpdate = 'schema_update',
DataUpdate = 'data_update'
}

export class PositronDataExplorerComm extends PositronBaseComm {
constructor(instance: IRuntimeClientInstance<any, any>) {
super(instance);
this.onDidSchemaUpdate = super.createEventEmitter('schema_update', ['discard_state']);
this.onDidDataUpdate = super.createEventEmitter('data_update', []);
}

/**
Expand Down Expand Up @@ -436,5 +456,19 @@ export class PositronDataExplorerComm extends PositronBaseComm {
return super.performRpc('get_state', [], []);
}


/**
* Reset after a schema change
*
* Fully reset and redraw the data explorer after a schema change.
*/
onDidSchemaUpdate: Event<SchemaUpdateEvent>;
/**
* Clear cache and request fresh data
*
* Triggered when there is any data change detected, clearing cache data
* and triggering a refresh/redraw.
*/
onDidDataUpdate: Event<DataUpdateEvent>;
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TableDataCell } from 'vs/workbench/services/positronDataExplorer/browse
import { TableDataRowHeader } from 'vs/workbench/services/positronDataExplorer/browser/components/tableDataRowHeader';
import { PositronDataExplorerColumn } from 'vs/workbench/services/positronDataExplorer/browser/positronDataExplorerColumn';
import { DataExplorerClientInstance } from 'vs/workbench/services/languageRuntime/common/languageRuntimeDataExplorerClient';
import { ColumnSortKey } from 'vs/workbench/services/languageRuntime/common/positronDataExplorerComm';
import { ColumnSortKey, SchemaUpdateEvent } from 'vs/workbench/services/languageRuntime/common/positronDataExplorerComm';
import {
DataFetchRange,
FetchedData,
Expand All @@ -36,7 +36,7 @@ export class TableDataDataGridInstance extends DataGridInstance {
private _dataCache?: TableDataCache;
private _lastFetchedData?: FetchedData;

private _schemaCache?: TableSchemaCache;
private _schemaCache: TableSchemaCache;
private _lastFetchedSchema?: FetchedSchema;

//#endregion Private Properties
Expand Down Expand Up @@ -72,8 +72,35 @@ export class TableDataDataGridInstance extends DataGridInstance {
cellBorder: true
});

this._schemaCache = new TableSchemaCache(
async (req: SchemaFetchRange) => {
return this._dataExplorerClientInstance.getSchema(req.startIndex,
req.endIndex - req.startIndex);
}
);

// Set the data explorer client instance.
this._dataExplorerClientInstance = dataExplorerClientInstance;

this._dataExplorerClientInstance.onDidSchemaUpdate(async (e: SchemaUpdateEvent) => {
this._lastFetchedData = undefined;
this._lastFetchedSchema = undefined;

// Reset cursor to top left
// TODO: These attributes were made protected to allow this. Add a method to
// reset these without firing an update request which we don't want here yet.
this._firstColumnIndex = 0;
this._firstRowIndex = 0;

// Resets data schema, fetches initial schema and data
this.initialize();
});

this._dataExplorerClientInstance.onDidDataUpdate(async (_evt) => {
this._lastFetchedData = undefined;
this._dataCache?.clear();
this.fetchData();
});
}

//#endregion Constructor
Expand All @@ -96,12 +123,7 @@ export class TableDataDataGridInstance extends DataGridInstance {
*
*/
initialize() {
this._schemaCache = new TableSchemaCache(
async (req: SchemaFetchRange) => {
return this._dataExplorerClientInstance.getSchema(req.startIndex,
req.endIndex - req.startIndex);
}
);
this._schemaCache.clear();
this._schemaCache.initialize().then(async (_) => {
this._lastFetchedSchema = await this._schemaCache?.fetch({ startIndex: 0, endIndex: 1000 });

Expand Down

0 comments on commit 8cd668b

Please sign in to comment.