Skip to content

Commit

Permalink
Split form files
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Jul 19, 2024
1 parent 02260c9 commit b3acc89
Show file tree
Hide file tree
Showing 12 changed files with 315 additions and 243 deletions.
86 changes: 75 additions & 11 deletions packages/base/src/dialogs/formdialog.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,92 @@
import { IDict, IJupyterGISModel } from '@jupytergis/schema';
import {
IDict,
IJGISFormSchemaRegistry,
IJupyterGISModel,
LayerType,
SourceType
} from '@jupytergis/schema';
import { Dialog } from '@jupyterlab/apputils';
import { DocumentRegistry } from '@jupyterlab/docregistry';
import { LabIcon, errorIcon } from '@jupyterlab/ui-components';
import { Widget } from '@lumino/widgets';
import { ErrorObject } from 'ajv';
import * as React from 'react';

import { ObjectPropertiesForm } from '../formbuilder';
import { BaseForm } from '../formbuilder/baseform';
import { deepCopy } from '../tools';

export interface IFormDialogOptions {
schema: IDict;
sourceData: IDict;
title: string;
syncData: (props: IDict) => void;
export interface ICreationFormDialogOptions {
/**
* The type of layer to create.
*/
layerType?: LayerType;

/**
* The type of source to create.
*/
sourceType?: SourceType;

/**
* The initial layer data, if it applies.
*/
layerData?: IDict;

/**
* The initial source data, if it applies.
*/
sourceData?: IDict;

formSchemaRegistry: IJGISFormSchemaRegistry;
context: DocumentRegistry.IContext<IJupyterGISModel>;
}

export class FormDialog extends Dialog<IDict> {
constructor(options: IFormDialogOptions) {
/**
* Form for creating a source, a layer or both at the same time
*/
export class CreationFormDialog extends Dialog<IDict> {
constructor(options: ICreationFormDialogOptions) {
const filePath = options.context.path;
const jGISModel = options.context.model;

let layerSchema: IDict | undefined = undefined;
if (options.layerType) {
layerSchema = deepCopy(
options.formSchemaRegistry.getSchemas().get(options.layerType)
);

if (!layerSchema) {
console.log(`Cannot find schema for ${options.layerType}`);
return;
}

// If a source is created as part of this form, remove the source selection from the layer form
if (options.sourceType) {
delete layerSchema.properties?.source;
}
layerSchema['properties'] = {
name: { type: 'string', description: 'The name of the layer' },
...layerSchema['properties']
};
}

let sourceSchema: IDict | undefined = undefined;
if (options.sourceType) {
sourceSchema = deepCopy(
options.formSchemaRegistry.getSchemas().get(options.sourceType)
);
}

if (!layerSchema && !sourceSchema) {
// Unreachable
console.log(
`Cannot find schema for ${options.layerType}, ${options.sourceType}`
);
return;
}

const body = (
<div style={{ overflow: 'hidden' }}>
<ObjectPropertiesForm
<BaseForm
formContext="create"
model={jGISModel}
filePath={`${filePath}::dialog`}
Expand All @@ -34,7 +98,7 @@ export class FormDialog extends Dialog<IDict> {
);

super({ title: options.title, body, buttons: [Dialog.cancelButton()] });
this.addClass('jGIS-property-FormDialog');
this.addClass('jGIS-layer-CreationFormDialog');
}
}

Expand Down
5 changes: 3 additions & 2 deletions packages/base/src/dialogs/geoJsonLayerDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PathExt } from '@jupyterlab/coreutils';
import { UUID } from '@lumino/coreutils';
import * as React from 'react';

import { GeoJSONLayerPropertiesForm } from '../formbuilder';
import { VectorLayerPropertiesForm } from '../formbuilder';
import { deepCopy } from '../tools';

/**
Expand Down Expand Up @@ -78,7 +78,8 @@ export const GeoJSONLayerComponent = ({
};

return (
<GeoJSONLayerPropertiesForm
<VectorLayerPropertiesForm
sourceType="GeoJSONSource"
formContext={'create'}
model={model}
schema={schema}
Expand Down
4 changes: 2 additions & 2 deletions packages/base/src/dialogs/layerBrowserDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { Dialog } from '@jupyterlab/apputils';
import { UUID } from '@lumino/coreutils';
import React, { ChangeEvent, MouseEvent, useEffect, useState } from 'react';
import { RasterSourcePropertiesForm } from '../formbuilder';
import { TileSourcePropertiesForm } from '../formbuilder';
import { deepCopy } from '../tools';

import CUSTOM_RASTER_IMAGE from '../../rasterlayer_gallery/custom_raster.png';
Expand Down Expand Up @@ -163,7 +163,7 @@ export const LayerBrowserComponent = ({

return (
<div className="jGIS-customlayer-form">
<RasterSourcePropertiesForm
<TileSourcePropertiesForm
formContext="create"
model={model}
sourceData={{
Expand Down
Loading

0 comments on commit b3acc89

Please sign in to comment.