Skip to content

Commit

Permalink
feat: import form modal
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 committed Jan 20, 2024
1 parent cc3c65e commit a844983
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/core/findInputDefinitionSchema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { A, NonEmptyArray, ParsingFn, parse, pipe } from "@std";
import * as Separated from "fp-ts/Separated";
import * as E from "fp-ts/Either";
import { ValiError, BaseSchema } from "valibot";
import { FieldMinimal, FieldMinimalSchema } from "./formDefinitionSchema";
Expand All @@ -8,7 +7,8 @@ import { InputTypeToParserMap } from "./InputDefinitionSchema";

export function stringifyIssues(error: ValiError): NonEmptyArray<string> {
return error.issues.map(
(issue) => `${issue.path?.map((i) => i.key)}: ${issue.message} got ${issue.input}`,
(issue) =>
`${issue.path?.map((i) => i.key).join(".")}: ${issue.message} got ${issue.input}`,
) as NonEmptyArray<string>;
}
export class InvalidInputTypeError {
Expand Down
5 changes: 1 addition & 4 deletions src/core/formDefinitionSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ export class MigrationError {
${this.error.issues.map((issue) => issue.message).join(", ")}`;
}
toArrayOfStrings(): string[] {
return [
...stringifyIssues(this.error),
...this.fieldErrors.map((issue) => issue.toString()),
];
return stringifyIssues(this.error);
}
// This allows to store the error in the settings, along with the rest of the forms and
// have save all the data in one go transparently.
Expand Down
3 changes: 3 additions & 0 deletions src/views/FormImport.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,7 @@
padding: 1rem;
min-height: 50vh;
}
p {
margin: 0;
}
</style>
48 changes: 23 additions & 25 deletions src/views/ManageForms.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
export let forms: Readable<FormDefinition[]>;
export let invalidForms: Readable<MigrationError[]>;
function handleDeleteForm(formName: string) {
const confirmed = confirm(
`Are you sure you want to delete ${formName}?`,
);
const confirmed = confirm(`Are you sure you want to delete ${formName}?`);
if (confirmed) {
console.log(`Deleting ${formName}`);
deleteForm(formName);
Expand All @@ -39,16 +37,12 @@

<div class="header">
<h1>Manage forms</h1>
<Button onClick={createNewForm} text="Create new form" variant="primary"
></Button>
<Button onClick={createNewForm} text="Create new form" variant="primary"></Button>
{#if $invalidForms.length}
<h5 class="modal-form-danger">
There are {$invalidForms.length} invalid forms.
</h5>
<p>
Please take a look at the invalid forms section for details and
potential fixes.
</p>
<p>Please take a look at the invalid forms section for details and potential fixes.</p>
{/if}
</div>

Expand All @@ -64,8 +58,8 @@
>{Array.isArray(value)
? value.length
: typeof value === "object"
? !!value
: value}</span
? !!value
: value}</span
>
</KeyValue>
{/if}
Expand Down Expand Up @@ -110,21 +104,21 @@
<h4 class="form-name">{form.name}</h4>
{#each form.fieldErrors as error}
<div class="flex-row">
{#if E.isLeft(error)}
<pre class="invalid-field-json"><code>
{JSON.stringify(error.left.field, null, 1)}
<!-- {#if E.isLeft(error)} -->
<pre class="invalid-field-json"><code>
{"\n" + JSON.stringify(error.field, null, 1)}
</code></pre>
<KeyValue key={error.left.path}>
{#each error.left.getFieldErrors() as fieldError}
<span>{fieldError}</span>
{/each}
</KeyValue>
<hr />
{:else}
<KeyValue key="field">
<span>{error.right.name} ✅</span>
</KeyValue>
{/if}
<KeyValue key={error.path}>
{#each error.getFieldErrors() as fieldError}
<span>{fieldError}</span>
{/each}
</KeyValue>
<hr />
<!-- {:else} -->
<!-- <KeyValue key="field"> -->
<!-- <span>{error.right.name} ✅</span> -->
<!-- </KeyValue> -->
<!-- {/if} -->
</div>
{/each}
</div>
Expand Down Expand Up @@ -166,6 +160,10 @@
}
.invalid-field-json {
background-color: var(--background-secondary);
padding: 0 8px;
margin: 0;
}
.invalid-field-json code {
display: flex;
}
</style>

0 comments on commit a844983

Please sign in to comment.