Browse Source

Fix for Create and Edit with nested field.

pull/364/head^2
Sebastian Stehle 7 years ago
parent
commit
362e8d71c6
  1. 2
      src/Squidex/app/shared/services/schemas.service.ts
  2. 17
      src/Squidex/app/shared/state/schemas.state.spec.ts
  3. 2
      src/Squidex/app/shared/state/schemas.state.ts

2
src/Squidex/app/shared/services/schemas.service.ts

@ -213,7 +213,7 @@ export class SchemaPropertiesDto {
export interface AddFieldDto { export interface AddFieldDto {
readonly name: string; readonly name: string;
readonly partitioning: string; readonly partitioning?: string;
readonly properties: FieldPropertiesDto; readonly properties: FieldPropertiesDto;
} }

17
src/Squidex/app/shared/state/schemas.state.spec.ts

@ -13,6 +13,7 @@ import { SchemasState } from './schemas.state';
import { import {
DialogService, DialogService,
FieldDto,
SchemaDetailsDto, SchemaDetailsDto,
SchemasService, SchemasService,
UpdateSchemaCategoryDto, UpdateSchemaCategoryDto,
@ -329,28 +330,38 @@ describe('SchemasState', () => {
schemasService.setup(x => x.postField(app, schema1, It.isAny(), version)) schemasService.setup(x => x.postField(app, schema1, It.isAny(), version))
.returns(() => of(updated)).verifiable(); .returns(() => of(updated)).verifiable();
schemasState.addField(schema1, request).subscribe(); let newField: FieldDto;
schemasState.addField(schema1, request).subscribe(result => {
newField = result;
});
const schema1New = <SchemaDetailsDto>schemasState.snapshot.schemas.at(0); const schema1New = <SchemaDetailsDto>schemasState.snapshot.schemas.at(0);
expect(schema1New).toEqual(updated); expect(schema1New).toEqual(updated);
expect(schemasState.snapshot.selectedSchema).toEqual(updated); expect(schemasState.snapshot.selectedSchema).toEqual(updated);
expect(newField!).toBeDefined();
}); });
it('should update schema and selected schema when nested field added', () => { it('should update schema and selected schema when nested field added', () => {
const request = { ...schema.fields[0] }; const request = { ...schema.fields[0].nested[0] };
const updated = createSchemaDetails(1, newVersion, '-new'); const updated = createSchemaDetails(1, newVersion, '-new');
schemasService.setup(x => x.postField(app, schema.fields[0], It.isAny(), version)) schemasService.setup(x => x.postField(app, schema.fields[0], It.isAny(), version))
.returns(() => of(updated)).verifiable(); .returns(() => of(updated)).verifiable();
schemasState.addField(schema1, request, schema.fields[0]).subscribe(); let newField: FieldDto;
schemasState.addField(schema1, request, schema.fields[0]).subscribe(result => {
newField = result;
});
const schema1New = <SchemaDetailsDto>schemasState.snapshot.schemas.at(0); const schema1New = <SchemaDetailsDto>schemasState.snapshot.schemas.at(0);
expect(schema1New).toEqual(updated); expect(schema1New).toEqual(updated);
expect(schemasState.snapshot.selectedSchema).toEqual(updated); expect(schemasState.snapshot.selectedSchema).toEqual(updated);
expect(newField!).toBeDefined();
}); });
it('should update schema and selected schema when field removed', () => { it('should update schema and selected schema when field removed', () => {

2
src/Squidex/app/shared/state/schemas.state.ts

@ -322,7 +322,7 @@ export class SchemasState extends State<Snapshot> {
function getField(x: SchemaDetailsDto, request: AddFieldDto, parent?: RootFieldDto): FieldDto { function getField(x: SchemaDetailsDto, request: AddFieldDto, parent?: RootFieldDto): FieldDto {
if (parent) { if (parent) {
return parent.nested.find(f => f.name === request.name)!; return x.fields.find(f => f.fieldId === parent.fieldId)!.nested.find(f => f.name === request.name)!;
} else { } else {
return x.fields.find(f => f.name === request.name)!; return x.fields.find(f => f.name === request.name)!;
} }

Loading…
Cancel
Save