forked from MapComplete/MapComplete
Add option to deleteConfig to remove the default delete options
This commit is contained in:
parent
e5d67d42c8
commit
fe1cd0f120
3 changed files with 27 additions and 18 deletions
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ export default class DeleteWizard extends Toggle {
|
|||
return t.explanations.hardDelete
|
||||
}
|
||||
// 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(
|
||||
new FixedInputElement(
|
||||
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 })
|
||||
}
|
||||
}
|
||||
|
@ -453,7 +442,7 @@ class DeleteabilityChecker {
|
|||
return
|
||||
}
|
||||
if (waysOrRelations) {
|
||||
// not deleteble by mapcomplete
|
||||
// not deleteable by mapcomplete
|
||||
state.setData({
|
||||
canBeDeleted: false,
|
||||
reason: t.partOfOthers,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue