Skip to content

Commit

Permalink
fix: improved logging for enum dropdowns (#1856)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSlimvReal authored Apr 27, 2023
1 parent 6d41f2e commit 830397e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EntitySchemaDatatype } from "../../entity/schema/entity-schema-datatype
import { ConfigurableEnumValue } from "../configurable-enum.interface";
import { EntitySchemaField } from "../../entity/schema/entity-schema-field";
import { ConfigurableEnumService } from "../configurable-enum.service";
import { LoggingService } from "../../logging/logging.service";

export class ConfigurableEnumDatatype
implements EntitySchemaDatatype<ConfigurableEnumValue>
Expand All @@ -10,7 +11,10 @@ export class ConfigurableEnumDatatype
public readonly viewComponent = "DisplayConfigurableEnum";
public readonly editComponent = "EditConfigurableEnum";

constructor(private enumService: ConfigurableEnumService) {}
constructor(
private enumService: ConfigurableEnumService,
private logger: LoggingService = new LoggingService()
) {}

/**
* transforms Objects of InteractionType to strings to save in DB
Expand All @@ -33,7 +37,13 @@ export class ConfigurableEnumDatatype
let enumOption = this.enumService
.getEnumValues(enumId)
?.find((option) => option.id === value);
if (!enumOption) {
if (!enumOption && value) {
const loadedEnums = this.enumService["enums"]
? [...this.enumService["enums"].keys()].toString()
: "NONE LOADED";
this.logger.warn(
`invalid enum option: ${value} for enum: ${enumId}; existing enums: ${loadedEnums}`
);
enumOption = this.generateOptionForInvalid(value);
}

Expand Down
12 changes: 7 additions & 5 deletions src/app/core/configurable-enum/configurable-enum.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NgModule } from "@angular/core";
import { EntitySchemaService } from "../entity/schema/entity-schema.service";
import { ConfigurableEnumDatatype } from "./configurable-enum-datatype/configurable-enum-datatype";
import { ConfigurableEnumService } from "./configurable-enum.service";
import { LoggingService } from "../logging/logging.service";

/**
* Provides a generic functionality to define enums (collections of selectable options) in the config database
Expand Down Expand Up @@ -47,12 +48,13 @@ import { ConfigurableEnumService } from "./configurable-enum.service";
@NgModule({})
export class ConfigurableEnumModule {
constructor(
private enumService: ConfigurableEnumService,
private entitySchemaService: EntitySchemaService
enumService: ConfigurableEnumService,
entitySchemaService: EntitySchemaService,
logger: LoggingService
) {
this.entitySchemaService.registerSchemaDatatype(
new ConfigurableEnumDatatype(enumService)
);
enumService.preLoadEnums();
entitySchemaService.registerSchemaDatatype(
new ConfigurableEnumDatatype(enumService, logger)
);
}
}

0 comments on commit 830397e

Please sign in to comment.