Skip to content

Commit

Permalink
refactor(config): rename entity to entityType in config
Browse files Browse the repository at this point in the history
for clarity and future developments
  • Loading branch information
sleidig committed Apr 12, 2024
1 parent 0abd547 commit a326549
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("AdminEntityDetailsComponent", () => {
viewConfigId = `view:${AdminDetailsTestEntity.route.substring(1)}/:id`;
entityConfigId = `entity:${AdminDetailsTestEntity.ENTITY_TYPE}`;
viewConfig = {
entity: AdminDetailsTestEntity.ENTITY_TYPE,
entityType: AdminDetailsTestEntity.ENTITY_TYPE,
panels: [{ title: "Tab 1", components: [] }],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class AdminEntityListComponent implements OnChanges {
ngOnChanges(changes: SimpleChanges): void {
if (changes.config) {
this.config = this.config ?? {
entity: this.entityConstructor.ENTITY_TYPE,
entityType: this.entityConstructor.ENTITY_TYPE,
};
this.config.filters = this.config.filters ?? [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe("AdminEntityComponent", () => {
viewConfigId = `view:${AdminTestEntity.route.substring(1)}/:id`;
entityConfigId = `entity:${AdminTestEntity.ENTITY_TYPE}`;
viewConfig = {
entity: AdminTestEntity.ENTITY_TYPE,
entityType: AdminTestEntity.ENTITY_TYPE,
panels: [{ title: "Tab 1", components: [] }],
};
config = {
Expand Down Expand Up @@ -148,7 +148,7 @@ describe("AdminEntityComponent", () => {
component.save();
fixture.whenStable().then(() => {
const expectedViewConfig = {
entity: AdminTestEntity.ENTITY_TYPE,
entityType: AdminTestEntity.ENTITY_TYPE,
panels: [{ title: "Tab 1", components: [] }, newPanel],
};
const expectedEntityConfig = {
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/admin/admin-entity/admin-entity.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class AdminEntityComponent implements OnInit {
targetConfig.data[detailsViewId].config = viewConfig;
} else {
// create new config
viewConfig.entity = this.entityType;
viewConfig.entityType = this.entityType;
targetConfig.data[detailsViewId] = {
component: componentForNewConfig,
config: viewConfig,
Expand Down
20 changes: 10 additions & 10 deletions src/app/core/config/config-fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const defaultJsonConfig = {
"view:note": {
"component": "NotesManager",
"config": {
"entity": "Note",
"entityType": "Note",
"title": $localize`:Title for notes overview:Notes & Reports`,
"includeEventNotes": false,
"showEventNotesToggle": true,
Expand Down Expand Up @@ -243,15 +243,15 @@ export const defaultJsonConfig = {
"view:user": {
"component": "EntityList",
"config": {
"entity": "User",
"entityType": "User",
"columns": ["name", "phone"]
},
"permittedUserRoles": ["admin_app"]
},
"view:user/:id": {
"component": "EntityDetails",
"config": {
"entity": "User",
"entityType": "User",
"panels": [
{
"title": $localize`:Panel title:User Information`,
Expand Down Expand Up @@ -294,7 +294,7 @@ export const defaultJsonConfig = {
"view:school": {
"component": "EntityList",
"config": {
"entity": "School",
"entityType": "School",
"columns": [
"name",
{ id: "DisplayParticipantsCount", viewComponent: "DisplayParticipantsCount", label: $localize`Children` },
Expand All @@ -312,7 +312,7 @@ export const defaultJsonConfig = {
"view:school/:id": {
"component": "EntityDetails",
"config": {
"entity": "School",
"entityType": "School",
"panels": [
{
"title": $localize`:Panel title:Basic Information`,
Expand Down Expand Up @@ -355,7 +355,7 @@ export const defaultJsonConfig = {
"view:child": {
"component": "ChildrenList",
"config": {
"entity": "Child",
"entityType": "Child",
"columns": [
{
"viewComponent": "ChildBlock",
Expand Down Expand Up @@ -485,7 +485,7 @@ export const defaultJsonConfig = {
"view:child/:id": {
"component": "EntityDetails",
"config": {
"entity": "Child",
"entityType": "Child",
"panels": [
{
"title": $localize`:Panel title:Basic Information`,
Expand Down Expand Up @@ -709,7 +709,7 @@ export const defaultJsonConfig = {
"view:attendance/recurring-activity": {
"component": "EntityList",
"config": {
"entity": "RecurringActivity",
"entityType": "RecurringActivity",
"columns": [
"title",
"type",
Expand All @@ -720,7 +720,7 @@ export const defaultJsonConfig = {
"view:attendance/recurring-activity/:id": {
"component": "EntityDetails",
"config": {
"entity": "RecurringActivity",
"entityType": "RecurringActivity",
"panels": [
{
"title": $localize`:Panel title:Basic Information`,
Expand Down Expand Up @@ -903,7 +903,7 @@ export const defaultJsonConfig = {
"view:todo": {
"component": "TodoList",
"config": {
"entity": "Todo",
"entityType": "Todo",
"columns": ["deadline", "subject", "assignedTo", "startDate", "relatedEntities"],
"filters": [
{"id": "assignedTo"},
Expand Down
23 changes: 23 additions & 0 deletions src/app/core/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class ConfigService extends LatestEntityLoader<Config> {
migrateFormHeadersIntoFieldGroups,
migrateFormFieldConfigView2ViewComponent,
migrateMenuItemConfig,
migrateEntityDetailsInputEntityType,
];

const newConfig = JSON.parse(JSON.stringify(config), (_that, rawValue) => {
Expand Down Expand Up @@ -188,3 +189,25 @@ const migrateMenuItemConfig: ConfigMigration = (key, configPart) => {

return configPart;
};

/**
* Config properties specifying an entityType should be name "entityType" rather than "entity"
* to avoid confusion with a specific instance of an entity being passed in components.
* @param key
* @param configPart
*/
const migrateEntityDetailsInputEntityType: ConfigMigration = (
key,
configPart,
) => {
if (key !== "config") {
return configPart;
}

if (configPart["entity"]) {
configPart["entityType"] = configPart["entity"];
delete configPart["entity"];
}

return configPart;
};
2 changes: 1 addition & 1 deletion src/app/core/entity-details/EntityDetailsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface EntityDetailsConfig {
/**
* The name of the entity (according to the ENTITY_TYPE).
*/
entity: string;
entityType: string;

/**
* The configuration for the panels on this details page.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("EntityDetailsComponent", () => {
let fixture: ComponentFixture<EntityDetailsComponent>;

const routeConfig: EntityDetailsConfig = {
entity: "Child",
entityType: "Child",
panels: [
{
title: "One Form",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,10 @@ export class EntityDetailsComponent implements OnChanges {
isLoading = true;
private changesSubscription: Subscription;

/** @deprecated use "entityType" instead, this remains for config backwards compatibility */
@Input() set entity(v: string) {
this.entityType = v;
}
@Input() entityType: string;
entityConstructor: EntityConstructor;

// TODO: instead use an @Input entity: Entity and let RoutedView handle the entity loading
@Input() id: string;
record: Entity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const demoEntity = Child.create("John Doe");
demoEntity._rev = "1"; // make not "isNew"

const config: EntityDetailsConfig = {
entity: "Child",
entityType: "Child",
panels: [
{
title: $localize`:Panel title:Basic Information`,
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/entity-list/EntityListConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface EntityListConfig {
* Select which entities should be displayed in the table
* (optional) This is only used and necessary if EntityListComponent is used directly in config
*/
entity?: string;
entityType?: string;

/**
* Custom overwrites or additional columns to be displayed in the table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe("EntityListComponent", () => {

createComponent();
component.listConfig = {
entity: "Child",
entityType: "Child",
title: "Some title",
columns: ["name", "gender"],
};
Expand Down
6 changes: 3 additions & 3 deletions src/app/core/entity-list/entity-list/entity-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class EntityListComponent<T extends Entity>
/** @deprecated this is often used when this has a wrapper component (e.g. ChildrenList), preferably use individual @Input properties */
@Input() listConfig: EntityListConfig;

@Input() entity: string;
@Input() entityType: string;
@Input() entityConstructor: EntityConstructor<T>;
@Input() defaultSort: Sort;
@Input() exportConfig: ExportColumnConfig[];
Expand Down Expand Up @@ -199,9 +199,9 @@ export class EntityListComponent<T extends Entity>
}

private async buildComponentFromConfig() {
if (this.entity) {
if (this.entityType) {
this.entityConstructor = this.entities.get(
this.entity,
this.entityType,
) as EntityConstructor<T>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ describe("ConfigImportParserService", () => {
],
{
title: "",
entity: "test",
entityType: "test",
columns: [],
columnGroups: {
groups: [
Expand Down Expand Up @@ -241,7 +241,7 @@ describe("ConfigImportParserService", () => {
],
{
icon: "child",
entity: "test",
entityType: "test",
title: "",
panels: [
{
Expand Down Expand Up @@ -278,7 +278,7 @@ describe("ConfigImportParserService", () => {
],
{
icon: "child",
entity: "test",
entityType: "test",
title: "",
panels: [
{
Expand Down Expand Up @@ -335,7 +335,7 @@ describe("ConfigImportParserService", () => {
],
{
icon: "child",
entity: "test",
entityType: "test",
title: "",
panels: [
{
Expand Down Expand Up @@ -380,7 +380,7 @@ describe("ConfigImportParserService", () => {
],
{
icon: "child",
entity: "test",
entityType: "test",
title: "",
panels: [
{
Expand Down
6 changes: 3 additions & 3 deletions src/app/features/config-setup/config-import-parser.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ export class ConfigImportParserService {
}

private generateEmptyListView(entityType: string): EntityListConfig {
const newListView = {
const newListView: EntityListConfig = {
columns: [],
entity: entityType,
entityType: entityType,
title: "",
columnGroups: { groups: [] },
};
Expand Down Expand Up @@ -288,7 +288,7 @@ export class ConfigImportParserService {
entityType: string,
): EntityDetailsConfig {
const newDetailsView = {
entity: entityType,
entityType: entityType,
icon: "child",
panels: [],
title: "",
Expand Down

0 comments on commit a326549

Please sign in to comment.