Skip to content

Commit

Permalink
Merge branch 'master' into support-check-constraint-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
akashthawaitcc authored Dec 26, 2024
2 parents deabaa6 + fd0dc21 commit b142a67
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests-against-emulator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:

services:
spanner_emulator:
image: gcr.io/cloud-spanner-emulator/emulator:1.5.27
image: gcr.io/cloud-spanner-emulator/emulator:1.5.28
ports:
- 9010:9010
- 9020:9020
Expand Down
1 change: 1 addition & 0 deletions ui/cypress/e2e/spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('template spec', () => {
cy.intercept('GET', `${url}/GetSessions`, { statusCode: 200, body: [] }).as('getSessions');
cy.intercept('GET', `${url}/GetConfig`, { statusCode: 200 }).as('getConfig');
cy.intercept('GET', `${url}/GetLatestSessionDetails`, { statusCode: 200 }).as('getLatestSessionDetails');
cy.intercept('GET', `${url}/IsConfigSet`, { statusCode: 200, body: true }).as('IsConfigSet');
cy.visit('http://localhost:4200/');
});

Expand Down
2 changes: 1 addition & 1 deletion ui/dist/ui/index.html

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion ui/dist/ui/main.1cfa12bd9a851a7a.js

This file was deleted.

1 change: 1 addition & 0 deletions ui/dist/ui/main.c082b8f8593afb56.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { MatInputModule } from '@angular/material/input'
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
import { SnackbarService } from 'src/app/services/snackbar/snackbar.service'
import { MatSnackBarModule } from '@angular/material/snack-bar'
import { MatDialog } from '@angular/material/dialog'

const appRoutes: Routes = [{ path: 'workspace', component: WorkspaceComponent }]

Expand All @@ -35,7 +36,10 @@ describe('DirectConnectionComponent', () => {
BrowserAnimationsModule,
MatSnackBarModule,
],
providers: [SnackbarService],
providers: [
SnackbarService,
{ provide: MatDialog, useValue: {} }
],
}).compileComponents()
})

Expand Down
104 changes: 66 additions & 38 deletions ui/src/app/components/direct-connection/direct-connection.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { DialectList, InputType, PersistedFormValues, StorageKeys } from 'src/ap
import { SnackbarService } from 'src/app/services/snackbar/snackbar.service'
import { extractSourceDbName } from 'src/app/utils/utils'
import { ClickEventService } from 'src/app/services/click-event/click-event.service'
import { MatDialog } from '@angular/material/dialog'
import { InfodialogComponent } from '../infodialog/infodialog.component'

