feat(data-viewer-plugin): grid footer menu

refactor(data-viewer-plugin): TableViewerModel
This commit is contained in:
Wroud
2020-04-30 14:48:51 +03:00
parent 75ea44588d
commit 3a8ffb9c24
21 changed files with 383 additions and 148 deletions
@@ -7,23 +7,17 @@
*/
import { IExecutionContext } from '@dbeaver/data-viewer-plugin';
import { SqlExecutionState } from './SqlExecutionState';
import { SQLQueryExecutionProcess } from './SqlResultTabs/SQLQueryExecutionProcess';
export interface ISqlContextParams {
contextId: string;
connectionId: string;
objectCatalogId?: string;
objectSchemaId?: string;
}
export interface ISqlQueryParams extends ISqlContextParams {
export interface ISqlQueryParams extends IExecutionContext {
query: string;
}
export interface ISqlResultPanelParams {
resultTabId: string; // to store tableView in tableViewStore
resultId: string | null; // returns from the server, new id returns after each data fetch
indexInResultSet: number;
sqlQueryParams: ISqlQueryParams;
sqlExecutionState: SqlExecutionState;
@@ -40,7 +34,7 @@ export interface IResultsTabState {
panelParams: ISqlResultPanelParams;
}
export interface ISqlEditorTabState extends ISqlContextParams {
export interface ISqlEditorTabState extends IExecutionContext {
order: number;
query: string;
currentResultTabId?: string;
@@ -21,8 +21,9 @@ import {
import { injectable } from '@dbeaver/core/di';
import { NotificationService } from '@dbeaver/core/eventsLog';
import { GraphQLService } from '@dbeaver/core/sdk';
import { IExecutionContext } from '@dbeaver/data-viewer-plugin';
import { ISqlEditorTabState, ISqlContextParams } from './ISqlEditorTabState';
import { ISqlEditorTabState } from './ISqlEditorTabState';
import { SqlDialectInfoService } from './SqlDialectInfoService';
import { sqlEditorTabHandlerKey } from './sqlEditorTabHandlerKey';
import { SqlExecutionState } from './SqlExecutionState';
@@ -201,7 +202,7 @@ export class SqlEditorNavigatorService {
connectionId: string,
defaultCatalog?: string,
defaultSchema?: string
): Promise<ISqlContextParams> {
): Promise<IExecutionContext> {
const response = await this.gql.gql.sqlContextCreate({
connectionId,
@@ -17,9 +17,9 @@ import { PromiseCancelledError } from '@dbeaver/core/utils';
import {
fetchingSettings,
IRequestDataResult,
ITableViewerModelInit, RowDiff,
TableViewerModel,
RowDiff,
TableViewerStorageService,
TableViewerModel,
} from '@dbeaver/data-viewer-plugin';
import { ISqlResultPanelParams } from '../../ISqlEditorTabState';
@@ -69,10 +69,14 @@ implements IInitializableController<[ISqlResultPanelParams]>, IDestructibleContr
} else {
this.state = EPanelState.TABLE_RESULT;
this.panelInit.resultId = dataSet.resultSet.id;
const initialState = this.sqlResultService
.sqlExecuteInfoToData(response, this.panelInit.indexInResultSet, fetchingSettings.fetchDefault);
this.createTableModel(initialState, panelInit.sqlExecutionState);
this.createTableModel(
initialState,
panelInit.sqlQueryParams.connectionId,
dataSet.resultSet.id,
panelInit.sqlExecutionState
);
}
} catch (exception) {
@@ -109,7 +113,7 @@ implements IInitializableController<[ISqlResultPanelParams]>, IDestructibleContr
destruct() {
if (this.state === EPanelState.TABLE_RESULT) {
this.tableViewerStorageService.removeTableModel(this.getTableId());
this.tableViewerStorageService.remove(this.getTableId());
}
}
@@ -123,20 +127,29 @@ implements IInitializableController<[ISqlResultPanelParams]>, IDestructibleContr
}
}
private createTableModel(initialState: IRequestDataResult, sqlExecutingState: SqlExecutionState): void {
const callbacks: ITableViewerModelInit = {
private createTableModel(
initialState: IRequestDataResult,
connectionId: string,
resultId: string,
sqlExecutingState: SqlExecutionState
) {
return this.tableViewerStorageService.create({
tableId: this.getTableId(),
connectionId,
resultId,
initialState,
requestDataAsync: this.requestDataAsync.bind(this, sqlExecutingState),
noLoaderWhileRequestingDataAsync: true,
saveChanges: this.saveChanges.bind(this),
};
const table = new TableViewerModel(callbacks, this.commonDialogService);
this.tableViewerStorageService.addTableModel(this.getTableId(), table);
});
}
private async requestDataAsync(sqlExecutingState: SqlExecutionState,
rowOffset: number,
count: number): Promise<IRequestDataResult> {
private async requestDataAsync(
sqlExecutingState: SqlExecutionState,
model: TableViewerModel,
rowOffset: number,
count: number,
): Promise<IRequestDataResult> {
const queryExecutionProcess = this.sqlResultService.asyncSqlQuery(this.panelInit.sqlQueryParams, rowOffset, count);
sqlExecutingState.setCurrentlyExecutingQuery(queryExecutionProcess);
@@ -147,14 +160,16 @@ implements IInitializableController<[ISqlResultPanelParams]>, IDestructibleContr
* Note that each data fetching overwrites resultId
*/
const dataSet = response.results![this.panelInit.indexInResultSet]!.resultSet!;
this.panelInit.resultId = dataSet.id;
model.resultId = dataSet.id;
return dataResults;
}
async saveChanges(diffs: RowDiff[]): Promise<IRequestDataResult> {
async saveChanges(model: TableViewerModel, diffs: RowDiff[]): Promise<IRequestDataResult> {
if (!model.resultId) {
throw new Error('resultId must be provided before saving changes');
}
const resultId = this.panelInit.resultId!; // must be set after first data request;
const response = await this.sqlResultService.saveChanges(this.panelInit.sqlQueryParams, resultId, diffs);
const response = await this.sqlResultService.saveChanges(this.panelInit.sqlQueryParams, model.resultId, diffs);
return this.sqlResultService.sqlExecuteInfoToData(response, this.panelInit.indexInResultSet);
}
@@ -23,7 +23,6 @@ export class SqlResultService {
constructor(private graphQLService: GraphQLService,
private notificationService: NotificationService) { }
/**
* @deprecated use asyncSqlQuery
*/
@@ -7,7 +7,7 @@
*/
import { injectable } from '@dbeaver/core/di';
import { isPromiseCancelledError, PromiseCancelledError, uuid } from '@dbeaver/core/utils';
import { isPromiseCancelledError, uuid } from '@dbeaver/core/utils';
import { fetchingSettings } from '@dbeaver/data-viewer-plugin';
import {
@@ -38,10 +38,9 @@ export class SqlResultTabsService {
editorState.sqlExecutionState.setCurrentlyExecutingQuery(queryExecutionProcess);
function createTabPanelParams(resultId: string | null, indexInResultSet: number): ISqlResultPanelParams {
function createTabPanelParams(indexInResultSet: number): ISqlResultPanelParams {
const params: ISqlResultPanelParams = {
resultTabId: uuid(),
resultId,
indexInResultSet,
sqlQueryParams,
firstDataPortion: queryExecutionProcess,
@@ -50,7 +49,7 @@ export class SqlResultTabsService {
return params;
}
const firstTabPanelParams = createTabPanelParams(null, 0);
const firstTabPanelParams = createTabPanelParams(0);
const currentTab = editorState.resultTabs.find(tab => tab.resultTabId === editorState.currentResultTabId);
const groupToReplace = inNewTab ? undefined : currentTab?.groupId;
@@ -75,7 +74,7 @@ export class SqlResultTabsService {
if (data.results && data.results?.length > 1) {
// ignore first dataset, it was already added
for (let i = 1; i < data.results.length; i++) {
const tabPanelParams = createTabPanelParams(data.results[i].resultSet?.id || null, i);
const tabPanelParams = createTabPanelParams(i);
this.addTabToGroup(editorState.resultTabs, tabPanelParams, newGroupId);
}
}