Skip to content

Commit

Permalink
Merge pull request #95 from polypheny/console-namespace-fix
Browse files Browse the repository at this point in the history
Fix to correctly set and persist namespace in the console
  • Loading branch information
vogti authored May 18, 2024
2 parents a74a97e + 362396a commit a6fddbb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/app/views/adapters/adapters.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ <h4 cModalTitle>{{ activeMode() ? "Settings" : "Deployment Mode" }}</h4>
[formControlName]="control.key"
(change)="onChange(control.key,control.value)">
<option *ngFor="let option of getAdapterSetting(control.key).template.options"
[value]="option">{{ getAdapterSetting(control.key).template.alias[option] }}
[value]="option">{{ getAdapterSetting(control.key).template?.alias?.[option] ? getAdapterSetting(control.key).template?.alias?.[option] : option }}
</option>
</select>
<c-form-feedback>{{ getGenericFeedback(control.key) }}</c-form-feedback>
Expand Down
39 changes: 25 additions & 14 deletions src/app/views/querying/console/console.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class ConsoleComponent implements OnInit, OnDestroy {
confirmDeletingHistory;
readonly activeNamespace: WritableSignal<string> = signal(null);
readonly namespaces: WritableSignal<NamespaceModel[]> = signal([]);
delayedNamespace: string = null

entityConfig: EntityConfig = {
create: false,
Expand Down Expand Up @@ -98,7 +99,6 @@ export class ConsoleComponent implements OnInit, OnDestroy {
const namespace = this._catalog.namespaces();
untracked(() => {
this.namespaces.set(Array.from(namespace.values()));
this.loadAndSetNamespaceDB();
});
});

Expand Down Expand Up @@ -133,6 +133,7 @@ export class ConsoleComponent implements OnInit, OnDestroy {
if (!namespaceName) {
return;
}

this.activeNamespace.set(namespaceName);

this.storeNamespace(namespaceName);
Expand All @@ -149,27 +150,32 @@ export class ConsoleComponent implements OnInit, OnDestroy {


submitQuery() {
this.delayedNamespace = null;
const code = this.codeEditor.getCode();
if (!code) {
return;
}
if (this.saveInHistory) {
this.addToHistory(code, this.language());
}
if (this.usesAdvancedConsole(this.language())) { // maybe adjust
const matchGraph = code.toLowerCase().match('use graph [a-zA-Z][a-zA-Z0-1]*');
if (matchGraph !== null && matchGraph.length >= 0) {
const namespace = matchGraph[matchGraph.length - 1].replace('use ', '');
this.activeNamespace.set(namespace);
}
if (this.usesAdvancedConsole(this.language())) {
code.split(";").forEach((query: string) => {
// maybe adjust
const graphUse = /use *graph *([a-zA-Z][a-zA-Z0-9-_]*)/gmi
const matchGraph = graphUse.exec(query.trim());
if (matchGraph !== null && matchGraph.length > 1) {
this.delayedNamespace = matchGraph[1];
}

const match = code.toLowerCase().match('use [a-zA-Z][a-zA-Z0-1]*');
if (match !== null && match.length >= 0) {
const namespace = match[match.length - 1].replace('use ', '');
if (namespace !== 'placement') {
this.activeNamespace.set(namespace);
const useRegex = /use ([a-zA-Z][a-zA-Z0-9-_]*)/gmi
const match = useRegex.exec(query.trim());
if (match !== null && match.length > 1) {
const namespace = match[1];
if (namespace !== 'placement') {
this.delayedNamespace = namespace;
}
}
}
})


if (code.match('show db')) {
Expand Down Expand Up @@ -315,6 +321,12 @@ export class ConsoleComponent implements OnInit, OnDestroy {
}

} else if (Array.isArray(msg) && ((msg[0].hasOwnProperty('data') || msg[0].hasOwnProperty('affectedTuples') || msg[0].hasOwnProperty('error')))) { // array of ResultSets
if (this.delayedNamespace && !msg[0].hasOwnProperty('error')) {
this.activeNamespace.set(this.delayedNamespace);
this.storeNamespace(this.delayedNamespace)
}
this.delayedNamespace = null;

this.loading.set(false);
this.results.set(<Result<any, any>[]>msg);

Expand Down Expand Up @@ -425,7 +437,6 @@ export class ConsoleComponent implements OnInit, OnDestroy {
}

changedDefaultDB(n) {
console.log(n);
this.activeNamespace.set(n);
}

Expand Down

0 comments on commit a6fddbb

Please sign in to comment.