Fixed error list for JSON-schema form, and adressed other comments (#4242)

This commit is contained in:
darth-coder00 2022-04-19 22:48:56 +05:30 committed by GitHub
parent 6b77ab29f2
commit dbfef5e195
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 105 additions and 44 deletions

View File

@ -195,6 +195,7 @@ const AddService = ({
{activeStepperStep === 3 && ( {activeStepperStep === 3 && (
<ConnectionConfigForm <ConnectionConfigForm
cancelText="Back"
data={ data={
(serviceCategory !== ServiceCategory.PIPELINE_SERVICES (serviceCategory !== ServiceCategory.PIPELINE_SERVICES
? { ? {

View File

@ -38,6 +38,8 @@ import FormBuilder from '../common/FormBuilder/FormBuilder';
interface Props { interface Props {
data: DatabaseService | MessagingService | DashboardService | PipelineService; data: DatabaseService | MessagingService | DashboardService | PipelineService;
okText?: string;
cancelText?: string;
serviceCategory: ServiceCategory; serviceCategory: ServiceCategory;
status: LoadingState; status: LoadingState;
onCancel?: () => void; onCancel?: () => void;
@ -46,6 +48,8 @@ interface Props {
const ConnectionConfigForm: FunctionComponent<Props> = ({ const ConnectionConfigForm: FunctionComponent<Props> = ({
data, data,
okText = 'Save',
cancelText = 'Discard',
serviceCategory, serviceCategory,
status, status,
onCancel, onCancel,
@ -103,7 +107,9 @@ const ConnectionConfigForm: FunctionComponent<Props> = ({
return ( return (
<FormBuilder <FormBuilder
cancelText={cancelText}
formData={validConfig} formData={validConfig}
okText={okText}
schema={connSch.schema} schema={connSch.schema}
status={status} status={status}
uiSchema={connSch.uiSchema} uiSchema={connSch.uiSchema}

View File

@ -26,6 +26,8 @@ import { Button } from '../../buttons/Button/Button';
import Loader from '../../Loader/Loader'; import Loader from '../../Loader/Loader';
interface Props extends FormProps<ConfigData> { interface Props extends FormProps<ConfigData> {
okText: string;
cancelText: string;
showFormHeader?: boolean; showFormHeader?: boolean;
status?: LoadingState; status?: LoadingState;
onCancel?: () => void; onCancel?: () => void;
@ -33,15 +35,34 @@ interface Props extends FormProps<ConfigData> {
function ArrayFieldTemplate(props: ArrayFieldTemplateProps) { function ArrayFieldTemplate(props: ArrayFieldTemplateProps) {
return ( return (
<> <Fragment>
<label className="control-label">{props.title}</label> <div className="tw-flex tw-justify-between tw-items-center">
<p className="field-description">{props.schema.description}</p> <div>
<label className="control-label">{props.title}</label>
<p className="field-description">{props.schema.description}</p>
</div>
{props.canAdd && (
<Button
className="tw-h-7 tw-w-7 tw-px-2"
data-testid={`add-item-${props.title}`}
size="small"
theme="primary"
variant="contained"
onClick={props.onAddClick}>
<FontAwesomeIcon icon="plus" />
</Button>
)}
</div>
{props.items.map((element, index) => ( {props.items.map((element, index) => (
<div className="tw-flex tw-items-center tw-w-full" key={index}> <div
<div className="tw-flex-1">{element.children}</div> className={classNames('tw-flex tw-items-center tw-w-full', {
'tw-mt-2': index > 0,
})}
key={`${element.key}-${index}`}>
<div className="tw-flex-1 array-fields">{element.children}</div>
{element.hasRemove && ( {element.hasRemove && (
<button <button
className="focus:tw-outline-none tw-w-1/12" className="focus:tw-outline-none tw-w-7 tw-ml-3"
type="button" type="button"
onClick={(event) => { onClick={(event) => {
element.onDropIndexClick(element.index)(event); element.onDropIndexClick(element.index)(event);
@ -50,55 +71,61 @@ function ArrayFieldTemplate(props: ArrayFieldTemplateProps) {
alt="delete" alt="delete"
icon={Icons.DELETE} icon={Icons.DELETE}
title="Delete" title="Delete"
width="16px" width="14px"
/> />
</button> </button>
)} )}
</div> </div>
))} ))}
{props.canAdd && ( </Fragment>
<Button
className="tw-h-7 tw-px-2 tw-mb-3"
data-testid={`add-item-${props.title}`}
size="small"
theme="primary"
variant="contained"
onClick={props.onAddClick}>
<FontAwesomeIcon icon="plus" />
</Button>
)}
</>
); );
} }
function ObjectFieldTemplate(props: ObjectFieldTemplateProps) { function ObjectFieldTemplate(props: ObjectFieldTemplateProps) {
return ( return (
<Fragment> <Fragment>
<label className="control-label">{props.title}</label> <div className="tw-flex tw-justify-between tw-items-center">
<p className="field-description">{props.description}</p> <div>
{props.properties.map((element) => ( <label className="control-label" id={`${props.idSchema.$id}__title`}>
<div className="property-wrapper" key={element.content.key}> {props.title}
</label>
<p
className="field-description"
id={`${props.idSchema.$id}__description`}>
{props.description}
</p>
</div>
{props.schema.additionalProperties && (
<Button
className="tw-h-7 tw-w-7 tw-px-2"
data-testid={`add-item-${props.title}`}
id={`${props.idSchema.$id}__add`}
size="small"
theme="primary"
variant="contained"
onClick={() => {
props.onAddClick(props.schema)();
}}>
<FontAwesomeIcon icon="plus" />
</Button>
)}
</div>
{props.properties.map((element, index) => (
<div
className={classNames('property-wrapper', {
'additional-fields': props.schema.additionalProperties,
})}
key={`${element.content.key}-${index}`}>
{element.content} {element.content}
</div> </div>
))} ))}
{props.schema.additionalProperties && (
<Button
className="tw-h-7 tw-px-2 tw-mb-3"
data-testid={`add-item-${props.title}`}
size="small"
theme="primary"
variant="contained"
onClick={() => {
props.onAddClick(props.schema)();
}}>
<FontAwesomeIcon icon="plus" />
</Button>
)}
</Fragment> </Fragment>
); );
} }
const FormBuilder: FunctionComponent<Props> = ({ const FormBuilder: FunctionComponent<Props> = ({
okText,
cancelText,
showFormHeader = false, showFormHeader = false,
status = 'initial', status = 'initial',
onCancel, onCancel,
@ -137,7 +164,7 @@ const FormBuilder: FunctionComponent<Props> = ({
theme="primary" theme="primary"
variant="text" variant="text"
onClick={handleCancel}> onClick={handleCancel}>
Discard {cancelText}
</Button> </Button>
{status === 'waiting' ? ( {status === 'waiting' ? (
<Button <Button
@ -165,7 +192,7 @@ const FormBuilder: FunctionComponent<Props> = ({
theme="primary" theme="primary"
variant="contained" variant="contained"
onClick={handleSubmit}> onClick={handleSubmit}>
Save {okText}
</Button> </Button>
)} )}
</div> </div>

View File

@ -354,7 +354,9 @@
} }
.rjsf.no-header #root__title, .rjsf.no-header #root__title,
.rjsf.no-header #root__description { .rjsf.no-header #root__description,
.rjsf .form-additional .control-label,
.rjsf .panel.panel-danger.errors .panel-heading {
@apply tw-hidden; @apply tw-hidden;
} }
@ -362,6 +364,15 @@
@apply tw-my-3; @apply tw-my-3;
} }
.rjsf .additional-fields .form-group.field,
.rjsf .array-fields .form-group.field {
@apply tw-my-0;
}
.rjsf .property-wrapper.additional-fields ~ .button-comp {
@apply tw-mt-1.5;
}
.rjsf .control-label { .rjsf .control-label {
@apply tw-capitalize; @apply tw-capitalize;
} }
@ -389,21 +400,37 @@
} }
.rjsf .btn.array-item-remove { .rjsf .btn.array-item-remove {
@apply tw-mt-4 tw-p-4; @apply tw-p-3.5;
background: url(../assets/svg/ic-delete.svg) center center no-repeat; background: url(../assets/svg/ic-delete.svg) center center no-repeat;
background-size: 35%; background-size: 50%;
} }
.rjsf .row { .rjsf .row {
@apply tw-flex tw-items-center tw-w-full tw--m-1; @apply tw-flex tw-items-center tw-w-full tw--m-1.5;
} }
.rjsf .col-xs-5 { .rjsf .col-xs-5 {
@apply tw-flex-1 tw-p-1; @apply tw-flex-1 tw-p-1.5;
} }
.rjsf .col-xs-2 { .rjsf .col-xs-2 {
@apply tw-w-1/12 tw-p-1; @apply tw-w-7 tw-p-1.5;
}
.rjsf .errors .list-group > .list-group-item {
list-style-type: disc;
}
.rjsf .panel-danger.errors {
@apply tw-mb-0 tw-mt-2;
}
.rjsf .list-group {
@apply tw-px-5;
}
.rjsf .list-group-item {
@apply tw-list-disc;
} }
@keyframes highlight { @keyframes highlight {