forked from MapComplete/MapComplete
Chore: cleanup of imports and unused arguments
This commit is contained in:
parent
cc741d8ac1
commit
def7523334
4 changed files with 24 additions and 30 deletions
|
@ -124,7 +124,7 @@
|
||||||
|
|
||||||
{#if $currentlyMissing.length > 0}
|
{#if $currentlyMissing.length > 0}
|
||||||
{#each requiredFields as required}
|
{#each requiredFields as required}
|
||||||
<SchemaBasedInput {state} schema={configForRequiredField(required)} path={[required]} />
|
<SchemaBasedInput {state} path={[required]} />
|
||||||
{/each}
|
{/each}
|
||||||
{:else}
|
{:else}
|
||||||
<div class="m4 h-full overflow-y-auto">
|
<div class="m4 h-full overflow-y-auto">
|
||||||
|
|
|
@ -172,7 +172,8 @@ export abstract class EditJsonState<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public getSchema(path: string[]): ConfigMeta[] {
|
public getSchema(path: (string | number)[]): ConfigMeta[] {
|
||||||
|
path = path.filter(p => typeof p === "string")
|
||||||
const schemas = this.schema.filter(
|
const schemas = this.schema.filter(
|
||||||
(sch) =>
|
(sch) =>
|
||||||
sch !== undefined &&
|
sch !== undefined &&
|
||||||
|
|
|
@ -5,16 +5,16 @@
|
||||||
import { TrashIcon } from "@babeard/svelte-heroicons/mini"
|
import { TrashIcon } from "@babeard/svelte-heroicons/mini"
|
||||||
import ShowConversionMessage from "./ShowConversionMessage.svelte"
|
import ShowConversionMessage from "./ShowConversionMessage.svelte"
|
||||||
import Markdown from "../Base/Markdown.svelte"
|
import Markdown from "../Base/Markdown.svelte"
|
||||||
import { Utils } from "../../Utils"
|
import type {
|
||||||
import type { QuestionableTagRenderingConfigJson } from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"
|
QuestionableTagRenderingConfigJson,
|
||||||
|
} from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"
|
||||||
import CollapsedTagRenderingPreview from "./CollapsedTagRenderingPreview.svelte"
|
import CollapsedTagRenderingPreview from "./CollapsedTagRenderingPreview.svelte"
|
||||||
import { Accordion } from "flowbite-svelte"
|
import { Accordion } from "flowbite-svelte"
|
||||||
|
|
||||||
export let state: EditJsonState<any>
|
export let state: EditJsonState<any>
|
||||||
export let path: (string | number)[] = []
|
export let path: (string | number)[] = []
|
||||||
export let schema: ConfigMeta
|
let schema: ConfigMeta = state.getSchema(path)[0]
|
||||||
|
|
||||||
schema = Utils.Clone(schema)
|
|
||||||
let title = schema.path.at(-1)
|
let title = schema.path.at(-1)
|
||||||
let singular = title
|
let singular = title
|
||||||
if (title?.endsWith("s")) {
|
if (title?.endsWith("s")) {
|
||||||
|
@ -37,7 +37,8 @@
|
||||||
.filter((part) => part.path.length - 1 === schema.path.length)
|
.filter((part) => part.path.length - 1 === schema.path.length)
|
||||||
let messages = state.messagesFor(path)
|
let messages = state.messagesFor(path)
|
||||||
|
|
||||||
const currentValue = state.getStoreFor<(string | QuestionableTagRenderingConfigJson)[]>(path)
|
let datapath = path
|
||||||
|
const currentValue = state.getStoreFor<(string | QuestionableTagRenderingConfigJson)[]>(datapath)
|
||||||
if (currentValue.data === undefined) {
|
if (currentValue.data === undefined) {
|
||||||
currentValue.setData([])
|
currentValue.setData([])
|
||||||
}
|
}
|
||||||
|
@ -54,18 +55,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function fusePath(i: number, subpartPath: string[]): (string | number)[] {
|
function fusePath(i: number): (string | number)[] {
|
||||||
const newPath = [...path, i]
|
return [...path, i]
|
||||||
const toAdd = [...subpartPath]
|
|
||||||
for (const part of path) {
|
|
||||||
if (toAdd[0] === part) {
|
|
||||||
toAdd.splice(0, 1)
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
newPath.push(...toAdd)
|
|
||||||
return newPath
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function del(i: number) {
|
function del(i: number) {
|
||||||
|
@ -74,7 +65,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="pl-2">
|
<div class="pl-2">
|
||||||
|
@ -85,18 +75,20 @@
|
||||||
{/if}
|
{/if}
|
||||||
{#if $currentValue === undefined}
|
{#if $currentValue === undefined}
|
||||||
No array defined
|
No array defined
|
||||||
{:else if $currentValue.length === 0}
|
{:else if !Array.isArray($currentValue)}
|
||||||
|
Not an array: {typeof $currentValue} {JSON.stringify(path)} {JSON.stringify($currentValue).slice(0,120)}
|
||||||
|
{:else if $currentValue?.length === 0}
|
||||||
No values are defined
|
No values are defined
|
||||||
{#if $messages.length > 0}
|
{#if $messages.length > 0}
|
||||||
{#each $messages as message}
|
{#each $messages as message}
|
||||||
<ShowConversionMessage {message} />
|
<ShowConversionMessage {message} />
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
{:else if subparts.length === 0}
|
{:else if subparts.length === 0}
|
||||||
<!-- We need an array of values, so we use the typehint of the _parent_ element as field -->
|
<!-- We need an array of values, so we use the typehint of the _parent_ element as field -->
|
||||||
{#each $currentValue as value, i}
|
{#each $currentValue as value, i}
|
||||||
<div class="flex w-full">
|
<div class="flex w-full">
|
||||||
<SchemaBasedField {state} {schema} path={fusePath(i, [])} />
|
<SchemaBasedField {state} {schema} path={fusePath(i)} />
|
||||||
<button
|
<button
|
||||||
class="h-fit w-fit rounded-full border border-black p-1"
|
class="h-fit w-fit rounded-full border border-black p-1"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
|
@ -109,9 +101,9 @@
|
||||||
{/each}
|
{/each}
|
||||||
{:else}
|
{:else}
|
||||||
<Accordion>
|
<Accordion>
|
||||||
{#each $currentValue as value, i (value)}
|
{#each $currentValue as value, i (value)}
|
||||||
<CollapsedTagRenderingPreview {state} {isTagRenderingBlock} {schema} {currentValue} {value} {i} {singular} path={fusePath(i, [])}/>
|
<CollapsedTagRenderingPreview {state} {isTagRenderingBlock} {schema} {currentValue} {value} {i} {singular} path={fusePath(i)} />
|
||||||
{/each}
|
{/each}
|
||||||
</Accordion>
|
</Accordion>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
|
|
|
@ -12,15 +12,16 @@
|
||||||
let schema: ConfigMeta = state.getSchema(<any> path)[0]
|
let schema: ConfigMeta = state.getSchema(<any> path)[0]
|
||||||
let expertMode = state.expertMode
|
let expertMode = state.expertMode
|
||||||
</script>
|
</script>
|
||||||
|
{#if schema === undefined}
|
||||||
{#if (schema.hints?.group !== "expert" || $expertMode) && schema.hints.group !== "hidden"}
|
<div>ERROR: no schema found for {path.join(".")}</div>
|
||||||
|
{:else if (schema.hints?.group !== "expert" || $expertMode) && schema.hints.group !== "hidden"}
|
||||||
{#if schema.hints?.typehint?.endsWith("[]")}
|
{#if schema.hints?.typehint?.endsWith("[]")}
|
||||||
<!-- We cheat a bit here by matching this 'magical' type... -->
|
<!-- We cheat a bit here by matching this 'magical' type... -->
|
||||||
<SchemaBasedArray {path} {state} {schema} />
|
<SchemaBasedArray {path} {state} />
|
||||||
{:else if schema.type === "array" && schema.hints.multianswer === "true"}
|
{:else if schema.type === "array" && schema.hints.multianswer === "true"}
|
||||||
<ArrayMultiAnswer {path} {state} {schema} />
|
<ArrayMultiAnswer {path} {state} {schema} />
|
||||||
{:else if schema.type === "array"}
|
{:else if schema.type === "array"}
|
||||||
<SchemaBasedArray {path} {state} {schema} />
|
<SchemaBasedArray {path} {state} />
|
||||||
{:else if schema.hints?.types}
|
{:else if schema.hints?.types}
|
||||||
<SchemaBasedMultiType {path} {state} {schema} />
|
<SchemaBasedMultiType {path} {state} {schema} />
|
||||||
{:else}
|
{:else}
|
||||||
|
|
Loading…
Reference in a new issue