Skip to content

Commit c17a1f3

Browse files
committed
formating removed-102
1 parent 516151e commit c17a1f3

File tree

1 file changed

+101
-136
lines changed

1 file changed

+101
-136
lines changed

client/packages/lowcoder/src/comps/comps/jsonSchemaFormComp/jsonSchemaFormComp.tsx

Lines changed: 101 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,30 @@
1-
import {withTheme} from '@rjsf/core';
2-
import type {
3-
RJSFValidationError,
4-
ErrorListProps,
5-
UISchemaSubmitButtonOptions,
6-
} from '@rjsf/utils';
7-
import validator from '@rjsf/validator-ajv8';
1+
import { withTheme } from '@rjsf/core';
2+
import type { RJSFValidationError, ErrorListProps, UISchemaSubmitButtonOptions } from "@rjsf/utils";
3+
import validator from "@rjsf/validator-ajv8";
84
// import Ajv from "@rjsf/validator-ajv8";
9-
import {default as Button} from 'antd/es/button';
10-
import {BoolControl} from 'comps/controls/boolControl';
11-
import {jsonObjectExposingStateControl} from 'comps/controls/codeStateControl';
12-
import {styleControl} from 'comps/controls/styleControl';
13-
import {
14-
AnimationStyle,
15-
AnimationStyleType,
16-
JsonSchemaFormStyle,
17-
type JsonSchemaFormStyleType,
18-
} from 'comps/controls/styleControlConstants';
19-
import {
20-
depsConfig,
21-
NameConfigHidden,
22-
withExposingConfigs,
23-
} from 'comps/generators/withExposing';
24-
import {withMethodExposing} from 'comps/generators/withMethodExposing';
25-
import type {ValueFromOption} from 'lowcoder-design';
26-
import {i18nObjs, trans} from 'i18n';
27-
import type {JSONSchema7} from 'json-schema';
28-
import styled from 'styled-components';
29-
import {toBoolean, toNumber, toString} from 'util/convertUtils';
30-
import {Section, sectionNames} from 'lowcoder-design';
31-
import {jsonObjectControl} from '../../controls/codeControl';
32-
import {
33-
eventHandlerControl,
34-
submitEvent,
35-
} from '../../controls/eventHandlerControl';
36-
import {UICompBuilder} from '../../generators';
37-
import DateWidget from './dateWidget';
38-
import ErrorBoundary from './errorBoundary';
39-
import {Theme} from '@rjsf/antd';
40-
import {hiddenPropertyView} from 'comps/utils/propertyUtils';
5+
import { default as Button } from "antd/es/button";
6+
import { BoolControl } from "comps/controls/boolControl";
7+
import { jsonObjectExposingStateControl } from "comps/controls/codeStateControl";
8+
import { styleControl } from "comps/controls/styleControl";
9+
import { AnimationStyle, AnimationStyleType, JsonSchemaFormStyle, type JsonSchemaFormStyleType } from "comps/controls/styleControlConstants";
10+
import { depsConfig, NameConfigHidden, withExposingConfigs } from "comps/generators/withExposing";
11+
import { withMethodExposing } from "comps/generators/withMethodExposing";
12+
import type { ValueFromOption } from "lowcoder-design";
13+
import { i18nObjs, trans } from "i18n";
14+
import type { JSONSchema7 } from "json-schema";
15+
import styled from "styled-components";
16+
import { toBoolean, toNumber, toString } from "util/convertUtils";
17+
import { Section, sectionNames } from "lowcoder-design";
18+
import { jsonObjectControl } from "../../controls/codeControl";
19+
import { eventHandlerControl, submitEvent } from "../../controls/eventHandlerControl";
20+
import { UICompBuilder } from "../../generators";
21+
import DateWidget from "./dateWidget";
22+
import ErrorBoundary from "./errorBoundary";
23+
import { Theme } from "@rjsf/antd";
24+
import { hiddenPropertyView } from "comps/utils/propertyUtils";
4125

42-
import {useContext} from 'react';
43-
import {EditorContext} from 'comps/editorState';
26+
import { useContext } from "react";
27+
import { EditorContext } from "comps/editorState";
4428

