feat(plugin-data-viewer): CB-630 moved source from class scope to create func scope

This commit is contained in:
Naumov Alexey
2021-01-13 19:12:50 +03:00
parent b3a8ecff70
commit 65d7af0013
3 changed files with 8 additions and 9 deletions
@@ -46,12 +46,12 @@ export class ContainerDataSource extends DatabaseDataSource<IDataContainerOption
this.executionContext = null;
}
cancel = (): boolean => {
cancel(): boolean {
if (this.currentFetchTableProcess) {
return this.currentFetchTableProcess.cancel();
}
throw new Error('currentFetchTableProcess must be provided to run cancel method');
};
}
async request(
prevResults: IDataContainerResult[]
@@ -21,13 +21,10 @@ import { TableViewerStorageService } from './TableViewer/TableViewerStorageServi
@injectable()
export class DataViewerTableService {
private source: ContainerDataSource;
constructor(private tableViewerStorageService: TableViewerStorageService,
private connectionInfoResource: ConnectionInfoResource,
private graphQLService: GraphQLService,
private notificationService: NotificationService) {
this.source = new ContainerDataSource(graphQLService, notificationService);
}
has(tableId: string): boolean {
@@ -57,6 +54,7 @@ export class DataViewerTableService {
containerNodePath = ''
): Promise<TableViewerModel> {
const connectionInfo = await this.connectionInfoResource.load(connectionId);
const source = new ContainerDataSource(this.graphQLService, this.notificationService);
return this.tableViewerStorageService.create(
{
@@ -64,10 +62,10 @@ export class DataViewerTableService {
connectionId,
containerNodePath,
access: connectionInfo.readOnly ? DatabaseDataAccessMode.Readonly : DatabaseDataAccessMode.Default,
requestDataAsync: this.requestDataAsync.bind(this),
requestDataAsync: this.requestDataAsync.bind(this, source),
saveChanges: this.saveChanges.bind(this),
},
this.source
source
.setOptions({
connectionId,
containerNodePath,
@@ -127,6 +125,7 @@ export class DataViewerTableService {
}
private async requestDataAsync(
source: ContainerDataSource,
model: TableViewerModel,
offset: number,
count: number,
@@ -156,7 +155,7 @@ export class DataViewerTableService {
},
);
this.source.currentFetchTableProcess = fetchTableProcess;
source.currentFetchTableProcess = fetchTableProcess;
const response = await fetchTableProcess.promise;
const dataSet = response!.results[0].resultSet!; // we expect only one dataset for a table
@@ -104,7 +104,7 @@ export const TableViewer = observer(function TableViewer({
loading={dataModel.isLoading()}
cancelDisabled={!dataModel.source.canCancel}
overlay
onCancel={dataModel.source.cancel}
onCancel={() => dataModel.source.cancel()}
/>
</table-viewer>
);