Skip to content

Commit bf72850

Browse files
authored
Cleanup (#31)
1 parent f81bb2d commit bf72850

File tree

7 files changed

+13
-210
lines changed

7 files changed

+13
-210
lines changed

packages/base/src/commands.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,6 @@ namespace Private {
167167

168168
current.context.model.syncFormData(form);
169169

170-
const syncSelectedField = (
171-
id: string | null,
172-
value: any,
173-
parentType: 'panel' | 'dialog'
174-
): void => {
175-
let property: string | null = null;
176-
if (id) {
177-
const prefix = id.split('_')[0];
178-
property = id.substring(prefix.length);
179-
}
180-
current.context.model.syncSelectedPropField({
181-
id: property,
182-
value,
183-
parentType
184-
});
185-
};
186-
187170
const dialog = new FormDialog({
188171
context: current.context,
189172
title: form.title,
@@ -223,8 +206,7 @@ namespace Private {
223206
},
224207
cancelButton: () => {
225208
current.context.model.syncFormData(undefined);
226-
},
227-
syncSelectedPropField: syncSelectedField
209+
}
228210
});
229211
await dialog.launch();
230212
};

packages/base/src/formdialog.tsx

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
1-
import {
2-
IDict,
3-
IJupyterGISClientState,
4-
IJupyterGISModel
5-
} from '@jupytergis/schema';
1+
import { IDict, IJupyterGISModel } from '@jupytergis/schema';
62
import { Dialog } from '@jupyterlab/apputils';
73
import { DocumentRegistry } from '@jupyterlab/docregistry';
84
import * as React from 'react';
95

106
import { ObjectPropertiesForm } from './panelview/formbuilder';
11-
import { focusInputField, removeStyleFromProperty } from './tools';
127

138
export interface IFormDialogOptions {
149
schema: IDict;
1510
sourceData: IDict;
1611
title: string;
1712
cancelButton: (() => void) | boolean;
1813
syncData: (props: IDict) => void;
19-
syncSelectedPropField?: (
20-
id: string | null,
21-
value: any,
22-
parentType: 'dialog' | 'panel'
23-
) => void;
2414
context: DocumentRegistry.IContext<IJupyterGISModel>;
2515
}
2616

@@ -40,52 +30,16 @@ export class FormDialog extends Dialog<IDict> {
4030
const body = (
4131
<div style={{ overflow: 'hidden' }}>
4232
<ObjectPropertiesForm
43-
parentType="dialog"
4433
model={jGISModel}
4534
filePath={`${filePath}::dialog`}
4635
sourceData={options.sourceData}
4736
schema={options.schema}
4837
syncData={options.syncData}
4938
cancel={cancelCallback}
50-
syncSelectedField={options.syncSelectedPropField}
5139
/>
5240
</div>
5341
);
54-
let lastSelectedPropFieldId;
55-
const onClientSharedStateChanged = (
56-
sender: IJupyterGISModel,
57-
clients: Map<number, IJupyterGISClientState>
58-
): void => {
59-
const remoteUser = jGISModel?.localState?.remoteUser;
60-
if (remoteUser) {
61-
const newState = clients.get(remoteUser);
6242

63-
const id = newState?.selectedPropField?.id;
64-
const value = newState?.selectedPropField?.value;
65-
const parentType = newState?.selectedPropField?.parentType;
66-
if (parentType === 'dialog') {
67-
lastSelectedPropFieldId = focusInputField(
68-
`${filePath}::dialog`,
69-
id,
70-
value,
71-
newState?.user?.color,
72-
lastSelectedPropFieldId
73-
);
74-
}
75-
} else {
76-
if (lastSelectedPropFieldId) {
77-
removeStyleFromProperty(
78-
`${filePath}::dialog`,
79-
lastSelectedPropFieldId,
80-
['border-color', 'box-shadow']
81-
);
82-
83-
lastSelectedPropFieldId = undefined;
84-
}
85-
}
86-
};
87-
88-
jGISModel?.clientStateChanged.connect(onClientSharedStateChanged);
8943
super({ title: options.title, body, buttons: [Dialog.cancelButton()] });
9044
this.addClass('jGIS-property-FormDialog');
9145
}

packages/base/src/panelview/formbuilder.tsx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,10 @@ interface IStates {
1414
}
1515

1616
interface IProps {
17-
parentType: 'dialog' | 'panel';
1817
sourceData: IDict | undefined;
1918
filePath?: string;
2019
model: IJupyterGISModel;
2120
syncData: (properties: IDict) => void;
22-
syncSelectedField?: (
23-
id: string | null,
24-
value: any,
25-
parentType: 'panel' | 'dialog'
26-
) => void;
2721
schema?: IDict;
2822
cancel?: () => void;
2923
}
@@ -104,7 +98,7 @@ export class ObjectPropertiesForm extends React.Component<IProps, IStates> {
10498
}
10599

