Skip to content

Commit

Permalink
feat: create sequence UI (#828)
Browse files Browse the repository at this point in the history
* feat: uuid changes

* changes

* linting

* test cases

* fixes

tests

tests

tests

test fix

* fixes

* changes

* changes

* changes

* changes to backend

* changes to backend

* ui

* changes

* changes

* merge changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* tests

* create sequence backend

* fixing css

* cahnegs

* comment fixes

* change

* tests

* fixes

* changes

* changes

* comment changes

* comment changes

* test

* test
  • Loading branch information
asthamohta authored Jun 3, 2024
1 parent 4af4747 commit 8c5e085
Show file tree
Hide file tree
Showing 38 changed files with 963 additions and 78 deletions.
3 changes: 2 additions & 1 deletion accessors/spanner/spanner_accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ func (sp *SpannerAccessorImpl) UpdateDDLForeignKeys(ctx context.Context, adminCl
// The schema we send to Spanner excludes comments (since Cloud
// Spanner DDL doesn't accept them), and protects table and col names
// using backticks (to avoid any issues with Spanner reserved words).
fkStmts := ddl.GetDDL(ddl.Config{Comments: false, ProtectIds: true, Tables: false, ForeignKeys: true, SpDialect: conv.SpDialect, Source: driver}, conv.SpSchema, conv.SpSequences)
// Sequences will not be passed as they have already been created.
fkStmts := ddl.GetDDL(ddl.Config{Comments: false, ProtectIds: true, Tables: false, ForeignKeys: true, SpDialect: conv.SpDialect, Source: driver}, conv.SpSchema, make(map[string]ddl.Sequence))
if len(fkStmts) == 0 {
return
}
Expand Down
3 changes: 2 additions & 1 deletion ui/cypress/e2e/spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ describe('template spec', () => {
// Check that workspace is rendered with correct number of tables in Object Viewer
cy.url().should('include', '/workspace');
cy.fixture('mysql-config').then((json) => {
cy.get('#table-and-index-list').find('tbody tr').should('have.length', json.tableCount + 2);
cy.get('#schema-object-list').find('tbody tr').should('have.length', json.tableCount + 3);
cy.get('#schema-object-list').contains('td', 'Sequences (1)').should('exist');
})
});
});
8 changes: 4 additions & 4 deletions ui/dist/ui/index.html

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

This file was deleted.

1 change: 0 additions & 1 deletion ui/dist/ui/polyfills.0ace4ea3e0ea1aea.js

This file was deleted.

1 change: 1 addition & 0 deletions ui/dist/ui/polyfills.c2c201edf5092294.js

Large diffs are not rendered by default.

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

1 change: 1 addition & 0 deletions ui/dist/ui/styles.9b18c896a09ee20d.css

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion ui/dist/ui/styles.bf77748ba70110fe.css

This file was deleted.

19 changes: 19 additions & 0 deletions ui/src/app/app.constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { MatDialogConfig } from "@angular/material/dialog"

