Fix: unit rewriting metatagger now only uses units as defined in the layer itself

This commit is contained in:
Pieter Vander Vennet 2025-03-09 23:22:32 +01:00
parent f706fa7b5e
commit 0cf3d07100
2 changed files with 9 additions and 12 deletions

View file

@ -2,7 +2,6 @@ import BaseUIElement from "../UI/BaseUIElement"
import { Denomination } from "./Denomination"
import UnitConfigJson from "./ThemeConfig/Json/UnitConfigJson"
import unit from "../../assets/layers/unit/unit.json"
import { QuestionableTagRenderingConfigJson } from "./ThemeConfig/Json/QuestionableTagRenderingConfigJson"
import TagRenderingConfig from "./ThemeConfig/TagRenderingConfig"
import Validators, { ValidatorType } from "../UI/InputElement/Validators"
import { Validator } from "../UI/InputElement/Validator"
@ -14,7 +13,6 @@ export class Unit {
public readonly denominationsSorted: Denomination[]
public readonly eraseInvalid: boolean
public readonly quantity: string
private readonly _validator: Validator
public readonly inverted: boolean
constructor(
@ -26,7 +24,6 @@ export class Unit {
inverted: boolean = false
) {
this.quantity = quantity
this._validator = validator
if (
!inverted &&
["string", "text", "key", "icon", "translation", "fediverse", "id"].indexOf(
@ -97,7 +94,7 @@ export class Unit {
tagRenderings: TagRenderingConfig[],
ctx: string
): Unit[] {
let types: Record<string, ValidatorType> = {}
const types: Record<string, ValidatorType> = {}
for (const tagRendering of tagRenderings) {
if (tagRendering.freeform?.type) {
types[tagRendering.freeform.key] = tagRendering.freeform.type
@ -185,7 +182,7 @@ export class Unit {
): Unit[] {
const appliesTo = json.appliesToKey
for (let i = 0; i < (appliesTo ?? []).length; i++) {
let key = appliesTo[i]
const key = appliesTo[i]
if (key.trim() !== key) {
throw `${ctx}.appliesToKey[${i}] is invalid: it starts or ends with whitespace`
}
@ -265,7 +262,7 @@ export class Unit {
const loaded = this.getFromLibrary(toLoad.quantity, ctx)
const quantity = toLoad.quantity
function fetchDenom(d: string): Denomination {
const fetchDenom = (d: string): Denomination => {
const found = loaded.denominations.find(
(denom) => denom.canonical.toLowerCase() === d
)