diff --git a/frontend/app/shared/state/schemas.state.spec.ts b/frontend/app/shared/state/schemas.state.spec.ts index a9e4308fa..0e3a9c54a 100644 --- a/frontend/app/shared/state/schemas.state.spec.ts +++ b/frontend/app/shared/state/schemas.state.spec.ts @@ -63,6 +63,7 @@ describe('SchemasState', () => { const categories = getCategories(schemasState); expect(categories!).toEqual([ + { name: '', upper: '', schemas: [] }, { name: 'category1', upper: 'CATEGORY1', schemas: [schema1] }, { name: 'category2', upper: 'CATEGORY2', schemas: [schema2] } ]); @@ -84,6 +85,7 @@ describe('SchemasState', () => { const categories = getCategories(schemasState); expect(categories!).toEqual([ + { name: '', upper: '', schemas: [] }, { name: 'category1', upper: 'CATEGORY1', schemas: [schema1] }, { name: 'category2', upper: 'CATEGORY2', schemas: [schema2] }, { name: 'category3', upper: 'CATEGORY3', schemas: [] } @@ -151,6 +153,7 @@ describe('SchemasState', () => { const categories = getCategories(schemasState); expect(categories!).toEqual([ + { name: '', upper: '', schemas: [] }, { name: 'category1', upper: 'CATEGORY1', schemas: [schema1] }, { name: 'category2', upper: 'CATEGORY2', schemas: [schema2] }, { name: 'category3', upper: 'CATEGORY3', schemas: [] } @@ -163,6 +166,7 @@ describe('SchemasState', () => { const categories = getCategories(schemasState); expect(categories!).toEqual([ + { name: '', upper: '', schemas: [] }, { name: 'category1', upper: 'CATEGORY1', schemas: [schema1] }, { name: 'category2', upper: 'CATEGORY2', schemas: [schema2] } ]); @@ -175,6 +179,7 @@ describe('SchemasState', () => { const categories = getCategories(schemasState); expect(categories!).toEqual([ + { name: '', upper: '', schemas: [] }, { name: 'category1', upper: 'CATEGORY1', schemas: [schema1] }, { name: 'category2', upper: 'CATEGORY2', schemas: [schema2] } ]); diff --git a/frontend/app/shared/state/schemas.state.ts b/frontend/app/shared/state/schemas.state.ts index 7d82d06bc..33a2b32f1 100644 --- a/frontend/app/shared/state/schemas.state.ts +++ b/frontend/app/shared/state/schemas.state.ts @@ -385,23 +385,25 @@ function getField(x: SchemaDetailsDto, request: AddFieldDto, parent?: RootFieldD const NO_NAME = ''; -function buildCategories(categories: ReadonlyArray, schemas: SchemasList): ReadonlyArray { - const uniqueCategories: { [name: string]: true } = { [NO_NAME]: true }; +function buildCategories(categories: ReadonlyArray, allSchemas: SchemasList): ReadonlyArray { + const uniqueCategories: { [name: string]: true } = { + [NO_NAME]: true + }; for (const category of categories) { uniqueCategories[category] = true; } - for (const schema of schemas) { + for (const schema of allSchemas) { uniqueCategories[getCategory(schema)] = true; } const result: SchemaCategory[] = []; - for (const name in uniqueCategories) { - if (uniqueCategories.hasOwnProperty(name)) { - result.push({ name, upper: name.toUpperCase(), schemas: schemas.filter(x => isSameCategory(name, x))}); - } + for (const name of Object.keys(uniqueCategories)) { + const schemas = allSchemas.filter(x => isSameCategory(name, x)); + + result.push({ name, upper: name.toUpperCase(), schemas }); } result.sort((a, b) => compareStrings(a.upper, b.upper));