From bce8ae3e3424afbadf1c763741df9df12904a49b Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Tue, 19 Apr 2022 23:42:58 +0200 Subject: [PATCH] Fixes to import flow --- UI/ImportFlow/ConfirmProcess.ts | 9 +++++---- UI/ImportFlow/ConflationChecker.ts | 6 +++--- UI/ImportFlow/CreateNotes.ts | 28 +++++++++++++++++++++------- UI/ImportFlow/Introdution.ts | 5 +++-- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/UI/ImportFlow/ConfirmProcess.ts b/UI/ImportFlow/ConfirmProcess.ts index d7168a86d..c8e3f570e 100644 --- a/UI/ImportFlow/ConfirmProcess.ts +++ b/UI/ImportFlow/ConfirmProcess.ts @@ -13,19 +13,20 @@ export class ConfirmProcess extends Combine implements FlowStep<{ features: any[ constructor(v: { features: any[], theme: string }) { const t = Translations.t.importHelper.confirmProcess; - const toConfirm = [ + const elements = [ new Link(t.readImportGuidelines, "https://wiki.openstreetmap.org/wiki/Import_guidelines", true), t.contactedCommunity, t.licenseIsCompatible, t.wikipageIsMade - ]; + ] + const toConfirm = new CheckBoxes(elements); super([ new Title(t.titleLong), - new CheckBoxes(toConfirm), + toConfirm, ]); this.SetClass("link-underline") - this.IsValid = new CheckBoxes(toConfirm).GetValue().map(selected => toConfirm.length == selected.length) + this.IsValid = toConfirm.GetValue().map(selected => elements.length == selected.length) this.Value = new UIEventSource<{ features: any[], theme: string }>(v) } } \ No newline at end of file diff --git a/UI/ImportFlow/ConflationChecker.ts b/UI/ImportFlow/ConflationChecker.ts index 0f01ce3c9..91b78fb24 100644 --- a/UI/ImportFlow/ConflationChecker.ts +++ b/UI/ImportFlow/ConflationChecker.ts @@ -217,7 +217,7 @@ export default class ConflationChecker extends Combine implements FlowStep<{ fea new Title(t.titleLive), t.importCandidatesCount.Subs({count:toImport.features.length }), new VariableUiElement(geojson.map(geojson => { - if(geojson?.features?.length === undefined && geojson?.features?.length === 0){ + if(geojson?.features?.length === undefined || geojson?.features?.length === 0){ return t.nothingLoaded.Subs(layer).SetClass("alert") } return new Combine([ @@ -233,7 +233,7 @@ export default class ConflationChecker extends Combine implements FlowStep<{ fea new Combine([t.mapShowingNearbyIntro, nearbyCutoff]).SetClass("flex"), new VariableUiElement(toImportWithNearby.features.map(feats => t.nearbyWarn.Subs({count: feats.length}).SetClass("alert"))), - ,t.setRangeToZero, + t.setRangeToZero, matchedFeaturesMap]).SetClass("flex flex-col") super([ @@ -246,7 +246,7 @@ export default class ConflationChecker extends Combine implements FlowStep<{ fea return new Loading(t.states.running) } if (d["error"] !== undefined) { - return t.states.error.Subs(d).SetClass("alert") + return t.states.error.Subs({error: d["error"]}).SetClass("alert") } if (d === "cached") { diff --git a/UI/ImportFlow/CreateNotes.ts b/UI/ImportFlow/CreateNotes.ts index 8b8f1ffc4..249be836e 100644 --- a/UI/ImportFlow/CreateNotes.ts +++ b/UI/ImportFlow/CreateNotes.ts @@ -9,12 +9,14 @@ import {FixedUiElement} from "../Base/FixedUiElement"; import {SubtleButton} from "../Base/SubtleButton"; import Svg from "../../Svg"; import Translations from "../i18n/Translations"; +import {Translation} from "../i18n/Translation"; export class CreateNotes extends Combine { - public static createNoteContents(feature: {properties: any, geometry: {coordinates: [number,number]}}, - options: {wikilink: string; intro: string; source: string, theme: string } - ): string[]{ + + public static createNoteContentsUi(feature: {properties: any, geometry: {coordinates: [number,number]}}, + options: {wikilink: string; intro: string; source: string, theme: string } + ): (Translation | string)[]{ const src = feature.properties["source"] ?? feature.properties["src"] ?? options.source delete feature.properties["source"] delete feature.properties["src"] @@ -41,14 +43,26 @@ export class CreateNotes extends Combine { return [ options.intro, extraNote, - note.datasource.Subs({source: src}).txt, - note.wikilink.Subs(options).txt, + note.datasource.Subs({source: src}), + note.wikilink.Subs(options), '', - note.importEasily.txt, + note.importEasily, `https://mapcomplete.osm.be/${options.theme}.html?z=18&lat=${lat}&lon=${lon}#import`, ...tags] } + public static createNoteContents(feature: {properties: any, geometry: {coordinates: [number,number]}}, + options: {wikilink: string; intro: string; source: string, theme: string } + ): string[]{ + return CreateNotes.createNoteContentsUi(feature, options).map(trOrStr => { + if(typeof trOrStr === "string"){ + return trOrStr + } + return trOrStr.txt + }) + } + + constructor(state: { osmConnection: OsmConnection }, v: { features: any[]; wikilink: string; intro: string; source: string, theme: string }) { const t = Translations.t.importHelper.createNotes; const createdNotes: UIEventSource = new UIEventSource([]) @@ -83,7 +97,7 @@ export class CreateNotes extends Combine { )))), new Combine([ Svg.party_svg().SetClass("w-24"), - t.done.Subs(v.features.length).SetClass("thanks"), + t.done.Subs({count: v.features.length}).SetClass("thanks"), new SubtleButton(Svg.note_svg(), t.openImportViewer , { url: "import_viewer.html" diff --git a/UI/ImportFlow/Introdution.ts b/UI/ImportFlow/Introdution.ts index e46dd3c9f..d80090196 100644 --- a/UI/ImportFlow/Introdution.ts +++ b/UI/ImportFlow/Introdution.ts @@ -4,13 +4,14 @@ import {UIEventSource} from "../../Logic/UIEventSource"; import Translations from "../i18n/Translations"; import Title from "../Base/Title"; import {CreateNotes} from "./CreateNotes"; +import {FixedUiElement} from "../Base/FixedUiElement"; export default class Introdution extends Combine implements FlowStep { readonly IsValid: UIEventSource; readonly Value: UIEventSource; constructor() { - const example = CreateNotes.createNoteContents({ + const example = CreateNotes.createNoteContentsUi({ properties:{ "some_key":"some_value", "note":"a note in the original dataset" @@ -23,7 +24,7 @@ export default class Introdution extends Combine implements FlowStep { intro: "There might be an XYZ here", theme: "theme", source: "source of the data" - }) + }).map(el => el === "" ? new FixedUiElement("").SetClass("block") : el) super([ new Title(Translations.t.importHelper.introduction.title),