Skip to content

Commit

Permalink
added feature with adding schemes after query
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy Borzenko committed Nov 13, 2024
1 parent 9516249 commit 4c58aad
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/app/dataset-view/dataset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export class DatasetService {
map((result: GetDatasetDataSqlRunQuery) => {
const queryResult = result.data.query;
if (queryResult.__typename === "DataQueryResultSuccess") {
const involvedDatasetsId = queryResult.datasets?.map((item) => item.id) ?? [];
const content: DataRow[] = DatasetService.parseDataRows(queryResult);
const schema: MaybeNull<DatasetSchema> = queryResult.schema
? DatasetService.parseSchema(queryResult.schema.content)
Expand All @@ -213,6 +214,7 @@ export class DatasetService {
currentVocab: this.currentSetVocab,
};
this.datasetSubsService.emitSqlQueryDataChanged(dataUpdate);
this.datasetSubsService.emitInvolvedSqlDatasetsId(involvedDatasetsId);
this.datasetSubsService.resetSqlError();
} else if (queryResult.errorKind === DataQueryResultErrorKind.InvalidSql) {
this.datasetSubsService.emitSqlErrorOccurred({
Expand Down
9 changes: 9 additions & 0 deletions src/app/dataset-view/dataset.subscriptions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class DatasetSubscriptionsService {
private permissions$: Subject<DatasetPermissionsFragment> = new ReplaySubject<DatasetPermissionsFragment>(
1 /*bufferSize*/,
);
private involvedSqlDatasetsId$: Subject<string[]> = new ReplaySubject<string[]>(1 /*bufferSize*/);

public emitOverviewChanged(data: OverviewUpdate): void {
this.overview$.next(data);
Expand Down Expand Up @@ -55,6 +56,14 @@ export class DatasetSubscriptionsService {
return this.sqlError$.asObservable();
}

public emitInvolvedSqlDatasetsId(ids: string[]): void {
this.involvedSqlDatasetsId$.next(ids);
}

public get involvedSqlDatasetsIdChanges(): Observable<string[]> {
return this.involvedSqlDatasetsId$.asObservable();
}

// history

public emitHistoryChanged(historyUpdate: MaybeNull<DatasetHistoryUpdate>): void {
Expand Down
69 changes: 53 additions & 16 deletions src/app/query/global-query/global-query.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, inject, OnInit } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { debounceTime, distinctUntilChanged, finalize, Observable, OperatorFunction, switchMap } from "rxjs";
import {
combineLatest,
debounceTime,
distinctUntilChanged,
finalize,
map,
Observable,
OperatorFunction,
switchMap,
} from "rxjs";
import { BaseComponent } from "src/app/common/base.component";
import { DatasetService } from "src/app/dataset-view/dataset.service";
import { DatasetRequestBySql, DatasetSchema } from "src/app/interface/dataset.interface";
Expand All @@ -13,6 +22,7 @@ import { parseCurrentSchema } from "src/app/common/app.helpers";
import { DatasetAutocompleteItem, TypeNames } from "src/app/interface/search.interface";
import { SearchApi } from "src/app/api/search.api";
import { GlobalQuerySearchItem } from "./global-query.model";
import { DatasetSubscriptionsService } from "src/app/dataset-view/dataset.subscriptions.service";

@Component({
selector: "app-global-query",
Expand All @@ -33,8 +43,32 @@ export class GlobalQueryComponent extends BaseComponent implements OnInit {
private datasetService = inject(DatasetService);
private cdr = inject(ChangeDetectorRef);
private appSearchAPI = inject(SearchApi);
private datasetSubsService = inject(DatasetSubscriptionsService);

ngOnInit(): void {}
ngOnInit(): void {
this.datasetSubsService.emitInvolvedSqlDatasetsId([]);
this.datasetSubsService.involvedSqlDatasetsIdChanges
.pipe(
switchMap((ids: string[]) => {
const array = ids.map((id) => this.datasetService.requestDatasetSchema(id));
return combineLatest(array).pipe(
map((datasets: GetDatasetSchemaQuery[]) => {
const result = datasets.map((item) => {
const datasetAlias = item.datasets.byId?.alias;
const schema = parseCurrentSchema(item.datasets.byId?.metadata.currentSchema);
return { datasetAlias, schema } as GlobalQuerySearchItem;
});
return result;
}),
);
}),
takeUntilDestroyed(this.destroyRef),
)
.subscribe((data: GlobalQuerySearchItem[]) => {
this.searchResult = data;
this.cdr.detectChanges();
});
}

public deleteDataset(datasetAlias: string): void {
this.searchResult = this.searchResult.filter(
Expand Down Expand Up @@ -69,22 +103,25 @@ export class GlobalQueryComponent extends BaseComponent implements OnInit {
});
if (value.__typename !== TypeNames.allDataType && !this.inputDatasets.has(inputDataset)) {
this.inputDatasets.add(inputDataset);
this.requestDatasetSchemaById(id);
}
}

this.datasetService
.requestDatasetSchema(id)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((data: GetDatasetSchemaQuery) => {
if (data.datasets.byId) {
const datasetAlias = (data.datasets.byId as DatasetBasicsFragment).alias;
const schema: MaybeNull<DatasetSchema> = parseCurrentSchema(
data.datasets.byId.metadata.currentSchema,
);
private requestDatasetSchemaById(id: string): void {
this.datasetService
.requestDatasetSchema(id)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((data: GetDatasetSchemaQuery) => {
if (data.datasets.byId) {
const datasetAlias = (data.datasets.byId as DatasetBasicsFragment).alias;
const schema: MaybeNull<DatasetSchema> = parseCurrentSchema(
data.datasets.byId.metadata.currentSchema,
);

this.searchResult = [...this.searchResult, { datasetAlias, schema }];
this.cdr.detectChanges();
}
});
}
this.searchResult = [...this.searchResult, { datasetAlias, schema }];
this.cdr.detectChanges();
}
});
}

public clearSearch(): void {
Expand Down

0 comments on commit 4c58aad

Please sign in to comment.