2022-05-01 04:17:40 +02:00
|
|
|
import { Translation, TypedTranslation } from "../../UI/i18n/Translation"
|
2021-07-03 14:35:44 +02:00
|
|
|
import { TagsFilter } from "../../Logic/Tags/TagsFilter"
|
2021-08-07 23:11:34 +02:00
|
|
|
import { DeleteConfigJson } from "./Json/DeleteConfigJson"
|
2021-07-03 14:35:44 +02:00
|
|
|
import Translations from "../../UI/i18n/Translations"
|
2021-08-07 23:11:34 +02:00
|
|
|
import { TagUtils } from "../../Logic/Tags/TagUtils"
|
2021-07-03 14:35:44 +02:00
|
|
|
|
|
|
|
export default class DeleteConfig {
|
2022-05-01 04:17:40 +02:00
|
|
|
public static readonly defaultDeleteReasons: {
|
|
|
|
changesetMessage: string
|
|
|
|
explanation: Translation
|
|
|
|
}[] = [
|
|
|
|
{
|
|
|
|
changesetMessage: "testing point",
|
|
|
|
explanation: Translations.t.delete.reasons.test,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
changesetMessage: "disused",
|
|
|
|
explanation: Translations.t.delete.reasons.disused,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
changesetMessage: "not found",
|
|
|
|
explanation: Translations.t.delete.reasons.notFound,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
changesetMessage: "duplicate",
|
|
|
|
explanation: Translations.t.delete.reasons.duplicate,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2021-08-07 23:11:34 +02:00
|
|
|
public readonly extraDeleteReasons?: {
|
2022-05-01 04:17:40 +02:00
|
|
|
explanation: TypedTranslation<object>
|
2021-07-03 14:35:44 +02:00
|
|
|
changesetMessage: string
|
|
|
|
}[]
|
|
|
|
|
2022-05-01 04:17:40 +02:00
|
|
|
public readonly nonDeleteMappings?: { if: TagsFilter; then: TypedTranslation<object> }[]
|
2021-07-03 14:35:44 +02:00
|
|
|
|
2021-08-07 23:11:34 +02:00
|
|
|
public readonly softDeletionTags?: TagsFilter
|
|
|
|
public readonly neededChangesets?: number
|
2021-07-03 14:35:44 +02:00
|
|
|
|
|
|
|
constructor(json: DeleteConfigJson, context: string) {
|
2022-05-01 04:17:40 +02:00
|
|
|
this.extraDeleteReasons = (json.extraDeleteReasons ?? []).map((reason, i) => {
|
2021-07-03 14:35:44 +02:00
|
|
|
const ctx = `${context}.extraDeleteReasons[${i}]`
|
|
|
|
if ((reason.changesetMessage ?? "").length <= 5) {
|
|
|
|
throw `${ctx}.explanation is too short, needs at least 4 characters`
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
explanation: Translations.T(reason.explanation, ctx + ".explanation"),
|
|
|
|
changesetMessage: reason.changesetMessage,
|
|
|
|
}
|
|
|
|
})
|
2022-05-01 04:17:40 +02:00
|
|
|
this.nonDeleteMappings = (json.nonDeleteMappings ?? []).map((nonDelete, i) => {
|
2021-07-03 14:35:44 +02:00
|
|
|
const ctx = `${context}.extraDeleteReasons[${i}]`
|
|
|
|
return {
|
2021-08-07 23:11:34 +02:00
|
|
|
if: TagUtils.Tag(nonDelete.if, ctx + ".if"),
|
2021-07-03 14:35:44 +02:00
|
|
|
then: Translations.T(nonDelete.then, ctx + ".then"),
|
|
|
|
}
|
|
|
|
})
|
2021-08-07 23:11:34 +02:00
|
|
|
|
2021-07-28 15:41:16 +02:00
|
|
|
this.softDeletionTags = undefined
|
2021-08-07 23:11:34 +02:00
|
|
|
if (json.softDeletionTags !== undefined) {
|
|
|
|
this.softDeletionTags = TagUtils.Tag(
|
|
|
|
json.softDeletionTags,
|
|
|
|
`${context}.softDeletionTags`
|
|
|
|
)
|
2021-07-03 14:35:44 +02:00
|
|
|
}
|
2021-08-07 23:11:34 +02:00
|
|
|
|
|
|
|
if (json["hardDeletionTags"] !== undefined) {
|
2021-08-05 16:20:25 +02:00
|
|
|
throw `You probably meant 'softDeletionTags' instead of 'hardDeletionTags' (at ${context})`
|
|
|
|
}
|
2021-07-03 14:35:44 +02:00
|
|
|
this.neededChangesets = json.neededChangesets
|
|
|
|
}
|
|
|
|
}
|