Skip to content

Commit

Permalink
First version of giving feedback to contriubtors on invalid values
Browse files Browse the repository at this point in the history
  • Loading branch information
pietervdvn committed Feb 12, 2022
1 parent e07b770 commit 5221e91
Show file tree
Hide file tree
Showing 16 changed files with 480 additions and 330 deletions.
4 changes: 2 additions & 2 deletions Models/ThemeConfig/FilterConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export default class FilterConfig {

const fields: { name: string, type: string }[] = ((option.fields) ?? []).map((f, i) => {
const type = f.type ?? "string"
if (!ValidatedTextField.AllTypes.has(type)) {
throw `Invalid filter: ${type} is not a valid validated textfield type (at ${ctx}.fields[${i}])\n\tTry one of ${Array.from(ValidatedTextField.AllTypes.keys()).join(",")}`
if (!ValidatedTextField.ForType(type) === undefined) {
throw `Invalid filter: ${type} is not a valid validated textfield type (at ${ctx}.fields[${i}])\n\tTry one of ${Array.from(ValidatedTextField.AvailableTypes()).join(",")}`
}
if (f.name === undefined || f.name === "" || f.name.match(/[a-z0-9_-]+/) == null) {
throw `Invalid filter: a variable name should match [a-z0-9_-]+ at ${ctx}.fields[${i}]`
Expand Down
2 changes: 1 addition & 1 deletion Models/ThemeConfig/TagRenderingConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default class TagRenderingConfig {
}


if (!ValidatedTextField.AllTypes.has(this.freeform.type)) {
if (!ValidatedTextField.ForType(this.freeform.key) === undefined) {
const knownKeys = ValidatedTextField.AvailableTypes().join(", ");
throw `Freeform.key ${this.freeform.key} is an invalid type. Known keys are ${knownKeys}`
}
Expand Down
4 changes: 2 additions & 2 deletions UI/AutomatonGui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class AutomatonGui {

LocalStorageSource.Get("automation-theme-id", "missing_streets").syncWith(themeSelect.GetValue())

const tilepath = ValidatedTextField.InputForType("url", {
const tilepath = ValidatedTextField.ForType("url").ConstructInputElement({
placeholder: "Specifiy the path of the overview",
inputStyle: "width: 100%"
})
Expand Down Expand Up @@ -305,7 +305,7 @@ class AutomatonGui {
return Array.from(rezoomed)
})

const extraComment = ValidatedTextField.InputForType("text")
const extraComment = ValidatedTextField.ForType("text").ConstructInputElement()
LocalStorageSource.Get("automaton-extra-comment").syncWith(extraComment.GetValue())

return new Combine([
Expand Down
2 changes: 1 addition & 1 deletion UI/BigComponents/FilterView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default class FilterView extends VariableUiElement {
const properties = new UIEventSource<any>({})
for (const {name, type} of filter.fields) {
const value = QueryParameters.GetQueryParameter("filter-" + filterConfig.id + "-" + name, "", "Value for filter " + filterConfig.id)
const field = ValidatedTextField.InputForType(type, {
const field = ValidatedTextField.ForType(type).ConstructInputElement({
value
}).SetClass("inline-block")
mappings.set(name, field)
Expand Down
8 changes: 4 additions & 4 deletions UI/ImportFlow/AskMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ export class AskMetadata extends Combine implements FlowStep<{

constructor(params: ({ features: any[], layer: LayerConfig })) {

const introduction = ValidatedTextField.InputForType("text", {
const introduction = ValidatedTextField.ForType("text").ConstructInputElement({
value: LocalStorageSource.Get("import-helper-introduction-text"),
inputStyle: "width: 100%"
})

const wikilink = ValidatedTextField.InputForType("string", {
const wikilink = ValidatedTextField.ForType("string").ConstructInputElement({
value: LocalStorageSource.Get("import-helper-wikilink-text"),
inputStyle: "width: 100%"
})

const source = ValidatedTextField.InputForType("string", {
const source = ValidatedTextField.ForType("string").ConstructInputElement({
value: LocalStorageSource.Get("import-helper-source-text"),
inputStyle: "width: 100%"
})
Expand All @@ -59,7 +59,7 @@ export class AskMetadata extends Combine implements FlowStep<{

const theme = new DropDown("Which theme should be linked in the note?", options)

ValidatedTextField.InputForType("string", {
ValidatedTextField.ForType("string").ConstructInputElement({
value: LocalStorageSource.Get("import-helper-theme-text"),
inputStyle: "width: 100%"
})
Expand Down
4 changes: 2 additions & 2 deletions UI/ImportFlow/ConflationChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class ConflationChecker extends Combine implements FlowStep<{ fea
const background = new UIEventSource<BaseLayer>(AvailableBaseLayers.osmCarto)
const location = new UIEventSource<Loc>({lat: 0, lon: 0, zoom: 1})
const currentBounds = new UIEventSource<BBox>(undefined)
const zoomLevel = ValidatedTextField.InputForType("pnat")
const zoomLevel = ValidatedTextField.ForType("pnat").ConstructInputElement()
zoomLevel.SetClass("ml-1 border border-black")
zoomLevel.GetValue().syncWith(LocalStorageSource.Get("importer-zoom-level", "14"), true)
const osmLiveData = Minimap.createMiniMap({
Expand Down Expand Up @@ -146,7 +146,7 @@ export default class ConflationChecker extends Combine implements FlowStep<{ fea
features: new StaticFeatureSource(toImport.features, false)
})

const nearbyCutoff = ValidatedTextField.InputForType("pnat")
const nearbyCutoff = ValidatedTextField.ForType("pnat").ConstructInputElement()
nearbyCutoff.SetClass("ml-1 border border-black")
nearbyCutoff.GetValue().syncWith(LocalStorageSource.Get("importer-cutoff", "25"), true)

Expand Down
2 changes: 1 addition & 1 deletion UI/ImportFlow/ImportViewerGui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface NoteState {

class MassAction extends Combine {
constructor(state: UserRelatedState, props: NoteProperties[]) {
const textField = ValidatedTextField.InputForType("text")
const textField = ValidatedTextField.ForType("text").ConstructInputElement()

const actions = new DropDown<{
predicate: (p: NoteProperties) => boolean,
Expand Down
11 changes: 9 additions & 2 deletions UI/Input/TextField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export class TextField extends InputElement<string> {
private readonly value: UIEventSource<string>;
private _element: HTMLElement;
private readonly _isValid: (s: string, country?: () => string) => boolean;

private _rawValue: UIEventSource<string>

constructor(options?: {
placeholder?: string | BaseUIElement,
value?: UIEventSource<string>,
Expand All @@ -23,6 +24,7 @@ export class TextField extends InputElement<string> {
const self = this;
options = options ?? {};
this.value = options?.value ?? new UIEventSource<string>(undefined);
this._rawValue = new UIEventSource<string>("")
this._isValid = options.isValid ?? (_ => true);

const placeholder = Translations.W(options.placeholder ?? "").ConstructElement().innerText.replace("'", "&#39");
Expand Down Expand Up @@ -77,6 +79,7 @@ export class TextField extends InputElement<string> {
const endDistance = field.value.substring(field.selectionEnd).replace(/ /g, '').length;
// @ts-ignore
let val: string = field.value;
self._rawValue.setData(val)
if (!self.IsValid(val)) {
self.value.setData(undefined);
} else {
Expand Down Expand Up @@ -128,7 +131,11 @@ export class TextField extends InputElement<string> {
GetValue(): UIEventSource<string> {
return this.value;
}


GetRawValue(): UIEventSource<string>{
return this._rawValue
}

IsValid(t: string): boolean {
if (t === undefined || t === null) {
return false
Expand Down
Loading

0 comments on commit 5221e91

Please sign in to comment.