Skip to content

Commit

Permalink
feat: add default backstage properties for services (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbystedt authored Jan 16, 2025
1 parent cabf526 commit 99cd670
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 19 deletions.
28 changes: 28 additions & 0 deletions scripts/db/mongo-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ result = db.collectionConfig.insertOne({
update: true,
},
},
lifecycle: {
name: 'Lifecycle',
required: false,
type: 'select',
options: [
{ value: 'experimental', label: 'Experimental' },
{ value: 'production', label: 'Production' },
{ value: 'deprecated', label: 'Deprecated' },
],
hint: 'The lifecycle stage of the service',
mask: {
update: true,
},
},
scmUrl: {
name: 'SCM URL',
required: false,
Expand All @@ -273,6 +287,20 @@ result = db.collectionConfig.insertOne({
update: true,
},
},
type: {
name: 'Type',
required: false,
type: 'select',
options: [
{ value: 'service', label: 'Service' },
{ value: 'website', label: 'Website' },
{ value: 'library', label: 'Library' },
],
hint: 'The type of service',
mask: {
update: true,
},
},
vaultConfig: {
type: 'embeddedDoc',
required: false,
Expand Down
8 changes: 7 additions & 1 deletion src/persistence/dto/collection-config.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export type CollectionEdgeInstanceConfig = Omit<
prototype: CollectionEdgePrototype;
};

export class CollectionFieldSelectOption {
value!: string;
label!: string;
}

export class CollectionFieldConfig {
hint!: string;
init?: 'uuid' | 'now';
Expand All @@ -54,13 +59,14 @@ export class CollectionFieldConfig {
| 'embeddedDocArray'
| 'json'
| 'number'
| 'select'
| 'string'
| 'stringArray'
| 'url';
unique?: boolean;
uniqueParent?: boolean;
value?: string | boolean;
valuePath?: string;
options?: CollectionFieldSelectOption[];
}

export class CollectionFieldConfigMap {
Expand Down
2 changes: 2 additions & 0 deletions src/persistence/dto/intention-action-pointer.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ export class IntentionActionPointerDto {
@IsString()
@IsDefined()
intention!: string;

@IsOptional()
source?: any;
}
8 changes: 8 additions & 0 deletions src/persistence/dto/service.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ export class ServiceBaseDto extends CollectionBaseDto {
@IsOptional()
title?: string;

@IsString()
@IsOptional()
lifecycle?: string;

@IsString()
@IsOptional()
type?: string;

@IsString()
@IsOptional()
scmUrl?: string;
Expand Down
6 changes: 6 additions & 0 deletions src/persistence/entity/service.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export class ServiceEntity extends VertexPointerEntity {
@Property({ nullable: true })
title?: string;

@Property({ nullable: true })
lifecycle?: string;

@Property({ nullable: true })
type?: string;

@Property({ nullable: true })
scmUrl?: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
@case ('number') {
{{value}}
}
@case ('select') {
{{ selectValueToLabel(value) }}
}
@case ('string') {
{{value}}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@ import { Component, Input } from '@angular/core';
import { CollectionFieldConfig } from '../../service/persistence/dto/collection-config.dto';

@Component({
selector: 'app-inspector-vertex-field',
imports: [DatePipe],
templateUrl: './inspector-vertex-field.component.html',
styleUrl: './inspector-vertex-field.component.scss'
selector: 'app-inspector-vertex-field',
imports: [DatePipe],
templateUrl: './inspector-vertex-field.component.html',
styleUrl: './inspector-vertex-field.component.scss',
})
export class InspectorVertexFieldComponent {
@Input() public config: CollectionFieldConfig | undefined;
@Input() public value: any;

selectValueToLabel(value: any): string {
if (value) {
return (
this.config?.options?.find((option) => option.value === value)?.label ??
value
);
}
return '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ export class VertexFormBuilderComponent implements OnInit, OnChanges {
);
}

if (f.type === 'select') {
fieldCtrls[f.key] = new FormControl(
data && data[f.key] ? data[f.key] : '',
validators,
);
}

if (f.type === 'email') {
validators.push(Validators.email);
fieldCtrls[f.key] = new FormControl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@
}
</mat-form-field>
}
@case ('select') {
<mat-form-field appearance="fill">
@if (field.name) {
<mat-label>{{field.name}}</mat-label>
}
<mat-select [formControlName]="field.key">
@for (option of field.options; track option) {
<mat-option value="{{option.value}}">{{option.label}}</mat-option>
}
</mat-select>
@if (field.hint) {
<mat-hint>{{field.hint}}</mat-hint>
}
</mat-form-field>
}
@case ('date') {
<mat-form-field appearance="fill">
@if (field.name) {
Expand Down
30 changes: 17 additions & 13 deletions ui/src/app/graph/vertex-form-field/vertex-form-field.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CommonModule } from '@angular/common';
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { TextFieldModule } from '@angular/cdk/text-field';
Expand All @@ -6,23 +7,26 @@ import { MatInputModule } from '@angular/material/input';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatTooltipModule } from '@angular/material/tooltip';
import { MatSelectModule } from '@angular/material/select';

import { CollectionFieldConfigNameMapped } from '../../service/graph.types';

@Component({
selector: 'app-vertex-form-field',
templateUrl: './vertex-form-field.component.html',
styleUrls: ['./vertex-form-field.component.scss'],
imports: [
FormsModule,
ReactiveFormsModule,
MatFormFieldModule,
MatCheckboxModule,
MatDatepickerModule,
MatInputModule,
MatTooltipModule,
TextFieldModule,
]
selector: 'app-vertex-form-field',
templateUrl: './vertex-form-field.component.html',
styleUrls: ['./vertex-form-field.component.scss'],
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
MatFormFieldModule,
MatCheckboxModule,
MatDatepickerModule,
MatInputModule,
MatSelectModule,
MatTooltipModule,
TextFieldModule,
],
})
export class VertexFormFieldComponent {
@Input() field!: CollectionFieldConfigNameMapped;
Expand Down
8 changes: 7 additions & 1 deletion ui/src/app/service/persistence/dto/collection-config.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export type CollectionEdgeInstanceConfig = Omit<
prototype: CollectionEdgePrototype;
};

export class CollectionFieldSelectOption {
value!: string;
label!: string;
}

export class CollectionFieldConfig {
hint!: string;
init?: 'uuid' | 'now';
Expand All @@ -54,13 +59,14 @@ export class CollectionFieldConfig {
| 'embeddedDocArray'
| 'json'
| 'number'
| 'select'
| 'string'
| 'stringArray'
| 'url';
unique?: boolean;
uniqueParent?: boolean;
value?: string | boolean;
valuePath?: string;
options?: CollectionFieldSelectOption[];
}

export class CollectionFieldConfigMap {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ export class IntentionActionPointerDto {
@IsString()
@IsDefined()
intention!: string;

@IsOptional()
source?: any;
}
8 changes: 8 additions & 0 deletions ui/src/app/service/persistence/dto/service.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ export class ServiceBaseDto extends CollectionBaseDto {
@IsOptional()
title?: string;

@IsString()
@IsOptional()
lifecycle?: string;

@IsString()
@IsOptional()
type?: string;

@IsString()
@IsOptional()
scmUrl?: string;
Expand Down

0 comments on commit 99cd670

Please sign in to comment.