Skip to content

Commit

Permalink
updated schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Meriem-BenIsmail committed Dec 4, 2024
1 parent 0febd15 commit 1416d92
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 66 deletions.
16 changes: 8 additions & 8 deletions packages/base/src/panelview/customarrayfield.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const CustomArrayField: React.FC<IProps> = props => {
onChange,
onBlur
} = props;
let fieldErrors: any = {};

const handleInputChange = (index: number, value: any) => {
const updatedValue = [...formData];
updatedValue[index] = value;
Expand All @@ -29,8 +29,6 @@ const CustomArrayField: React.FC<IProps> = props => {

const renderInputField = (value: any, index: number) => {
const { enum: enumOptions, type: itemType } = schema.items || {};
fieldErrors = errorSchema?.[index]?.__errors || [];

if (enumOptions) {
return (
<select
Expand Down Expand Up @@ -98,11 +96,13 @@ const CustomArrayField: React.FC<IProps> = props => {

{errorSchema?.[index]?.__errors?.length > 0 && (
<div className="validationErrors">
{fieldErrors.map((error: string, errorIndex: number) => (
<div key={`${index}-${errorIndex}`} className="error">
{error}
</div>
))}
{errorSchema?.[index]?.__errors.map(
(error: string, errorIndex: number) => (
<div key={`${index}-${errorIndex}`} className="error">
{error}
</div>
)
)}
</div>
)}
</div>
Expand Down
121 changes: 63 additions & 58 deletions packages/base/src/panelview/formbuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,70 +143,75 @@ export class ObjectPropertiesForm extends React.Component<IProps, IStates> {
};

render(): React.ReactNode {
const { schema, internalData } = this.state;
const uiSchema = this.generateUiSchema(this.props.schema || {});
const submitRef = React.createRef<HTMLButtonElement>();
if (this.props.schema) {
const schema = { ...this.props.schema, additionalProperties: true };

if (!schema) {
return <div>{this.buildForm()}</div>;
}
return (
<div
className="jpcad-property-panel"
data-path={this.props.filePath ?? ''}
>
<div className="jpcad-property-outer jp-scrollbar-tiny">
<WrappedFormComponent
schema={schema}
uiSchema={uiSchema}
formData={internalData}
onSubmit={this.onFormSubmit}
liveValidate
onFocus={(id, value) => {
this.props.syncSelectedField
? this.props.syncSelectedField(id, value, this.props.parentType)
: null;
}}
onBlur={(id, value) => {
this.props.syncSelectedField
? this.props.syncSelectedField(
null,
value,
this.props.parentType
)
: null;
}}
children={
const submitRef = React.createRef<HTMLButtonElement>();

return (
<div
className="jpcad-property-panel"
data-path={this.props.filePath ?? ''}
>
<div className="jpcad-property-outer jp-scrollbar-tiny">
<WrappedFormComponent
schema={{ ...schema, additionalProperties: true }}
uiSchema={this.generateUiSchema(this.props.schema)}
formData={this.state.internalData}
onSubmit={this.onFormSubmit}
liveValidate
onFocus={(id, value) => {
this.props.syncSelectedField
? this.props.syncSelectedField(
id,
value,
this.props.parentType
)
: null;
}}
onBlur={(id, value) => {
this.props.syncSelectedField
? this.props.syncSelectedField(
null,
value,
this.props.parentType
)
: null;
}}
children={
<button
ref={submitRef}
type="submit"
style={{ display: 'none' }}
/>
}
/>
</div>

<div className="jpcad-property-buttons">
{this.props.cancel ? (
<button
ref={submitRef}
type="submit"
style={{ display: 'none' }}
/>
}
/>
</div>
className="jp-Dialog-button jp-mod-reject jp-mod-styled"
onClick={this.props.cancel}
>
<div className="jp-Dialog-buttonLabel">Cancel</div>
</button>
) : null}

<div className="jpcad-property-buttons">
{this.props.cancel ? (
<button
className="jp-Dialog-button jp-mod-reject jp-mod-styled"
onClick={this.props.cancel}
className="jp-Dialog-button jp-mod-accept jp-mod-styled"
type="button"
onClick={() => {
submitRef.current?.click();
}}
>
<div className="jp-Dialog-buttonLabel">Cancel</div>
<div className="jp-Dialog-buttonLabel">Submit</div>
</button>
) : null}

<button
className="jp-Dialog-button jp-mod-accept jp-mod-styled"
type="button"
onClick={() => {
submitRef.current?.click();
}}
>
<div className="jp-Dialog-buttonLabel">Submit</div>
</button>
</div>
</div>
</div>
);
);
} else {
return <div>{this.buildForm()}</div>;
}
}
}
4 changes: 4 additions & 0 deletions python/jupytercad_lab/style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -640,3 +640,7 @@ body[data-jp-theme-light='true'] {
margin: 0;
padding: 0;
}

.jpcad-property-panel .rjsf .jp-ArrayOperationsButton {
display: none;
}

0 comments on commit 1416d92

Please sign in to comment.