forked from MapComplete/MapComplete
Fix: some fixes to make studio useable again, probably fixes #2139
This commit is contained in:
parent
f2fca2dad8
commit
6672fc87b4
4 changed files with 89 additions and 65 deletions
|
@ -30,7 +30,7 @@
|
||||||
.getSchemaStartingWith(schema.path)
|
.getSchemaStartingWith(schema.path)
|
||||||
.filter((part) => part.path.length - 1 === schema.path.length)
|
.filter((part) => part.path.length - 1 === schema.path.length)
|
||||||
|
|
||||||
let usesOverride = value["builtin"] !== undefined
|
let usesOverride = value?.["builtin"] !== undefined
|
||||||
|
|
||||||
function schemaForMultitype() {
|
function schemaForMultitype() {
|
||||||
const sch = { ...schema }
|
const sch = { ...schema }
|
||||||
|
@ -138,7 +138,7 @@
|
||||||
</div>
|
</div>
|
||||||
{:else if typeof value === "string"}
|
{:else if typeof value === "string"}
|
||||||
Builtin: <b>{value}</b>
|
Builtin: <b>{value}</b>
|
||||||
{:else if value["builtin"]}
|
{:else if value?.["builtin"]}
|
||||||
reused tagrendering <span class="font-bold">{JSON.stringify(value["builtin"])}</span>
|
reused tagrendering <span class="font-bold">{JSON.stringify(value["builtin"])}</span>
|
||||||
{:else}
|
{:else}
|
||||||
<Tr cls="font-bold" t={Translations.T(value?.question ?? value?.render)} />
|
<Tr cls="font-bold" t={Translations.T(value?.question ?? value?.render)} />
|
||||||
|
|
|
@ -159,6 +159,9 @@ export abstract class EditJsonState<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public getSchemaStartingWith(path: string[]) {
|
public getSchemaStartingWith(path: string[]) {
|
||||||
|
if(path === undefined){
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
return this.schema.filter(
|
return this.schema.filter(
|
||||||
(sch) =>
|
(sch) =>
|
||||||
!path.some((part, i) => !(sch.path.length > path.length && sch.path[i] === part))
|
!path.some((part, i) => !(sch.path.length > path.length && sch.path[i] === part))
|
||||||
|
|
|
@ -5,18 +5,23 @@
|
||||||
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 type { QuestionableTagRenderingConfigJson } from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"
|
import type {
|
||||||
|
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"
|
||||||
|
import { Utils } from "../../Utils"
|
||||||
|
|
||||||
export let state: EditJsonState<any>
|
export let state: EditJsonState<any>
|
||||||
export let path: (string | number)[] = []
|
export let path: (string | number)[] = []
|
||||||
let schema: ConfigMeta = state.getSchema(path)[0]
|
let schema: ConfigMeta = state.getSchema(path)[0]
|
||||||
|
console.log("SBA got schema", schema, "for path", path)
|
||||||
|
|
||||||
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")) {
|
||||||
singular = title.slice(0, title.length - 1)
|
singular = title?.slice(0, title.length - 1)
|
||||||
}
|
}
|
||||||
let article = "a"
|
let article = "a"
|
||||||
if (singular?.match(/^[aeoui]/)) {
|
if (singular?.match(/^[aeoui]/)) {
|
||||||
|
@ -25,18 +30,20 @@
|
||||||
|
|
||||||
const isTagRenderingBlock = path.length === 1 && path[0] === "tagRenderings"
|
const isTagRenderingBlock = path.length === 1 && path[0] === "tagRenderings"
|
||||||
|
|
||||||
if (isTagRenderingBlock) {
|
if (isTagRenderingBlock && schema !== undefined) {
|
||||||
schema = { ...schema }
|
schema = { ...schema }
|
||||||
schema.description = undefined
|
schema.description = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
const subparts: ConfigMeta[] = state
|
const subparts: ConfigMeta[] = state
|
||||||
.getSchemaStartingWith(schema.path)
|
.getSchemaStartingWith(schema?.path)
|
||||||
.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)
|
||||||
|
|
||||||
let datapath = path
|
let datapath = path
|
||||||
const currentValue = state.getStoreFor<(string | QuestionableTagRenderingConfigJson)[]>(datapath)
|
const currentValue = state.getStoreFor<(string | QuestionableTagRenderingConfigJson)[]>(datapath)
|
||||||
|
currentValue.set(Utils.DedupT(currentValue.data))
|
||||||
|
console.log("Current value is", currentValue.data)
|
||||||
if (currentValue.data === undefined) {
|
if (currentValue.data === undefined) {
|
||||||
currentValue.setData([])
|
currentValue.setData([])
|
||||||
}
|
}
|
||||||
|
@ -62,68 +69,69 @@
|
||||||
currentValue.ping()
|
currentValue.ping()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
{#if schema !== undefined}
|
||||||
|
<div class="pl-2">
|
||||||
|
<h3>{schema.path.at(-1)}</h3>
|
||||||
|
|
||||||
<div class="pl-2">
|
{#if subparts.length > 0}
|
||||||
<h3>{schema.path.at(-1)}</h3>
|
<Markdown src={schema.description} />
|
||||||
|
|
||||||
{#if subparts.length > 0}
|
|
||||||
<Markdown src={schema.description} />
|
|
||||||
{/if}
|
|
||||||
{#if $currentValue === undefined}
|
|
||||||
No array defined
|
|
||||||
{: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
|
|
||||||
{#if $messages.length > 0}
|
|
||||||
{#each $messages as message}
|
|
||||||
<ShowConversionMessage {message} />
|
|
||||||
{/each}
|
|
||||||
{/if}
|
{/if}
|
||||||
{:else if subparts.length === 0}
|
{#if $currentValue === undefined}
|
||||||
<!-- We need an array of values, so we use the typehint of the _parent_ element as field -->
|
No array defined
|
||||||
{#each $currentValue as value, i}
|
{:else if !Array.isArray($currentValue)}
|
||||||
<div class="flex w-full">
|
Not an array: {typeof $currentValue}
|
||||||
<SchemaBasedField {state} {schema} path={fusePath(i)} />
|
{JSON.stringify(path)}
|
||||||
<button
|
{JSON.stringify($currentValue).slice(0, 120)}
|
||||||
class="h-fit w-fit rounded-full border border-black p-1"
|
{:else if $currentValue?.length === 0}
|
||||||
on:click={() => {
|
No values are defined
|
||||||
|
{#if $messages.length > 0}
|
||||||
|
{#each $messages as message}
|
||||||
|
<ShowConversionMessage {message} />
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
|
{:else if subparts.length === 0}
|
||||||
|
<!-- We need an array of values, so we use the typehint of the _parent_ element as field -->
|
||||||
|
{#each $currentValue as value, i}
|
||||||
|
<div class="flex w-full">
|
||||||
|
<SchemaBasedField {state} {schema} path={fusePath(i)} />
|
||||||
|
<button
|
||||||
|
class="h-fit w-fit rounded-full border border-black p-1"
|
||||||
|
on:click={() => {
|
||||||
del(i)
|
del(i)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TrashIcon class="h-4 w-4" />
|
<TrashIcon class="h-4 w-4" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
|
||||||
{:else}
|
|
||||||
<Accordion>
|
|
||||||
{#each $currentValue as value, i (value)}
|
|
||||||
<CollapsedTagRenderingPreview
|
|
||||||
{state}
|
|
||||||
{isTagRenderingBlock}
|
|
||||||
{schema}
|
|
||||||
{currentValue}
|
|
||||||
{value}
|
|
||||||
{i}
|
|
||||||
{singular}
|
|
||||||
path={fusePath(i)}
|
|
||||||
/>
|
|
||||||
{/each}
|
{/each}
|
||||||
</Accordion>
|
{:else}
|
||||||
{/if}
|
<Accordion>
|
||||||
<div class="flex">
|
{#each $currentValue as value, i}
|
||||||
<button on:click={() => createItem()}>Add {article} {singular}</button>
|
<CollapsedTagRenderingPreview
|
||||||
{#if path.length === 1 && path[0] === "tagRenderings"}
|
{state}
|
||||||
<button
|
{isTagRenderingBlock}
|
||||||
on:click={() => {
|
{schema}
|
||||||
|
{currentValue}
|
||||||
|
{value}
|
||||||
|
{i}
|
||||||
|
{singular}
|
||||||
|
path={fusePath(i)}
|
||||||
|
/>
|
||||||
|
{/each}
|
||||||
|
</Accordion>
|
||||||
|
{/if}
|
||||||
|
<div class="flex">
|
||||||
|
<button on:click={() => createItem()}>Add {article} {singular}</button>
|
||||||
|
{#if path.length === 1 && path[0] === "tagRenderings"}
|
||||||
|
<button
|
||||||
|
on:click={() => {
|
||||||
createItem("images")
|
createItem("images")
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Add a builtin tagRendering
|
Add a builtin tagRendering
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
<slot name="extra-button" />
|
<slot name="extra-button" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{/if}
|
||||||
|
|
13
src/Utils.ts
13
src/Utils.ts
|
@ -401,6 +401,19 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
||||||
return newArr
|
return newArr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DedupT<T>(arr: T[]): T[]{
|
||||||
|
if(!arr){
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
const items = []
|
||||||
|
for (const item of arr) {
|
||||||
|
if(items.indexOf(item) < 0){
|
||||||
|
items.push(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return items
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds all duplicates in a list of strings
|
* Finds all duplicates in a list of strings
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue