@tap-payments/os-micro-frontend-shared 0.1.415-test.1 → 0.1.415-test.10
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/index.d.ts +0 -2
- package/build/components/FilterDropdown/components/index.js +0 -2
- package/build/components/RangeCalender/RangeCalender.js +10 -3
- package/package.json +2 -2
- package/build/components/FilterDropdown/components/MerchantsFilterItem/MerchantsFilterItem.d.ts +0 -3
- package/build/components/FilterDropdown/components/MerchantsFilterItem/MerchantsFilterItem.js +0 -45
- package/build/components/FilterDropdown/components/MerchantsFilterItem/index.d.ts +0 -4
- package/build/components/FilterDropdown/components/MerchantsFilterItem/index.js +0 -4
- package/build/components/FilterDropdown/components/MerchantsFilterItem/type.d.ts +0 -20
- package/build/components/FilterDropdown/components/MerchantsFilterItem/type.js +0 -7
- package/build/components/FilterDropdown/components/MerchantsFilterItem/utils.d.ts +0 -5
- package/build/components/FilterDropdown/components/MerchantsFilterItem/utils.js +0 -55
|
@@ -2,5 +2,3 @@ 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,5 +2,3 @@ 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';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { useEffect, useRef, useState, useCallback } from 'react';
|
|
3
3
|
import Box from '@mui/material/Box';
|
|
4
4
|
import Collapse from '@mui/material/Collapse';
|
|
5
5
|
import Popper from '@mui/material/Popper';
|
|
6
6
|
import dayjs from 'dayjs';
|
|
7
7
|
import { useTranslation } from 'react-i18next';
|
|
8
8
|
import { DateObject } from 'react-multi-date-picker';
|
|
9
|
+
import isEqual from 'lodash/isEqual';
|
|
9
10
|
import { CustomBackdrop, Error } from '../index.js';
|
|
10
11
|
import GroupBy from './components/GroupBy';
|
|
11
12
|
import Hijri from './components/Hijri';
|
|
@@ -40,6 +41,12 @@ function RangeCalender({ defaultDate, onDateChange, mode = 'gregorian', onCalend
|
|
|
40
41
|
setValues(getDateRange(defaultDate));
|
|
41
42
|
}
|
|
42
43
|
}, [open]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!isEqual(defaultDate, dates)) {
|
|
46
|
+
console.log('defaultDate', defaultDate);
|
|
47
|
+
setDates(getDateRange(defaultDate));
|
|
48
|
+
}
|
|
49
|
+
}, [defaultDate]);
|
|
43
50
|
useEffect(() => {
|
|
44
51
|
setSelectedTimezone(timezone);
|
|
45
52
|
}, [timezone, open]);
|
|
@@ -57,11 +64,11 @@ function RangeCalender({ defaultDate, onDateChange, mode = 'gregorian', onCalend
|
|
|
57
64
|
onCalendarGroupChange === null || onCalendarGroupChange === void 0 ? void 0 : onCalendarGroupChange(selectedGroupBy || 'day');
|
|
58
65
|
onChangeTimezone === null || onChangeTimezone === void 0 ? void 0 : onChangeTimezone(selectedTimezone);
|
|
59
66
|
};
|
|
60
|
-
const getSelectedDate = () => {
|
|
67
|
+
const getSelectedDate = useCallback(() => {
|
|
61
68
|
const startSelectedTime = dates[0].format('MMM D');
|
|
62
69
|
const endSelectedTime = dates[1] ? dates[1].format('MMM D') : dates[0].format('MMM D');
|
|
63
70
|
return startSelectedTime === endSelectedTime && !noTimezone ? startSelectedTime : `${startSelectedTime} - ${endSelectedTime}`;
|
|
64
|
-
};
|
|
71
|
+
}, [dates, noTimezone]);
|
|
65
72
|
const onChange = (newDate) => {
|
|
66
73
|
if (newDate.length < 2 || !maxDateRange) {
|
|
67
74
|
setValues(newDate);
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tap-payments/os-micro-frontend-shared",
|
|
3
3
|
"description": "Shared components and utilities for Tap Payments micro frontends",
|
|
4
|
-
"version": "0.1.415-test.
|
|
5
|
-
"testVersion":
|
|
4
|
+
"version": "0.1.415-test.10",
|
|
5
|
+
"testVersion": 10,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
8
8
|
"module": "build/index.js",
|
package/build/components/FilterDropdown/components/MerchantsFilterItem/MerchantsFilterItem.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
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;
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
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;
|
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
};
|