@dilicorp/ui 0.0.78 → 0.0.79
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.
|
@@ -13,7 +13,7 @@ declare type FilterSelectProps = {
|
|
|
13
13
|
placeholder: string;
|
|
14
14
|
groupedOptions?: GroupedOptions[];
|
|
15
15
|
id?: string;
|
|
16
|
-
value?: string |
|
|
16
|
+
value?: string | Options | Options[];
|
|
17
17
|
isDisabled?: boolean;
|
|
18
18
|
isLoading?: boolean;
|
|
19
19
|
isClearable?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter-select-group.d.ts","sourceRoot":"","sources":["../../../../src/components/page-list/filters/filter-select-group.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAoB,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAErE,UAAU,OAAO;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,EAAE,CAAA;CACnB;
|
|
1
|
+
{"version":3,"file":"filter-select-group.d.ts","sourceRoot":"","sources":["../../../../src/components/page-list/filters/filter-select-group.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAoB,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAErE,UAAU,OAAO;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,EAAE,CAAA;CACnB;AAID,aAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,cAAc,EAAE,CAAA;IACjC,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,EAAE,CAAA;IACpC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,CAAA;CACpF,CAAA;AA+BD,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAkDzD,CAAA"}
|
|
@@ -1,7 +1,34 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import ReactSelect from 'react-select';
|
|
3
|
+
const getValueInOption = (groups, value) => {
|
|
4
|
+
const initial = [];
|
|
5
|
+
const options = groups.reduce((total, curr) => (total.concat(curr.options)), initial);
|
|
6
|
+
return options.find(({ value: currValue }) => typeof currValue === 'number'
|
|
7
|
+
? currValue === Number(value)
|
|
8
|
+
: currValue === value);
|
|
9
|
+
};
|
|
10
|
+
const getValue = (value, options) => {
|
|
11
|
+
if (!value)
|
|
12
|
+
return undefined;
|
|
13
|
+
const isArray = typeof value === 'object' && Array.isArray(value);
|
|
14
|
+
const isObject = !isArray && typeof value === 'object';
|
|
15
|
+
if (!isObject && !isObject) {
|
|
16
|
+
return getValueInOption(options, (value).toString());
|
|
17
|
+
}
|
|
18
|
+
if (isArray) {
|
|
19
|
+
const selected = [];
|
|
20
|
+
value.forEach(val => {
|
|
21
|
+
const data = getValueInOption(options, (val.value).toString());
|
|
22
|
+
if (data)
|
|
23
|
+
selected.push(data);
|
|
24
|
+
});
|
|
25
|
+
return selected;
|
|
26
|
+
}
|
|
27
|
+
return getValueInOption(options, (value.value).toString());
|
|
28
|
+
};
|
|
3
29
|
export const FilterSelectGroup = (props) => {
|
|
4
|
-
const { groupedOptions = [], name, id = name, placeholder, isDisabled = false, isLoading = false, isClearable = false, isSearchable = true, onChange } = props;
|
|
30
|
+
const { groupedOptions = [], name, id = name, placeholder, isDisabled = false, isLoading = false, isClearable = false, isSearchable = true, value = undefined, onChange } = props;
|
|
31
|
+
const newValue = getValue(value, groupedOptions);
|
|
5
32
|
const handleChange = React.useCallback((event, action) => {
|
|
6
33
|
if (onChange) {
|
|
7
34
|
onChange({
|
|
@@ -20,5 +47,5 @@ export const FilterSelectGroup = (props) => {
|
|
|
20
47
|
Boolean(placeholder) && React.createElement("label", { className: "form-label", htmlFor: name },
|
|
21
48
|
placeholder,
|
|
22
49
|
":"),
|
|
23
|
-
React.createElement(ReactSelect, { placeholder: placeholder, className: "form-builder-select", classNamePrefix: "form-builder", options: groupedOptions, name: name, id: id, isDisabled: isDisabled, isLoading: isLoading, isClearable: isClearable, isSearchable: isSearchable, onChange: handleChange })));
|
|
50
|
+
React.createElement(ReactSelect, { placeholder: placeholder, className: "form-builder-select", classNamePrefix: "form-builder", options: groupedOptions, name: name, id: id, defaultValue: newValue, isDisabled: isDisabled, isLoading: isLoading, isClearable: isClearable, isSearchable: isSearchable, onChange: handleChange })));
|
|
24
51
|
};
|