Skip to content

Commit b294c7d

Browse files
HaudinFlorencegithub-actions[bot]gjmooneyarjxn-py
authored
Enable empty path for geojson layer (#810)
* Create an empty vector layer with empty embedded data when no path is provided. * Update tools.ts with removing condition on undefined path. * Fix failing lint test. * Update Playwright Snapshots * Remove ui-tests snapshots with wrong names. * Fix a bug in geojsonsource.ts. * Call super.processSchema method when formContext is set to update. * Apply suggestions from code review Co-authored-by: Greg Mooney <[email protected]> Co-authored-by: Arjun Verma <[email protected]> --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Greg Mooney <[email protected]> Co-authored-by: Arjun Verma <[email protected]>
1 parent 0424c9f commit b294c7d

File tree

2 files changed

+42
-86
lines changed

2 files changed

+42
-86
lines changed

packages/base/src/formbuilder/objectform/source/geojsonsource.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { IDict } from '@jupytergis/schema';
22
import * as geojson from '@jupytergis/schema/src/schema/geojson.json';
3+
import { showErrorMessage } from '@jupyterlab/apputils';
4+
import { ISubmitEvent } from '@rjsf/core';
35
import { Ajv, ValidateFunction } from 'ajv';
46

57
import { loadFile } from '@/src/tools';
@@ -27,6 +29,10 @@ export class GeoJSONSourcePropertiesForm extends PathBasedSourcePropertiesForm {
2729
if (data?.path !== '') {
2830
this.removeFormEntry('data', data, schema, uiSchema);
2931
}
32+
if (this.props.formContext === 'create') {
33+
schema.properties.path.description =
34+
'The local path to a GeoJSON file. (If no path/url is provided, an empty GeoJSON is created.)';
35+
}
3036

3137
super.processSchema(data, schema, uiSchema);
3238
}
@@ -36,11 +42,11 @@ export class GeoJSONSourcePropertiesForm extends PathBasedSourcePropertiesForm {
3642
*
3743
* @param path - the path to validate.
3844
*/
39-
protected async _validatePath(path: string) {
45+
protected async _validatePath(path: string | undefined) {
4046
const extraErrors: IDict = this.state.extraErrors;
4147

4248
let error = '';
43-
let valid = false;
49+
let valid = true;
4450
if (path) {
4551
try {
4652
const geoJSONData = await loadFile({
@@ -55,8 +61,6 @@ export class GeoJSONSourcePropertiesForm extends PathBasedSourcePropertiesForm {
5561
} catch (e) {
5662
error = `"${path}" is not a valid GeoJSON file: ${e}`;
5763
}
58-
} else {
59-
error = 'Path is required';
6064
}
6165

6266
if (!valid) {
@@ -79,4 +83,17 @@ export class GeoJSONSourcePropertiesForm extends PathBasedSourcePropertiesForm {
7983
this.props.formErrorSignal.emit(!valid);
8084
}
8185
}
86+
protected onFormSubmit(e: ISubmitEvent<any>) {
87+
if (this.state.extraErrors?.path?.__errors?.length >= 1) {
88+
showErrorMessage('Invalid file', this.state.extraErrors.path.__errors[0]);
89+
return;
90+
}
91+
if (!e.formData.path) {
92+
e.formData.data = {
93+
type: 'FeatureCollection',
94+
features: [],
95+
};
96+
}
97+
super.onFormSubmit(e);
98+
}
8299
}

yarn.lock

Lines changed: 21 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -642,22 +642,6 @@ __metadata:
642642
languageName: node
643643
linkType: hard
644644

645-
"@isaacs/balanced-match@npm:^4.0.1":
646-
version: 4.0.1
647-
resolution: "@isaacs/balanced-match@npm:4.0.1"
648-
checksum: 102fbc6d2c0d5edf8f6dbf2b3feb21695a21bc850f11bc47c4f06aa83bd8884fde3fe9d6d797d619901d96865fdcb4569ac2a54c937992c48885c5e3d9967fe8
649-
languageName: node
650-
linkType: hard
651-
652-
"@isaacs/brace-expansion@npm:^5.0.0":
653-
version: 5.0.0
654-
resolution: "@isaacs/brace-expansion@npm:5.0.0"
655-
dependencies:
656-
"@isaacs/balanced-match": ^4.0.1
657-
checksum: d7a3b8b0ddbf0ccd8eeb1300e29dd0a0c02147e823d8138f248375a365682360620895c66d113e05ee02389318c654379b0e538b996345b83c914941786705b1
658-
languageName: node
659-
linkType: hard
660-
661645
"@isaacs/cliui@npm:^8.0.2":
662646
version: 8.0.2
663647
resolution: "@isaacs/cliui@npm:8.0.2"
@@ -1751,9 +1735,9 @@ __metadata:
17511735
languageName: node
17521736
linkType: hard
17531737

1754-
"@lerna/create@npm:8.2.3":
1755-
version: 8.2.3
1756-
resolution: "@lerna/create@npm:8.2.3"
1738+
"@lerna/create@npm:8.2.4":
1739+
version: 8.2.4
1740+
resolution: "@lerna/create@npm:8.2.4"
17571741
dependencies:
17581742
"@npmcli/arborist": 7.5.4
17591743
"@npmcli/package-json": 5.2.0
@@ -1788,7 +1772,6 @@ __metadata:
17881772
js-yaml: 4.1.0
17891773
libnpmpublish: 9.0.9
17901774
load-json-file: 6.2.0
1791-
lodash: ^4.17.21
17921775
make-dir: 4.0.0
17931776
minimatch: 3.0.5
17941777
multimatch: 5.0.0
@@ -1825,7 +1808,7 @@ __metadata:
18251808
write-pkg: 4.0.0
18261809
yargs: 17.7.2
18271810
yargs-parser: 21.1.1
1828-
checksum: 4e8d3f1955c021e7206ebdd0f35e64e11b4396cff5e0fe12611cb5a645166512bd9105dead00f97bee61400b8bbe07dffcaf39eba69d3984e91118d50a71484a
1811+
checksum: 79ccd20fac694813728b6582f806f12b3549a3bc87a91d6df6260e0c623b669fa1f84815d985b1c5c9f6d717a57e7407b8e8c5e5e770d7ff39b3bdba9e91883f
18291812
languageName: node
18301813
linkType: hard
18311814

@@ -3562,11 +3545,12 @@ __metadata:
35623545
linkType: hard
35633546

35643547
"@types/glob@npm:*":
3565-
version: 9.0.0
3566-
resolution: "@types/glob@npm:9.0.0"
3548+
version: 8.1.0
3549+
resolution: "@types/glob@npm:8.1.0"
35673550
dependencies:
3568-
glob: "*"
3569-
checksum: a9ea3afe1eafbc8fb303d2d39cd786084aece75fd8eeae1bad8febbf6e0323b429145f31e779a3d68fa693b2a53648ec2c639ee4858fb29132f801c74678051c
3551+
"@types/minimatch": ^5.1.2
3552+
"@types/node": "*"
3553+
checksum: 9101f3a9061e40137190f70626aa0e202369b5ec4012c3fabe6f5d229cce04772db9a94fa5a0eb39655e2e4ad105c38afbb4af56a56c0996a8c7d4fc72350e3d
35703554
languageName: node
35713555
linkType: hard
35723556

@@ -3643,6 +3627,13 @@ __metadata:
36433627
languageName: node
36443628
linkType: hard
36453629

3630+
"@types/minimatch@npm:^5.1.2":
3631+
version: 5.1.2
3632+
resolution: "@types/minimatch@npm:5.1.2"
3633+
checksum: 0391a282860c7cb6fe262c12b99564732401bdaa5e395bee9ca323c312c1a0f45efbf34dce974682036e857db59a5c9b1da522f3d6055aeead7097264c8705a8
3634+
languageName: node
3635+
linkType: hard
3636+
36463637
"@types/minimist@npm:^1.2.0":
36473638
version: 1.2.5
36483639
resolution: "@types/minimist@npm:1.2.5"
@@ -6704,7 +6695,7 @@ __metadata:
67046695
languageName: node
67056696
linkType: hard
67066697

6707-
"foreground-child@npm:^3.1.0, foreground-child@npm:^3.3.1":
6698+
"foreground-child@npm:^3.1.0":
67086699
version: 3.3.1
67096700
resolution: "foreground-child@npm:3.3.1"
67106701
dependencies:
@@ -7068,22 +7059,6 @@ __metadata:
70687059
languageName: node
70697060
linkType: hard
70707061

7071-
"glob@npm:*":
7072-
version: 11.0.3
7073-
resolution: "glob@npm:11.0.3"
7074-
dependencies:
7075-
foreground-child: ^3.3.1
7076-
jackspeak: ^4.1.1
7077-
minimatch: ^10.0.3
7078-
minipass: ^7.1.2
7079-
package-json-from-dist: ^1.0.0
7080-
path-scurry: ^2.0.0
7081-
bin:
7082-
glob: dist/esm/bin.mjs
7083-
checksum: 65ddc1e3c969e87999880580048763cc8b5bdd375930dd43b8100a5ba481d2e2563e4553de42875790800c602522a98aa8d3ed1c5bd4d27621609e6471eb371d
7084-
languageName: node
7085-
linkType: hard
7086-
70877062
"glob@npm:^10.2.2, glob@npm:^10.3.10":
70887063
version: 10.4.5
70897064
resolution: "glob@npm:10.4.5"
@@ -8095,15 +8070,6 @@ __metadata:
80958070
languageName: node
80968071
linkType: hard
80978072

8098-
"jackspeak@npm:^4.1.1":
8099-
version: 4.1.1
8100-
resolution: "jackspeak@npm:4.1.1"
8101-
dependencies:
8102-
"@isaacs/cliui": ^8.0.2
8103-
checksum: daca714c5adebfb80932c0b0334025307b68602765098d73d52ec546bc4defdb083292893384261c052742255d0a77d8fcf96f4c669bcb4a99b498b94a74955e
8104-
languageName: node
8105-
linkType: hard
8106-
81078073
"jake@npm:^10.8.5":
81088074
version: 10.9.2
81098075
resolution: "jake@npm:10.9.2"
@@ -8516,10 +8482,10 @@ __metadata:
85168482
linkType: hard
85178483

85188484
"lerna@npm:^8.1.9":
8519-
version: 8.2.3
8520-
resolution: "lerna@npm:8.2.3"
8485+
version: 8.2.4
8486+
resolution: "lerna@npm:8.2.4"
85218487
dependencies:
8522-
"@lerna/create": 8.2.3
8488+
"@lerna/create": 8.2.4
85238489
"@npmcli/arborist": 7.5.4
85248490
"@npmcli/package-json": 5.2.0
85258491
"@npmcli/run-script": 8.1.0
@@ -8559,7 +8525,6 @@ __metadata:
85598525
libnpmaccess: 8.0.6
85608526
libnpmpublish: 9.0.9
85618527
load-json-file: 6.2.0
8562-
lodash: ^4.17.21
85638528
make-dir: 4.0.0
85648529
minimatch: 3.0.5
85658530
multimatch: 5.0.0
@@ -8601,7 +8566,7 @@ __metadata:
86018566
yargs-parser: 21.1.1
86028567
bin:
86038568
lerna: dist/cli.js
8604-
checksum: 450bbd422e4d4d8ae86389e03797b5330a4718614c70f5820b4dc3099869a98839a1b0bebaace049c7a65a0e31010c1d77c4892a21eedbe29e15035219ff6a17
8569+
checksum: ab46ecdf65a35d5171caa1d34023219c444aba328287e8ba49d22310f43918c98feb50b074c3191fa2da4102dd71f1292a4226b68083057c55aa811486c58cd8
86058570
languageName: node
86068571
linkType: hard
86078572

@@ -8828,13 +8793,6 @@ __metadata:
88288793
languageName: node
88298794
linkType: hard
88308795

8831-
"lru-cache@npm:^11.0.0":
8832-
version: 11.1.0
8833-
resolution: "lru-cache@npm:11.1.0"
8834-
checksum: 6274e90b5fdff87570fe26fe971467a5ae1f25f132bebe187e71c5627c7cd2abb94b47addd0ecdad034107667726ebde1abcef083d80f2126e83476b2c4e7c82
8835-
languageName: node
8836-
linkType: hard
8837-
88388796
"lru-cache@npm:^6.0.0":
88398797
version: 6.0.0
88408798
resolution: "lru-cache@npm:6.0.0"
@@ -9073,15 +9031,6 @@ __metadata:
90739031
languageName: node
90749032
linkType: hard
90759033

9076-
"minimatch@npm:^10.0.3":
9077-
version: 10.0.3
9078-
resolution: "minimatch@npm:10.0.3"
9079-
dependencies:
9080-
"@isaacs/brace-expansion": ^5.0.0
9081-
checksum: 20bfb708095a321cb43c20b78254e484cb7d23aad992e15ca3234a3331a70fa9cd7a50bc1a7c7b2b9c9890c37ff0685f8380028fcc28ea5e6de75b1d4f9374aa
9082-
languageName: node
9083-
linkType: hard
9084-
90859034
"minimatch@npm:^3.0.4, minimatch@npm:^3.0.5, minimatch@npm:^3.1.1, minimatch@npm:^3.1.2":
90869035
version: 3.1.2
90879036
resolution: "minimatch@npm:3.1.2"
@@ -10218,16 +10167,6 @@ __metadata:
1021810167
languageName: node
1021910168
linkType: hard
1022010169

10221-
"path-scurry@npm:^2.0.0":
10222-
version: 2.0.0
10223-
resolution: "path-scurry@npm:2.0.0"
10224-
dependencies:
10225-
lru-cache: ^11.0.0
10226-
minipass: ^7.1.2
10227-
checksum: 9953ce3857f7e0796b187a7066eede63864b7e1dfc14bf0484249801a5ab9afb90d9a58fc533ebb1b552d23767df8aa6a2c6c62caf3f8a65f6ce336a97bbb484
10228-
languageName: node
10229-
linkType: hard
10230-
1023110170
"path-type@npm:^3.0.0":
1023210171
version: 3.0.0
1023310172
resolution: "path-type@npm:3.0.0"

0 commit comments

Comments
 (0)