Skip to content

Commit 1e2c864

Browse files
committed
Fixed version sorting; moved version functions to separate file
1 parent e5ce681 commit 1e2c864

File tree

13 files changed

+76
-73
lines changed

13 files changed

+76
-73
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
*Note: Numbers like (\#123) point to closed Pull Requests on the fractal-web repository.*
22

3+
# Unreleased
4+
5+
* Fixed task version sorting issue (\#733);
6+
37
# 1.16.1
48

59
* Improved handling of new default values in task version update (\#731);

__tests__/v2/AddWorkflowTaskModal.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ describe('AddWorkflowTaskModal', () => {
175175

176176
const dropdown = await screen.findByRole('combobox');
177177
expect(dropdown.options.length).eq(2);
178-
expect(dropdown.options[0].text).eq('0.0.1');
179-
expect(dropdown.options[1].text).eq('INVALID');
180-
expect(dropdown.value).eq('0.0.1');
178+
expect(dropdown.options[0].text).eq('INVALID');
179+
expect(dropdown.options[1].text).eq('0.0.1');
180+
expect(dropdown.value).eq('INVALID');
181181
});
182182
});

components/__tests__/utils.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect } from 'vitest';
2-
import { stripNullAndEmptyObjectsAndArrays } from '../src/lib/utils';
2+
import { stripNullAndEmptyObjectsAndArrays } from '../src/lib/common/utils';
33

44
describe('utils', () => {
55
it('should strip data objects correctly', () => {

__tests__/semver.test.js renamed to components/__tests__/version.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { it, expect } from 'vitest';
22
import valid from 'semver/functions/valid';
3-
import { greatestVersionAsc } from '../src/lib/common/component_utilities';
3+
import { greatestVersionAsc } from '../src/lib/common/version';
44

55
it('should be able to loosely validate versions', () => {
66
const cases = [

components/src/lib/utils.js renamed to components/src/lib/common/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { JsonSchemaDataError } from './jschema/form_manager';
1+
import { JsonSchemaDataError } from '../jschema/form_manager';
22

33
/**
44
* @param {any} value
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import coerce from 'semver/functions/coerce';
2+
import gte from 'semver/functions/gte';
3+
import lte from 'semver/functions/lte';
4+
import valid from 'semver/functions/valid';
5+
6+
/**
7+
* @param {string | null} version1
8+
* @param {string | null} version2
9+
* @returns {-1|0|1}
10+
*/
11+
export function greatestVersionAsc(version1, version2) {
12+
const t1Version = validateVersion(version1);
13+
const t2Version = validateVersion(version2);
14+
if (t1Version !== null && t2Version !== null) {
15+
const t1VersionLt = lte(t1Version, t2Version);
16+
return t1VersionLt ? -1 : 1;
17+
}
18+
return 0;
19+
}
20+
21+
/**
22+
* @param {string | null} version1
23+
* @param {string | null} version2
24+
* @returns {-1|0|1}
25+
*/
26+
export function greatestVersionDesc(version1, version2) {
27+
const t1Version = validateVersion(version1);
28+
const t2Version = validateVersion(version2);
29+
if (t1Version !== null && t2Version !== null) {
30+
const t1VersionGt = gte(t1Version, t2Version);
31+
return t1VersionGt ? -1 : 1;
32+
}
33+
return 0;
34+
}
35+
36+
const semverValidationOptions = {
37+
loose: true,
38+
includePrerelease: true
39+
};
40+
41+
/**
42+
* @param {string|null} version
43+
* @returns {string | null}
44+
*/
45+
function validateVersion(version) {
46+
return (
47+
valid(version, semverValidationOptions) ||
48+
valid(coerce(version), semverValidationOptions) ||
49+
null
50+
);
51+
}

components/src/lib/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import JSchema from './jschema/JSchema.svelte';
22
import PropertyDescription from './jschema/properties/PropertyDescription.svelte';
33
import { SchemaValidator, detectSchemaVersion } from './jschema/jschema_validation';
4-
import { deepCopy, getValidationErrorMessage, stripNullAndEmptyObjectsAndArrays } from './utils';
4+
import {
5+
deepCopy,
6+
getValidationErrorMessage,
7+
stripNullAndEmptyObjectsAndArrays
8+
} from './common/utils';
9+
import { greatestVersionDesc, greatestVersionAsc } from './common/version';
510
import { getPropertiesToIgnore } from './jschema/property_utils';
611
import { JsonSchemaDataError } from './jschema/form_manager';
712
import { stripIgnoredProperties } from './jschema/jschema_adapter';
@@ -19,5 +24,7 @@ export {
1924
getValidationErrorMessage,
2025
PropertyDescription,
2126
detectSchemaVersion,
22-
FilteredTasksTable
27+
FilteredTasksTable,
28+
greatestVersionDesc,
29+
greatestVersionAsc
2330
};

components/src/lib/jschema/form_manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { deepCopy, stripNullAndEmptyObjectsAndArrays, undefinedToNull } from '../utils';
1+
import { deepCopy, stripNullAndEmptyObjectsAndArrays, undefinedToNull } from '../common/utils';
22
import {
33
ArrayFormElement,
44
EnumFormElement,

components/src/lib/jschema/jschema_adapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { deepCopy, isObject } from '../utils.js';
1+
import { deepCopy, isObject } from '../common/utils.js';
22

33
/**
44
* Creates a simpler but still equivalent JSON Schema. Removes properties to ignore,

components/src/lib/jschema/jschema_initial_data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { undefinedToNull } from '../utils.js';
1+
import { undefinedToNull } from '../common/utils.js';
22
import { getAllObjectProperties, isTuple } from './property_utils.js';
33

44
/**

0 commit comments

Comments
 (0)