Skip to content
Open
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
15 changes: 8 additions & 7 deletions webapp/packages/core-ui/src/Form/FormPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import type { IFormPart } from './IFormPart.js';
import type { IFormState } from './IFormState.js';
import { formSubmitContext } from './formSubmitContext.js';
import { safeParseSchema } from './safeParseSchema.js';
import { formValidationContext } from './formValidationContext.js';

export abstract class FormPart<TPartState extends object, TFormState = any> implements IFormPart<TPartState> {
Expand Down Expand Up @@ -165,14 +166,14 @@
private async handleValidation(data: IFormState<TFormState>, contexts: IExecutionContextProvider<IFormState<TFormState>>): Promise<void> {
const validation = contexts.getContext(formValidationContext);

try {
if (this.schema) {
const parsedState = this.schema.parse(toJS(this.state));
this.setState(observable(parsedState));
if (this.schema) {
const result = safeParseSchema(this.schema, toJS(this.state), validation);

if (!result.success) {
return;
}
} catch (e: any) {
validation.error(schema.prettifyError(e));
return;

this.setState(observable(result.data));
}

try {
Expand Down Expand Up @@ -200,8 +201,8 @@
this.state = state;
}

protected format(data: IFormState<TFormState>, contexts: IExecutionContextProvider<IFormState<TFormState>>): void | Promise<void> {}

Check warning on line 204 in webapp/packages/core-ui/src/Form/FormPart.ts

View workflow job for this annotation

GitHub Actions / Frontend / Lint

'contexts' is defined but never used

Check warning on line 204 in webapp/packages/core-ui/src/Form/FormPart.ts

View workflow job for this annotation

GitHub Actions / Frontend / Lint

'data' is defined but never used
protected validate(data: IFormState<TFormState>, contexts: IExecutionContextProvider<IFormState<TFormState>>): void | Promise<void> {}

Check warning on line 205 in webapp/packages/core-ui/src/Form/FormPart.ts

View workflow job for this annotation

GitHub Actions / Frontend / Lint

'contexts' is defined but never used

Check warning on line 205 in webapp/packages/core-ui/src/Form/FormPart.ts

View workflow job for this annotation

GitHub Actions / Frontend / Lint

'data' is defined but never used

protected abstract loader(): Promise<void>;
protected abstract saveChanges(data: IFormState<TFormState>, contexts: IExecutionContextProvider<IFormState<TFormState>>): Promise<void>;
Expand Down
27 changes: 27 additions & 0 deletions webapp/packages/core-ui/src/Form/safeParseSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { schema } from '@cloudbeaver/core-utils';

import type { IFormValidationContext } from './formValidationContext.js';

export function safeParseSchema<T>(zodSchema: schema.ZodType<T>, value: unknown, validation: IFormValidationContext): schema.ZodSafeParseResult<T> {
const result = zodSchema.safeParse(value);

if (!result.success) {
const seenMessages = new Set<string>();
for (const issue of result.error.issues) {
const message = issue.message || schema.prettifyError(result.error);
if (!seenMessages.has(message)) {
seenMessages.add(message);
validation.error(message);
}
}
}

return result;
}
1 change: 1 addition & 0 deletions webapp/packages/core-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
export * from './ContextMenu/IContextMenuItemProps.js';
export * from './ContextMenu/MenuBar/MenuBarLazy.js';
export * from './ContextMenu/MenuBar/MenuBarItemLoader.js';
export * from './ContextMenu/MenuActionElement.js';

Check failure on line 17 in webapp/packages/core-ui/src/index.ts

View workflow job for this annotation

GitHub Actions / Frontend / Lint

Don't import/export .tsx files from .ts files directly, use React.lazy()
export * from './ContextMenu/MenuContext.js';
export { default as MenuBarStyles } from './ContextMenu/MenuBar/MenuBar.module.css';
export { default as MenuBarItemStyles } from './ContextMenu/MenuBar/MenuBarItem.module.css';
Expand All @@ -35,6 +35,7 @@
export * from './Form/FormMode.js';
export * from './Form/FormState.js';
export * from './Form/FormPart.js';
export * from './Form/safeParseSchema.js';
export * from './Form/formStateContext.js';
export * from './Form/formStatusContext.js';
export * from './Form/formValidationContext.js';
Expand Down
1 change: 1 addition & 0 deletions webapp/packages/plugin-codemirror6/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@codemirror/lang-sql": "^6",
"@codemirror/lang-xml": "^6",
"@codemirror/language": "^6",
"@codemirror/lint": "^6",
"@codemirror/merge": "^6",
"@codemirror/search": "^6",
"@codemirror/state": "^6",
Expand Down
6 changes: 4 additions & 2 deletions webapp/packages/plugin-codemirror6/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2025 DBeaver Corp and others
* Copyright (C) 2020-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
Expand All @@ -9,7 +9,7 @@
import './module.js';
import { createLazyLoader } from '@cloudbeaver/core-blocks';

export * from './ReactCodemirrorPanel.js';

Check failure on line 12 in webapp/packages/plugin-codemirror6/src/index.ts

View workflow job for this annotation

GitHub Actions / Frontend / Lint

Don't import/export .tsx files from .ts files directly, use React.lazy()
export * from './EditorLoader.js';
export * from './IEditorProps.js';
export * from './IEditorRef.js';
Expand All @@ -26,9 +26,11 @@
export * from '@codemirror/autocomplete';
export * from './highlightNewLine.js';

export { history } from '@codemirror/commands';
export { html as HTML_EDITOR } from '@codemirror/lang-html';
export { javascript as JAVASCRIPT_EDITOR } from '@codemirror/lang-javascript';
export { json as JSON_EDITOR } from '@codemirror/lang-json';
export { json as JSON_EDITOR, jsonParseLinter } from '@codemirror/lang-json';
export { linter, lintGutter } from '@codemirror/lint';
export { sql as SQL_EDITOR, SQLDialect } from '@codemirror/lang-sql';
export { xml as XML_EDITOR } from '@codemirror/lang-xml';

Expand Down
1 change: 1 addition & 0 deletions webapp/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2587,6 +2587,7 @@ __metadata:
"@codemirror/lang-sql": "npm:^6"
"@codemirror/lang-xml": "npm:^6"
"@codemirror/language": "npm:^6"
"@codemirror/lint": "npm:^6"
"@codemirror/merge": "npm:^6"
"@codemirror/search": "npm:^6"
"@codemirror/state": "npm:^6"
Expand Down
Loading