4529
Theme.widgets.DateWidget = DateWidget(false);
4630
Theme.widgets.DateTimeWidget = DateWidget(true);
@@ -97,35 +81,29 @@ function convertData(schema?: JSONSchema7, data?: any) {
9781
return data;
9882
}
9983
// fix required invalidation problem
100-
if (
101-
schema.type !== 'object' &&
102-
(data === undefined || data === null || data === '')
103-
) {
84+
if (schema.type !== "object" && (data === undefined || data === null || data === "")) {
10485
return undefined;
10586
}
10687
switch (schema.type) {
107-
case 'string':
88+
case "string":
10889
return toString(data);
109-
case 'number':
90+
case "number":
11091
return toNumber(data);
111-
case 'integer':
92+
case "integer":
11293
return Math.trunc(toNumber(data));
113-
case 'boolean':
94+
case "boolean":
11495
return toBoolean(data);
115-
case 'null':
96+
case "null":
11697
return null;
117-
case 'object': {
98+
case "object": {
11899
const properties = schema.properties;
119100
if (!properties) {
120101
return data;
121102
}
122103
let newData: Record<string, unknown> = {};
123104
Object.entries(properties).forEach(([key, definition]) => {
124105
const value = data ? data[key] : undefined;
125-
newData[key] =
126-
typeof definition === 'object'
127-
? convertData(definition, value)
128-
: value;
106+
newData[key] = typeof definition === "object" ? convertData(definition, value) : value;
129107
});
130108
return newData;
131109
}
@@ -140,34 +118,28 @@ function convertData(schema?: JSONSchema7, data?: any) {
140118
// JSON schema refer to https://json-schema.org/understanding-json-schema/reference/
141119
function getErrorMessage(error: RJSFValidationError): string {
142120
switch (error.name) {
143-
case 'required':
144-
return trans('jsonSchemaForm.required');
145-
case 'maximum':
146-
return trans('jsonSchemaForm.maximum', {value: error.params.limit});
147-
case 'minimum':
148-
return trans('jsonSchemaForm.minimum', {value: error.params.limit});
149-
case 'exclusiveMaximum':
150-
return trans('jsonSchemaForm.exclusiveMaximum', {
151-
value: error.params.limit,
152-
});
153-
case 'exclusiveMinimum':
154-
return trans('jsonSchemaForm.exclusiveMinimum', {
155-
value: error.params.limit,
156-
});
157-
case 'multipleOf':
158-
return trans('jsonSchemaForm.multipleOf', {
159-
value: error.params.multipleOf,
160-
});
161-
case 'minLength':
162-
return trans('jsonSchemaForm.minLength', {value: error.params.limit});
163-
case 'maxLength':
164-
return trans('jsonSchemaForm.maxLength', {value: error.params.limit});
165-
case 'pattern':
166-
return trans('jsonSchemaForm.pattern', {value: error.params.pattern});
167-
case 'format':
168-
return trans('jsonSchemaForm.format', {value: error.params.format});
121+
case "required":
122+
return trans("jsonSchemaForm.required");
123+
case "maximum":
124+
return trans("jsonSchemaForm.maximum", { value: error.params.limit });
125+
case "minimum":
126+
return trans("jsonSchemaForm.minimum", { value: error.params.limit });
127+
case "exclusiveMaximum":
128+
return trans("jsonSchemaForm.exclusiveMaximum", { value: error.params.limit });
129+
case "exclusiveMinimum":
130+
return trans("jsonSchemaForm.exclusiveMinimum", { value: error.params.limit });
131+
case "multipleOf":
132+
return trans("jsonSchemaForm.multipleOf", { value: error.params.multipleOf });
133+
case "minLength":
134+
return trans("jsonSchemaForm.minLength", { value: error.params.limit });
135+
case "maxLength":
136+
return trans("jsonSchemaForm.maxLength", { value: error.params.limit });
137+
case "pattern":
138+
return trans("jsonSchemaForm.pattern", { value: error.params.pattern });
139+
case "format":
140+
return trans("jsonSchemaForm.format", { value: error.params.format });
169141
}
170-
return '';
142+
return "";
171143
}
172144

173145
function transformErrors(errors: RJSFValidationError[]): RJSFValidationError[] {
@@ -177,7 +149,7 @@ function transformErrors(errors: RJSFValidationError[]): RJSFValidationError[] {
177149
// Error message displayed below the comp (will not be displayed when "ui:help" is set in the UI schema)
178150
error.message = message;
179151
// Errors displayed in the error list, not displayed when empty
180-
error.stack = '';
152+
error.stack = "";
181153
}
182154
return error;
183155
});
@@ -190,7 +162,7 @@ function ErrorList(props: ErrorListProps) {
190162
return <></>;
191163
}
192164
return (
193-
<div style={{color: 'red'}}>
165+
<div style={{ color: "red" }}>
194166
<ul>
195167
{errors.map((error) => (
196168
<li key={error.stack}>{error.stack}</li>
@@ -202,12 +174,10 @@ function ErrorList(props: ErrorListProps) {
202174

203175
function onSubmit(props: {
204176
resetAfterSubmit: boolean;
205-
data: {reset: () => void};
206-
onEvent: (
207-
eventName: ValueFromOption<typeof EventOptions>
208-
) => Promise<unknown>;
177+
data: { reset: () => void };
178+
onEvent: (eventName: ValueFromOption<typeof EventOptions>) => Promise<unknown>;
209179
}): Promise<void> {
210-
return props.onEvent('submit').then(() => {
180+
return props.onEvent("submit").then(() => {
211181
if (props.resetAfterSubmit) {
212182
props.data.reset();
213183
}
@@ -230,7 +200,7 @@ let FormBasicComp = (function () {
230200
return new UICompBuilder(childrenMap, (props) => {
231201
// rjsf 4.20 supports ui:submitButtonOptions, but if the button is customized, it will not take effect. Here we implement it ourselves
232202
const buttonOptions = props?.uiSchema?.[
233-
'ui:submitButtonOptions'
203+
"ui:submitButtonOptions"
234204
] as UISchemaSubmitButtonOptions;
235205

236206
return (
@@ -265,41 +235,37 @@ let FormBasicComp = (function () {
265235
.setPropertyViewFn((children) => {
266236
return (
267237
<>
268-
{(useContext(EditorContext).editorModeStatus === 'logic' ||
269-
useContext(EditorContext).editorModeStatus === 'both') && (
238+
{(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && (
270239
<Section name={sectionNames.basic}>
240+
271241
{children.schema.propertyView({
272242
label: (
273243
<>
274-
{trans('jsonSchemaForm.jsonSchema') + ' ('}
244+
{trans("jsonSchemaForm.jsonSchema") + " ("}
275245
<a
276-
href={
277-
'http://json-schema.org/learn/getting-started-step-by-step'
278-
}
279-
target={'_blank'}
246+
href={"http://json-schema.org/learn/getting-started-step-by-step"}
247+
target={"_blank"}
280248
rel="noreferrer"
281249
>
282250
Docs 1
283251
</a>
284-
{', '}
252+
{", "}
285253
<a
286-
href={'https://jsonforms.io/examples/basic'}
287-
target={'_blank'}
254+
href={"https://jsonforms.io/examples/basic"}
255+
target={"_blank"}
288256
rel="noreferrer"
289257
>
290258
Docs 2
291259
</a>
292-
{')'}
260+
{")"}
293261
</>
294262
),
295263
tooltip: (
296264
<>
297-
{trans('jsonSchemaForm.schemaTooltip') + ' '}
265+
{trans("jsonSchemaForm.schemaTooltip") + " "}
298266
<a
299-
href={
300-
'http://json-schema.org/learn/getting-started-step-by-step'
301-
}
302-
target={'_blank'}
267+
href={"http://json-schema.org/learn/getting-started-step-by-step"}
268+
target={"_blank"}
303269
rel="noreferrer"
304270
>
305271
JSON schema
@@ -310,33 +276,33 @@ let FormBasicComp = (function () {
310276
{children.uiSchema.propertyView({
311277
label: (
312278
<>
313-
{trans('jsonSchemaForm.uiSchema') + ' ('}
279+
{trans("jsonSchemaForm.uiSchema") + " ("}
314280
<a
315-
href={'https://jsonforms.io/docs/uischema'}
316-
target={'_blank'}
281+
href={"https://jsonforms.io/docs/uischema"}
282+
target={"_blank"}
317283
rel="noreferrer"
318284
>
319285
Docs 1
320286
</a>
321-
{', '}
287+
{", "}
322288
<a
323-
href={
324-
'https://rjsf-team.github.io/react-jsonschema-form/docs/api-reference/uiSchema'
325-
}
326-
target={'_blank'}
289+
href={"https://rjsf-team.github.io/react-jsonschema-form/docs/api-reference/uiSchema"}
290+
target={"_blank"}
327291
rel="noreferrer"
328292
>
329293
Docs 2
330294
</a>
331-
{')'}
332-
</>
295+
{")"}
296+
</>
333297
),
334298
tooltip: (
335299
<>
336-
{trans('jsonSchemaForm.schemaTooltip') + ' '}
300+
{trans("jsonSchemaForm.schemaTooltip") + " "}
337301
<a
338-
href={'https://jsonforms.io/docs/uischema'}
339-
target={'_blank'}
302+
href={
303+
"https://jsonforms.io/docs/uischema"
304+
}
305+
target={"_blank"}
340306
rel="noreferrer"
341307
>
342308
UI schema
@@ -345,33 +311,32 @@ let FormBasicComp = (function () {
345311
),
346312
})}
347313
{children.data.propertyView({
348-
label: trans('jsonSchemaForm.defaultData'),
314+
label: trans("jsonSchemaForm.defaultData"),
349315
})}
350316
</Section>
351317
)}
352318

353-
{(useContext(EditorContext).editorModeStatus === 'logic' ||
354-
useContext(EditorContext).editorModeStatus === 'both') && (
319+
{(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && (
355320
<Section name={sectionNames.interaction}>
356321
{children.onEvent.getPropertyView()}
357322
{hiddenPropertyView(children)}
358323
{children.resetAfterSubmit.propertyView({
359-
label: trans('jsonSchemaForm.resetAfterSubmit'),
324+
label: trans("jsonSchemaForm.resetAfterSubmit"),
360325
})}
361326
</Section>
362327
)}
363328

364-
{(useContext(EditorContext).editorModeStatus === 'layout' ||
365-
useContext(EditorContext).editorModeStatus === 'both') && (
329+
{(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && (
366330
<>
367-
<Section name={sectionNames.style}>
368-
{children.style.getPropertyView()}
369-
</Section>
370-
<Section name={sectionNames.animationStyle}>
371-
{children.animationStyle.getPropertyView()}
331+
<Section name={sectionNames.style}>
332+
{children.style.getPropertyView()}
333+
</Section>
334+
<Section name={sectionNames.animationStyle}>
335+
{children.animationStyle.getPropertyView()}
372336
</Section>
373-
</>
337+
</>
374338
)}
339+
375340
</>
376341
);
377342
})
@@ -380,9 +345,9 @@ let FormBasicComp = (function () {
380345

381346
let FormTmpComp = withExposingConfigs(FormBasicComp, [
382347
depsConfig({
383-
name: 'data',
384-
desc: trans('jsonSchemaForm.dataDesc'),
385-
depKeys: ['schema', 'data'],
348+
name: "data",
349+
desc: trans("jsonSchemaForm.dataDesc"),
350+
depKeys: ["schema", "data"],
386351
func: (input) => {
387352
return convertData(input.schema, input.data);
388353
},
@@ -393,8 +358,8 @@ let FormTmpComp = withExposingConfigs(FormBasicComp, [
393358
FormTmpComp = withMethodExposing(FormTmpComp, [
394359
{
395360
method: {
396-
name: 'submit',
397-
description: trans('export.submitDesc'),
361+
name: "submit",
362+
description: trans("export.submitDesc"),
398363
params: [],
399364
},
400365
// FIXME: currently, it cannot be verified when submitted through the method, fix it later

0 commit comments

Comments
 (0)