Browse Source

Fix build.

pull/786/head
Sebastian 4 years ago
parent
commit
b2716a8ba2
  1. 2
      frontend/app/features/schemas/pages/schemas/schema-form.component.html
  2. 29
      frontend/app/shared/state/schemas.state.ts

2
frontend/app/features/schemas/pages/schemas/schema-form.component.html

@ -87,7 +87,7 @@
</sqx-form-alert>
<ng-container *ngIf="schemasState.categoryNames | async; let categories">
<div class="form-group" *ngIf="categories.size > 0">
<div class="form-group" *ngIf="categories.length > 0">
<label for="category">{{ 'common.category' | sqxTranslate }}</label>
<select class="form-select" id="category" formControlName="initialCategory">

29
frontend/app/shared/state/schemas.state.ts

@ -59,6 +59,9 @@ export class SchemasState extends State<Snapshot> {
public addedCategories =
this.project(x => x.addedCategories);
public categoryNames =
this.projectFrom2(this.schemas, this.addedCategories, (s, c) => buildCategoryNames(c, s));
public get schemaId() {
return this.snapshot.selectedSchema?.id || '';
}
@ -363,6 +366,26 @@ function getField(x: SchemaDto, request: AddFieldDto, parent?: RootFieldDto | nu
}
}
function buildCategoryNames(categories: Set<string>, allSchemas: SchemasList): ReadonlyArray<string> {
const uniqueCategories: { [name: string]: boolean } = {};
function addCategory(name: string) {
if (name) {
uniqueCategories[name] = true;
}
}
for (const category of categories) {
addCategory(category);
}
for (const schema of allSchemas) {
addCategory(schema.category);
}
return Object.keys(uniqueCategories).sortByString(x => x);
}
export type SchemaCategory = {
displayName: string;
name?: string;
@ -468,10 +491,8 @@ export function getCategoryTree(allSchemas: ReadonlyArray<SchemaDto>, categories
}
for (const schema of allSchemas) {
const name = schema.category;
if (name) {
addSchemaToCategory(schema, getOrCreateCategory(name));
if (schema.category) {
addSchemaToCategory(schema, getOrCreateCategory(schema.category));
} else if (schema.type === 'Component') {
addSchemaToCategory(schema, components);
} else {

Loading…
Cancel
Save