Add option to deleteConfig to remove the default delete options

This commit is contained in:
Pieter Vander Vennet 2022-12-06 00:49:34 +01:00
parent e5d67d42c8
commit fe1cd0f120
3 changed files with 27 additions and 18 deletions

View file

@ -5,7 +5,7 @@ import Translations from "../../UI/i18n/Translations"
import { TagUtils } from "../../Logic/Tags/TagUtils"
export default class DeleteConfig {
public static readonly defaultDeleteReasons: {
private static readonly defaultDeleteReasons: {
changesetMessage: string
explanation: Translation
}[] = [
@ -27,8 +27,8 @@ export default class DeleteConfig {
},
]
public readonly extraDeleteReasons?: {
explanation: TypedTranslation<object>
public readonly deleteReasons?: {
explanation: TypedTranslation<object> | Translation
changesetMessage: string
}[]
@ -38,7 +38,7 @@ export default class DeleteConfig {
public readonly neededChangesets?: number
constructor(json: DeleteConfigJson, context: string) {
this.extraDeleteReasons = (json.extraDeleteReasons ?? []).map((reason, i) => {
this.deleteReasons = (json.extraDeleteReasons ?? []).map((reason, i) => {
const ctx = `${context}.extraDeleteReasons[${i}]`
if ((reason.changesetMessage ?? "").length <= 5) {
throw `${ctx}.explanation is too short, needs at least 4 characters`
@ -48,6 +48,16 @@ export default class DeleteConfig {
changesetMessage: reason.changesetMessage,
}
})
if(!json.omitDefaultDeleteReasons ){
for (const defaultDeleteReason of DeleteConfig.defaultDeleteReasons) {
this.deleteReasons.push({
changesetMessage: defaultDeleteReason.changesetMessage,
explanation: defaultDeleteReason.explanation.Clone(/*Must clone, hides translation otherwise*/)
})
}
}
this.nonDeleteMappings = (json.nonDeleteMappings ?? []).map((nonDelete, i) => {
const ctx = `${context}.extraDeleteReasons[${i}]`
return {
@ -56,6 +66,10 @@ export default class DeleteConfig {
}
})
if(this.nonDeleteMappings.length + this.deleteReasons.length == 0){
throw "At "+context+": a deleteconfig should have some reasons to delete: either the default delete reasons or a nonDeleteMapping or extraDeletereason should be given"
}
this.softDeletionTags = undefined
if (json.softDeletionTags !== undefined) {
this.softDeletionTags = TagUtils.Tag(

View file

@ -72,4 +72,10 @@ export interface DeleteConfigJson {
* For some small features (e.g. bicycle racks) this is too much and this requirement can be lowered or dropped, which can be done here.
*/
neededChangesets?: number
/**
* Set this flag if the default delete reasons should be omitted from the dialog.
* This requires at least one extraDeleteReason or nonDeleteMapping
*/
omitDefaultDeleteReasons?: false | boolean
}