@luomus/laji-form 15.1.16 → 15.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/laji-form.js +1 -1
- package/lib/components/fields/CombinedValueDisplayField.d.ts +4 -0
- package/lib/components/fields/CombinedValueDisplayField.js +23 -9
- package/lib/components/fields/ScopeField.js +1 -1
- package/package.json +8 -1
- package/protractor.conf.js +0 -59
- package/test.Dockerfile +0 -11
|
@@ -5,6 +5,7 @@ export default class CombinedValueDisplayField extends React.Component<any, any,
|
|
|
5
5
|
combined: PropTypes.Requireable<PropTypes.InferProps<{
|
|
6
6
|
firstField: PropTypes.Validator<string>;
|
|
7
7
|
secondField: PropTypes.Validator<string>;
|
|
8
|
+
additionalFields: PropTypes.Requireable<(string | null | undefined)[]>;
|
|
8
9
|
name: PropTypes.Requireable<string>;
|
|
9
10
|
title: PropTypes.Requireable<string>;
|
|
10
11
|
combineType: PropTypes.Requireable<string>;
|
|
@@ -12,6 +13,7 @@ export default class CombinedValueDisplayField extends React.Component<any, any,
|
|
|
12
13
|
}> | (PropTypes.InferProps<{
|
|
13
14
|
firstField: PropTypes.Validator<string>;
|
|
14
15
|
secondField: PropTypes.Validator<string>;
|
|
16
|
+
additionalFields: PropTypes.Requireable<(string | null | undefined)[]>;
|
|
15
17
|
name: PropTypes.Requireable<string>;
|
|
16
18
|
title: PropTypes.Requireable<string>;
|
|
17
19
|
combineType: PropTypes.Requireable<string>;
|
|
@@ -34,7 +36,9 @@ export default class CombinedValueDisplayField extends React.Component<any, any,
|
|
|
34
36
|
formData: any;
|
|
35
37
|
onChange: (formData: any) => void;
|
|
36
38
|
};
|
|
39
|
+
getFieldValue: (formData: any, field: any) => any;
|
|
37
40
|
toMinutes: (time: any) => number;
|
|
41
|
+
getCount: (value: any) => number;
|
|
38
42
|
onChange: (formData: any) => void;
|
|
39
43
|
}
|
|
40
44
|
import * as React from "react";
|
|
@@ -11,14 +11,16 @@ const PropTypes = require("prop-types");
|
|
|
11
11
|
const utils_1 = require("../../utils");
|
|
12
12
|
const VirtualSchemaField_1 = require("../VirtualSchemaField");
|
|
13
13
|
/**
|
|
14
|
-
* Combines values of two fields into one value which can be used for displaying (editing that value doesn't change formData)
|
|
14
|
+
* Combines values of two (or more) fields into one value which can be used for displaying (editing that value doesn't change formData)
|
|
15
15
|
* Combine types:
|
|
16
16
|
* timeDifference: combines the values by calculating their time difference
|
|
17
|
+
* totalCount: combines the values by summing their counts together. if the value is an array the count is its length and if it is a number the count is the value
|
|
17
18
|
* stringJoin (default): combines the values by joining them. delimiter is added between if given
|
|
18
19
|
*/
|
|
19
20
|
const combinedPropType = PropTypes.shape({
|
|
20
21
|
firstField: PropTypes.string.isRequired,
|
|
21
22
|
secondField: PropTypes.string.isRequired,
|
|
23
|
+
additionalFields: PropTypes.arrayOf(PropTypes.string),
|
|
22
24
|
name: PropTypes.string,
|
|
23
25
|
title: PropTypes.string,
|
|
24
26
|
combineType: PropTypes.string,
|
|
@@ -27,10 +29,16 @@ const combinedPropType = PropTypes.shape({
|
|
|
27
29
|
let CombinedValueDisplayField = class CombinedValueDisplayField extends React.Component {
|
|
28
30
|
constructor() {
|
|
29
31
|
super(...arguments);
|
|
32
|
+
this.getFieldValue = (formData, field) => {
|
|
33
|
+
return field[0] === "/" ? utils_1.parseJSONPointer(formData, field, !!"safely") : formData[field];
|
|
34
|
+
};
|
|
30
35
|
this.toMinutes = (time) => {
|
|
31
36
|
const parts = time.split(":");
|
|
32
37
|
return Number(parts[0]) * 60 + Number(parts[1]);
|
|
33
38
|
};
|
|
39
|
+
this.getCount = (value) => {
|
|
40
|
+
return Array.isArray(value) ? value.length : (typeof value === "number" ? value : 0);
|
|
41
|
+
};
|
|
34
42
|
this.onChange = (formData) => {
|
|
35
43
|
const uiOptions = this.getUiOptions();
|
|
36
44
|
const combined = Array.isArray(uiOptions.combined) ? uiOptions.combined : [uiOptions.combined];
|
|
@@ -49,12 +57,14 @@ let CombinedValueDisplayField = class CombinedValueDisplayField extends React.Co
|
|
|
49
57
|
let { schema, idSchema, formData } = props;
|
|
50
58
|
const combined = Array.isArray(uiOptions.combined) ? uiOptions.combined : [uiOptions.combined];
|
|
51
59
|
combined.forEach(options => {
|
|
52
|
-
const { name, title, combineType, firstField, secondField } = options;
|
|
60
|
+
const { name, title, combineType, firstField, secondField, additionalFields = [] } = options;
|
|
53
61
|
schema = Object.assign(Object.assign({}, schema), { properties: Object.assign(Object.assign({}, schema.properties), { [name || ""]: { title: title || "", type: "string" } }) });
|
|
54
62
|
idSchema = this.props.registry.schemaUtils.toIdSchema(schema, idSchema.$id);
|
|
55
63
|
let value = undefined;
|
|
56
|
-
const firstValue =
|
|
57
|
-
const secondValue =
|
|
64
|
+
const firstValue = this.getFieldValue(formData, firstField);
|
|
65
|
+
const secondValue = this.getFieldValue(formData, secondField);
|
|
66
|
+
const additionalValues = additionalFields.map(field => this.getFieldValue(formData, field));
|
|
67
|
+
const allValues = [firstValue, secondValue].concat(additionalValues);
|
|
58
68
|
if (combineType === "timeDifference") {
|
|
59
69
|
if (firstValue && secondValue) {
|
|
60
70
|
const difference = this.toMinutes(secondValue) - this.toMinutes(formData[firstField]);
|
|
@@ -65,13 +75,17 @@ let CombinedValueDisplayField = class CombinedValueDisplayField extends React.Co
|
|
|
65
75
|
}
|
|
66
76
|
}
|
|
67
77
|
}
|
|
78
|
+
else if (combineType === "totalCount") {
|
|
79
|
+
value = allValues.reduce((result, current) => result + this.getCount(current), 0);
|
|
80
|
+
}
|
|
68
81
|
else {
|
|
69
82
|
const delimiter = options.delimiter || "";
|
|
70
|
-
value =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
value = allValues.reduce((result, current) => {
|
|
84
|
+
if (current) {
|
|
85
|
+
result.push(current);
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}, []);
|
|
75
89
|
value = value.join(delimiter);
|
|
76
90
|
}
|
|
77
91
|
formData = Object.assign(Object.assign({}, formData), { [name]: value });
|
|
@@ -303,7 +303,7 @@ class ScopeField extends React.Component {
|
|
|
303
303
|
}, this.state.additionalFields);
|
|
304
304
|
if (this._globals) {
|
|
305
305
|
const additionalsPersistenceVal = this.getAdditionalPersistenceValue(this.props, !"don't include undefined");
|
|
306
|
-
let globalsEntry = this._globals
|
|
306
|
+
let globalsEntry = this._globals ? Object.assign({}, this._globals) : {};
|
|
307
307
|
if (additionalsPersistenceField) {
|
|
308
308
|
let additionalsKeys = this.props.schema.properties[additionalsPersistenceField].type === "array"
|
|
309
309
|
? additionalsPersistenceVal
|
package/package.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luomus/laji-form",
|
|
3
|
-
"version": "15.1.
|
|
3
|
+
"version": "15.1.18",
|
|
4
4
|
"description": "React module capable of building dynamic forms from Laji form json schemas",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"dist",
|
|
10
|
+
"test-export",
|
|
11
|
+
"README.md",
|
|
12
|
+
"CHANGELOG.md"
|
|
13
|
+
],
|
|
7
14
|
"scripts": {
|
|
8
15
|
"start": "npx webpack serve",
|
|
9
16
|
"staging": "webpack-dev-server --content-base playground playground/app.js --host 0.0.0.0 --port 4010",
|
package/protractor.conf.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// Firefox isn't run default since it has a bug with mousemove (See https://github.com/angular/protractor/issues/4715 )
|
|
2
|
-
|
|
3
|
-
const [width, height] = [800, 1000];
|
|
4
|
-
const common = {
|
|
5
|
-
shardTestFiles: parseInt(process.env.THREADS) !== 1,
|
|
6
|
-
maxInstances: process.env.THREADS ? parseInt(process.env.THREADS) : 4
|
|
7
|
-
};
|
|
8
|
-
const chrome = {
|
|
9
|
-
...common,
|
|
10
|
-
browserName: "chrome",
|
|
11
|
-
chromeOptions: {
|
|
12
|
-
args: ["--headless", "--disable-gpu", `window-size=${width}x${height}`, "--no-sandbox", "--disable-dev-shm-usage"]
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const firefox = {
|
|
17
|
-
...common,
|
|
18
|
-
browserName: "firefox",
|
|
19
|
-
"firefoxOptions": {
|
|
20
|
-
args: ["--headless", `--width=${width}', '--height=${height}`]
|
|
21
|
-
},
|
|
22
|
-
"moz:firefoxOptions": {
|
|
23
|
-
args: ["--headless", `--width=${width}', '--height=${height}`]
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
let multiCapabilities = [chrome];
|
|
28
|
-
if (process.env.TEST_BROWSER === "firefox") {
|
|
29
|
-
multiCapabilities = [firefox];
|
|
30
|
-
} else if (process.env.TEST_BROWSER === "multi") {
|
|
31
|
-
multiCapabilities = [chrome, firefox];
|
|
32
|
-
}
|
|
33
|
-
if (process.env.HEADLESS && process.env.HEADLESS !== "true") multiCapabilities.forEach(capabilities => {
|
|
34
|
-
const options = [capabilities["chromeOptions"], capabilities["firefoxOptions"], capabilities["moz:firefoxOptions"]];
|
|
35
|
-
options.filter(o => o).forEach(_options => {
|
|
36
|
-
_options.args = _options.args.filter(a => a !== "--headless");
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
exports.config = {
|
|
41
|
-
specs: ["test/*-spec.ts"],
|
|
42
|
-
multiCapabilities,
|
|
43
|
-
maxSessions: 4,
|
|
44
|
-
SELENIUM_PROMISE_MANAGER: false,
|
|
45
|
-
onPrepare: async () => {
|
|
46
|
-
require("ts-node").register({
|
|
47
|
-
project: require("path").join(__dirname, "./tsconfig.json")
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
browser.waitForAngularEnabled(false);
|
|
51
|
-
|
|
52
|
-
// Set manually since Firefox cli size options don't work.
|
|
53
|
-
await browser.driver.manage().window().setSize(width, height);
|
|
54
|
-
},
|
|
55
|
-
plugins: multiCapabilities.length === 1 && multiCapabilities[0] === chrome && [{
|
|
56
|
-
package: "protractor-console-plugin",
|
|
57
|
-
exclude: [/Uncaught \(in promise\)/]
|
|
58
|
-
}]
|
|
59
|
-
};
|