@tap-payments/os-micro-frontend-shared 0.0.34 → 0.0.35
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.
|
@@ -4,79 +4,30 @@ import Box from '@mui/material/Box';
|
|
|
4
4
|
import Collapse from '@mui/material/Collapse';
|
|
5
5
|
import lodashValues from 'lodash/values';
|
|
6
6
|
import { useTranslation } from 'react-i18next';
|
|
7
|
-
import { PhoneInputBase } from '../../../../InputBase';
|
|
8
7
|
import { grayCloseIcon, searchIcon } from '../../../../../constants/index.js';
|
|
9
8
|
import { Wrapper, Text, InputStyled, InputsWrapper, ClearButton, ClearWrapper } from './style';
|
|
10
9
|
import { CancelButton, Footer, OkayButton } from '../style';
|
|
11
10
|
function Inputs({ onCloseDropdown, filter: { options = [], onConfirm, data, isOnlyOneFilter } }) {
|
|
12
11
|
const [values, setValues] = useState({});
|
|
13
12
|
useEffect(() => {
|
|
14
|
-
setValues((options || []).reduce((acc, { apiKey,
|
|
15
|
-
var _a;
|
|
16
|
-
const optionData = data === null || data === void 0 ? void 0 : data[apiKey];
|
|
17
|
-
if (type === 'phone') {
|
|
18
|
-
const phoneData = optionData;
|
|
19
|
-
return Object.assign(Object.assign({}, acc), { [apiKey]: (_a = phoneData === null || phoneData === void 0 ? void 0 : phoneData.phone) !== null && _a !== void 0 ? _a : '', [`${apiKey}_country`]: phoneData === null || phoneData === void 0 ? void 0 : phoneData.country });
|
|
20
|
-
}
|
|
21
|
-
return Object.assign(Object.assign({}, acc), { [apiKey]: optionData !== null && optionData !== void 0 ? optionData : '' });
|
|
22
|
-
}, {}));
|
|
13
|
+
setValues((options || []).reduce((acc, { apiKey }) => { var _a; return (Object.assign(Object.assign({}, acc), { [apiKey]: (_a = data === null || data === void 0 ? void 0 : data[apiKey]) !== null && _a !== void 0 ? _a : '' })); }, {}));
|
|
23
14
|
}, []);
|
|
24
15
|
const { t } = useTranslation();
|
|
25
16
|
const onClickOkay = () => {
|
|
26
|
-
|
|
27
|
-
if (type === 'phone') {
|
|
28
|
-
const phoneValue = values[apiKey];
|
|
29
|
-
const countryValue = values[`${apiKey}_country`];
|
|
30
|
-
if (phoneValue || countryValue) {
|
|
31
|
-
acc[apiKey] = {
|
|
32
|
-
phone: phoneValue || '',
|
|
33
|
-
country: countryValue,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
const value = values[apiKey];
|
|
39
|
-
if (value !== undefined && value !== '') {
|
|
40
|
-
acc[apiKey] = value;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return acc;
|
|
44
|
-
}, {});
|
|
45
|
-
onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(transformedValues);
|
|
17
|
+
onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(values);
|
|
46
18
|
onCloseDropdown();
|
|
47
19
|
};
|
|
48
20
|
const onClickCancel = () => {
|
|
49
21
|
onCloseDropdown();
|
|
50
22
|
};
|
|
51
23
|
const onClickClear = () => {
|
|
52
|
-
setValues(options.reduce((acc, { apiKey
|
|
53
|
-
if (type === 'phone') {
|
|
54
|
-
return Object.assign(Object.assign({}, acc), { [apiKey]: '', [`${apiKey}_country`]: undefined });
|
|
55
|
-
}
|
|
56
|
-
return Object.assign(Object.assign({}, acc), { [apiKey]: '' });
|
|
57
|
-
}, {}));
|
|
24
|
+
setValues(options.reduce((acc, { apiKey }) => (Object.assign(Object.assign({}, acc), { [apiKey]: '' })), {}));
|
|
58
25
|
};
|
|
59
|
-
const isInputHasValue = (key
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
};
|
|
65
|
-
const getInputValue = (key, type) => {
|
|
66
|
-
if (type === 'phone') {
|
|
67
|
-
return values[key] !== undefined && typeof values[key] === 'string' && values[key].length ? values[key] : '';
|
|
68
|
-
}
|
|
69
|
-
return values[key] !== undefined && typeof values[key] === 'string' && values[key].length ? values[key] : '';
|
|
70
|
-
};
|
|
71
|
-
const onClickResetInput = (key, type) => {
|
|
72
|
-
if (isInputHasValue(key, type)) {
|
|
73
|
-
if (type === 'phone') {
|
|
74
|
-
setValues(Object.assign(Object.assign({}, values), { [key]: '', [`${key}_country`]: undefined }));
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
setValues(Object.assign(Object.assign({}, values), { [key]: '' }));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
26
|
+
const isInputHasValue = (key) => values[key] !== undefined && values[key].length > 0;
|
|
27
|
+
const getInputValue = (key) => (values[key] !== undefined && values[key].length ? values[key] : '');
|
|
28
|
+
const onClickResetInput = (key) => {
|
|
29
|
+
if (isInputHasValue(key))
|
|
30
|
+
setValues(Object.assign(Object.assign({}, values), { [key]: '' }));
|
|
80
31
|
};
|
|
81
32
|
const showClearButton = useMemo(() => lodashValues(values).some((x) => Boolean(x)), [values]);
|
|
82
33
|
const getFilterByApiKey = useCallback((apiKey) => {
|
|
@@ -87,29 +38,14 @@ function Inputs({ onCloseDropdown, filter: { options = [], onConfirm, data, isOn
|
|
|
87
38
|
const isAnyInputWithValue = Object.entries(values).some(([inputKey, val]) => { var _a; return Boolean(val) && (((_a = getFilterByApiKey(inputKey)) === null || _a === void 0 ? void 0 : _a.filterGroup) !== filterGroup || !filterGroup); });
|
|
88
39
|
return isOnlyOneFilter && !inputWithValue && isAnyInputWithValue;
|
|
89
40
|
}, [options, values, isOnlyOneFilter]);
|
|
90
|
-
return (_jsxs(Wrapper, Object.assign({ component: "article", "data-testid": "ColumnFilterInputs" }, { children: [_jsx(Text, Object.assign({ component: "header", "data-testid": "ColumnFilterInputs_title" }, { children: t('filterBy') })), _jsx(InputsWrapper, Object.assign({ "data-testid": "ColumnFilterInputs_inputs", component: "main" }, { children: options.map(({ placeholder, apiKey, isDisabled, filterGroup,
|
|
91
|
-
if (
|
|
92
|
-
return
|
|
93
|
-
key: apiKey,
|
|
94
|
-
value: values[apiKey],
|
|
95
|
-
setValue: (value) => {
|
|
96
|
-
setValues(Object.assign(Object.assign({}, values), { [apiKey]: value }));
|
|
97
|
-
},
|
|
98
|
-
isDisabled: isInputDisabled(apiKey, filterGroup),
|
|
99
|
-
getInputValue: (keyToGet) => getInputValue(keyToGet, type),
|
|
100
|
-
isInputHasValue: () => isInputHasValue(apiKey, type),
|
|
101
|
-
onClickReset: () => {
|
|
102
|
-
onClickResetInput(apiKey, type);
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
if (type === 'phone') {
|
|
107
|
-
return (_jsx(PhoneInputBase, { "data-testid": `ColumnFilterInputs_PhoneInput_${apiKey}`, phoneValue: getInputValue(apiKey, 'phone'), onPhoneChange: (val) => setValues(Object.assign(Object.assign({}, values), { [apiKey]: val, [`${apiKey}_country`]: values[`${apiKey}_country`] })), countryValue: values[`${apiKey}_country`], onCountryChange: (country) => setValues(Object.assign(Object.assign({}, values), { [`${apiKey}_country`]: country, [apiKey]: values[apiKey] })), countries: countries || [], isCountriesLoading: isCountriesLoading || false, hasError: false, disabled: isDisabled || isInputDisabled(apiKey, filterGroup), placeholder: placeholder }, apiKey));
|
|
41
|
+
return (_jsxs(Wrapper, Object.assign({ component: "article", "data-testid": "ColumnFilterInputs" }, { children: [_jsx(Text, Object.assign({ component: "header", "data-testid": "ColumnFilterInputs_title" }, { children: t('filterBy') })), _jsx(InputsWrapper, Object.assign({ "data-testid": "ColumnFilterInputs_inputs", component: "main" }, { children: options.map(({ placeholder, apiKey, isDisabled, filterGroup, render }) => {
|
|
42
|
+
if (render) {
|
|
43
|
+
return render();
|
|
108
44
|
}
|
|
109
45
|
return (_jsx(InputStyled, { className: "input", "data-testid": "ColumnFilterInputs_InputStyled", name: apiKey, placeholder: placeholder, onChange: (e) => {
|
|
110
46
|
setValues(Object.assign(Object.assign({}, values), { [apiKey]: e.target.value }));
|
|
111
|
-
}, disabled: isDisabled || isInputDisabled(apiKey, filterGroup), value: getInputValue(apiKey
|
|
112
|
-
onClickResetInput(apiKey
|
|
47
|
+
}, disabled: isDisabled || isInputDisabled(apiKey, filterGroup), value: getInputValue(apiKey), inputProps: { autoComplete: 'off', 'data-testid': 'ColumnFilterInputs_input' }, endAdornment: _jsx(Box, { component: "img", "data-testid": "ColumnFilterInputs_icon", "data-icon": isInputHasValue(apiKey) ? 'close' : 'search', src: isInputHasValue(apiKey) ? grayCloseIcon : searchIcon, alt: "search", className: "icon", sx: { cursor: isInputHasValue(apiKey) ? 'pointer' : 'default' }, onClick: () => {
|
|
48
|
+
onClickResetInput(apiKey);
|
|
113
49
|
} }) }, apiKey));
|
|
114
50
|
}) })), _jsx(Collapse, Object.assign({ in: showClearButton, component: "section", "data-testid": "ColumnFilterInputs_Collapse" }, { children: _jsx(ClearWrapper, Object.assign({ "data-testid": "ColumnFilterInputs_ClearWrapper" }, { children: _jsx(ClearButton, Object.assign({ type: "button", onClick: onClickClear, "data-testid": "ColumnFilterInputs_ClearButton" }, { children: t('clear') })) })) })), _jsxs(Footer, Object.assign({ component: "footer", "data-testid": "ColumnFilterInputs_footer" }, { children: [_jsx(CancelButton, Object.assign({ type: "button", onClick: onClickCancel, "data-testid": "ColumnFilterInputs_CancelButton" }, { children: t('cancel') })), _jsx(OkayButton, Object.assign({ type: "button", onClick: onClickOkay, "data-testid": "ColumnFilterInputs_OkayButton" }, { children: t('okay') }))] }))] })));
|
|
115
51
|
}
|
package/build/types/table.d.ts
CHANGED
|
@@ -67,18 +67,7 @@ export interface IColumnFilterOption {
|
|
|
67
67
|
options?: IColumnFilterOption[];
|
|
68
68
|
isDisabled?: boolean;
|
|
69
69
|
filterGroup?: string;
|
|
70
|
-
|
|
71
|
-
key: string;
|
|
72
|
-
value: unknown;
|
|
73
|
-
setValue: (value: unknown) => void;
|
|
74
|
-
isDisabled?: boolean;
|
|
75
|
-
getInputValue: (key: string, type?: string) => string;
|
|
76
|
-
isInputHasValue: (key: string, type?: string) => boolean;
|
|
77
|
-
onClickReset: (key: string, type?: string) => void;
|
|
78
|
-
}) => React.ReactNode;
|
|
79
|
-
type?: 'text' | 'phone';
|
|
80
|
-
countries?: Country[];
|
|
81
|
-
isCountriesLoading?: boolean;
|
|
70
|
+
render?: () => React.ReactNode;
|
|
82
71
|
}
|
|
83
72
|
export type IColumnListFilterOption = Omit<IColumnFilterOption, 'apiKey' | 'options'> & {
|
|
84
73
|
value: string;
|
package/package.json
CHANGED