-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial form for adding connections
- Loading branch information
1 parent
d43328c
commit 7ec82f5
Showing
45 changed files
with
782 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
import { Route } from '@angular/router'; | ||
|
||
export const appRoutes: Route[] = []; | ||
export const appRoutes: Route[] = [ | ||
{ | ||
path: 'connections', | ||
loadChildren: () => import('@service-bus-browser/connections-flow').then(m => m.connectionsRoutes) | ||
}, | ||
{ | ||
path: '', | ||
redirectTo: 'connections', | ||
pathMatch: 'full' | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# @service-bus-browser/connections-flow | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Running unit tests | ||
|
||
Run `nx test @service-bus-browser/connections-flow` to execute the unit tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const nx = require('@nx/eslint-plugin'); | ||
const baseConfig = require('../../../eslint.config.js'); | ||
|
||
module.exports = [ | ||
...baseConfig, | ||
...nx.configs['flat/angular'], | ||
...nx.configs['flat/angular-template'], | ||
{ | ||
files: ['**/*.ts'], | ||
rules: { | ||
'@angular-eslint/directive-selector': [ | ||
'error', | ||
{ | ||
type: 'attribute', | ||
prefix: 'lib', | ||
style: 'camelCase', | ||
}, | ||
], | ||
'@angular-eslint/component-selector': [ | ||
'error', | ||
{ | ||
type: 'element', | ||
prefix: 'lib', | ||
style: 'kebab-case', | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
files: ['**/*.html'], | ||
// Override or add rules here | ||
rules: {}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export default { | ||
displayName: '@service-bus-browser/connections-flow', | ||
preset: '../../../jest.preset.js', | ||
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'], | ||
coverageDirectory: '../../../coverage/libs/connections/flow', | ||
transform: { | ||
'^.+\\.(ts|mjs|js|html)$': [ | ||
'jest-preset-angular', | ||
{ | ||
tsconfig: '<rootDir>/tsconfig.spec.json', | ||
stringifyContentPathRegex: '\\.(html|svg)$', | ||
}, | ||
], | ||
}, | ||
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], | ||
snapshotSerializers: [ | ||
'jest-preset-angular/build/serializers/no-ng-attributes', | ||
'jest-preset-angular/build/serializers/ng-snapshot', | ||
'jest-preset-angular/build/serializers/html-comment', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "@service-bus-browser/connections-flow", | ||
"$schema": "../../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "libs/connections/flow/src", | ||
"prefix": "lib", | ||
"projectType": "library", | ||
"tags": [], | ||
"targets": { | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "libs/connections/flow/jest.config.ts" | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx/eslint:lint" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Routes } from '@angular/router'; | ||
import { provideConnectionsState } from '@service-bus-browser/connections-store'; | ||
|
||
export const connectionsRoutes: Routes = [ | ||
{ | ||
path: 'add', | ||
loadComponent: () => import('./lib/add-connection.component').then(m => m.AddConnectionComponent), | ||
providers: [ | ||
provideConnectionsState() | ||
] | ||
}, | ||
{ | ||
path: '', | ||
redirectTo: 'add', | ||
pathMatch: 'full' | ||
} | ||
] |
38 changes: 38 additions & 0 deletions
38
libs/connections/flow/src/lib/add-connection.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<main class="page-container"> | ||
<h2 class="page-title">Add connection</h2> | ||
<div role="form"> | ||
<section class="name"> | ||
<p-floatlabel variant="on"> | ||
<input id="connectionName" class="full-width" pInputText [(ngModel)]="connectionName" /> | ||
<label for="connectionName">Connection Name</label> | ||
</p-floatlabel> | ||
</section> | ||
<section class="connection-type"> | ||
<label for="connectionType" class="heading">Connection type</label> | ||
<div class="connection-type-option full-width" id="connectionType"> | ||
<p-radiobutton | ||
name="connectionType" | ||
value="connectionString" | ||
inputId="connectionStringConnection" | ||
[(ngModel)]="connectionType" | ||
></p-radiobutton> | ||
<label for="connectionStringConnection">Connection String</label> | ||
</div> | ||
</section> | ||
@if (connectionType() === 'connectionString') { | ||
<section class="connection-string"> | ||
<p-floatlabel variant="on"> | ||
<input id="connectionString" class="full-width" pInputText [(ngModel)]="connectionString" /> | ||
<label for="connectionString">Connection String</label> | ||
</p-floatlabel> | ||
</section> | ||
} | ||
|
||
|
||
<section class="actions"> | ||
<button pButton severity="secondary" type="button">Cancel</button> | ||
<button pButton severity="primary" type="button" [disabled]="!canSave()" (click)="testConnection()">test</button> | ||
<button pButton severity="primary" type="button" [disabled]="!canSave()" (click)="save()">Save</button> | ||
</section> | ||
</div> | ||
</main> |
33 changes: 33 additions & 0 deletions
33
libs/connections/flow/src/lib/add-connection.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
:host{ | ||
display: block; | ||
width: 100%; | ||
} | ||
|
||
.connection-type-option > * { | ||
margin: 0 0 0 0.5em; | ||
} | ||
|
||
.heading { | ||
font-size: 0.7rem; | ||
font-weight: normal; | ||
margin: 0 0 1rem 1rem; | ||
color: var(--p-floatlabel-active-color); | ||
} | ||
|
||
section { | ||
margin: 0 0 1rem 0; | ||
} | ||
|
||
.full-width { | ||
width: 100%; | ||
} | ||
|
||
.actions { | ||
display: flex; | ||
justify-content: flex-end; | ||
margin: 1rem 0 0 0; | ||
|
||
button { | ||
margin: 0 0 0 0.5rem; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
libs/connections/flow/src/lib/add-connection.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { AddConnectionComponent } from './add-connection.component'; | ||
|
||
describe('AddConnectionComponent', () => { | ||
let component: AddConnectionComponent; | ||
let fixture: ComponentFixture<AddConnectionComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [AddConnectionComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(AddConnectionComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { Component, computed, effect, inject, model } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { RadioButton } from 'primeng/radiobutton'; | ||
import { FloatLabel } from 'primeng/floatlabel'; | ||
import { InputText } from 'primeng/inputtext'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { Store } from '@ngrx/store'; | ||
import { ConnectionsActions } from '@service-bus-browser/connections-store'; | ||
import { ButtonDirective } from 'primeng/button'; | ||
import { Connection } from '@service-bus-browser/service-bus-contracts'; | ||
|
||
@Component({ | ||
selector: 'lib-add-connection', | ||
imports: [ | ||
CommonModule, | ||
RadioButton, | ||
FloatLabel, | ||
InputText, | ||
FormsModule, | ||
ButtonDirective, | ||
], | ||
templateUrl: './add-connection.component.html', | ||
styleUrl: './add-connection.component.scss', | ||
}) | ||
export class AddConnectionComponent { | ||
store = inject(Store); | ||
|
||
connectionName = model<string>(); | ||
connectionType = model<'connectionString'>('connectionString'); | ||
connectionString = model<string>(); | ||
|
||
connection = computed<Connection | undefined>(() => { | ||
const connectionType = this.connectionType(); | ||
const name = this.connectionName(); | ||
if (connectionType === undefined || name === undefined) { | ||
return undefined; | ||
} | ||
|
||
if (connectionType === 'connectionString') { | ||
const connectionString = this.connectionString(); | ||
|
||
return !connectionString ? undefined : { | ||
id: crypto.randomUUID(), | ||
name: name, | ||
connectionString: connectionString, | ||
type: 'connectionString', | ||
}; | ||
} | ||
|
||
return undefined; | ||
}); | ||
|
||
canSave = computed(() => { | ||
return this.connection() !== undefined; | ||
}); | ||
|
||
constructor() { | ||
effect(() => { | ||
const connectionType = this.connectionType(); | ||
if (connectionType !== 'connectionString') { | ||
this.connectionString.set(undefined); | ||
return; | ||
} | ||
|
||
const connectionString = this.connectionString(); | ||
if (!this.connectionName() && !!connectionString) { | ||
const capture = /.*Endpoint=sb:\/\/([a-z1-9-.]*)\/?;.*/i.exec(connectionString); | ||
if (capture?.[1]) { | ||
this.connectionName.set(capture[1]); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
testConnection() { | ||
const connection = this.connection(); | ||
if (!connection) { | ||
return; | ||
} | ||
|
||
this.store.dispatch(ConnectionsActions.checkConnection({ | ||
connection | ||
})) | ||
} | ||
|
||
save() { | ||
const connection = this.connection(); | ||
if (!connection) { | ||
return; | ||
} | ||
|
||
this.store.dispatch( | ||
ConnectionsActions.addConnection({ | ||
connection: connection | ||
}) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone'; | ||
|
||
setupZoneTestEnv({ | ||
errorOnUnknownElements: true, | ||
errorOnUnknownProperties: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2022", | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"noImplicitOverride": true, | ||
"noPropertyAccessFromIndexSignature": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
], | ||
"extends": "../../../tsconfig.base.json", | ||
"angularCompilerOptions": { | ||
"enableI18nLegacyMessageIdFormat": false, | ||
"strictInjectionParameters": true, | ||
"strictInputAccessModifiers": true, | ||
"strictTemplates": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../../dist/out-tsc", | ||
"declaration": true, | ||
"declarationMap": true, | ||
"inlineSources": true, | ||
"types": [] | ||
}, | ||
"exclude": [ | ||
"src/**/*.spec.ts", | ||
"src/test-setup.ts", | ||
"jest.config.ts", | ||
"src/**/*.test.ts" | ||
], | ||
"include": ["src/**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../../dist/out-tsc", | ||
"module": "commonjs", | ||
"target": "es2016", | ||
"types": ["jest", "node"] | ||
}, | ||
"files": ["src/test-setup.ts"], | ||
"include": [ | ||
"jest.config.ts", | ||
"src/**/*.test.ts", | ||
"src/**/*.spec.ts", | ||
"src/**/*.d.ts" | ||
] | ||
} |
Oops, something went wrong.