@ssa-ui-kit/widgets 0.0.3-alpha → 0.0.4-alpha
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/dist/components/Filters/Filters.d.ts +4 -3
- package/dist/components/Filters/FiltersContext.d.ts +6 -3
- package/dist/components/TableFilters/TableFilters.d.ts +1 -1
- package/dist/components/TableFilters/hooks/useTableData.d.ts +8 -2
- package/dist/components/TableFilters/types.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Filters/Filters.spec.tsx +10 -1
- package/src/components/Filters/Filters.tsx +3 -1
- package/src/components/Filters/FiltersBlock.tsx +3 -4
- package/src/components/Filters/FiltersContext.tsx +4 -1
- package/src/components/Filters/FiltersWrapper.tsx +4 -1
- package/src/components/Filters/stories/StoryComponent.tsx +2 -1
- package/src/components/TableFilters/TableFilters.spec.tsx +7 -2
- package/src/components/TableFilters/TableFilters.tsx +2 -2
- package/src/components/TableFilters/hooks/useTableData.ts +32 -2
- package/src/components/TableFilters/stories/StoryComponent.tsx +4 -4
- package/src/components/TableFilters/types.ts +1 -1
- package/tsbuildcache +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ssa-ui-kit/widgets",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4-alpha",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"private": false,
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"js-tokens": "^4.0.0",
|
|
30
30
|
"loose-envify": "^1.4.0",
|
|
31
31
|
"scheduler": "^0.23.0",
|
|
32
|
+
"@ssa-ui-kit/core": "^0.0.4-alpha",
|
|
32
33
|
"@ssa-ui-kit/hooks": "^0.0.1-alpha",
|
|
33
|
-
"@ssa-ui-kit/core": "^0.0.3-alpha",
|
|
34
34
|
"@ssa-ui-kit/utils": "^0.0.1-alpha"
|
|
35
35
|
},
|
|
36
36
|
"browserslist": [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { within, fireEvent } from '@testing-library/dom';
|
|
1
2
|
import { mockIntersectionObserver } from 'jsdom-testing-mocks';
|
|
2
3
|
import { StoryComponent } from './stories/StoryComponent';
|
|
3
|
-
import { within, fireEvent } from '@testing-library/dom';
|
|
4
4
|
|
|
5
5
|
describe('Filters', () => {
|
|
6
6
|
mockIntersectionObserver();
|
|
@@ -30,9 +30,18 @@ describe('Filters', () => {
|
|
|
30
30
|
const listItemEls = within(listboxEl).getAllByRole('listitem');
|
|
31
31
|
expect(listItemEls.length).toBe(5);
|
|
32
32
|
|
|
33
|
+
const logSpy = jest.spyOn(console, 'log');
|
|
33
34
|
await fireEvent.click(listItemEls[0]);
|
|
34
35
|
|
|
35
36
|
dropdownToggleEl = within(dropdownElement).getByRole('combobox');
|
|
36
37
|
expect(dropdownToggleEl).toHaveTextContent('Strategy: checkbox4Carrot up');
|
|
38
|
+
expect(logSpy).toHaveBeenCalledWith('>>>Filters onSubmit', {
|
|
39
|
+
exchange: ['binance'],
|
|
40
|
+
pairs: ['btcfdusd'],
|
|
41
|
+
status: ['running'],
|
|
42
|
+
strategy: ['checkbox4'],
|
|
43
|
+
strategy2: ['strategy2Checkbox1'],
|
|
44
|
+
strategy3: [],
|
|
45
|
+
});
|
|
37
46
|
});
|
|
38
47
|
});
|
|
@@ -19,11 +19,12 @@ export const Filters = ({
|
|
|
19
19
|
handleSubmit,
|
|
20
20
|
handleCancel,
|
|
21
21
|
handleClear,
|
|
22
|
+
handleDropdownChange,
|
|
22
23
|
}: Pick<UseTableDataResult, 'checkboxData'> & {
|
|
23
24
|
updatedCheckboxData?: TableFilterConfig;
|
|
24
25
|
} & Pick<
|
|
25
26
|
UseTableDataParameters,
|
|
26
|
-
'handleSubmit' | 'handleCancel' | 'handleClear'
|
|
27
|
+
'handleSubmit' | 'handleCancel' | 'handleClear' | 'handleDropdownChange'
|
|
27
28
|
>) => {
|
|
28
29
|
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
29
30
|
const [hiddenCheckboxData, setHiddenCheckboxData] =
|
|
@@ -38,6 +39,7 @@ export const Filters = ({
|
|
|
38
39
|
handleSubmit,
|
|
39
40
|
handleCancel,
|
|
40
41
|
handleClear,
|
|
42
|
+
handleDropdownChange,
|
|
41
43
|
});
|
|
42
44
|
|
|
43
45
|
const { checkboxData, refsList } = useTableDataResult;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { DropdownOption, MultipleDropdown } from '@ssa-ui-kit/core';
|
|
2
1
|
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { DropdownOption, MultipleDropdown } from '@ssa-ui-kit/core';
|
|
3
3
|
import { useFiltersContext } from './FiltersContext';
|
|
4
4
|
|
|
5
5
|
export const FiltersBlock = () => {
|
|
6
|
-
const { setElementRef,
|
|
7
|
-
useFiltersContext();
|
|
6
|
+
const { setElementRef, onDropdownChange, checkboxData } = useFiltersContext();
|
|
8
7
|
const handleOnChange = (groupName: string) => (item: string | number) => {
|
|
9
|
-
|
|
8
|
+
onDropdownChange(groupName, item);
|
|
10
9
|
};
|
|
11
10
|
|
|
12
11
|
const [selectedItemsWithValue, setSelectedItemsWithValue] = useState<
|
|
@@ -10,7 +10,10 @@ import {
|
|
|
10
10
|
export const FiltersContext = createContext<UseTableDataResult>({
|
|
11
11
|
checkboxData: mockData,
|
|
12
12
|
selectedItemsByGroup: {},
|
|
13
|
-
|
|
13
|
+
onCheckboxToggle: (groupName: string, name: string | number) => () => {
|
|
14
|
+
// no action
|
|
15
|
+
},
|
|
16
|
+
onDropdownChange: (groupName: string, name: string | number) => () => {
|
|
14
17
|
// no action
|
|
15
18
|
},
|
|
16
19
|
onClear: () => {
|
|
@@ -8,8 +8,11 @@ export const FiltersWrapper = styled.div<{ isMoreButtonVisible?: boolean }>`
|
|
|
8
8
|
flex-direction: ${({ isMoreButtonVisible }) =>
|
|
9
9
|
isMoreButtonVisible ? 'row' : 'row-reverse'};
|
|
10
10
|
|
|
11
|
-
& > div:first-
|
|
11
|
+
& > div:first-of-type > div:last-child {
|
|
12
12
|
margin-right: ${({ isMoreButtonVisible }) =>
|
|
13
13
|
isMoreButtonVisible ? '10px' : 0};
|
|
14
|
+
ul: {
|
|
15
|
+
right: ${({ isMoreButtonVisible }) => (isMoreButtonVisible ? 'auto' : 0)};
|
|
16
|
+
}
|
|
14
17
|
}
|
|
15
18
|
`;
|
|
@@ -3,8 +3,9 @@ import { Filters } from '..';
|
|
|
3
3
|
|
|
4
4
|
export const StoryComponent = () => {
|
|
5
5
|
const handleSubmit = (submitData: Record<string, string[]>) => {
|
|
6
|
-
console.log('>>>onSubmit', submitData);
|
|
6
|
+
console.log('>>>Filters onSubmit', submitData);
|
|
7
7
|
};
|
|
8
|
+
|
|
8
9
|
return (
|
|
9
10
|
<div
|
|
10
11
|
css={{
|
|
@@ -8,7 +8,8 @@ import { createRef } from 'react';
|
|
|
8
8
|
|
|
9
9
|
const mockTableFiltersProps: UseTableDataResult = {
|
|
10
10
|
checkboxData: mockData,
|
|
11
|
-
|
|
11
|
+
onCheckboxToggle: jest.fn(),
|
|
12
|
+
onDropdownChange: jest.fn(),
|
|
12
13
|
setElementRef: jest.fn(),
|
|
13
14
|
onSubmit: jest.fn((e) => {
|
|
14
15
|
e?.preventDefault();
|
|
@@ -27,6 +28,10 @@ const mockTableFiltersProps: UseTableDataResult = {
|
|
|
27
28
|
describe('TableFilters', () => {
|
|
28
29
|
mockIntersectionObserver();
|
|
29
30
|
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
jest.clearAllMocks();
|
|
33
|
+
});
|
|
34
|
+
|
|
30
35
|
it('Should be correctly rendered', () => {
|
|
31
36
|
const { getByText, getByRole, queryByText } = render(<StoryComponent />);
|
|
32
37
|
|
|
@@ -126,7 +131,7 @@ describe('TableFilters', () => {
|
|
|
126
131
|
|
|
127
132
|
const logSpy = jest.spyOn(console, 'log');
|
|
128
133
|
fireEvent.click(getByText('Apply'));
|
|
129
|
-
expect(logSpy).toHaveBeenCalledWith('>>>onSubmit', {
|
|
134
|
+
expect(logSpy).toHaveBeenCalledWith('>>>TableFilters onSubmit', {
|
|
130
135
|
exchange: ['binance'],
|
|
131
136
|
pairs: ['btcfdusd'],
|
|
132
137
|
status: ['running'],
|
|
@@ -38,8 +38,8 @@ export const TableFilters = ({
|
|
|
38
38
|
onReset,
|
|
39
39
|
onSubmit,
|
|
40
40
|
onClear,
|
|
41
|
+
onCheckboxToggle,
|
|
41
42
|
handleMoreButtonVisibleChange,
|
|
42
|
-
handleCheckboxToggle,
|
|
43
43
|
}: TableFiltersView) => {
|
|
44
44
|
const [localCheckboxData, setLocalCheckboxData] =
|
|
45
45
|
useState<TableFilterConfig>(checkboxData);
|
|
@@ -87,7 +87,7 @@ export const TableFilters = ({
|
|
|
87
87
|
name,
|
|
88
88
|
);
|
|
89
89
|
setLocalCheckboxData(assocPath(path, items));
|
|
90
|
-
|
|
90
|
+
onCheckboxToggle?.(groupName, name);
|
|
91
91
|
};
|
|
92
92
|
|
|
93
93
|
const handleSubmit = (event: BaseSyntheticEvent) => {
|
|
@@ -15,6 +15,11 @@ export interface UseTableDataParameters {
|
|
|
15
15
|
handleCancel?: () => void;
|
|
16
16
|
handleClear?: () => void;
|
|
17
17
|
handleSubmit?: (data: Record<string, string[]>) => void;
|
|
18
|
+
handleDropdownChange?: (data: {
|
|
19
|
+
groupName: string;
|
|
20
|
+
name: string | number;
|
|
21
|
+
checked: boolean;
|
|
22
|
+
}) => void;
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
export const useTableData = ({
|
|
@@ -24,6 +29,7 @@ export const useTableData = ({
|
|
|
24
29
|
handleCancel,
|
|
25
30
|
handleSubmit,
|
|
26
31
|
handleClear,
|
|
32
|
+
handleDropdownChange,
|
|
27
33
|
}: UseTableDataParameters) => {
|
|
28
34
|
const [checkboxData, setCheckboxData] = useState<TableFilterConfig>(
|
|
29
35
|
{} as TableFilterConfig,
|
|
@@ -64,7 +70,7 @@ export const useTableData = ({
|
|
|
64
70
|
proceedSettingCheckboxData(updatedCheckboxData);
|
|
65
71
|
}, [updatedCheckboxData]);
|
|
66
72
|
|
|
67
|
-
const
|
|
73
|
+
const onCheckboxToggle = (groupName: string, name: string | number) => {
|
|
68
74
|
const { items, path } = getCheckboxChangedItems(
|
|
69
75
|
checkboxData,
|
|
70
76
|
groupName,
|
|
@@ -73,6 +79,29 @@ export const useTableData = ({
|
|
|
73
79
|
setCheckboxData(assocPath(path, items));
|
|
74
80
|
};
|
|
75
81
|
|
|
82
|
+
const onDropdownChange = (groupName: string, name: string | number) => {
|
|
83
|
+
const { items, path } = getCheckboxChangedItems(
|
|
84
|
+
checkboxData,
|
|
85
|
+
groupName,
|
|
86
|
+
name,
|
|
87
|
+
);
|
|
88
|
+
const newCheckboxData = assocPath<TableFilterConfig>(
|
|
89
|
+
path,
|
|
90
|
+
items,
|
|
91
|
+
)(checkboxData);
|
|
92
|
+
handleDropdownChange?.({
|
|
93
|
+
groupName,
|
|
94
|
+
name,
|
|
95
|
+
checked: items.includes(name),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const { submitCheckboxData, dataForSubmit } =
|
|
99
|
+
getSubmitData(newCheckboxData);
|
|
100
|
+
|
|
101
|
+
setCheckboxData(submitCheckboxData);
|
|
102
|
+
handleSubmit?.(dataForSubmit);
|
|
103
|
+
};
|
|
104
|
+
|
|
76
105
|
const onSubmit = (event?: BaseSyntheticEvent) => {
|
|
77
106
|
event?.preventDefault();
|
|
78
107
|
const { submitCheckboxData, dataForSubmit } = getSubmitData(checkboxData);
|
|
@@ -97,7 +126,8 @@ export const useTableData = ({
|
|
|
97
126
|
wrapperRef,
|
|
98
127
|
refsList,
|
|
99
128
|
setElementRef,
|
|
100
|
-
|
|
129
|
+
onCheckboxToggle,
|
|
130
|
+
onDropdownChange,
|
|
101
131
|
onSubmit,
|
|
102
132
|
onReset,
|
|
103
133
|
onClear,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import { Wrapper } from '@ssa-ui-kit/core';
|
|
3
|
+
import { FiltersContextProvider } from '@components/Filters/FiltersContext';
|
|
1
4
|
import { mockData } from './mockData';
|
|
2
5
|
import { useTableData } from '../hooks/useTableData';
|
|
3
|
-
import { FiltersContextProvider } from '@components/Filters/FiltersContext';
|
|
4
6
|
import { TableFiltersWrapper } from './TableFiltersWrapper';
|
|
5
|
-
import { useRef } from 'react';
|
|
6
|
-
import { Wrapper } from '@ssa-ui-kit/core';
|
|
7
7
|
|
|
8
8
|
export const StoryComponent = () => {
|
|
9
9
|
const handleSubmit = (submitData: Record<string, string[]>) => {
|
|
10
|
-
console.log('>>>onSubmit', submitData);
|
|
10
|
+
console.log('>>>TableFilters onSubmit', submitData);
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
@@ -28,7 +28,7 @@ export interface TableFiltersView {
|
|
|
28
28
|
onReset?: () => void;
|
|
29
29
|
onClear?: () => void;
|
|
30
30
|
onSubmit?: () => void;
|
|
31
|
-
|
|
31
|
+
onCheckboxToggle?: (groupName: string, name: string) => void;
|
|
32
32
|
handleMoreButtonVisibleChange?: (isVisible: boolean) => void;
|
|
33
33
|
checkboxData?: TableFilterConfig;
|
|
34
34
|
}
|