Make IHierarchicalLabeledIdCriterion backwards compatible (#1716)

Add some form of backwards compatibility in the UI for
`IHierarchicalLabeledIdCriterion`. With this backwards compatibility
it's possible to recall saved filters which use the tags filter.
Otherwise stuff would blow up because the saved filter has a different
structure than what the `IHierarchicalLabeledIdCriterion` expects.
This commit is contained in:
gitgiggety 2021-09-11 02:01:57 +02:00 committed by GitHub
parent 13a289a4a8
commit 565064b441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -99,6 +99,10 @@ export abstract class Criterion<V extends CriterionValue> {
return this.value; return this.value;
} }
public decodeValue(value: V) {
this.value = value;
}
public toJSON() { public toJSON() {
const encodedCriterion = { const encodedCriterion = {
type: this.criterionOption.type, type: this.criterionOption.type,
@ -411,6 +415,15 @@ export class IHierarchicalLabeledIdCriterion extends Criterion<IHierarchicalLabe
}; };
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public decodeValue(value: any) {
if (Array.isArray(value)) {
this.value.items = value;
} else {
this.value = value;
}
}
protected toCriterionInput(): HierarchicalMultiCriterionInput { protected toCriterionInput(): HierarchicalMultiCriterionInput {
return { return {
value: (this.value.items ?? []).map((v) => v.id), value: (this.value.items ?? []).map((v) => v.id),

View File

@ -116,7 +116,7 @@ export class ListFilterModel {
const criterion = makeCriteria(encodedCriterion.type); const criterion = makeCriteria(encodedCriterion.type);
// it's possible that we have unsupported criteria. Just skip if so. // it's possible that we have unsupported criteria. Just skip if so.
if (criterion) { if (criterion) {
criterion.value = encodedCriterion.value; criterion.decodeValue(encodedCriterion.value);
criterion.modifier = encodedCriterion.modifier; criterion.modifier = encodedCriterion.modifier;
this.criteria.push(criterion); this.criteria.push(criterion);
} }