Skip to content

Commit a77bd02

Browse files
authored
feat: show ui for inherited default field values (#2437)
1 parent 0642a68 commit a77bd02

File tree

56 files changed

+1733
-1341
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1733
-1341
lines changed

e2e/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"extends": "../tsconfig.json",
33
"include": [
4-
"integration"
4+
"**/*.ts",
5+
"../cypress.config.ts"
56
],
7+
"exclude": [],
68
"compilerOptions": {
79
"sourceMap": false,
810
"types": [

karma.conf.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
/*
2-
* This file is part of ndb-core.
3-
*
4-
* ndb-core is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation, either version 3 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* ndb-core is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
13-
*
14-
* You should have received a copy of the GNU General Public License
15-
* along with ndb-core. If not, see <http://www.gnu.org/licenses/>.
16-
*/
17-
181
// Karma configuration file, see link for more information
192
// https://karma-runner.github.io/0.13/config/configuration-file.html
203

package-lock.json

Lines changed: 9 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"@typescript-eslint/eslint-plugin": "^8.2.0",
103103
"@typescript-eslint/parser": "^8.2.0",
104104
"babel-loader": "^9.1.3",
105-
"cypress": "13.6.0",
105+
"cypress": "~13.14.0",
106106
"eslint": "^8.57.0",
107107
"eslint-config-prettier": "^9.1.0",
108108
"eslint-plugin-prettier": "^5.2.1",

src/app/child-dev-project/notes/note-details/note-details.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
</div>
4848

4949
<app-view-actions>
50-
<app-dialog-buttons [form]="form" [entity]="entity">
50+
<app-dialog-buttons [form]="form.formGroup" [entity]="entity">
5151
<button
5252
mat-menu-item
5353
[appExportData]="[entity]"

src/app/child-dev-project/notes/note-details/note-details.component.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,17 @@ export class NoteDetailsComponent
115115
this.topFieldGroups = this.topForm.map((f) => ({ fields: [f] }));
116116
this.bottomFieldGroups = [{ fields: this.bottomForm }];
117117

118-
this.form = this.entityFormService.createFormGroup(
118+
this.form = await this.entityFormService.createEntityForm(
119119
this.middleForm.concat(this.topForm, this.bottomForm),
120120
this.entity,
121121
);
122+
122123
// create an object reflecting unsaved changes to use in template (e.g. for dynamic title)
123124
this.tmpEntity = this.entity.copy();
124-
this.form.valueChanges.pipe(untilDestroyed(this)).subscribe((value) => {
125-
this.tmpEntity = Object.assign(this.tmpEntity, value);
126-
});
125+
this.form.formGroup.valueChanges
126+
.pipe(untilDestroyed(this))
127+
.subscribe((value) => {
128+
this.tmpEntity = Object.assign(this.tmpEntity, value);
129+
});
127130
}
128131
}

src/app/core/admin/admin-entity-details/admin-entity-form/admin-entity-form.component.spec.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import {
77

88
import { AdminEntityFormComponent } from "./admin-entity-form.component";
99
import { CoreTestingModule } from "../../../../utils/core-testing.module";
10-
import { EntityFormService } from "../../../common-components/entity-form/entity-form.service";
10+
import {
11+
EntityForm,
12+
EntityFormService,
13+
} from "../../../common-components/entity-form/entity-form.service";
1114
import { MatDialog } from "@angular/material/dialog";
1215
import { FontAwesomeTestingModule } from "@fortawesome/angular-fontawesome/testing";
1316
import { FormGroup } from "@angular/forms";
@@ -18,6 +21,7 @@ import { AdminModule } from "../../admin.module";
1821
import { FormConfig } from "../../../entity-details/form/form.component";
1922
import { ColumnConfig } from "../../../common-components/entity-form/FormConfig";
2023
import { TestEntity } from "../../../../utils/test-utils/TestEntity";
24+
import { DefaultValueService } from "../../../default-values/default-value.service";
2125

2226
describe("AdminEntityFormComponent", () => {
2327
let component: AdminEntityFormComponent;
@@ -28,7 +32,7 @@ describe("AdminEntityFormComponent", () => {
2832

2933
let testConfig: FormConfig;
3034

31-
beforeEach(() => {
35+
beforeEach(async () => {
3236
testConfig = {
3337
fieldGroups: [
3438
{ header: "Group 1", fields: ["name", "other"] },
@@ -37,9 +41,13 @@ describe("AdminEntityFormComponent", () => {
3741
};
3842

3943
mockFormService = jasmine.createSpyObj("EntityFormService", [
40-
"createFormGroup",
44+
"createEntityForm",
4145
]);
42-
mockFormService.createFormGroup.and.returnValue(new FormGroup({}));
46+
mockFormService.createEntityForm.and.returnValue(
47+
Promise.resolve({
48+
formGroup: new FormGroup({}),
49+
} as EntityForm<any>),
50+
);
4351
mockDialog = jasmine.createSpyObj("MatDialog", ["open"]);
4452

4553
TestBed.configureTestingModule({
@@ -58,6 +66,10 @@ describe("AdminEntityFormComponent", () => {
5866
provide: MatDialog,
5967
useValue: mockDialog,
6068
},
69+
{
70+
provide: DefaultValueService,
71+
useValue: jasmine.createSpyObj(["getDefaultValueUiHint"]),
72+
},
6173
],
6274
});
6375
fixture = TestBed.createComponent(AdminEntityFormComponent);
@@ -68,7 +80,7 @@ describe("AdminEntityFormComponent", () => {
6880

6981
fixture.detectChanges();
7082

71-
component.ngOnChanges({ config: true as any });
83+
await component.ngOnChanges({ config: true as any });
7284
});
7385

7486
it("should create and init a form", () => {
@@ -78,12 +90,13 @@ describe("AdminEntityFormComponent", () => {
7890
expect(component.dummyForm).toBeTruthy();
7991
});
8092

81-
it("should load all fields from schema that are not already in form as available fields", () => {
93+
it("should load all fields from schema that are not already in form as available fields", async () => {
8294
const fieldsInView = ["date"];
8395
component.config = {
8496
fieldGroups: [{ fields: fieldsInView }],
8597
};
86-
component.ngOnChanges({ config: true as any });
98+
99+
await component.ngOnChanges({ config: true as any });
87100

88101
const noteUserFacingFields = Array.from(TestEntity.schema.entries())
89102
.filter(([key, value]) => value.label)

src/app/core/admin/admin-entity-details/admin-entity-form/admin-entity-form.component.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { Component, Input, OnChanges, SimpleChanges } from "@angular/core";
22
import { Entity, EntityConstructor } from "../../../entity/model/entity";
3-
import { EntityFormService } from "../../../common-components/entity-form/entity-form.service";
4-
import { FormControl, FormGroup } from "@angular/forms";
3+
import {
4+
EntityForm,
5+
EntityFormService,
6+
} from "../../../common-components/entity-form/entity-form.service";
7+
import { FormControl } from "@angular/forms";
58
import { MatDialog } from "@angular/material/dialog";
69
import { AdminEntityFieldComponent } from "../admin-entity-field/admin-entity-field.component";
710
import {
@@ -59,7 +62,7 @@ export class AdminEntityFormComponent implements OnChanges {
5962
@Input() config: FormConfig;
6063

6164
dummyEntity: Entity;
62-
dummyForm: FormGroup;
65+
dummyForm: EntityForm<any>;
6366

6467
availableFields: ColumnConfig[] = [];
6568
readonly createNewFieldPlaceholder: FormFieldConfig = {
@@ -85,21 +88,21 @@ export class AdminEntityFormComponent implements OnChanges {
8588
});
8689
}
8790

88-
ngOnChanges(changes: SimpleChanges): void {
91+
async ngOnChanges(changes: SimpleChanges): Promise<void> {
8992
if (changes.config) {
90-
this.initForm();
93+
await this.initForm();
9194
}
9295
}
9396

94-
private initForm() {
97+
private async initForm() {
9598
this.initAvailableFields();
9699

97100
this.dummyEntity = new this.entityType();
98-
this.dummyForm = this.entityFormService.createFormGroup(
101+
this.dummyForm = await this.entityFormService.createEntityForm(
99102
[...this.getUsedFields(this.config), ...this.availableFields],
100103
this.dummyEntity,
101104
);
102-
this.dummyForm.disable();
105+
this.dummyForm.formGroup.disable();
103106
}
104107

105108
private getUsedFields(config: FormConfig): ColumnConfig[] {
@@ -220,7 +223,7 @@ export class AdminEntityFormComponent implements OnChanges {
220223
if (configDetails.editComponent == "EditDescriptionOnly") {
221224
const updatedField = await this.openTextConfig(configDetails);
222225
Object.assign(field, updatedField);
223-
this.initForm();
226+
await this.initForm();
224227
} else {
225228
await this.openFieldConfig(field);
226229
}
@@ -244,8 +247,8 @@ export class AdminEntityFormComponent implements OnChanges {
244247
return;
245248
}
246249

247-
this.dummyForm.addControl(newFieldId, new FormControl());
248-
this.dummyForm.disable();
250+
this.dummyForm.formGroup.addControl(newFieldId, new FormControl());
251+
this.dummyForm.formGroup.disable();
249252
event.container.data.splice(event.currentIndex, 0, newFieldId);
250253

251254
// the schema update has added the new field to the available fields already, remove it from there
@@ -269,8 +272,8 @@ export class AdminEntityFormComponent implements OnChanges {
269272
return;
270273
}
271274

272-
this.dummyForm.addControl(newTextField.id, new FormControl());
273-
this.dummyForm.disable();
275+
this.dummyForm.formGroup.addControl(newTextField.id, new FormControl());
276+
this.dummyForm.formGroup.disable();
274277
event.container.data.splice(event.currentIndex, 0, newTextField);
275278

276279
// the schema update has added the new Text field to the available fields already, remove it from there

src/app/core/common-components/edit-text-with-autocomplete/edit-text-with-autocomplete.component.spec.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,23 @@ describe("EditTextWithAutocompleteComponent", () => {
3131
}).compileComponents();
3232
}));
3333

34-
beforeEach(waitForAsync(() => {
34+
beforeEach(waitForAsync(async () => {
3535
fixture = TestBed.createComponent(EditTextWithAutocompleteComponent);
3636
component = fixture.componentInstance;
3737
loadTypeSpy = spyOn(TestBed.inject(EntityMapperService), "loadType");
3838
loadTypeSpy.and.resolveTo([]);
3939
const entityFormService = TestBed.inject(EntityFormService);
40-
component.parent = entityFormService.createFormGroup(
41-
[
42-
{ id: "title" },
43-
{ id: "type" },
44-
{ id: "assignedTo" },
45-
{ id: "linkedGroups" },
46-
],
47-
new RecurringActivity(),
48-
);
40+
component.parent = (
41+
await entityFormService.createEntityForm(
42+
[
43+
{ id: "title" },
44+
{ id: "type" },
45+
{ id: "assignedTo" },
46+
{ id: "linkedGroups" },
47+
],
48+
new RecurringActivity(),
49+
)
50+
).formGroup;
4951
component.formControl = component.parent.get(
5052
"title",
5153
) as FormControl<string>;

src/app/core/common-components/entities-table/entities-table.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
toFormFieldConfig,
3131
} from "../entity-form/FormConfig";
3232
import {
33-
EntityForm,
33+
EntityFormGroup,
3434
EntityFormService,
3535
} from "../entity-form/entity-form.service";
3636
import { tableSort } from "./table-sort/table-sort";
@@ -448,5 +448,5 @@ export class EntitiesTableComponent<T extends Entity> {
448448
*/
449449
export interface TableRow<T extends Entity> {
450450
record: T;
451-
formGroup?: EntityForm<T>;
451+
formGroup?: EntityFormGroup<T>;
452452
}

0 commit comments

Comments
 (0)