Skip to content

Commit

Permalink
fix: configurable enum filters work with enum name in additional field (
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSlimvReal authored Feb 7, 2023
1 parent 99a5290 commit b303533
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,33 @@ describe("FilterGeneratorService", () => {
interactionTypes.push({ key: "all", label: "All" });
const schema = Note.schema.get("category");

const filter = (await service.generate([{ id: "category" }], Note, []))[0];
let filter = (await service.generate([{ id: "category" }], Note, []))[0];

expect(filter.filterSettings.label).toEqual(schema.label);
expect(filter.filterSettings.name).toEqual("category");
const comparableOptions = filter.filterSettings.options.map((option) => {
let comparableOptions = filter.filterSettings.options.map((option) => {
return { key: option.key, label: option.label };
});
expect(comparableOptions).toEqual(
jasmine.arrayWithExactContents(interactionTypes)
);

// enum name in additional field
const schemaAdditional = {
dataType: schema.dataType,
additional: schema.innerDataType,
};
Note.schema.set("otherEnum", schemaAdditional);

filter = (await service.generate([{ id: "otherEnum" }], Note, []))[0];

comparableOptions = filter.filterSettings.options.map((option) => {
return { key: option.key, label: option.label };
});
expect(comparableOptions).toEqual(
jasmine.arrayWithExactContents(interactionTypes)
);
Note.schema.delete("otherEnum");
});

it("should create a entity filter", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class FilterGeneratorService {
filtersConfig: FilterConfig[],
entityConstructor: EntityConstructor<T>,
data: T[],
onlyShowUsedOptions: boolean = false
onlyShowUsedOptions = false
): Promise<FilterComponentSettings<T>[]> {
const filterSettings: FilterComponentSettings<T>[] = [];
for (const filter of filtersConfig) {
Expand Down Expand Up @@ -91,7 +91,7 @@ export class FilterGeneratorService {
} else if (schema.dataType === "configurable-enum") {
return this.createConfigurableEnumFilterOptions(
config.id,
schema.innerDataType
schema.additional ?? schema.innerDataType
);
} else if (
this.entities.has(config.type) ||
Expand Down

0 comments on commit b303533

Please sign in to comment.