Skip to content

Commit c53d910

Browse files
committed
Adapted code to Svelte 4
1 parent 49d935e commit c53d910

37 files changed

+104
-121
lines changed

__tests__/v1/JobLogsModal.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ vi.mock('$env/dynamic/public', () => {
88

99
// Mocking bootstrap.Modal
1010
class MockModal {
11-
show = vi.fn();
11+
constructor() {
12+
this.show = vi.fn();
13+
}
1214
}
1315
MockModal.getInstance = vi.fn();
1416

__tests__/v2/CreateDatasetModal.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ vi.mock('$app/stores', () => {
1818

1919
// Mocking bootstrap.Modal
2020
class MockModal {
21-
show = vi.fn();
22-
hide = vi.fn();
21+
constructor() {
22+
this.show = vi.fn();
23+
this.hide = vi.fn();
24+
}
2325
}
2426
MockModal.getInstance = vi.fn();
2527

__tests__/v2/RunWorkflowModal.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ fetch.mockResolvedValue({
1212

1313
// Mocking bootstrap.Modal
1414
class MockModal {
15-
show = vi.fn();
16-
hide = vi.fn();
15+
constructor() {
16+
this.show = vi.fn();
17+
this.hide = vi.fn();
18+
}
1719
}
1820
MockModal.getInstance = vi.fn();
1921

docs/development/structure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export const actions = {
163163
console.log(cookieOptions);
164164
cookies.set(AUTH_COOKIE_NAME, authData.access_token, cookieOptions);
165165

166-
throw redirect(302, '/');
166+
redirect(302, '/');
167167
}
168168
};
169169
```

jschema/src/lib/components/form_element.js

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,28 @@ import { getPropertyData } from './jschema_initial_data';
66
* @abstract
77
*/
88
export class BaseFormElement {
9-
manager;
10-
/**
11-
* Unique identifier associated with the HTML element
12-
*/
13-
id;
14-
key;
15-
type;
16-
title;
17-
description;
18-
required;
19-
/**
20-
* Tells if the property can be removed from an object: true for custom properties
21-
* of schema objects having additionalProperties set to true.
22-
*/
23-
removable;
24-
/**
25-
* @type {import("../types/jschema").JSONSchemaProperty}
26-
*/
27-
property;
28-
299
/**
3010
* @param {import("../types/form").BaseFormElementFields} fields
3111
*/
3212
constructor(fields) {
3313
this.manager = fields.manager;
14+
/**
15+
* Unique identifier associated with the HTML element
16+
*/
3417
this.id = fields.id;
3518
this.key = fields.key;
3619
this.type = fields.type;
3720
this.title = fields.title;
3821
this.required = fields.required;
3922
this.description = fields.description;
23+
/**
24+
* Tells if the property can be removed from an object: true for custom properties
25+
* of schema objects having additionalProperties set to true.
26+
*/
4027
this.removable = fields.removable;
28+
/**
29+
* @type {import("../types/jschema").JSONSchemaProperty}
30+
*/
4131
this.property = fields.property;
4232
}
4333

@@ -52,8 +42,6 @@ export class BaseFormElement {
5242
* @abstract
5343
*/
5444
export class ValueFormElement extends BaseFormElement {
55-
value;
56-
5745
/**
5846
* @param {import("../types/form").ValueFormElementFields<T>} fields
5947
*/
@@ -82,8 +70,6 @@ export class BooleanFormElement extends ValueFormElement {
8270
}
8371

8472
export class EnumFormElement extends ValueFormElement {
85-
options;
86-
8773
/**
8874
* @param {import("../types/form").EnumFormElementFields} fields
8975
*/
@@ -94,29 +80,26 @@ export class EnumFormElement extends ValueFormElement {
9480
}
9581

9682
export class NumberFormElement extends ValueFormElement {
97-
badInput = false;
9883
/**
9984
* @param {import("../types/form").NumberFormElementFields} fields
10085
*/
10186
constructor(fields) {
10287
super(fields);
10388
this.min = fields.min;
10489
this.max = fields.max;
90+
this.badInput = false;
10591
}
10692
}
10793

10894
export class ObjectFormElement extends BaseFormElement {
109-
children;
110-
/**
111-
* @type {import("../types/jschema").JSONSchemaProperty | false}
112-
*/
113-
additionalProperties = false;
114-
11595
/**
11696
* @param {import("../types/form").ObjectFormElementFields} fields
11797
*/
11898
constructor(fields) {
11999
super(fields);
100+
/**
101+
* @type {import("../types/jschema").JSONSchemaProperty | false}
102+
*/
120103
this.additionalProperties = fields.additionalProperties;
121104
this.children = fields.children;
122105
this.collapsed = !fields.required;
@@ -201,11 +184,6 @@ export class ObjectFormElement extends BaseFormElement {
201184
}
202185

203186
export class ArrayFormElement extends BaseFormElement {
204-
children;
205-
items;
206-
minItems;
207-
maxItems;
208-
209187
/**
210188
* @param {import("../types/form").ArrayFormElementFields} fields
211189
*/
@@ -283,10 +261,6 @@ export class ArrayFormElement extends BaseFormElement {
283261
}
284262

285263
export class TupleFormElement extends BaseFormElement {
286-
children;
287-
items;
288-
size;
289-
290264
/**
291265
* @param {import("../types/form").TupleFormElementFields} fields
292266
*/

jschema/src/lib/components/form_manager.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,6 @@ import { SchemaValidator } from './jschema_validation.js';
2525
* validate the form and retrieve an object based on the data present in the form.
2626
*/
2727
export class FormManager {
28-
/**
29-
* The root of the object representing the form.
30-
* @type {ObjectFormElement}
31-
*/
32-
root;
33-
34-
/**
35-
* List of unique identifiers generated for elements
36-
* @type {string[]}
37-
*/
38-
ids = [];
39-
40-
/** @type {'pydantic_v1'|'pydantic_v2'} */
41-
schemaVersion;
42-
4328
/**
4429
* @param {import("../types/jschema").JSONSchema} originalJsonSchema
4530
* @param {(type: string, detail?: any) => boolean} dispatch
@@ -48,6 +33,7 @@ export class FormManager {
4833
* @param {any} initialValue
4934
*/
5035
constructor(originalJsonSchema, dispatch, schemaVersion, propertiesToIgnore = [], initialValue = undefined) {
36+
/** @type {'pydantic_v1'|'pydantic_v2'} */
5137
this.schemaVersion = schemaVersion;
5238
this.jsonSchema = adaptJsonSchema(originalJsonSchema, propertiesToIgnore);
5339

@@ -57,13 +43,23 @@ export class FormManager {
5743
throw new Error('Invalid JSON Schema');
5844
}
5945

46+
/**
47+
* List of unique identifiers generated for elements
48+
* @type {string[]}
49+
*/
50+
this.ids = [];
51+
6052
const data = getJsonSchemaData(this.jsonSchema, schemaVersion, initialValue);
6153
this.dispatch = dispatch;
6254
this.notifyChange = () => {
6355
const data = this.getFormData();
6456
this.dispatch('change', { value: data });
6557
};
6658

59+
/**
60+
* The root of the object representing the form.
61+
* @type {ObjectFormElement}
62+
*/
6763
this.root = this.createObjectElement({
6864
key: null,
6965
property: this.jsonSchema,

jschema/src/lib/components/jschema_validation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function detectSchemaVersion(schema) {
6868
const schemaValidatorV2 = new SchemaValidator('pydantic_v2');
6969
schemaValidatorV2.validateSchema(schema);
7070
return 'pydantic_v2';
71-
} catch (_) {
71+
} catch {
7272
const schemaValidatorV1 = new SchemaValidator('pydantic_v1');
7373
schemaValidatorV1.validateSchema(schema);
7474
return 'pydantic_v1';

jschema/src/lib/components/properties/EnumProperty.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
function handleValueChange() {
1212
formElement.notifyChange();
1313
validationError = '';
14-
if (formElement.required && field.value === 'null') {
14+
if (formElement.required && field.value === '') {
1515
validationError = 'Field is required';
1616
}
1717
}
@@ -31,7 +31,7 @@
3131
id="property-{formElement.id}"
3232
class:is-invalid={validationError}
3333
>
34-
<option value={null}>Select...</option>
34+
<option value="">Select...</option>
3535
{#each formElement.options as optionValue}
3636
<option>{optionValue}</option>
3737
{/each}

jschema/src/lib/components/properties/TupleProperty.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
{/if}
4040
</div>
4141
<div>
42-
{#each children as nestedProperty, index (nestedProperty.id)}
42+
{#each children as nestedProperty}
4343
<div class="d-flex">
4444
<div class="flex-fill">
4545
<PropertyDiscriminator formElement={nestedProperty} />

sandbox/src/lib/components/DragAndDropUploader.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
on:dragover={handleDragOver}
9595
on:dragleave={handleDragLeave}
9696
class:dragOver
97+
role="region"
9798
>
9899
<div class="m-1">
99100
<div class="input-group has-validation">

0 commit comments

Comments
 (0)