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" import { TagUtils } from "../../Logic/Tags/TagUtils"
export default class DeleteConfig { export default class DeleteConfig {
public static readonly defaultDeleteReasons: { private static readonly defaultDeleteReasons: {
changesetMessage: string changesetMessage: string
explanation: Translation explanation: Translation
}[] = [ }[] = [
@ -27,8 +27,8 @@ export default class DeleteConfig {
}, },
] ]
public readonly extraDeleteReasons?: { public readonly deleteReasons?: {
explanation: TypedTranslation<object> explanation: TypedTranslation<object> | Translation
changesetMessage: string changesetMessage: string
}[] }[]
@ -38,7 +38,7 @@ export default class DeleteConfig {
public readonly neededChangesets?: number public readonly neededChangesets?: number
constructor(json: DeleteConfigJson, context: string) { constructor(json: DeleteConfigJson, context: string) {
this.extraDeleteReasons = (json.extraDeleteReasons ?? []).map((reason, i) => { this.deleteReasons = (json.extraDeleteReasons ?? []).map((reason, i) => {
const ctx = `${context}.extraDeleteReasons[${i}]` const ctx = `${context}.extraDeleteReasons[${i}]`
if ((reason.changesetMessage ?? "").length <= 5) { if ((reason.changesetMessage ?? "").length <= 5) {
throw `${ctx}.explanation is too short, needs at least 4 characters` throw `${ctx}.explanation is too short, needs at least 4 characters`
@ -48,6 +48,16 @@ export default class DeleteConfig {
changesetMessage: reason.changesetMessage, 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) => { this.nonDeleteMappings = (json.nonDeleteMappings ?? []).map((nonDelete, i) => {
const ctx = `${context}.extraDeleteReasons[${i}]` const ctx = `${context}.extraDeleteReasons[${i}]`
return { 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 this.softDeletionTags = undefined
if (json.softDeletionTags !== undefined) { if (json.softDeletionTags !== undefined) {
this.softDeletionTags = TagUtils.Tag( 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. * 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 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
} }

View file

@ -235,7 +235,7 @@ export default class DeleteWizard extends Toggle {
return t.explanations.hardDelete return t.explanations.hardDelete
} }
// This is a soft deletion: we explain _why_ the deletion is soft // This is a soft deletion: we explain _why_ the deletion is soft
return t.explanations.softDelete.Subs({ reason: reason }) return t.explanations.softDelete.Subs({ reason: reason})
}) })
) )
} }
@ -263,7 +263,7 @@ export default class DeleteWizard extends Toggle {
) )
} }
for (const extraDeleteReason of config.extraDeleteReasons ?? []) { for (const extraDeleteReason of config.deleteReasons ?? []) {
elements.push( elements.push(
new FixedInputElement( new FixedInputElement(
new SubstitutedTranslation(extraDeleteReason.explanation, tagsSource, state), new SubstitutedTranslation(extraDeleteReason.explanation, tagsSource, state),
@ -274,17 +274,6 @@ export default class DeleteWizard extends Toggle {
) )
} }
for (const extraDeleteReason of DeleteConfig.defaultDeleteReasons) {
elements.push(
new FixedInputElement(
extraDeleteReason.explanation.Clone(/*Must clone here, as this explanation might be used on many locations*/),
{
deleteReason: extraDeleteReason.changesetMessage,
}
)
)
}
return new RadioButton(elements, { selectFirstAsDefault: false }) return new RadioButton(elements, { selectFirstAsDefault: false })
} }
} }
@ -453,7 +442,7 @@ class DeleteabilityChecker {
return return
} }
if (waysOrRelations) { if (waysOrRelations) {
// not deleteble by mapcomplete // not deleteable by mapcomplete
state.setData({ state.setData({
canBeDeleted: false, canBeDeleted: false,
reason: t.partOfOthers, reason: t.partOfOthers,