Skip to content

Commit

Permalink
Some form handling
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Jun 13, 2024
1 parent 8cd1e42 commit 9519b2a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
25 changes: 21 additions & 4 deletions src/components/JsonSchemaForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@
import Form from "@rjsf/core";
import validator from "@rjsf/validator-ajv8";
import { applyPureReactInVue } from "veaury";
import { FormEvent } from "react";

Check failure on line 5 in src/components/JsonSchemaForm.vue

View workflow job for this annotation

GitHub Actions / build (18.x)

Could not find a declaration file for module 'react'. '/home/runner/work/mink-frontend/mink-frontend/node_modules/react/index.js' implicitly has an 'any' type.

Check failure on line 5 in src/components/JsonSchemaForm.vue

View workflow job for this annotation

GitHub Actions / build (20.x)

Could not find a declaration file for module 'react'. '/home/runner/work/mink-frontend/mink-frontend/node_modules/react/index.js' implicitly has an 'any' type.

Check failure on line 5 in src/components/JsonSchemaForm.vue

View workflow job for this annotation

GitHub Actions / build (22.x)

Could not find a declaration file for module 'react'. '/home/runner/work/mink-frontend/mink-frontend/node_modules/react/index.js' implicitly has an 'any' type.
import useMessenger from "@/message/messenger.composable";
const VeauryForm = applyPureReactInVue(Form);
defineProps<{
schema: any;
data: any;
onChange?: () => {};
onSubmit?: () => {};
onError?: () => {};
onChange?: (event: FormEvent, fieldId: string) => {};
onSubmit?: (event: FormEvent) => {};
}>();
type Error = {
message: string;
property: string;
};
const { alert } = useMessenger();
function onError(errors: Error[]) {
errors.forEach((error) =>
alert(`${error.property.split(".").pop()} ${error.message}`, "error"),
);
}
</script>

<template>
Expand All @@ -23,7 +37,7 @@ defineProps<{
:formData="data"
:onChange
:onSubmit
:onError
:onError="onError"
:experimental_defaultFormStateBehavior="{
allOf: 'populateDefaults',
}"
Expand Down Expand Up @@ -55,4 +69,7 @@ defineProps<{
::v-deep(.unsupported-field) {
@apply bg-red-50;
}
::v-deep(.has-error) {
@apply bg-red-50;
}
</style>
21 changes: 13 additions & 8 deletions src/corpus/config/SchemaConfig.vue
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
<script setup lang="ts">
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import Yaml from "js-yaml";
import { FormEvent } from "react";

Check failure on line 4 in src/corpus/config/SchemaConfig.vue

View workflow job for this annotation

GitHub Actions / build (18.x)

Could not find a declaration file for module 'react'. '/home/runner/work/mink-frontend/mink-frontend/node_modules/react/index.js' implicitly has an 'any' type.

Check failure on line 4 in src/corpus/config/SchemaConfig.vue

View workflow job for this annotation

GitHub Actions / build (20.x)

Could not find a declaration file for module 'react'. '/home/runner/work/mink-frontend/mink-frontend/node_modules/react/index.js' implicitly has an 'any' type.

Check failure on line 4 in src/corpus/config/SchemaConfig.vue

View workflow job for this annotation

GitHub Actions / build (22.x)

Could not find a declaration file for module 'react'. '/home/runner/work/mink-frontend/mink-frontend/node_modules/react/index.js' implicitly has an 'any' type.
import schema from "@/assets/sparvconfig.schema.json";
import useCorpusIdParam from "@/corpus/corpusIdParam.composable";
import useMessenger from "@/message/messenger.composable";
import useConfig from "@/corpus/config/config.composable";
import JsonSchemaForm from "@/components/JsonSchemaForm.vue";
const router = useRouter();
const corpusId = useCorpusIdParam();
const { config, uploadConfig } = useConfig(corpusId);
const { alert, alertError } = useMessenger();
const { t } = useI18n();
const { config, uploadConfigRaw } = useConfig(corpusId);
const configParsed = computed(() =>
config.value ? Yaml.load(config.value) : undefined,
);
async function onSubmit(event: FormEvent) {
const configYaml = Yaml.dump(event.formData);
await uploadConfigRaw(configYaml);
}
</script>

<template>
<JsonSchemaForm v-if="configParsed" :schema="schema" :data="configParsed" />
<JsonSchemaForm
v-if="configParsed"
:schema="schema"
:data="configParsed"
:on-submit="onSubmit"
/>
</template>

0 comments on commit 9519b2a

Please sign in to comment.