@performant-software/semantic-components 0.5.16-beta.9 → 0.5.17-beta.1
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/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/LazyDocument.js +1 -1
- package/src/components/ReferenceCodeDropdown.js +34 -14
- package/types/components/LazyDocument.js.flow +1 -1
- package/types/components/ReferenceCodeDropdown.js.flow +34 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@performant-software/semantic-components",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.17-beta.1",
|
|
4
4
|
"description": "A package of shared components based on the Semantic UI Framework.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./build/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"build": "webpack --mode production && flow-copy-source -v src types"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@performant-software/shared-components": "^0.5.
|
|
15
|
+
"@performant-software/shared-components": "^0.5.17-beta.1",
|
|
16
16
|
"@react-google-maps/api": "^2.8.1",
|
|
17
17
|
"axios": "^0.26.1",
|
|
18
18
|
"i18next": "^19.4.4",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"react-dom": ">= 16.13.1 < 18.0.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@performant-software/webpack-config": "^0.5.
|
|
36
|
+
"@performant-software/webpack-config": "^0.5.17-beta.1",
|
|
37
37
|
"flow-copy-source": "^2.0.9",
|
|
38
38
|
"less": "^4.1.2",
|
|
39
39
|
"less-loader": "^11.0.0",
|
|
@@ -7,8 +7,8 @@ import React, {
|
|
|
7
7
|
useMemo,
|
|
8
8
|
useState
|
|
9
9
|
} from 'react';
|
|
10
|
-
import _ from 'underscore';
|
|
11
10
|
import { Dropdown } from 'semantic-ui-react';
|
|
11
|
+
import _ from 'underscore';
|
|
12
12
|
|
|
13
13
|
type Item = {
|
|
14
14
|
reference_table_id: number,
|
|
@@ -28,6 +28,14 @@ const ReferenceCodeDropdown = (props: Props) => {
|
|
|
28
28
|
const [loading, setLoading] = useState(false);
|
|
29
29
|
const [options, setOptions] = useState([]);
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Sets the "value" variable for the Dropdown component.
|
|
33
|
+
*/
|
|
34
|
+
const value = useMemo(() => {
|
|
35
|
+
const v = _.pluck(_.filter(props.value, (x) => !x._destroy), 'reference_code_id');
|
|
36
|
+
return props.multiple ? v : _.first(v);
|
|
37
|
+
}, [props.multiple, props.value]);
|
|
38
|
+
|
|
31
39
|
/**
|
|
32
40
|
* Converts the passed ID to a reference code item.
|
|
33
41
|
*
|
|
@@ -53,25 +61,37 @@ const ReferenceCodeDropdown = (props: Props) => {
|
|
|
53
61
|
*
|
|
54
62
|
* @type {(function(*, {value: *}): void)|*}
|
|
55
63
|
*/
|
|
56
|
-
const onChange = useCallback((e,
|
|
57
|
-
let
|
|
64
|
+
const onChange = useCallback((e, data) => {
|
|
65
|
+
let referenceCodeIds;
|
|
58
66
|
|
|
59
67
|
if (props.multiple) {
|
|
60
|
-
|
|
68
|
+
referenceCodeIds = data.value;
|
|
61
69
|
} else {
|
|
62
|
-
|
|
70
|
+
referenceCodeIds = _.compact([data.value]);
|
|
63
71
|
}
|
|
64
72
|
|
|
65
|
-
|
|
66
|
-
}, [toItem, props.multiple, props.onChange]);
|
|
73
|
+
const items = [];
|
|
67
74
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
// Find existing records or create new records
|
|
76
|
+
_.each(referenceCodeIds, (referenceCodeId) => {
|
|
77
|
+
let newValue = _.findWhere(props.value, { reference_code_id: referenceCodeId });
|
|
78
|
+
|
|
79
|
+
if (!newValue) {
|
|
80
|
+
newValue = toItem(referenceCodeId);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
items.push(_.omit(newValue, '_destroy'));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Mark records for delete
|
|
87
|
+
_.each(props.value, (v) => {
|
|
88
|
+
if (v.id && !_.contains(referenceCodeIds, v.reference_code_id)) {
|
|
89
|
+
items.push({ ...v, _destroy: true });
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
props.onChange(items);
|
|
94
|
+
}, [toItem, props.multiple, props.onChange, props.value]);
|
|
75
95
|
|
|
76
96
|
/**
|
|
77
97
|
* Loads the list of reference codes from the server.
|
|
@@ -7,8 +7,8 @@ import React, {
|
|
|
7
7
|
useMemo,
|
|
8
8
|
useState
|
|
9
9
|
} from 'react';
|
|
10
|
-
import _ from 'underscore';
|
|
11
10
|
import { Dropdown } from 'semantic-ui-react';
|
|
11
|
+
import _ from 'underscore';
|
|
12
12
|
|
|
13
13
|
type Item = {
|
|
14
14
|
reference_table_id: number,
|
|
@@ -28,6 +28,14 @@ const ReferenceCodeDropdown = (props: Props) => {
|
|
|
28
28
|
const [loading, setLoading] = useState(false);
|
|
29
29
|
const [options, setOptions] = useState([]);
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Sets the "value" variable for the Dropdown component.
|
|
33
|
+
*/
|
|
34
|
+
const value = useMemo(() => {
|
|
35
|
+
const v = _.pluck(_.filter(props.value, (x) => !x._destroy), 'reference_code_id');
|
|
36
|
+
return props.multiple ? v : _.first(v);
|
|
37
|
+
}, [props.multiple, props.value]);
|
|
38
|
+
|
|
31
39
|
/**
|
|
32
40
|
* Converts the passed ID to a reference code item.
|
|
33
41
|
*
|
|
@@ -53,25 +61,37 @@ const ReferenceCodeDropdown = (props: Props) => {
|
|
|
53
61
|
*
|
|
54
62
|
* @type {(function(*, {value: *}): void)|*}
|
|
55
63
|
*/
|
|
56
|
-
const onChange = useCallback((e,
|
|
57
|
-
let
|
|
64
|
+
const onChange = useCallback((e, data) => {
|
|
65
|
+
let referenceCodeIds;
|
|
58
66
|
|
|
59
67
|
if (props.multiple) {
|
|
60
|
-
|
|
68
|
+
referenceCodeIds = data.value;
|
|
61
69
|
} else {
|
|
62
|
-
|
|
70
|
+
referenceCodeIds = _.compact([data.value]);
|
|
63
71
|
}
|
|
64
72
|
|
|
65
|
-
|
|
66
|
-
}, [toItem, props.multiple, props.onChange]);
|
|
73
|
+
const items = [];
|
|
67
74
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
// Find existing records or create new records
|
|
76
|
+
_.each(referenceCodeIds, (referenceCodeId) => {
|
|
77
|
+
let newValue = _.findWhere(props.value, { reference_code_id: referenceCodeId });
|
|
78
|
+
|
|
79
|
+
if (!newValue) {
|
|
80
|
+
newValue = toItem(referenceCodeId);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
items.push(_.omit(newValue, '_destroy'));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Mark records for delete
|
|
87
|
+
_.each(props.value, (v) => {
|
|
88
|
+
if (v.id && !_.contains(referenceCodeIds, v.reference_code_id)) {
|
|
89
|
+
items.push({ ...v, _destroy: true });
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
props.onChange(items);
|
|
94
|
+
}, [toItem, props.multiple, props.onChange, props.value]);
|
|
75
95
|
|
|
76
96
|
/**
|
|
77
97
|
* Loads the list of reference codes from the server.
|