Skip to content

Commit 8c689da

Browse files
authored
Add more explicit typing on RJSF objects (#789)
* Add more explicit typing on RJSF objects * Use typeguard instead of non-null assertion * Lint
1 parent 3d1adfa commit 8c689da

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

packages/base/src/formbuilder/objectform/baseform.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { Dialog } from '@jupyterlab/apputils';
44
import { FormComponent } from '@jupyterlab/ui-components';
55
import { Signal } from '@lumino/signaling';
66
import { IChangeEvent, ISubmitEvent } from '@rjsf/core';
7+
import { RJSFSchema, UiSchema } from '@rjsf/utils';
78
import validatorAjv8 from '@rjsf/validator-ajv8';
89
import * as React from 'react';
910

1011
import { deepCopy } from '@/src/tools';
1112
import { IDict } from '@/src/types';
1213

1314
export interface IBaseFormStates {
14-
schema?: IDict;
15+
schema?: RJSFSchema;
1516
extraErrors?: any;
1617
}
1718

@@ -118,8 +119,8 @@ export class BaseForm extends React.Component<IBaseFormProps, IBaseFormStates> {
118119

119120
protected processSchema(
120121
data: IDict<any> | undefined,
121-
schema: IDict,
122-
uiSchema: IDict,
122+
schema: RJSFSchema,
123+
uiSchema: UiSchema,
123124
): void {
124125
if (!schema['properties']) {
125126
return;
@@ -251,13 +252,15 @@ export class BaseForm extends React.Component<IBaseFormProps, IBaseFormStates> {
251252
protected removeFormEntry(
252253
entry: string,
253254
data: IDict<any> | undefined,
254-
schema: IDict,
255-
uiSchema: IDict,
255+
schema: RJSFSchema,
256+
uiSchema: UiSchema,
256257
) {
257258
if (data) {
258259
delete data[entry];
259260
}
260-
delete schema.properties[entry];
261+
if (schema.properties) {
262+
delete schema.properties[entry];
263+
}
261264
delete uiSchema[entry];
262265
if (schema.required && schema.required.includes(entry)) {
263266
schema.required.splice(schema.required.indexOf(entry), 1);

packages/base/src/formbuilder/objectform/process/dissolveProcessForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IDict, IJupyterGISModel, IGeoJSONSource } from '@jupytergis/schema';
22
import { IChangeEvent } from '@rjsf/core';
3+
import { RJSFSchema } from '@rjsf/utils';
34

45
import {
56
BaseForm,
@@ -85,7 +86,7 @@ export class DissolveForm extends BaseForm {
8586
properties: {
8687
...prevState.schema?.properties,
8788
dissolveField: {
88-
...prevState.schema?.properties?.dissolveField,
89+
...(prevState.schema?.properties?.dissolveField as RJSFSchema),
8990
enum: [...this.features],
9091
},
9192
},

0 commit comments

Comments
 (0)