@Component({
selector: 'app-direct-connection',
Expand Down Expand Up @@ -38,6 +40,7 @@ export class DirectConnectionComponent implements OnInit {

connectRequest: any = null
getSchemaRequest: any = null
isConfigSet: boolean = false
shardedResponseList = [
{ value: false, displayName: 'No'},
{ value: true, displayName: 'Yes'},
Expand All @@ -51,7 +54,8 @@ export class DirectConnectionComponent implements OnInit {
private data: DataService,
private loader: LoaderService,
private snackbarService: SnackbarService,
private clickEvent: ClickEventService
private clickEvent: ClickEventService,
private dialog: MatDialog,
) {}

ngOnInit(): void {
Expand Down Expand Up @@ -103,43 +107,67 @@ export class DirectConnectionComponent implements OnInit {
})
}

connectToDb() {
this.clickEvent.openDatabaseLoader('direct', this.connectForm.value.dbName!)
window.scroll(0, 0)
this.data.resetStore()
localStorage.clear()
const { dbEngine, isSharded, hostName, port, userName, password, dbName, dialect } = this.connectForm.value
localStorage.setItem(PersistedFormValues.DirectConnectForm, JSON.stringify(this.connectForm.value))
let config: IDbConfig = {
dbEngine: dbEngine!,
isSharded: isSharded!,
hostName: hostName!,
port: port!,
userName: userName!,
password: password!,
dbName: dbName!,
}
this.connectRequest =this.fetch.connectTodb(config, dialect!).subscribe({
next: () => {
this.getSchemaRequest = this.data.getSchemaConversionFromDb()
this.data.conv.subscribe((res) => {
localStorage.setItem(
StorageKeys.Config,
JSON.stringify({ dbEngine, hostName, port, userName, password, dbName })
)
localStorage.setItem(StorageKeys.Type, InputType.DirectConnect)
localStorage.setItem(StorageKeys.SourceDbName, extractSourceDbName(dbEngine!))
this.clickEvent.closeDatabaseLoader()
//after a successful load, remove the persisted values.
localStorage.removeItem(PersistedFormValues.DirectConnectForm)
this.router.navigate(['/workspace'])
})
},
error: (e) => {
this.snackbarService.openSnackBar(e.error, 'Close')
this.clickEvent.closeDatabaseLoader()
},
})
async connectToDb() {
this.data.updateIsConfigSet();
this.fetch.getIsConfigSet().subscribe({
next: (res: boolean) => {
this.isConfigSet = res;

if (!this.isConfigSet) {
this.dialog.open(InfodialogComponent, {
data: {
message: "Please configure spanner project id and instance id to proceed",
type: 'error',
title: 'Configure Spanner',
},
maxWidth: '500px',
});
return;
}

this.clickEvent.openDatabaseLoader('direct', this.connectForm.value.dbName!);
window.scroll(0, 0);
this.data.resetStore();
localStorage.clear();
const { dbEngine, isSharded, hostName, port, userName, password, dbName, dialect } = this.connectForm.value;
localStorage.setItem(PersistedFormValues.DirectConnectForm, JSON.stringify(this.connectForm.value));

let config: IDbConfig = {
dbEngine: dbEngine!,
isSharded: isSharded!,
hostName: hostName!,
port: port!,
userName: userName!,
password: password!,
dbName: dbName!,
};

this.connectRequest = this.fetch.connectTodb(config, dialect!).subscribe({
next: () => {
this.getSchemaRequest = this.data.getSchemaConversionFromDb();
this.data.conv.subscribe((res) => {
localStorage.setItem(
StorageKeys.Config,
JSON.stringify({ dbEngine, hostName, port, userName, password, dbName })
);
localStorage.setItem(StorageKeys.Type, InputType.DirectConnect);
localStorage.setItem(StorageKeys.SourceDbName, extractSourceDbName(dbEngine!));
this.clickEvent.closeDatabaseLoader();
// After a successful load, remove the persisted values.
localStorage.removeItem(PersistedFormValues.DirectConnectForm);
this.router.navigate(['/workspace']);
});
},
error: (e) => {
this.snackbarService.openSnackBar(e.error, 'Close');
this.clickEvent.closeDatabaseLoader();
},
});
},
error: (err) => {
console.error('Error fetching configuration:', err);
},
});
}

refreshDbSpecifcConnectionOptions() {
Expand Down
8 changes: 8 additions & 0 deletions ui/src/app/services/data/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class DataService {
// currentSessionSub not using any where
private currentSessionSub = new BehaviorSubject({} as ISession)
private isOfflineSub = new BehaviorSubject<boolean>(false)
private isConfigSetSub = new BehaviorSubject<boolean>(false)
private ruleMapSub = new BehaviorSubject<IRule[]>([])
private treeUpdatedSub = new Subject<void>();

Expand All @@ -55,6 +56,7 @@ export class DataService {
sessions = this.sessionsSub.asObservable()
config = this.configSub.asObservable().pipe(filter((res) => Object.keys(res).length !== 0))
isOffline = this.isOfflineSub.asObservable()
isConfigSet = this.isConfigSetSub.asObservable()
currentSession = this.currentSessionSub
.asObservable()
.pipe(filter((res) => Object.keys(res).length !== 0))
Expand Down Expand Up @@ -448,6 +450,12 @@ export class DataService {
})
}

updateIsConfigSet() {
this.fetch.getIsConfigSet().subscribe((res: boolean) => {
this.isConfigSetSub.next(res)
})
}

addColumn(tableId: string,payload: IAddColumn) {
this.fetch.addColumn(tableId,payload).subscribe({
next: (res: any) => {
Expand Down
4 changes: 4 additions & 0 deletions ui/src/app/services/fetch/fetch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ export class FetchService {
return this.http.get<ISpannerConfig>(`${this.url}/GetConfig`)
}

getIsConfigSet() {
return this.http.get<boolean>(`${this.url}/IsConfigSet`);
}

setSpannerConfig(payload: ISpannerConfig) {
return this.http.post<ISpannerConfig>(`${this.url}/SetSpannerConfig`, payload)
}
Expand Down
5 changes: 5 additions & 0 deletions webv2/config/config_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ type ConfigWithMetadata struct {
IsConfigValid bool
}

func IsConfigSet(w http.ResponseWriter, r *http.Request) {
config := TryInitializeSpannerConfig()
json.NewEncoder(w).Encode(config.GCPProjectID != "")
}

func GetConfig(w http.ResponseWriter, r *http.Request) {
content, err := GetSpannerConfig()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions webv2/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func getRoutes() *mux.Router {
// Application Configuration
router.HandleFunc("/GetConfig", config.GetConfig).Methods("GET")
router.HandleFunc("/SetSpannerConfig", config.SetSpannerConfig).Methods("POST")
router.HandleFunc("/IsConfigSet", config.IsConfigSet).Methods("GET")

// Run migration
router.HandleFunc("/Migrate", migrate).Methods("POST")
Expand Down

0 comments on commit b142a67

Please sign in to comment.