@tap-payments/os-micro-frontend-shared 0.1.415 → 0.1.416
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/components/FilterDropdown/components/MerchantsFilterItem/MerchantsFilterItem.d.ts +3 -0
- package/build/components/FilterDropdown/components/MerchantsFilterItem/MerchantsFilterItem.js +45 -0
- package/build/components/FilterDropdown/components/MerchantsFilterItem/index.d.ts +4 -0
- package/build/components/FilterDropdown/components/MerchantsFilterItem/index.js +4 -0
- package/build/components/FilterDropdown/components/MerchantsFilterItem/type.d.ts +20 -0
- package/build/components/FilterDropdown/components/MerchantsFilterItem/type.js +7 -0
- package/build/components/FilterDropdown/components/MerchantsFilterItem/utils.d.ts +5 -0
- package/build/components/FilterDropdown/components/MerchantsFilterItem/utils.js +55 -0
- package/build/components/FilterDropdown/components/index.d.ts +2 -0
- package/build/components/FilterDropdown/components/index.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { MenuItem, SelectedState, Text, TreeDropdown, TreeManager } from '../../../index.js';
|
|
3
|
+
import { useState, useMemo, useCallback, useRef } from 'react';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { createTreeDefinitions } from './utils';
|
|
6
|
+
import { TreeLevel } from './type';
|
|
7
|
+
import { rightArrow } from '../../../../constants/index.js';
|
|
8
|
+
const MerchantsFilterItem = (props) => {
|
|
9
|
+
const { brands, isLoading, initialValue, onFilterChange, BrandLogoComponent } = props;
|
|
10
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
11
|
+
const [merchantSelectStatus, setMerchantSelectStatus] = useState(SelectedState.UNCHECKED);
|
|
12
|
+
const treeDropdownRef = useRef(null);
|
|
13
|
+
const open = Boolean(anchorEl);
|
|
14
|
+
const { t, i18n } = useTranslation();
|
|
15
|
+
const treeDefinition = useMemo(() => createTreeDefinitions(brands, initialValue, i18n.language), [brands, initialValue, i18n.language]);
|
|
16
|
+
const brandsTreeItems = treeDefinition.children;
|
|
17
|
+
const isDisabled = isLoading || !brandsTreeItems.length;
|
|
18
|
+
const getMerchantSelectStatus = useCallback((selectedTree) => {
|
|
19
|
+
const checkedBrands = selectedTree.filter((brand) => brand.status === SelectedState.CHECKED);
|
|
20
|
+
const indeterminateBrands = selectedTree.filter((brand) => brand.status === SelectedState.INDETERMINATE);
|
|
21
|
+
return checkedBrands.length === brandsTreeItems.length
|
|
22
|
+
? SelectedState.CHECKED
|
|
23
|
+
: indeterminateBrands.length > 0 || checkedBrands.length > 0
|
|
24
|
+
? SelectedState.INDETERMINATE
|
|
25
|
+
: SelectedState.UNCHECKED;
|
|
26
|
+
}, [brandsTreeItems]);
|
|
27
|
+
const handleTreeMounted = useCallback(({ selectedTree }) => {
|
|
28
|
+
setMerchantSelectStatus(getMerchantSelectStatus(selectedTree));
|
|
29
|
+
}, [getMerchantSelectStatus]);
|
|
30
|
+
const handleTreeChange = useCallback((nextTree) => {
|
|
31
|
+
setMerchantSelectStatus(getMerchantSelectStatus(nextTree));
|
|
32
|
+
const mids = TreeManager.filterNodesByLevelKey(nextTree, TreeLevel.MERCHANT).map(({ id }) => id);
|
|
33
|
+
onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange(mids);
|
|
34
|
+
}, [onFilterChange, getMerchantSelectStatus]);
|
|
35
|
+
const handleClick = useCallback(() => {
|
|
36
|
+
var _a;
|
|
37
|
+
(_a = treeDropdownRef.current) === null || _a === void 0 ? void 0 : _a.toggleAll(merchantSelectStatus !== SelectedState.CHECKED);
|
|
38
|
+
}, [merchantSelectStatus]);
|
|
39
|
+
return (_jsxs(MenuItem, Object.assign({ isSelected: merchantSelectStatus === SelectedState.CHECKED, isIndeterminate: merchantSelectStatus === SelectedState.INDETERMINATE, isDisabled: isDisabled, onMouseEnter: (e) => setAnchorEl(e.currentTarget), onMouseLeave: () => setAnchorEl(null), onClick: handleClick, sx: Object.assign(Object.assign({ maxHeight: 36, minHeight: 36, padding: '12px 8px 12px 16px' }, (open && { boxShadow: '0px 0px 16px 0px #00000021' })), (isDisabled && {
|
|
40
|
+
pointerEvents: 'none',
|
|
41
|
+
opacity: 0.5,
|
|
42
|
+
cursor: 'default',
|
|
43
|
+
})) }, { children: [_jsx(Text, Object.assign({ sx: { fontSize: '11px', flex: 1 } }, { children: t('merchant') })), brands.length > 0 && _jsx("img", { src: rightArrow, alt: "arrow", style: { height: 12 } }), !isLoading && (_jsx(TreeDropdown, { ref: treeDropdownRef, placement: "right-start", anchorEl: anchorEl, exposeOnlySelectedTree: true, treeDefinition: treeDefinition, onChange: handleTreeChange, onMounted: handleTreeMounted, IconComponent: BrandLogoComponent }))] })));
|
|
44
|
+
};
|
|
45
|
+
export default MerchantsFilterItem;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Brand } from '../../../../types/index.js';
|
|
3
|
+
export declare enum TreeLevel {
|
|
4
|
+
BRAND = "BRAND",
|
|
5
|
+
COUNTRY = "COUNTRY",
|
|
6
|
+
ENTITY = "ENTITY",
|
|
7
|
+
MERCHANT = "MERCHANT"
|
|
8
|
+
}
|
|
9
|
+
export type MerchantsFilterItemProps = {
|
|
10
|
+
brands: Brand[];
|
|
11
|
+
isLoading: boolean;
|
|
12
|
+
initialValue: string[];
|
|
13
|
+
atLeastOneMerchantSelected?: boolean | undefined;
|
|
14
|
+
showSearchInput?: boolean | undefined;
|
|
15
|
+
hideCheckbox?: boolean | undefined;
|
|
16
|
+
onFilterChange?: ((value: string[]) => void) | undefined;
|
|
17
|
+
BrandLogoComponent: React.ComponentType<{
|
|
18
|
+
fileId: string;
|
|
19
|
+
}>;
|
|
20
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TreeDefinition } from '../../../index.js';
|
|
2
|
+
import { Brand } from '../../../../types/index.js';
|
|
3
|
+
export declare const ID_SEPERATOR = "/";
|
|
4
|
+
export declare const generateIdFromParts: (...args: string[]) => string;
|
|
5
|
+
export declare const createTreeDefinitions: (brands: Brand[], selectedMerchantIds: string[], language: string) => TreeDefinition;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { CountryFlag, SelectedState } from '../../../index.js';
|
|
3
|
+
import { getNameText } from '../../../../utils/index.js';
|
|
4
|
+
import { TreeLevel } from './type';
|
|
5
|
+
export const ID_SEPERATOR = '/';
|
|
6
|
+
export const generateIdFromParts = (...args) => args.join(ID_SEPERATOR);
|
|
7
|
+
export const createTreeDefinitions = (brands, selectedMerchantIds, language) => {
|
|
8
|
+
const children = brands.map((brand) => {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
const entities = (_a = brand.entities) !== null && _a !== void 0 ? _a : [];
|
|
11
|
+
// level 2: unique countries per brand
|
|
12
|
+
const countries = Array.from(new Set(entities.map((entity) => entity.country).filter(Boolean)));
|
|
13
|
+
const countryNodes = countries.map((countryCode) => {
|
|
14
|
+
const entitiesInCountry = entities.filter((entity) => entity.country === countryCode);
|
|
15
|
+
// level 3: entities per country
|
|
16
|
+
const entityNodes = entitiesInCountry.map((entity) => {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
const merchants = (_a = entity.merchants) !== null && _a !== void 0 ? _a : [];
|
|
19
|
+
// level 4: merchants per entity
|
|
20
|
+
const merchantNodes = merchants.map((merchant) => ({
|
|
21
|
+
id: merchant.legacy_id,
|
|
22
|
+
label: merchant.display_name,
|
|
23
|
+
levelKey: TreeLevel.MERCHANT,
|
|
24
|
+
status: selectedMerchantIds.includes(merchant.legacy_id) ? SelectedState.CHECKED : SelectedState.UNCHECKED,
|
|
25
|
+
hintText: merchant.legacy_id,
|
|
26
|
+
}));
|
|
27
|
+
return Object.assign({ id: generateIdFromParts(brand.id, countryCode, entity.id), label: (_b = getNameText(entity.legal_name, language)) !== null && _b !== void 0 ? _b : entity.id, levelKey: TreeLevel.ENTITY, children: merchantNodes, header: 'Merchants' }, (merchantNodes.length > 10 && {
|
|
28
|
+
searchProps: {
|
|
29
|
+
getValues: (item) => [item.label, item.id],
|
|
30
|
+
},
|
|
31
|
+
}));
|
|
32
|
+
});
|
|
33
|
+
return Object.assign({ id: generateIdFromParts(brand.id, countryCode), label: countryCode, levelKey: TreeLevel.COUNTRY, children: entityNodes, header: 'Entities', iconComponent: _jsx(CountryFlag, { countryCode: countryCode, width: 14 }) }, (entityNodes.length > 10 && {
|
|
34
|
+
searchProps: {
|
|
35
|
+
getValues: (item) => [item.label, item.id],
|
|
36
|
+
},
|
|
37
|
+
}));
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
id: brand.id,
|
|
41
|
+
label: (_b = getNameText(brand.name, language)) !== null && _b !== void 0 ? _b : brand.id,
|
|
42
|
+
levelKey: TreeLevel.BRAND,
|
|
43
|
+
children: countryNodes,
|
|
44
|
+
header: 'Countries',
|
|
45
|
+
icon: {
|
|
46
|
+
fileId: brand.logo,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
return Object.assign({ levelKey: TreeLevel.BRAND, children, header: 'Brands' }, (children.length > 10 && {
|
|
51
|
+
searchProps: {
|
|
52
|
+
getValues: (item) => [item.label, item.id],
|
|
53
|
+
},
|
|
54
|
+
}));
|
|
55
|
+
};
|
|
@@ -2,3 +2,5 @@ export { default as MerchantItem } from './MerchantItem';
|
|
|
2
2
|
export { default as RetailersItem } from './RetailersItem';
|
|
3
3
|
export { default as CountriesItem } from './CountriesItem';
|
|
4
4
|
export { default as CurrenciesItem } from './CurrenciesItem';
|
|
5
|
+
export { default as MerchantsFilterItem } from './MerchantsFilterItem';
|
|
6
|
+
export * from './MerchantsFilterItem';
|
|
@@ -2,3 +2,5 @@ export { default as MerchantItem } from './MerchantItem';
|
|
|
2
2
|
export { default as RetailersItem } from './RetailersItem';
|
|
3
3
|
export { default as CountriesItem } from './CountriesItem';
|
|
4
4
|
export { default as CurrenciesItem } from './CurrenciesItem';
|
|
5
|
+
export { default as MerchantsFilterItem } from './MerchantsFilterItem';
|
|
6
|
+
export * from './MerchantsFilterItem';
|
package/package.json
CHANGED