-
Couldn't load subscription status.
- Fork 11
Fix JsonForms i18n integration and add coverage #1762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,135 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { defineComponent, h, nextTick, ref } from 'vue'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { createI18n } from 'vue-i18n'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { jsonFormsAjv } from '@unraid/ui'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { JsonForms } from '@jsonforms/vue'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { vanillaRenderers } from '@jsonforms/vue-vanilla'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { render, screen } from '@testing-library/vue'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useJsonFormsI18n } from '~/helpers/jsonforms-i18n'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { describe, expect, it } from 'vitest'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const schema = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| properties: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| provider: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| minLength: 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| i18n: 'jsonforms.test.provider', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: ['provider'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } as const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const uischema = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'Control', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scope: '#/properties/provider', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } as const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const messages = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| en: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jsonforms: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| test: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| provider: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: 'Provider label (en)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'English description', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errors: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: 'Field is required (en)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fr: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jsonforms: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| test: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| provider: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: 'Libellé du fournisseur (fr)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Description française', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errors: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: 'Champ requis (fr)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } as const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const TestHarness = defineComponent(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const formData = ref<Record<string, unknown>>({}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const i18nState = useJsonFormsI18n(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const handleChange = ({ data }: { data: Record<string, unknown> }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| formData.value = data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return () => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| h(JsonForms, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uischema, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: formData.value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| renderers: vanillaRenderers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ajv: jsonFormsAjv, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| i18n: i18nState.value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| validationMode: 'ValidateAndShow', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onChange: handleChange, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const renderJsonForms = async (locale: 'en' | 'fr' = 'en') => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const i18n = createI18n({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| legacy: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| locale, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| messages, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const utils = render(TestHarness, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| global: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| plugins: [i18n], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await screen.findByText('Provider label (en)'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 91 in web/__test__/helpers/jsonforms-i18n.test.ts
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { i18n, ...utils }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+78
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add cleanup between tests to prevent duplicate DOM elements. Static analysis shows "Found multiple elements with the text: Provider label (en)" at line 91, indicating previous test renders aren't being cleaned up. Add cleanup to prevent test pollution: -import { describe, expect, it } from 'vitest';
+import { afterEach, describe, expect, it } from 'vitest';
+import { cleanup } from '@testing-library/vue';
// ... schemas and component ...
describe('useJsonFormsI18n', () => {
+ afterEach(() => {
+ cleanup();
+ });
+
it('translates labels, descriptions, and errors when the locale changes', async () => {As per coding guidelines.
🧰 Tools🪛 GitHub Check: Test API[failure] 91-91: test/helpers/jsonforms-i18n.test.ts > useJsonFormsI18n > responds to updated translations for the active locale Here are the matching elements: Ignored nodes: comments, script, style Provider label (en) Ignored nodes: comments, script, style Provider label (en) (If this is intentional, then use the Ignored nodes: comments, script, style
Provider label (en)
*
Provider label (en)
*
Ignored nodes: comments, script, style
Provider label (en)
*
Provider label (en)
*
[failure] 91-91: test/helpers/jsonforms-i18n.test.ts > useJsonFormsI18n > responds to updated translations for the active locale Here are the matching elements: Ignored nodes: comments, script, style Provider label (en) Ignored nodes: comments, script, style Provider label (en) (If this is intentional, then use the Ignored nodes: comments, script, style
Provider label (en)
*
Provider label (en)
*
Ignored nodes: comments, script, style
Provider label (en)
*
Provider label (en)
*
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| describe('useJsonFormsI18n', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('translates labels, descriptions, and errors when the locale changes', async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { i18n } = await renderJsonForms('en'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(await screen.findByText('Provider label (en)')).toBeTruthy(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(screen.getByText('English description')).toBeTruthy(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 101 in web/__test__/helpers/jsonforms-i18n.test.ts
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(screen.getByText('Field is required (en)')).toBeTruthy(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| i18n.global.locale.value = 'fr'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await nextTick(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await screen.findByText('Libellé du fournisseur (fr)'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(screen.getByText('Description française')).toBeTruthy(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(screen.getByText('Champ requis (fr)')).toBeTruthy(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('responds to updated translations for the active locale', async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { i18n } = await renderJsonForms('en'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| i18n.global.mergeLocaleMessage('en', { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jsonforms: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| test: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| provider: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: 'Provider label (updated)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Updated English description', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errors: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: 'Field is required (updated)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+115
to
+126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new i18n test updates error strings via Useful? React with 👍 / 👎. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await nextTick(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await screen.findByText('Provider label (updated)'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(screen.getByText('Updated English description')).toBeTruthy(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(screen.getByText('Field is required (updated)')).toBeTruthy(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+112
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix incorrect translation key for error messages. Line 124-126 updates Apply this diff: i18n.global.mergeLocaleMessage('en', {
jsonforms: {
test: {
provider: {
label: 'Provider label (updated)',
description: 'Updated English description',
},
},
+ errors: {
+ required: 'Field is required (updated)',
+ },
},
- errors: {
- required: 'Field is required (updated)',
- },
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,6 +106,20 @@ const formData = ref<FormData>({ | |
| const formValid = ref(false); | ||
| const jsonFormsI18n = useJsonFormsI18n(); | ||
|
|
||
| const jsonFormsConfig = { | ||
| restrict: false, | ||
| trim: false, | ||
| }; | ||
|
|
||
| const renderers = [...jsonFormsRenderers]; | ||
|
|
||
| const jsonFormsProps = computed(() => ({ | ||
| renderers, | ||
| config: jsonFormsConfig, | ||
| ajv: jsonFormsAjv, | ||
| i18n: jsonFormsI18n.value, | ||
| })); | ||
|
Comment on lines
+109
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major LGTM: Consistent JsonForms prop consolidation pattern. The 🤖 Prompt for AI Agents |
||
|
|
||
| // Use clipboard for copying | ||
| const { copyWithNotification, copied } = useClipboardWithToast(); | ||
|
|
||
|
|
@@ -464,10 +478,8 @@ const copyApiKey = async () => { | |
| <JsonForms | ||
| :schema="formSchema.dataSchema" | ||
| :uischema="formSchema.uiSchema" | ||
| :renderers="jsonFormsRenderers" | ||
| v-bind="jsonFormsProps" | ||
| :data="formData" | ||
| :ajv="jsonFormsAjv" | ||
| :i18n="jsonFormsI18n" | ||
| @change=" | ||
| ({ data, errors }) => { | ||
| formData = data; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,13 @@ const jsonFormsConfig = { | |
| const renderers = [...jsonFormsRenderers]; | ||
| const jsonFormsI18n = useJsonFormsI18n(); | ||
|
|
||
| const jsonFormsProps = computed(() => ({ | ||
| renderers, | ||
| config: jsonFormsConfig, | ||
| ajv: jsonFormsAjv, | ||
| i18n: jsonFormsI18n.value, | ||
| })); | ||
|
Comment on lines
+97
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major LGTM: Consolidating JsonForms props improves maintainability. The computed 🤖 Prompt for AI Agents |
||
|
|
||
| /** Called when the user clicks the "Apply" button */ | ||
| const submitSettingsUpdate = async () => { | ||
| console.log('[ConnectSettings] trying to update settings to', formState.value); | ||
|
|
@@ -122,13 +129,10 @@ const onChange = ({ data }: { data: Record<string, unknown> }) => { | |
| <div class="mt-6 pl-3 [&_.vertical-layout]:space-y-6"> | ||
| <JsonForms | ||
| v-if="settings" | ||
| v-bind="jsonFormsProps" | ||
| :schema="settings.dataSchema" | ||
| :uischema="settings.uiSchema" | ||
| :renderers="renderers" | ||
| :data="formState" | ||
| :config="jsonFormsConfig" | ||
| :ajv="jsonFormsAjv" | ||
| :i18n="jsonFormsI18n" | ||
| :readonly="isUpdating" | ||
| @change="onChange" | ||
| /> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,72 @@ | ||
| import { computed } from 'vue'; | ||
| import { ref, watch } from 'vue'; | ||
| import { useI18n } from 'vue-i18n'; | ||
|
|
||
| import type { JsonFormsI18nState } from '@jsonforms/core'; | ||
|
|
||
| const toStringIfNeeded = (value: unknown) => { | ||
| if (typeof value === 'string') { | ||
| return value; | ||
| } | ||
| if (value == null) { | ||
| return ''; | ||
| } | ||
| return String(value); | ||
| }; | ||
|
|
||
| export function useJsonFormsI18n() { | ||
| const { t, te, locale } = useI18n(); | ||
| const { t, te, locale, messages } = useI18n(); | ||
|
|
||
| const translate: NonNullable<JsonFormsI18nState['translate']> = (id, defaultMessage, values) => { | ||
| if (id && te(id)) { | ||
| const result = t(id, values ?? {}); | ||
| return toStringIfNeeded(result); | ||
| } | ||
|
|
||
| if (defaultMessage) { | ||
| return toStringIfNeeded(defaultMessage); | ||
| } | ||
|
|
||
| return id ?? ''; | ||
| }; | ||
|
|
||
| return computed<JsonFormsI18nState>(() => ({ | ||
| const translateError: NonNullable<JsonFormsI18nState['translateError']> = (error) => { | ||
| const key = error.keyword ? `jsonforms.errors.${error.keyword}` : undefined; | ||
| if (key && te(key)) { | ||
| const translated = t(key, error.params ?? {}); | ||
| return toStringIfNeeded(translated); | ||
| } | ||
| return error.message ?? error.keyword ?? ''; | ||
| }; | ||
|
|
||
| const state = ref<JsonFormsI18nState>({ | ||
| locale: locale.value, | ||
| translate: (id, defaultMessage, values) => { | ||
| if (id && te(id)) { | ||
| const result = t(id, values); | ||
| return typeof result === 'string' ? result : String(result); | ||
| } | ||
| if (defaultMessage) { | ||
| return defaultMessage; | ||
| } | ||
| return id; | ||
| translate, | ||
| translateError, | ||
| }); | ||
|
|
||
| watch( | ||
| locale, | ||
| (currentLocale) => { | ||
| state.value = { | ||
| locale: currentLocale, | ||
| translate, | ||
| translateError, | ||
| }; | ||
| }, | ||
| translateError: (error) => { | ||
| const key = error.keyword ? `jsonforms.errors.${error.keyword}` : undefined; | ||
| if (key && te(key)) { | ||
| const translated = t(key, error.params ?? {}); | ||
| return typeof translated === 'string' ? translated : String(translated); | ||
| } | ||
| return error.message ?? error.keyword ?? ''; | ||
| { immediate: true } | ||
| ); | ||
|
|
||
| watch( | ||
| () => messages.value?.[locale.value], | ||
| () => { | ||
| state.value = { | ||
| locale: locale.value, | ||
| translate, | ||
| translateError, | ||
| }; | ||
| }, | ||
| })); | ||
| { deep: true } | ||
| ); | ||
|
|
||
| return state; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Schema description not rendering in tests.
The test expects to find "English description" (line 101), but static analysis shows it's not rendered. The vanilla renderers may not display schema descriptions by default. Consider adding uischema options to enable description display:
const uischema = { type: 'Control', scope: '#/properties/provider', + options: { + showDescription: true, + }, } as const;Alternatively, verify that the vanilla renderers support description rendering and whether additional configuration is needed.
🤖 Prompt for AI Agents