export enum InputType {
DirectConnect = 'directConnect',
DumpFile = 'dumpFile',
Expand All @@ -24,6 +26,8 @@ export enum ObjectExplorerNodeType {
Table = 'tableName',
Indexes = 'indexes',
Index = 'indexName',
Sequences = 'sequences',
Sequence = 'sequenceName'
}

export enum RulesTypes {
Expand All @@ -40,6 +44,7 @@ export enum MigrationModes {
export enum ObjectDetailNodeType {
Table = 'table',
Index = 'index',
Sequence = 'sequence'
}

export enum MigrationTypes {
Expand Down Expand Up @@ -149,4 +154,18 @@ export const DataTypes = {
export enum PersistedFormValues {
DirectConnectForm = 'directConnectForm',
IsConnectionSuccessful = 'isConnectionSuccessful'
}

export const autoGenSupportedDbs: string[] = ['MySQL']

export const dialogConfigAddSequence: MatDialogConfig<any> = {
width: '50%',
minWidth: '40%',
maxWidth: '70%',
}

export const dialogConfigDropComponent: MatDialogConfig<any> = {
width: '100%',
minWidth: '50%',
maxWidth: '75%',
}
6 changes: 4 additions & 2 deletions ui/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { AddIndexFormComponent } from './components/add-index-form/add-index-for
import { EditGlobalDatatypeFormComponent } from './components/edit-global-datatype-form/edit-global-datatype-form.component'
import { SidenavViewAssessmentComponent } from './components/sidenav-view-assessment/sidenav-view-assessment.component'
import { SidenavSaveSessionComponent } from './components/sidenav-save-session/sidenav-save-session.component'
import { DropIndexOrTableDialogComponent } from './components/drop-index-or-table-dialog/drop-index-or-table-dialog.component'
import { DropObjectDetailDialogComponent } from './components/drop-object-detail-dialog/drop-object-detail-dialog.component'
import { DatabaseLoaderComponent } from './components/database-loader/database-loader.component'
import { PrepareMigrationComponent } from './components/prepare-migration/prepare-migration.component'
import { TargetDetailsFormComponent } from './components/target-details-form/target-details-form.component'
Expand All @@ -53,6 +53,7 @@ import { AddShardIdPrimaryKeyComponent } from './components/add-shard-id-primary
import { EquivalentGcloudCommandComponent } from './components/equivalent-gcloud-command/equivalent-gcloud-command.component';
import { TuneDatastreamFormComponent } from './components/tune-datastream-form/tune-datastream-form.component';
import { TuneGcsFormComponent } from './components/tune-gcs-form/tune-gcs-form.component';
import { AddNewSequenceComponent } from './components/add-new-sequence/add-new-sequence.component'

@NgModule({
declarations: [
Expand Down Expand Up @@ -80,7 +81,7 @@ import { TuneGcsFormComponent } from './components/tune-gcs-form/tune-gcs-form.c
SidenavViewAssessmentComponent,
SidenavSaveSessionComponent,
DatabaseLoaderComponent,
DropIndexOrTableDialogComponent,
DropObjectDetailDialogComponent,
PrepareMigrationComponent,
TargetDetailsFormComponent,
ConnectionProfileFormComponent,
Expand All @@ -98,6 +99,7 @@ import { TuneGcsFormComponent } from './components/tune-gcs-form/tune-gcs-form.c
EquivalentGcloudCommandComponent,
TuneDatastreamFormComponent,
TuneGcsFormComponent,
AddNewSequenceComponent
],
imports: [
BrowserModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<div mat-dialog-content>
<form [formGroup]="addNewSequenceForm" class="add-new-sequence-form">
<h2>Sequence Details</h2>
<mat-form-field class="full-width" appearance="outline">
<mat-label>Name</mat-label>
<input matInput placeholder="Sequence Name" type="text" formControlName="name" />
</mat-form-field>
<br>
<mat-form-field appearance="outline">
<mat-label>Sequence Type</mat-label>
<mat-select [(ngModel)]="selectedSequenceKind" class="input-field" formControlName="sequenceKind" required="true">
<mat-option *ngFor="let sk of sequenceKinds" [value]="sk">{{sk}}</mat-option>
</mat-select>
</mat-form-field>
<br>
<mat-form-field class="full-width" appearance="outline">
<mat-label>Skip Range Minimum</mat-label>
<input matInput placeholder="Skip Range Min" type="text" formControlName="skipRangeMin" />
</mat-form-field>
<br>
<mat-form-field class="full-width" appearance="outline">
<mat-label>Skip Range Maximum</mat-label>
<input matInput placeholder="Skip Range Max" type="text" formControlName="skipRangeMax" />
</mat-form-field>
<br>
<mat-form-field class="full-width" appearance="outline">
<mat-label>Start With Counter</mat-label>
<input matInput placeholder="Start With Counter" type="text" formControlName="startWithCounter" />
</mat-form-field>
<br>
</form>
<div mat-dialog-actions class="buttons-container">
<button mat-button color="primary" mat-dialog-close>CANCEL</button>
<button mat-button type="submit" color="primary" [disabled]="!(addNewSequenceForm.valid)"
(click)="addNewSequence()">
ADD
</button>
</div>
</div>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { HttpClientModule } from '@angular/common/http';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { MatDialogModule, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { AddNewSequenceComponent } from './add-new-sequence.component';
import { DataService } from 'src/app/services/data/data.service';

describe('AddNewSequenceComponent', () => {
let component: AddNewSequenceComponent;
let fixture: ComponentFixture<AddNewSequenceComponent>;
let dataServiceSpy: jasmine.SpyObj<DataService>;

beforeEach(async () => {
dataServiceSpy = jasmine.createSpyObj('DataService', ['addSequence']);
await TestBed.configureTestingModule({
declarations: [AddNewSequenceComponent],
imports: [ReactiveFormsModule, HttpClientModule, MatSnackBarModule, MatDialogModule, MatSelectModule, MatInputModule, BrowserAnimationsModule],
providers: [
{
provide: MatDialogRef,
useValue: {
close: () => { },
},
},
{
provide: DataService,
useValue: dataServiceSpy
}
],
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(AddNewSequenceComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('add new sequence', () => {
let formBuilder = new FormBuilder()
component.addNewSequenceForm = formBuilder.group({})
component.addNewSequence()
expect(dataServiceSpy.addSequence).toHaveBeenCalled()
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Component, OnInit} from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatDialogRef} from '@angular/material/dialog';
import ICreateSequence from 'src/app/model/auto-gen';
import { DataService } from 'src/app/services/data/data.service';
import { FetchService } from 'src/app/services/fetch/fetch.service'
import { linkedFieldsValidatorSequence } from 'src/app/utils/utils';
@Component({
selector: 'app-add-new-sequence',
templateUrl: './add-new-sequence.component.html',
styleUrls: ['./add-new-sequence.component.scss']
})

export class AddNewSequenceComponent implements OnInit {
addNewSequenceForm: FormGroup
selectedSequenceKind: string = ""
sequenceKinds : string[] = []
constructor(
private formBuilder: FormBuilder,
private dataService: DataService,
private fetchSerice: FetchService,
private dialogRef: MatDialogRef<AddNewSequenceComponent>) {
this.addNewSequenceForm = this.formBuilder.group({
name: ['', [Validators.required, Validators.minLength(1), Validators.maxLength(128), Validators.pattern('^[a-zA-Z][a-zA-Z0-9_]*$')]],
sequenceKind: ['', Validators.required],
skipRangeMin: ['', Validators.pattern('^[0-9]+$')],
skipRangeMax: ['', Validators.pattern('^[0-9]+$')],
startWithCounter: ['', Validators.pattern('^[0-9]+$')],
}, { validator: linkedFieldsValidatorSequence('skipRangeMin', 'skipRangeMax') })
this.fetchSerice.getSequenceKind().subscribe(
(sequenceKinds: any) => {
this.sequenceKinds = sequenceKinds;
}
);
}

ngOnInit(): void {}

addNewSequence() {
let formValue = this.addNewSequenceForm.value
let payload: ICreateSequence = {
Name: formValue.name,
SequenceKind: this.selectedSequenceKind,
SkipRangeMin: formValue.skipRangeMin,
SkipRangeMax: formValue.skipRangeMax,
StartWithCounter: formValue.startWithCounter
}
this.dataService.addSequence(payload)
this.dialogRef.close()
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'

import { DropIndexOrTableDialogComponent } from './drop-index-or-table-dialog.component'
import { DropObjectDetailDialogComponent } from './drop-object-detail-dialog.component'

describe('DropIndexOrTableDialogComponent', () => {
let component: DropIndexOrTableDialogComponent
let fixture: ComponentFixture<DropIndexOrTableDialogComponent>
describe('DropObjectDetailDialogComponent', () => {
let component: DropObjectDetailDialogComponent
let fixture: ComponentFixture<DropObjectDetailDialogComponent>

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [DropIndexOrTableDialogComponent],
declarations: [DropObjectDetailDialogComponent],
providers: [
{
provide: MatDialogRef,
Expand All @@ -27,7 +27,7 @@ describe('DropIndexOrTableDialogComponent', () => {
})

beforeEach(() => {
fixture = TestBed.createComponent(DropIndexOrTableDialogComponent)
fixture = TestBed.createComponent(DropObjectDetailDialogComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { ObjectDetailNodeType } from 'src/app/app.constants'

@Component({
selector: 'app-drop-index-dialog',
templateUrl: './drop-index-or-table-dialog.component.html',
styleUrls: ['./drop-index-or-table-dialog.component.scss'],
templateUrl: './drop-object-detail-dialog.component.html',
styleUrls: ['./drop-object-detail-dialog.component.scss'],
})
export class DropIndexOrTableDialogComponent implements OnInit {
export class DropObjectDetailDialogComponent implements OnInit {
ObjectDetailNodeType = ObjectDetailNodeType
confirmationInput: FormControl
constructor(
@Inject(MAT_DIALOG_DATA) public data: { name: string; type: string },
private dialogRef: MatDialogRef<DropIndexOrTableDialogComponent>
private dialogRef: MatDialogRef<DropObjectDetailDialogComponent>
) {
;(this.confirmationInput = new FormControl('', [
Validators.required,
Expand Down
Loading

0 comments on commit 8c5e085

Please sign in to comment.