Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion e2e/tests/plugin_metadata.crud-all-fields.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,29 @@ test('should CRUD plugin metadata with all fields', async ({ page }) => {
await expect(addPluginDialog).toBeVisible();
await addPluginDialog.getByRole('tab', { name: 'JSON' }).click();

// Fill in comprehensive configuration with all available fields
const pluginEditor = await uiGetMonacoEditor(page, addPluginDialog);
await page.evaluate(() => {
window.__monacoEditor__?.getModel()?.setValue('{');
});
await page.waitForFunction(
() => window.__monacoEditor__?.getModel()?.getValue() === '{'
);
await pluginEditor.blur();
Comment on lines +79 to +85
await expect(pluginEditor.getByText('{')).toBeVisible();
await addPluginDialog.getByRole('button', { name: 'Add Plugin' }).click();
const jsonErrorAlert = addPluginDialog.getByRole('alert').filter({
hasText: /Invalid JSON:|JSON format is not valid/,
});
await expect(jsonErrorAlert).toBeVisible();
await expect(
addPluginDialog.getByRole('button', { name: 'Format JSON after error' })
).toBeVisible();
await addPluginDialog
.getByRole('button', { name: 'Reset JSON after error' })
.click();
await expect(jsonErrorAlert).toBeHidden();

// Fill in comprehensive configuration with all available fields
await uiFillMonacoEditor(
page,
pluginEditor,
Expand Down
43 changes: 32 additions & 11 deletions src/components/form-slice/FormItemPlugins/PluginEditorDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,27 @@ export const PluginEditorDrawer = (props: PluginEditorDrawerProps) => {
setFormValue(nextValue);
setSaveError(null);
}, [config, methods, mode, schema]);
const saveErrorActions =
activeTab === 'json' && mode !== 'view' ? (
<Space wrap>
<Button
size="small"
icon={<IconFormatAlignLeft />}
onClick={formatJsonConfig}
aria-label="Format JSON after error"
>
Format JSON
</Button>
<Button
size="small"
icon={<IconRefresh />}
onClick={resetJsonConfig}
aria-label="Reset JSON after error"
>
Reset JSON
</Button>
</Space>
) : undefined;

const handleSave = methods.handleSubmit(
async () => {
Expand Down Expand Up @@ -444,6 +465,17 @@ export const PluginEditorDrawer = (props: PluginEditorDrawerProps) => {
</Tooltip>
</Space>
)}
{mode !== 'view' && saveError && (
<Alert
type="error"
showIcon
message={saveError}
action={saveErrorActions}
closable
onClose={() => setSaveError(null)}
style={{ marginBottom: 12, whiteSpace: 'pre-wrap' }}
/>
)}
<form>
{canUseForm ? (
<Tabs
Expand All @@ -461,17 +493,6 @@ export const PluginEditorDrawer = (props: PluginEditorDrawerProps) => {
/>
)}
</form>

{mode !== 'view' && saveError && (
<Alert
type="error"
showIcon
message={saveError}
closable
onClose={() => setSaveError(null)}
style={{ marginTop: 8, whiteSpace: 'pre-wrap' }}
/>
)}
</Drawer>
</FormProvider>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/form/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const FormItemEditor = <T extends FieldValues>(
trigger(props.name);
}}
onMount={(editor) => {
if (process.env.NODE_ENV === 'test') {
if (process.env.NODE_ENV === 'test' || import.meta.env.DEV) {
window.__monacoEditor__ = editor;
}
Comment on lines 184 to 187
}}
Expand Down