106100
// Don't show readOnly properties when coming from the properties panel
107-
if (v['readOnly'] && this.props.parentType === 'panel') {
101+
if (v['readOnly']) {
108102
this.removeFormEntry(k, data, schema, uiSchema);
109103
}
110104
});
@@ -180,17 +174,7 @@ export class ObjectPropertiesForm extends React.Component<IProps, IStates> {
180174
formData,
181175
onChange: this.onFormChange.bind(this),
182176
onSubmit: this.onFormSubmit.bind(this),
183-
onFocus: (id, value) => {
184-
this.props.syncSelectedField
185-
? this.props.syncSelectedField(id, value, this.props.parentType)
186-
: null;
187-
},
188-
onBlur: (id, value) => {
189-
this.props.syncSelectedField
190-
? this.props.syncSelectedField(null, value, this.props.parentType)
191-
: null;
192-
this.onFormBlur(id, value);
193-
},
177+
onBlur: this.onFormBlur.bind(this),
194178
uiSchema,
195179
children: (
196180
<button ref={submitRef} type="submit" style={{ display: 'none' }} />

packages/base/src/panelview/objectproperties.tsx

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { Panel } from '@lumino/widgets';
1515
import * as React from 'react';
1616
import { v4 as uuid } from 'uuid';
1717

18-
import { focusInputField, removeStyleFromProperty, deepCopy } from '../tools';
18+
import { deepCopy } from '../tools';
1919
import { IControlPanelModel } from '../types';
2020
import { LayerPropertiesForm, RasterSourcePropertiesForm } from './formbuilder';
2121
import { JupyterGISWidget } from '../widget';
@@ -112,23 +112,6 @@ class ObjectPropertiesReact extends React.Component<IProps, IStates> {
112112
model.sharedModel.updateObjectParameters(id, properties);
113113
}
114114

115-
syncSelectedField = (
116-
id: string | null,
117-
value: any,
118-
parentType: 'panel' | 'dialog'
119-
) => {
120-
let property: string | null = null;
121-
if (id) {
122-
const prefix = id.split('_')[0];
123-
property = id.substring(prefix.length);
124-
}
125-
this.props.cpModel.jGISModel?.syncSelectedPropField({
126-
parentType,
127-
id: property,
128-
value
129-
});
130-
};
131-
132115
private _sharedJGISModelChanged = (
133116
_: IJupyterGISDoc,
134117
changed: IJGISLayerDocChange
@@ -140,43 +123,17 @@ class ObjectPropertiesReact extends React.Component<IProps, IStates> {
140123
sender: IJupyterGISModel,
141124
clients: Map<number, IJupyterGISClientState>
142125
): void => {
143-
const remoteUser = this.props.cpModel.jGISModel?.localState?.remoteUser;
144126
let newState: IJupyterGISClientState | undefined;
145127
const clientId = this.state.clientId;
146-
if (remoteUser) {
147-
newState = clients.get(remoteUser);
148-
149-
const id = newState?.selectedPropField?.id;
150-
const value = newState?.selectedPropField?.value;
151-
const parentType = newState?.selectedPropField?.parentType;
152-
if (parentType === 'panel') {
153-
this._lastSelectedPropFieldId = focusInputField(
154-
`${this.state.filePath}::panel`,
155-
id,
156-
value,
157-
newState?.user?.color,
158-
this._lastSelectedPropFieldId
159-
);
160-
}
161-
} else {
162-
const localState = clientId ? clients.get(clientId) : null;
163-
if (this._lastSelectedPropFieldId) {
164-
removeStyleFromProperty(
165-
`${this.state.filePath}::panel`,
166-
this._lastSelectedPropFieldId,
167-
['border-color', 'box-shadow']
168-
);
169128

170-
this._lastSelectedPropFieldId = undefined;
171-
}
172-
if (
173-
localState &&
174-
localState.selected?.emitter &&
175-
localState.selected.emitter !== this.state.id &&
176-
localState.selected?.value
177-
) {
178-
newState = localState;
179-
}
129+
const localState = clientId ? clients.get(clientId) : null;
130+
if (
131+
localState &&
132+
localState.selected?.emitter &&
133+
localState.selected.emitter !== this.state.id &&
134+
localState.selected?.value
135+
) {
136+
newState = localState;
180137
}
181138
if (newState) {
182139
const selection = newState.selected.value;
@@ -250,7 +207,6 @@ class ObjectPropertiesReact extends React.Component<IProps, IStates> {
250207
<div>
251208
<h3>Source Properties</h3>
252209
<RasterSourcePropertiesForm
253-
parentType="panel"
254210
model={model}
255211
filePath={`${this.state.filePath}::panel`}
256212
schema={schema}
@@ -261,7 +217,6 @@ class ObjectPropertiesReact extends React.Component<IProps, IStates> {
261217
properties
262218
);
263219
}}
264-
syncSelectedField={this.syncSelectedField}
265220
/>
266221
</div>
267222
)
@@ -276,7 +231,6 @@ class ObjectPropertiesReact extends React.Component<IProps, IStates> {
276231
<div>
277232
<h3>Layer Properties</h3>
278233
<LayerPropertiesForm
279-
parentType="panel"
280234
sourceType={selectedObjSource.type}
281235
model={model}
282236
filePath={`${this.state.filePath}::panel`}
@@ -285,20 +239,17 @@ class ObjectPropertiesReact extends React.Component<IProps, IStates> {
285239
syncData={(properties: { [key: string]: any }) => {
286240
this.syncObjectProperties(this.state.selectedObject, properties);
287241
}}
288-
syncSelectedField={this.syncSelectedField}
289242
/>
290243
<h3>Source Properties</h3>
291244
{selectedObjSource.type === 'RasterSource' && (
292245
<RasterSourcePropertiesForm
293-
parentType="panel"
294246
model={model}
295247
filePath={`${this.state.filePath}::panel`}
296248
schema={sourceSchema}
297249
sourceData={selectedObjectSourceData}
298250
syncData={(properties: { [key: string]: any }) => {
299251
this.syncObjectProperties(selectedObjectSourceId, properties);
300252
}}
301-
syncSelectedField={this.syncSelectedField}
302253
/>
303254
)}
304255
{/* {selectedObjSource.type === 'GeoJSONSource' && (
@@ -309,7 +260,6 @@ class ObjectPropertiesReact extends React.Component<IProps, IStates> {
309260
);
310261
}
311262

312-
private _lastSelectedPropFieldId?: string;
313263
private _formSchema: Map<string, IDict>;
314264
}
315265

packages/base/src/tools.ts

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -43,41 +43,6 @@ export function throttle<T extends (...args: any[]) => void>(
4343
} as T;
4444
}
4545

46-
export function focusInputField(
47-
filePath?: string,
48-
fieldId?: string | null,
49-
value?: any,
50-
color?: string,
51-
lastSelectedPropFieldId?: string
52-
): string | undefined {
53-
const propsToRemove = ['border-color', 'box-shadow'];
54-
let newSelected: string | undefined;
55-
if (!fieldId) {
56-
if (lastSelectedPropFieldId) {
57-
removeStyleFromProperty(filePath, lastSelectedPropFieldId, propsToRemove);
58-
if (value) {
59-
const el = getElementFromProperty(filePath, lastSelectedPropFieldId);
60-
if (el?.tagName?.toLowerCase() === 'input') {
61-
(el as HTMLInputElement).value = value;
62-
}
63-
}
64-
newSelected = undefined;
65-
}
66-
} else {
67-
if (fieldId !== lastSelectedPropFieldId) {
68-
removeStyleFromProperty(filePath, lastSelectedPropFieldId, propsToRemove);
69-
70-
const el = getElementFromProperty(filePath, fieldId);
71-
if (el) {
72-
el.style.borderColor = color ?? 'red';
73-
el.style.boxShadow = `inset 0 0 4px ${color ?? 'red'}`;
74-
}
75-
newSelected = fieldId;
76-
}
77-
}
78-
return newSelected;
79-
}
80-
8146
export function getElementFromProperty(
8247
filePath?: string | null,
8348
prop?: string | null
@@ -93,20 +58,6 @@ export function getElementFromProperty(
9358
}
9459
}
9560

96-
export function removeStyleFromProperty(
97-
filePath: string | null | undefined,
98-
prop: string | null | undefined,
99-
properties: string[]
100-
): void {
101-
if (!filePath || !prop || properties.length === 0) {
102-
return;
103-
}
104-
const el = getElementFromProperty(filePath, prop);
105-
if (el) {
106-
properties.forEach(prop => el.style.removeProperty(prop));
107-
}
108-
}
109-
11061
export function nearest(n: number, tol: number): number {
11162
const round = Math.round(n);
11263
if (Math.abs(round - n) < tol) {

packages/schema/src/interfaces.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ export interface ISelection {
5353

5454
export interface IJupyterGISClientState {
5555
selected: { value?: { [key: string]: ISelection }; emitter?: string | null };
56-
selectedPropField?: {
57-
id: string | null;
58-
value: any;
59-
parentType: 'panel' | 'dialog';
60-
};
6156
user: User.IIdentity;
6257
remoteUser?: number;
6358
toolbarForm?: IDict;
@@ -153,11 +148,6 @@ export interface IJupyterGISModel extends DocumentRegistry.IModel {
153148
): void;
154149

155150
syncSelected(value: { [key: string]: ISelection }, emitter?: string): void;
156-
syncSelectedPropField(data: {
157-
id: string | null;
158-
value: any;
159-
parentType: 'panel' | 'dialog';
160-
}): void;
161151
setUserToFollow(userId?: number): void;
162152
syncFormData(form: any): void;
163153

packages/schema/src/model.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,6 @@ export class JupyterGISModel implements IJupyterGISModel {
281281
});
282282
}
283283

284-
syncSelectedPropField(data: {
285-
id: string | null;
286-
value: any;
287-
parentType: 'panel' | 'dialog';
288-
}): void {
289-
this.sharedModel.awareness.setLocalStateField('selectedPropField', data);
290-
}
291-
292284
setUserToFollow(userId?: number): void {
293285
if (this._sharedModel) {
294286
this._sharedModel.awareness.setLocalStateField('remoteUser', userId);

0 commit comments

Comments
 (0)