@blaze-cms/react-page-builder 0.124.0-alpha.32 → 0.124.0-alpha.33
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/CHANGELOG.md +11 -0
- package/README.md +8 -0
- package/lib/application/query/index.js +1 -1
- package/lib/application/query/index.js.map +1 -1
- package/lib/components/{ItemListButton → ItemList/ItemListButton}/ItemListButton.js +22 -32
- package/lib/components/ItemList/ItemListButton/ItemListButton.js.map +1 -0
- package/lib/components/{ItemListButton → ItemList/ItemListButton}/index.js +0 -0
- package/lib/components/ItemList/ItemListButton/index.js.map +1 -0
- package/lib/components/ItemList/ItemListCounter/ItemListCounter.js +83 -0
- package/lib/components/ItemList/ItemListCounter/ItemListCounter.js.map +1 -0
- package/lib/components/{ItemListCounter → ItemList/ItemListCounter}/index.js +0 -0
- package/lib/components/ItemList/ItemListCounter/index.js.map +1 -0
- package/lib/components/ItemList/ItemListNew/ItemListNew.js +75 -0
- package/lib/components/ItemList/ItemListNew/ItemListNew.js.map +1 -0
- package/lib/components/ItemList/ItemListNew/index.js +16 -0
- package/lib/components/ItemList/ItemListNew/index.js.map +1 -0
- package/lib/components/ItemList/constants.js +19 -0
- package/lib/components/ItemList/constants.js.map +1 -0
- package/lib/{helpers → components/ItemList/helpers}/get-item-list-data.js +0 -0
- package/lib/components/ItemList/helpers/get-item-list-data.js.map +1 -0
- package/lib/{helpers → components/ItemList/helpers}/get-item-list-id.js +0 -0
- package/lib/components/ItemList/helpers/get-item-list-id.js.map +1 -0
- package/lib/{helpers → components/ItemList/helpers}/get-item-list-ids.js +0 -0
- package/lib/components/ItemList/helpers/get-item-list-ids.js.map +1 -0
- package/lib/components/ItemList/helpers/index.js +50 -0
- package/lib/components/ItemList/helpers/index.js.map +1 -0
- package/lib/components/ItemList/helpers/set-item-list-id.js +22 -0
- package/lib/components/ItemList/helpers/set-item-list-id.js.map +1 -0
- package/lib/components/ItemList/helpers/set-param-and-redirect.js +51 -0
- package/lib/components/ItemList/helpers/set-param-and-redirect.js.map +1 -0
- package/lib/components/ItemList/hooks/index.js +18 -0
- package/lib/components/ItemList/hooks/index.js.map +1 -0
- package/lib/components/ItemList/hooks/use-item-list-id.js +45 -0
- package/lib/components/ItemList/hooks/use-item-list-id.js.map +1 -0
- package/lib/components/List/ListFactory.js +5 -5
- package/lib/components/List/ListFactory.js.map +1 -1
- package/lib/components/index.js +7 -2
- package/lib/components/index.js.map +1 -1
- package/lib/constants/index.js +2 -4
- package/lib/constants/index.js.map +1 -1
- package/lib/helpers/index.js +0 -24
- package/lib/helpers/index.js.map +1 -1
- package/lib-es/application/query/index.js +1 -0
- package/lib-es/application/query/index.js.map +1 -1
- package/lib-es/components/{ItemListButton → ItemList/ItemListButton}/ItemListButton.js +16 -23
- package/lib-es/components/ItemList/ItemListButton/ItemListButton.js.map +1 -0
- package/lib-es/components/{ItemListButton → ItemList/ItemListButton}/index.js +0 -0
- package/lib-es/components/ItemList/ItemListButton/index.js.map +1 -0
- package/lib-es/components/{ItemListCounter → ItemList/ItemListCounter}/ItemListCounter.js +9 -16
- package/lib-es/components/ItemList/ItemListCounter/ItemListCounter.js.map +1 -0
- package/lib-es/components/{ItemListCounter → ItemList/ItemListCounter}/index.js +0 -0
- package/lib-es/components/ItemList/ItemListCounter/index.js.map +1 -0
- package/lib-es/components/ItemList/ItemListNew/ItemListNew.js +56 -0
- package/lib-es/components/ItemList/ItemListNew/ItemListNew.js.map +1 -0
- package/lib-es/components/ItemList/ItemListNew/index.js +3 -0
- package/lib-es/components/ItemList/ItemListNew/index.js.map +1 -0
- package/lib-es/components/ItemList/constants.js +6 -0
- package/lib-es/components/ItemList/constants.js.map +1 -0
- package/lib-es/{helpers → components/ItemList/helpers}/get-item-list-data.js +0 -0
- package/lib-es/components/ItemList/helpers/get-item-list-data.js.map +1 -0
- package/lib-es/{helpers → components/ItemList/helpers}/get-item-list-id.js +0 -0
- package/lib-es/components/ItemList/helpers/get-item-list-id.js.map +1 -0
- package/lib-es/{helpers → components/ItemList/helpers}/get-item-list-ids.js +0 -0
- package/lib-es/components/ItemList/helpers/get-item-list-ids.js.map +1 -0
- package/lib-es/components/ItemList/helpers/index.js +6 -0
- package/lib-es/components/ItemList/helpers/index.js.map +1 -0
- package/lib-es/components/ItemList/helpers/set-item-list-id.js +10 -0
- package/lib-es/components/ItemList/helpers/set-item-list-id.js.map +1 -0
- package/lib-es/components/ItemList/helpers/set-param-and-redirect.js +20 -0
- package/lib-es/components/ItemList/helpers/set-param-and-redirect.js.map +1 -0
- package/lib-es/components/ItemList/hooks/index.js +2 -0
- package/lib-es/components/ItemList/hooks/index.js.map +1 -0
- package/lib-es/components/ItemList/hooks/use-item-list-id.js +26 -0
- package/lib-es/components/ItemList/hooks/use-item-list-id.js.map +1 -0
- package/lib-es/components/List/ListFactory.js +3 -4
- package/lib-es/components/List/ListFactory.js.map +1 -1
- package/lib-es/components/index.js +5 -2
- package/lib-es/components/index.js.map +1 -1
- package/lib-es/constants/index.js +1 -2
- package/lib-es/constants/index.js.map +1 -1
- package/lib-es/helpers/index.js +0 -3
- package/lib-es/helpers/index.js.map +1 -1
- package/package.json +2 -2
- package/src/application/query/index.js +1 -0
- package/src/components/{ItemListButton → ItemList/ItemListButton}/ItemListButton.js +13 -26
- package/src/components/{ItemListButton → ItemList/ItemListButton}/index.js +0 -0
- package/src/components/{ItemListCounter → ItemList/ItemListCounter}/ItemListCounter.js +5 -21
- package/src/components/{ItemListCounter → ItemList/ItemListCounter}/index.js +0 -0
- package/src/components/ItemList/ItemListNew/ItemListNew.js +47 -0
- package/src/components/ItemList/ItemListNew/index.js +3 -0
- package/src/components/ItemList/constants.js +5 -0
- package/src/{helpers → components/ItemList/helpers}/get-item-list-data.js +0 -0
- package/src/{helpers → components/ItemList/helpers}/get-item-list-id.js +0 -0
- package/src/{helpers → components/ItemList/helpers}/get-item-list-ids.js +0 -0
- package/src/components/ItemList/helpers/index.js +5 -0
- package/src/components/ItemList/helpers/set-item-list-id.js +9 -0
- package/src/components/ItemList/helpers/set-param-and-redirect.js +20 -0
- package/src/components/ItemList/hooks/index.js +1 -0
- package/src/components/ItemList/hooks/use-item-list-id.js +27 -0
- package/src/components/List/ListFactory.js +3 -4
- package/src/components/index.js +5 -2
- package/src/constants/index.js +1 -4
- package/src/helpers/index.js +0 -3
- package/tests/unit/src/components/ItemList/ItemListButton.test.js +175 -0
- package/tests/unit/src/components/ItemList/ItemListCounter.test.js +65 -0
- package/tests/unit/src/components/ItemList/ItemListNew.test.js +128 -0
- package/tests/unit/src/components/ItemList/__snapshots__/ItemListButton.test.js.snap +107 -0
- package/tests/unit/src/components/ItemList/__snapshots__/ItemListCounter.test.js.snap +31 -0
- package/tests/unit/src/components/ItemList/__snapshots__/ItemListNew.test.js.snap +16 -0
- package/tests/unit/src/{helpers → components/ItemList/helpers}/get-item-list-data.test.js +1 -1
- package/tests/unit/src/{helpers → components/ItemList/helpers}/get-item-list-id.test.js +1 -1
- package/tests/unit/src/{helpers → components/ItemList/helpers}/get-item-list-ids.test.js +1 -1
- package/tests/unit/src/components/ItemList/helpers/set-item-list-id.test.js +13 -0
- package/tests/unit/src/components/ItemList/helpers/set-param-and-redirect.test.js +30 -0
- package/tests/unit/src/components/ItemList/hooks/use-item-list-id.test.js +32 -0
- package/tests/unit/src/components/__snapshots__/index.test.js.snap +4 -0
- package/lib/components/ItemListButton/ItemListButton.js.map +0 -1
- package/lib/components/ItemListButton/index.js.map +0 -1
- package/lib/components/ItemListCounter/ItemListCounter.js +0 -114
- package/lib/components/ItemListCounter/ItemListCounter.js.map +0 -1
- package/lib/components/ItemListCounter/index.js.map +0 -1
- package/lib/helpers/get-item-list-data.js.map +0 -1
- package/lib/helpers/get-item-list-id.js.map +0 -1
- package/lib/helpers/get-item-list-ids.js.map +0 -1
- package/lib-es/components/ItemListButton/ItemListButton.js.map +0 -1
- package/lib-es/components/ItemListButton/index.js.map +0 -1
- package/lib-es/components/ItemListCounter/ItemListCounter.js.map +0 -1
- package/lib-es/components/ItemListCounter/index.js.map +0 -1
- package/lib-es/helpers/get-item-list-data.js.map +0 -1
- package/lib-es/helpers/get-item-list-id.js.map +0 -1
- package/lib-es/helpers/get-item-list-ids.js.map +0 -1
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
3
|
+
import { render, waitFor, fireEvent } from '@testing-library/react';
|
|
4
|
+
import { MockedProvider } from '@apollo/client/testing';
|
|
5
|
+
|
|
6
|
+
import ItemListNew from '../../../../../src/components/ItemList/ItemListNew';
|
|
7
|
+
import { getItemList } from '../../../../../src/application/query';
|
|
8
|
+
import userItemListId from '../../../../../src/components/ItemList/hooks/use-item-list-id';
|
|
9
|
+
import getItemListData from '../../../../../src/components/ItemList/helpers/get-item-list-data';
|
|
10
|
+
import setItemListId from '../../../../../src/components/ItemList/helpers/set-item-list-id';
|
|
11
|
+
import setParamAndRedirect from '../../../../../src/components/ItemList/helpers/set-param-and-redirect';
|
|
12
|
+
|
|
13
|
+
jest.mock('../../../../../src/components/ItemList/hooks/use-item-list-id', () =>
|
|
14
|
+
jest.fn(() => ({ listId: 'LIST ID' }))
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
jest.mock('../../../../../src/components/ItemList/helpers/set-item-list-id', () => {
|
|
18
|
+
const originalModule = jest.requireActual(
|
|
19
|
+
'../../../../../src/components/ItemList/helpers/set-item-list-id'
|
|
20
|
+
);
|
|
21
|
+
return jest.fn((...args) => originalModule.default(...args));
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
jest.mock('../../../../../src/components/ItemList/helpers/set-param-and-redirect', () => jest.fn());
|
|
25
|
+
|
|
26
|
+
jest.mock('../../../../../src/components/ItemList/helpers/get-item-list-data', () => {
|
|
27
|
+
const originalModule = jest.requireActual(
|
|
28
|
+
'../../../../../src/components/ItemList/helpers/get-item-list-data'
|
|
29
|
+
);
|
|
30
|
+
return jest.fn((...args) => originalModule.default(...args));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const listId = 'LIST ID';
|
|
34
|
+
const missingListId = 'MISSING';
|
|
35
|
+
const emptyListId = 'EMPTY';
|
|
36
|
+
const mocks = [
|
|
37
|
+
{
|
|
38
|
+
request: {
|
|
39
|
+
query: getItemList,
|
|
40
|
+
variables: { id: listId }
|
|
41
|
+
},
|
|
42
|
+
result: {
|
|
43
|
+
data: {
|
|
44
|
+
getItemList: { id: listId, listItems: [{ itemId: 'ID', itemEntity: 'ENTITY' }] }
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
request: {
|
|
50
|
+
query: getItemList,
|
|
51
|
+
variables: { id: missingListId }
|
|
52
|
+
},
|
|
53
|
+
result: {
|
|
54
|
+
data: {
|
|
55
|
+
getItemList: null
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
request: {
|
|
61
|
+
query: getItemList,
|
|
62
|
+
variables: { id: emptyListId }
|
|
63
|
+
},
|
|
64
|
+
result: {
|
|
65
|
+
data: {
|
|
66
|
+
getItemList: { id: emptyListId, listItems: [] }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
describe('ItemListNew component', () => {
|
|
73
|
+
const props = {
|
|
74
|
+
listName: 'list_name',
|
|
75
|
+
modifier: 'button',
|
|
76
|
+
text: 'Clear list'
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
beforeEach(() => {
|
|
80
|
+
jest.clearAllMocks();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should match snapshot and render without throwing an error', async () => {
|
|
84
|
+
const { asFragment, getByText } = render(
|
|
85
|
+
<MockedProvider mocks={mocks}>
|
|
86
|
+
<ItemListNew {...props} />
|
|
87
|
+
</MockedProvider>
|
|
88
|
+
);
|
|
89
|
+
await waitFor(() => expect(getByText(props.text)).toBeInTheDocument());
|
|
90
|
+
expect(asFragment()).toMatchSnapshot();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should not render if list not found', async () => {
|
|
94
|
+
userItemListId.mockReturnValue({ listId: missingListId });
|
|
95
|
+
const { asFragment } = render(
|
|
96
|
+
<MockedProvider mocks={mocks}>
|
|
97
|
+
<ItemListNew {...props} listName={missingListId} />
|
|
98
|
+
</MockedProvider>
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
await waitFor(() => expect(getItemListData).toHaveBeenCalled());
|
|
102
|
+
expect(asFragment()).toMatchSnapshot();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should not render if list has not items', async () => {
|
|
106
|
+
userItemListId.mockReturnValue({ listId: emptyListId });
|
|
107
|
+
const { asFragment } = render(
|
|
108
|
+
<MockedProvider mocks={mocks}>
|
|
109
|
+
<ItemListNew {...props} listName={emptyListId} />
|
|
110
|
+
</MockedProvider>
|
|
111
|
+
);
|
|
112
|
+
await waitFor(() => expect(getItemListData).toHaveBeenCalled());
|
|
113
|
+
expect(asFragment()).toMatchSnapshot();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should clear id and redirect onclick', async () => {
|
|
117
|
+
userItemListId.mockReturnValue({ listId });
|
|
118
|
+
const { getByText } = render(
|
|
119
|
+
<MockedProvider mocks={mocks}>
|
|
120
|
+
<ItemListNew {...props} />
|
|
121
|
+
</MockedProvider>
|
|
122
|
+
);
|
|
123
|
+
await waitFor(() => expect(getByText(props.text)).toBeInTheDocument());
|
|
124
|
+
fireEvent.click(getByText(props.text));
|
|
125
|
+
expect(setItemListId).toHaveBeenCalledWith(props.listName, '');
|
|
126
|
+
expect(setParamAndRedirect).toHaveBeenCalled();
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`ItemListButton component should add and remove item to the list on click 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<div
|
|
6
|
+
class="item-list-button item-list-button--selected modifier"
|
|
7
|
+
role="button"
|
|
8
|
+
>
|
|
9
|
+
<i>
|
|
10
|
+
<svg
|
|
11
|
+
fill="currentColor"
|
|
12
|
+
height="1em"
|
|
13
|
+
stroke="currentColor"
|
|
14
|
+
stroke-width="0"
|
|
15
|
+
viewBox="0 0 16 16"
|
|
16
|
+
width="1em"
|
|
17
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
18
|
+
>
|
|
19
|
+
<path
|
|
20
|
+
d="M2 15.5V2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v13.5a.5.5 0 0 1-.74.439L8 13.069l-5.26 2.87A.5.5 0 0 1 2 15.5zm8.854-9.646a.5.5 0 0 0-.708-.708L7.5 7.793 6.354 6.646a.5.5 0 1 0-.708.708l1.5 1.5a.5.5 0 0 0 .708 0l3-3z"
|
|
21
|
+
fill-rule="evenodd"
|
|
22
|
+
/>
|
|
23
|
+
</svg>
|
|
24
|
+
</i>
|
|
25
|
+
</div>
|
|
26
|
+
</DocumentFragment>
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
exports[`ItemListButton component should add and remove item to the list on click 2`] = `
|
|
30
|
+
<DocumentFragment>
|
|
31
|
+
<div
|
|
32
|
+
class="item-list-button item-list-button--selected modifier"
|
|
33
|
+
role="button"
|
|
34
|
+
>
|
|
35
|
+
<i>
|
|
36
|
+
<svg
|
|
37
|
+
fill="currentColor"
|
|
38
|
+
height="1em"
|
|
39
|
+
stroke="currentColor"
|
|
40
|
+
stroke-width="0"
|
|
41
|
+
viewBox="0 0 16 16"
|
|
42
|
+
width="1em"
|
|
43
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
44
|
+
>
|
|
45
|
+
<path
|
|
46
|
+
d="M2 15.5V2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v13.5a.5.5 0 0 1-.74.439L8 13.069l-5.26 2.87A.5.5 0 0 1 2 15.5zm8.854-9.646a.5.5 0 0 0-.708-.708L7.5 7.793 6.354 6.646a.5.5 0 1 0-.708.708l1.5 1.5a.5.5 0 0 0 .708 0l3-3z"
|
|
47
|
+
fill-rule="evenodd"
|
|
48
|
+
/>
|
|
49
|
+
</svg>
|
|
50
|
+
</i>
|
|
51
|
+
</div>
|
|
52
|
+
</DocumentFragment>
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
exports[`ItemListButton component should render button marked selected when current parent is in the list 1`] = `
|
|
56
|
+
<DocumentFragment>
|
|
57
|
+
<div
|
|
58
|
+
class="item-list-button item-list-button--selected modifier"
|
|
59
|
+
role="button"
|
|
60
|
+
>
|
|
61
|
+
<i>
|
|
62
|
+
<svg
|
|
63
|
+
fill="currentColor"
|
|
64
|
+
height="1em"
|
|
65
|
+
stroke="currentColor"
|
|
66
|
+
stroke-width="0"
|
|
67
|
+
viewBox="0 0 16 16"
|
|
68
|
+
width="1em"
|
|
69
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
70
|
+
>
|
|
71
|
+
<path
|
|
72
|
+
d="M2 15.5V2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v13.5a.5.5 0 0 1-.74.439L8 13.069l-5.26 2.87A.5.5 0 0 1 2 15.5zm8.854-9.646a.5.5 0 0 0-.708-.708L7.5 7.793 6.354 6.646a.5.5 0 1 0-.708.708l1.5 1.5a.5.5 0 0 0 .708 0l3-3z"
|
|
73
|
+
fill-rule="evenodd"
|
|
74
|
+
/>
|
|
75
|
+
</svg>
|
|
76
|
+
</i>
|
|
77
|
+
</div>
|
|
78
|
+
</DocumentFragment>
|
|
79
|
+
`;
|
|
80
|
+
|
|
81
|
+
exports[`ItemListButton component should render button not marked selected when current parent is not in the list 1`] = `
|
|
82
|
+
<DocumentFragment>
|
|
83
|
+
<div
|
|
84
|
+
class="item-list-button modifier"
|
|
85
|
+
role="button"
|
|
86
|
+
>
|
|
87
|
+
<i>
|
|
88
|
+
<svg
|
|
89
|
+
fill="currentColor"
|
|
90
|
+
height="1em"
|
|
91
|
+
stroke="currentColor"
|
|
92
|
+
stroke-width="0"
|
|
93
|
+
viewBox="0 0 16 16"
|
|
94
|
+
width="1em"
|
|
95
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
96
|
+
>
|
|
97
|
+
<path
|
|
98
|
+
d="M7.84 4.1a.178.178 0 0 1 .32 0l.634 1.285a.178.178 0 0 0 .134.098l1.42.206c.145.021.204.2.098.303L9.42 6.993a.178.178 0 0 0-.051.158l.242 1.414a.178.178 0 0 1-.258.187l-1.27-.668a.178.178 0 0 0-.165 0l-1.27.668a.178.178 0 0 1-.257-.187l.242-1.414a.178.178 0 0 0-.05-.158l-1.03-1.001a.178.178 0 0 1 .098-.303l1.42-.206a.178.178 0 0 0 .134-.098L7.84 4.1z"
|
|
99
|
+
/>
|
|
100
|
+
<path
|
|
101
|
+
d="M2 2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v13.5a.5.5 0 0 1-.777.416L8 13.101l-5.223 2.815A.5.5 0 0 1 2 15.5V2zm2-1a1 1 0 0 0-1 1v12.566l4.723-2.482a.5.5 0 0 1 .554 0L13 14.566V2a1 1 0 0 0-1-1H4z"
|
|
102
|
+
/>
|
|
103
|
+
</svg>
|
|
104
|
+
</i>
|
|
105
|
+
</div>
|
|
106
|
+
</DocumentFragment>
|
|
107
|
+
`;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`ItemListCounter component should display listItem count and route to url 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<div
|
|
6
|
+
class="item-list-counter modifier"
|
|
7
|
+
role="button"
|
|
8
|
+
type="button"
|
|
9
|
+
>
|
|
10
|
+
<svg
|
|
11
|
+
fill="currentColor"
|
|
12
|
+
height="1em"
|
|
13
|
+
stroke="currentColor"
|
|
14
|
+
stroke-width="0"
|
|
15
|
+
viewBox="0 0 16 16"
|
|
16
|
+
width="1em"
|
|
17
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
18
|
+
>
|
|
19
|
+
<path
|
|
20
|
+
d="M2 15.5V2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v13.5a.5.5 0 0 1-.74.439L8 13.069l-5.26 2.87A.5.5 0 0 1 2 15.5zM8.16 4.1a.178.178 0 0 0-.32 0l-.634 1.285a.178.178 0 0 1-.134.098l-1.42.206a.178.178 0 0 0-.098.303L6.58 6.993c.042.041.061.1.051.158L6.39 8.565a.178.178 0 0 0 .258.187l1.27-.668a.178.178 0 0 1 .165 0l1.27.668a.178.178 0 0 0 .257-.187L9.368 7.15a.178.178 0 0 1 .05-.158l1.028-1.001a.178.178 0 0 0-.098-.303l-1.42-.206a.178.178 0 0 1-.134-.098L8.16 4.1z"
|
|
21
|
+
fill-rule="evenodd"
|
|
22
|
+
/>
|
|
23
|
+
</svg>
|
|
24
|
+
<span
|
|
25
|
+
class="item-list-counter__badge"
|
|
26
|
+
>
|
|
27
|
+
1
|
|
28
|
+
</span>
|
|
29
|
+
</div>
|
|
30
|
+
</DocumentFragment>
|
|
31
|
+
`;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`ItemListNew component should match snapshot and render without throwing an error 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<button
|
|
6
|
+
class="item-list-new button"
|
|
7
|
+
type="button"
|
|
8
|
+
>
|
|
9
|
+
Clear list
|
|
10
|
+
</button>
|
|
11
|
+
</DocumentFragment>
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
exports[`ItemListNew component should not render if list has not items 1`] = `<DocumentFragment />`;
|
|
15
|
+
|
|
16
|
+
exports[`ItemListNew component should not render if list not found 1`] = `<DocumentFragment />`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@testing-library/jest-dom/extend-expect';
|
|
2
|
-
import getItemListData from '
|
|
2
|
+
import getItemListData from '../../../../../../src/components/ItemList/helpers/get-item-list-data';
|
|
3
3
|
|
|
4
4
|
describe('getItemListData helper', () => {
|
|
5
5
|
const noData = getItemListData();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@testing-library/jest-dom/extend-expect';
|
|
2
|
-
import getitemListId from '
|
|
2
|
+
import getitemListId from '../../../../../../src/components/ItemList/helpers/get-item-list-id';
|
|
3
3
|
|
|
4
4
|
describe('getitemListId helper', () => {
|
|
5
5
|
const noValues = getitemListId();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@testing-library/jest-dom/extend-expect';
|
|
2
|
-
import getitemListIds from '
|
|
2
|
+
import getitemListIds from '../../../../../../src/components/ItemList/helpers/get-item-list-ids';
|
|
3
3
|
|
|
4
4
|
describe('getitemListIds helper', () => {
|
|
5
5
|
const noData = getitemListIds();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
2
|
+
import setItemListId from '../../../../../../src/components/ItemList/helpers/set-item-list-id';
|
|
3
|
+
import { LIST_ITEM_LOCAL_KEY } from '../../../../../../src/components/ItemList/constants';
|
|
4
|
+
|
|
5
|
+
describe('setItemListId helper', () => {
|
|
6
|
+
const listId = 'LIST ID';
|
|
7
|
+
const listName = 'LIST';
|
|
8
|
+
|
|
9
|
+
it('should set list id in localstorage', () => {
|
|
10
|
+
setItemListId(listName, listId);
|
|
11
|
+
expect(localStorage.setItem).toHaveBeenCalledWith(`${LIST_ITEM_LOCAL_KEY}${listName}`, listId);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
2
|
+
import setParamAndRedirect from '../../../../../../src/components/ItemList/helpers/set-param-and-redirect';
|
|
3
|
+
import { LIST_ITEM_QUERY_PARAM } from '../../../../../../src/components/ItemList/constants';
|
|
4
|
+
|
|
5
|
+
describe('setParamAndRedirect helper', () => {
|
|
6
|
+
const url = '/test?otherParam=abc';
|
|
7
|
+
const urlWithQueryString = `${url}&${LIST_ITEM_QUERY_PARAM}=123`;
|
|
8
|
+
|
|
9
|
+
it('should return if no value and queryParam not present', () => {
|
|
10
|
+
const router = { asPath: url, push: jest.fn() };
|
|
11
|
+
expect(setParamAndRedirect(router)).toBeUndefined();
|
|
12
|
+
expect(router.push).not.toHaveBeenCalled();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should remove queryString if no value passed', () => {
|
|
16
|
+
const router = { asPath: urlWithQueryString, push: jest.fn() };
|
|
17
|
+
expect(setParamAndRedirect(router)).toBeUndefined();
|
|
18
|
+
expect(router.push).toHaveBeenCalledWith('/Resolver', url, {
|
|
19
|
+
shallow: true
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should add queryString if value passed', () => {
|
|
24
|
+
const router = { asPath: url, push: jest.fn() };
|
|
25
|
+
expect(setParamAndRedirect(router, '123')).toBeUndefined();
|
|
26
|
+
expect(router.push).toHaveBeenCalledWith('/Resolver', urlWithQueryString, {
|
|
27
|
+
shallow: true
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { renderHook, act } from '@testing-library/react-hooks';
|
|
2
|
+
import useItemListId from '../../../../../../src/components/ItemList/hooks/use-item-list-id';
|
|
3
|
+
import getItemListId from '../../../../../../src/components/ItemList/helpers/get-item-list-id';
|
|
4
|
+
|
|
5
|
+
jest.mock('../../../../../../src/components/ItemList/helpers/get-item-list-id', () =>
|
|
6
|
+
jest.fn(() => 'LIST ID')
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
describe('useItemListId hook', () => {
|
|
10
|
+
const listId = 'LIST ID';
|
|
11
|
+
const listName = 'LIST';
|
|
12
|
+
|
|
13
|
+
it('should return listId ', () => {
|
|
14
|
+
const { result } = renderHook(() => useItemListId({ listName }));
|
|
15
|
+
expect(result.current).toEqual({ listId });
|
|
16
|
+
expect(getItemListId).toHaveBeenCalledWith(listName);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should return listId after storage event', () => {
|
|
20
|
+
const noListValue = 'empty';
|
|
21
|
+
getItemListId.mockReturnValueOnce(noListValue);
|
|
22
|
+
const { result } = renderHook(() => useItemListId({ listName }));
|
|
23
|
+
expect(result.current).toEqual({ listId: noListValue });
|
|
24
|
+
|
|
25
|
+
act(() => {
|
|
26
|
+
window.dispatchEvent(new Event('storage'));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
expect(result.current).toEqual({ listId });
|
|
30
|
+
expect(getItemListId).toHaveBeenNthCalledWith(2, listName);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -54,6 +54,10 @@ Object {
|
|
|
54
54
|
"$$typeof": Symbol(react.forward_ref),
|
|
55
55
|
"render": [Function],
|
|
56
56
|
},
|
|
57
|
+
"itemlistnew": Object {
|
|
58
|
+
"$$typeof": Symbol(react.forward_ref),
|
|
59
|
+
"render": [Function],
|
|
60
|
+
},
|
|
57
61
|
"list": Object {
|
|
58
62
|
"$$typeof": Symbol(react.forward_ref),
|
|
59
63
|
"render": [Function],
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ItemListButton.js","names":["ItemListButton","listName","parent","modifier","itemId","itemEntity","idFromStorage","getItemListId","useState","listId","setListId","isHover","setIsHover","useEffect","storageEventHandler","newId","window","addEventListener","removeEventListener","getIcon","isInList","BsBookmarkXFill","BsBookmarkCheckFill","BsBookmarkStarFill","BsBookmarkStar","useQuery","getItemList","variables","id","skip","data","error","loading","useMutation","addItemsToList","onCompleted","listAddResult","result","localListName","LIST_ITEM_LOCAL_KEY","localStorage","setItem","dispatchEvent","Event","addListItem","removeItemsFromList","removeListItem","clickHandler","listItems","name","message","getItemListData","find","idToCheck","Icon","propTypes","PropTypes","object","string","defaultProps"],"sources":["../../../src/components/ItemListButton/ItemListButton.js"],"sourcesContent":["import React, { useState, useEffect } from 'react';\nimport PropTypes from 'prop-types';\nimport {\n BsBookmarkStarFill,\n BsBookmarkCheckFill,\n BsBookmarkStar,\n BsBookmarkXFill\n} from 'react-icons/bs';\nimport { useQuery, useMutation } from '@apollo/client';\nimport { getItemList, addItemsToList, removeItemsFromList } from '../../application/query';\nimport { getItemListData, getItemListId } from '../../helpers';\nimport { LIST_ITEM_LOCAL_KEY } from '../../constants';\n\nconst ItemListButton = ({ listName, parent, modifier }) => {\n const { itemId, itemEntity } = parent;\n const idFromStorage = getItemListId(listName);\n const [listId, setListId] = useState(idFromStorage);\n const [isHover, setIsHover] = useState(false);\n\n useEffect(\n () => {\n const storageEventHandler = () => {\n const newId = getItemListId(listName);\n setListId(newId);\n };\n\n window.addEventListener('storage', storageEventHandler);\n\n return () => {\n window.removeEventListener('storage', storageEventHandler);\n };\n },\n [listName]\n );\n const getIcon = () => {\n if (isInList) return isHover ? BsBookmarkXFill : BsBookmarkCheckFill;\n return isHover ? BsBookmarkStarFill : BsBookmarkStar;\n };\n\n const { data, error, loading } = useQuery(getItemList, {\n variables: { id: listId },\n skip: !listId\n });\n\n const [addListItem] = useMutation(addItemsToList, {\n onCompleted: ({ addItemsToList: listAddResult }) => {\n const {\n result: { id }\n } = listAddResult;\n\n if (!listId) {\n const localListName = `${LIST_ITEM_LOCAL_KEY}${listName}`;\n localStorage.setItem(localListName, id);\n window.dispatchEvent(new Event('storage'));\n }\n }\n });\n\n const [removeListItem] = useMutation(removeItemsFromList);\n\n const clickHandler = () => {\n setIsHover(false);\n isInList\n ? removeListItem({\n variables: { listId, listItems: [{ itemId, itemEntity }] },\n skip: !listId\n })\n : addListItem({\n variables: { name: listName, id: listId, listItems: [{ itemId, itemEntity }] },\n skip: !listId\n });\n };\n\n if (loading) return '';\n if (error) return error.message;\n\n const listItems = getItemListData(data);\n const isInList = !!listItems.find(({ itemId: idToCheck }) => idToCheck === itemId);\n const Icon = getIcon();\n\n return (\n <div\n className={`item-list-button ${modifier}`}\n role=\"button\"\n onClick={clickHandler}\n onMouseEnter={() => setIsHover(true)}\n onMouseLeave={() => setIsHover(false)}>\n <i>\n <Icon />\n </i>\n </div>\n );\n};\n\nItemListButton.propTypes = {\n parent: PropTypes.object,\n listName: PropTypes.string,\n modifier: PropTypes.string\n};\n\nItemListButton.defaultProps = {\n parent: {},\n listName: '',\n modifier: ''\n};\n\nexport default ItemListButton;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,OAAoC;EAAA,IAAjCC,QAAiC,QAAjCA,QAAiC;EAAA,IAAvBC,MAAuB,QAAvBA,MAAuB;EAAA,IAAfC,QAAe,QAAfA,QAAe;EACzD,IAAQC,MAAR,GAA+BF,MAA/B,CAAQE,MAAR;EAAA,IAAgBC,UAAhB,GAA+BH,MAA/B,CAAgBG,UAAhB;EACA,IAAMC,aAAa,GAAG,IAAAC,sBAAA,EAAcN,QAAd,CAAtB;;EACA,gBAA4B,IAAAO,eAAA,EAASF,aAAT,CAA5B;EAAA;EAAA,IAAOG,MAAP;EAAA,IAAeC,SAAf;;EACA,iBAA8B,IAAAF,eAAA,EAAS,KAAT,CAA9B;EAAA;EAAA,IAAOG,OAAP;EAAA,IAAgBC,UAAhB;;EAEA,IAAAC,gBAAA,EACE,YAAM;IACJ,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,GAAM;MAChC,IAAMC,KAAK,GAAG,IAAAR,sBAAA,EAAcN,QAAd,CAAd;MACAS,SAAS,CAACK,KAAD,CAAT;IACD,CAHD;;IAKAC,MAAM,CAACC,gBAAP,CAAwB,SAAxB,EAAmCH,mBAAnC;IAEA,OAAO,YAAM;MACXE,MAAM,CAACE,mBAAP,CAA2B,SAA3B,EAAsCJ,mBAAtC;IACD,CAFD;EAGD,CAZH,EAaE,CAACb,QAAD,CAbF;;EAeA,IAAMk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 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["ItemListButton"],"sources":["../../../src/components/ItemListButton/index.js"],"sourcesContent":["import ItemListButton from './ItemListButton';\n\nexport default ItemListButton;\n"],"mappings":";;;;;;;;;;;AAAA;;eAEeA,0B"}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/es.array.iterator.js");
|
|
4
|
-
|
|
5
|
-
require("core-js/modules/es.object.to-string.js");
|
|
6
|
-
|
|
7
|
-
require("core-js/modules/es.string.iterator.js");
|
|
8
|
-
|
|
9
|
-
require("core-js/modules/es.weak-map.js");
|
|
10
|
-
|
|
11
|
-
require("core-js/modules/web.dom-collections.iterator.js");
|
|
12
|
-
|
|
13
|
-
require("core-js/modules/es.object.define-property.js");
|
|
14
|
-
|
|
15
|
-
require("core-js/modules/es.object.get-own-property-descriptor.js");
|
|
16
|
-
|
|
17
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
18
|
-
|
|
19
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
20
|
-
|
|
21
|
-
Object.defineProperty(exports, "__esModule", {
|
|
22
|
-
value: true
|
|
23
|
-
});
|
|
24
|
-
exports["default"] = void 0;
|
|
25
|
-
|
|
26
|
-
require("core-js/modules/es.array.concat.js");
|
|
27
|
-
|
|
28
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
29
|
-
|
|
30
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
31
|
-
|
|
32
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
33
|
-
|
|
34
|
-
var _router = require("next/router");
|
|
35
|
-
|
|
36
|
-
var _client = require("@apollo/client");
|
|
37
|
-
|
|
38
|
-
var _bs = require("react-icons/bs");
|
|
39
|
-
|
|
40
|
-
var _query = require("../../application/query");
|
|
41
|
-
|
|
42
|
-
var _helpers = require("../../helpers");
|
|
43
|
-
|
|
44
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
45
|
-
|
|
46
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
47
|
-
|
|
48
|
-
var ItemListCounter = function ItemListCounter(_ref) {
|
|
49
|
-
var listName = _ref.listName,
|
|
50
|
-
modifier = _ref.modifier,
|
|
51
|
-
url = _ref.url;
|
|
52
|
-
var router = (0, _router.useRouter)();
|
|
53
|
-
var idFromStorage = (0, _helpers.getItemListId)(listName);
|
|
54
|
-
|
|
55
|
-
var _useState = (0, _react.useState)(idFromStorage),
|
|
56
|
-
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
57
|
-
listId = _useState2[0],
|
|
58
|
-
setListId = _useState2[1];
|
|
59
|
-
|
|
60
|
-
(0, _react.useEffect)(function () {
|
|
61
|
-
var storageEventHandler = function storageEventHandler() {
|
|
62
|
-
var newId = (0, _helpers.getItemListId)(listName);
|
|
63
|
-
setListId(newId);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
window.addEventListener('storage', storageEventHandler);
|
|
67
|
-
return function () {
|
|
68
|
-
window.removeEventListener('storage', storageEventHandler);
|
|
69
|
-
};
|
|
70
|
-
}, [listName]);
|
|
71
|
-
|
|
72
|
-
var _useQuery = (0, _client.useQuery)(_query.getItemList, {
|
|
73
|
-
variables: {
|
|
74
|
-
id: listId
|
|
75
|
-
},
|
|
76
|
-
skip: !listId
|
|
77
|
-
}),
|
|
78
|
-
data = _useQuery.data,
|
|
79
|
-
error = _useQuery.error,
|
|
80
|
-
loading = _useQuery.loading;
|
|
81
|
-
|
|
82
|
-
if (loading) return '';
|
|
83
|
-
if (error) return error.message;
|
|
84
|
-
var listItems = (0, _helpers.getItemListData)(data);
|
|
85
|
-
var listLength = listItems.length;
|
|
86
|
-
var CounterIcon = listLength ? _bs.BsBookmarkStarFill : _bs.BsBookmarkStar;
|
|
87
|
-
|
|
88
|
-
var handleClick = function handleClick() {
|
|
89
|
-
return router.push('/Resolver', "".concat(url, "?itemListId=").concat(listId));
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
93
|
-
role: "button",
|
|
94
|
-
type: "button",
|
|
95
|
-
className: "item-list-counter ".concat(modifier),
|
|
96
|
-
onClick: handleClick
|
|
97
|
-
}, /*#__PURE__*/_react["default"].createElement(CounterIcon, null), /*#__PURE__*/_react["default"].createElement("span", {
|
|
98
|
-
className: "item-list-counter__badge"
|
|
99
|
-
}, listLength));
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
ItemListCounter.propTypes = {
|
|
103
|
-
url: _propTypes["default"].string,
|
|
104
|
-
listName: _propTypes["default"].string,
|
|
105
|
-
modifier: _propTypes["default"].string
|
|
106
|
-
};
|
|
107
|
-
ItemListCounter.defaultProps = {
|
|
108
|
-
url: '',
|
|
109
|
-
listName: '',
|
|
110
|
-
modifier: ''
|
|
111
|
-
};
|
|
112
|
-
var _default = ItemListCounter;
|
|
113
|
-
exports["default"] = _default;
|
|
114
|
-
//# sourceMappingURL=ItemListCounter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ItemListCounter.js","names":["ItemListCounter","listName","modifier","url","router","useRouter","idFromStorage","getItemListId","useState","listId","setListId","useEffect","storageEventHandler","newId","window","addEventListener","removeEventListener","useQuery","getItemList","variables","id","skip","data","error","loading","message","listItems","getItemListData","listLength","length","CounterIcon","BsBookmarkStarFill","BsBookmarkStar","handleClick","push","propTypes","PropTypes","string","defaultProps"],"sources":["../../../src/components/ItemListCounter/ItemListCounter.js"],"sourcesContent":["import React, { useState, useEffect } from 'react';\nimport PropTypes from 'prop-types';\nimport { useRouter } from 'next/router';\nimport { useQuery } from '@apollo/client';\nimport { BsBookmarkStarFill, BsBookmarkStar } from 'react-icons/bs';\nimport { getItemList } from '../../application/query';\nimport { getItemListData, getItemListId } from '../../helpers';\n\nconst ItemListCounter = ({ listName, modifier, url }) => {\n const router = useRouter();\n const idFromStorage = getItemListId(listName);\n const [listId, setListId] = useState(idFromStorage);\n\n useEffect(\n () => {\n const storageEventHandler = () => {\n const newId = getItemListId(listName);\n setListId(newId);\n };\n\n window.addEventListener('storage', storageEventHandler);\n\n return () => {\n window.removeEventListener('storage', storageEventHandler);\n };\n },\n [listName]\n );\n\n const { data, error, loading } = useQuery(getItemList, {\n variables: { id: listId },\n skip: !listId\n });\n\n if (loading) return '';\n if (error) return error.message;\n\n const listItems = getItemListData(data);\n const listLength = listItems.length;\n const CounterIcon = listLength ? BsBookmarkStarFill : BsBookmarkStar;\n\n const handleClick = () => router.push('/Resolver', `${url}?itemListId=${listId}`);\n\n return (\n <div\n role=\"button\"\n type=\"button\"\n className={`item-list-counter ${modifier}`}\n onClick={handleClick}>\n <CounterIcon />\n <span className=\"item-list-counter__badge\">{listLength}</span>\n </div>\n );\n};\n\nItemListCounter.propTypes = {\n url: PropTypes.string,\n listName: PropTypes.string,\n modifier: PropTypes.string\n};\n\nItemListCounter.defaultProps = {\n url: '',\n listName: '',\n modifier: ''\n};\n\nexport default ItemListCounter;\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AGF,SAAS,CAACG,MAA7B;EACA,IAAMC,WAAW,GAAGF,UAAU,GAAGG,sBAAH,GAAwBC,kBAAtD;;EAEA,IAAMC,WAAW,GAAG,SAAdA,WAAc;IAAA,OAAM7B,MAAM,CAAC8B,IAAP,CAAY,WAAZ,YAA4B/B,GAA5B,yBAA8CM,MAA9C,EAAN;EAAA,CAApB;;EAEA,oBACE;IACE,IAAI,EAAC,QADP;IAEE,IAAI,EAAC,QAFP;IAGE,SAAS,8BAAuBP,QAAvB,CAHX;IAIE,OAAO,EAAE+B;EAJX,gBAKE,gCAAC,WAAD,OALF,eAME;IAAM,SAAS,EAAC;EAAhB,GAA4CL,UAA5C,CANF,CADF;AAUD,CA7CD;;AA+CA5B,eAAe,CAACmC,SAAhB,GAA4B;EAC1BhC,GAAG,EAAEiC,qBAAA,CAAUC,MADW;EAE1BpC,QAAQ,EAAEmC,qBAAA,CAAUC,MAFM;EAG1BnC,QAAQ,EAAEkC,qBAAA,CAAUC;AAHM,CAA5B;AAMArC,eAAe,CAACsC,YAAhB,GAA+B;EAC7BnC,GAAG,EAAE,EADwB;EAE7BF,QAAQ,EAAE,EAFmB;EAG7BC,QAAQ,EAAE;AAHmB,CAA/B;eAMeF,e"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["ItemListCounter"],"sources":["../../../src/components/ItemListCounter/index.js"],"sourcesContent":["import ItemListCounter from './ItemListCounter';\n\nexport default ItemListCounter;\n"],"mappings":";;;;;;;;;;;AAAA;;eAEeA,2B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-item-list-data.js","names":["getItemListData","data","getItemList","listItems"],"sources":["../../src/helpers/get-item-list-data.js"],"sourcesContent":["const getItemListData = data => {\n if (data && data.getItemList && data.getItemList.listItems) return data.getItemList.listItems;\n return [];\n};\n\nexport default getItemListData;\n"],"mappings":";;;;;;;;;AAAA,IAAMA,eAAe,GAAG,SAAlBA,eAAkB,CAAAC,IAAI,EAAI;EAC9B,IAAIA,IAAI,IAAIA,IAAI,CAACC,WAAb,IAA4BD,IAAI,CAACC,WAAL,CAAiBC,SAAjD,EAA4D,OAAOF,IAAI,CAACC,WAAL,CAAiBC,SAAxB;EAC5D,OAAO,EAAP;AACD,CAHD;;eAKeH,e"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-item-list-id.js","names":["getItemListId","listName","queryId","localStorage","localListName","LIST_ITEM_LOCAL_KEY","getItem"],"sources":["../../src/helpers/get-item-list-id.js"],"sourcesContent":["import { LIST_ITEM_LOCAL_KEY } from '../constants';\n\nconst getItemListId = (listName, queryId) => {\n if (queryId) return queryId;\n if (!listName || typeof localStorage === 'undefined') return '';\n\n const localListName = `${LIST_ITEM_LOCAL_KEY}${listName}`;\n return localStorage.getItem(localListName) || '';\n};\n\nexport default getItemListId;\n"],"mappings":";;;;;;;;;;;AAAA;;AAEA,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,CAACC,QAAD,EAAWC,OAAX,EAAuB;EAC3C,IAAIA,OAAJ,EAAa,OAAOA,OAAP;EACb,IAAI,CAACD,QAAD,IAAa,OAAOE,YAAP,KAAwB,WAAzC,EAAsD,OAAO,EAAP;EAEtD,IAAMC,aAAa,aAAMC,8BAAN,SAA4BJ,QAA5B,CAAnB;EACA,OAAOE,YAAY,CAACG,OAAb,CAAqBF,aAArB,KAAuC,EAA9C;AACD,CAND;;eAQeJ,a"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-item-list-ids.js","names":["getItemListIds","data","itemListElements","getItemListData","length","map","itemId","displayItems"],"sources":["../../src/helpers/get-item-list-ids.js"],"sourcesContent":["import getItemListData from './get-item-list-data';\n\nconst getItemListIds = data => {\n const itemListElements = getItemListData(data);\n return itemListElements.length\n ? itemListElements.map(({ itemId }) => ({ displayItems: [itemId] }))\n : null;\n};\n\nexport default getItemListIds;\n"],"mappings":";;;;;;;;;;;;;AAAA;;AAEA,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAAAC,IAAI,EAAI;EAC7B,IAAMC,gBAAgB,GAAG,IAAAC,2BAAA,EAAgBF,IAAhB,CAAzB;EACA,OAAOC,gBAAgB,CAACE,MAAjB,GACHF,gBAAgB,CAACG,GAAjB,CAAqB;IAAA,IAAGC,MAAH,QAAGA,MAAH;IAAA,OAAiB;MAAEC,YAAY,EAAE,CAACD,MAAD;IAAhB,CAAjB;EAAA,CAArB,CADG,GAEH,IAFJ;AAGD,CALD;;eAOeN,c"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ItemListButton.js","names":["React","useState","useEffect","PropTypes","BsBookmarkStarFill","BsBookmarkCheckFill","BsBookmarkStar","BsBookmarkXFill","useQuery","useMutation","getItemList","addItemsToList","removeItemsFromList","getItemListData","getItemListId","LIST_ITEM_LOCAL_KEY","ItemListButton","listName","parent","modifier","itemId","itemEntity","idFromStorage","listId","setListId","isHover","setIsHover","storageEventHandler","newId","window","addEventListener","removeEventListener","getIcon","isInList","data","error","loading","variables","id","skip","addListItem","onCompleted","listAddResult","result","localListName","localStorage","setItem","dispatchEvent","Event","removeListItem","clickHandler","listItems","name","message","find","idToCheck","Icon","propTypes","object","string","defaultProps"],"sources":["../../../src/components/ItemListButton/ItemListButton.js"],"sourcesContent":["import React, { useState, useEffect } from 'react';\nimport PropTypes from 'prop-types';\nimport {\n BsBookmarkStarFill,\n BsBookmarkCheckFill,\n BsBookmarkStar,\n BsBookmarkXFill\n} from 'react-icons/bs';\nimport { useQuery, useMutation } from '@apollo/client';\nimport { getItemList, addItemsToList, removeItemsFromList } from '../../application/query';\nimport { getItemListData, getItemListId } from '../../helpers';\nimport { LIST_ITEM_LOCAL_KEY } from '../../constants';\n\nconst ItemListButton = ({ listName, parent, modifier }) => {\n const { itemId, itemEntity } = parent;\n const idFromStorage = getItemListId(listName);\n const [listId, setListId] = useState(idFromStorage);\n const [isHover, setIsHover] = useState(false);\n\n useEffect(\n () => {\n const storageEventHandler = () => {\n const newId = getItemListId(listName);\n setListId(newId);\n };\n\n window.addEventListener('storage', storageEventHandler);\n\n return () => {\n window.removeEventListener('storage', storageEventHandler);\n };\n },\n [listName]\n );\n const getIcon = () => {\n if (isInList) return isHover ? BsBookmarkXFill : BsBookmarkCheckFill;\n return isHover ? BsBookmarkStarFill : BsBookmarkStar;\n };\n\n const { data, error, loading } = useQuery(getItemList, {\n variables: { id: listId },\n skip: !listId\n });\n\n const [addListItem] = useMutation(addItemsToList, {\n onCompleted: ({ addItemsToList: listAddResult }) => {\n const {\n result: { id }\n } = listAddResult;\n\n if (!listId) {\n const localListName = `${LIST_ITEM_LOCAL_KEY}${listName}`;\n localStorage.setItem(localListName, id);\n window.dispatchEvent(new Event('storage'));\n }\n }\n });\n\n const [removeListItem] = useMutation(removeItemsFromList);\n\n const clickHandler = () => {\n setIsHover(false);\n isInList\n ? removeListItem({\n variables: { listId, listItems: [{ itemId, itemEntity }] },\n skip: !listId\n })\n : addListItem({\n variables: { name: listName, id: listId, listItems: [{ itemId, itemEntity }] },\n skip: !listId\n });\n };\n\n if (loading) return '';\n if (error) return error.message;\n\n const listItems = getItemListData(data);\n const isInList = !!listItems.find(({ itemId: idToCheck }) => idToCheck === itemId);\n const Icon = getIcon();\n\n return (\n <div\n className={`item-list-button ${modifier}`}\n role=\"button\"\n onClick={clickHandler}\n onMouseEnter={() => setIsHover(true)}\n onMouseLeave={() => setIsHover(false)}>\n <i>\n <Icon />\n </i>\n </div>\n );\n};\n\nItemListButton.propTypes = {\n parent: PropTypes.object,\n listName: PropTypes.string,\n modifier: PropTypes.string\n};\n\nItemListButton.defaultProps = {\n parent: {},\n listName: '',\n modifier: ''\n};\n\nexport default ItemListButton;\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,SAA1B,QAA2C,OAA3C;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,SACEC,kBADF,EAEEC,mBAFF,EAGEC,cAHF,EAIEC,eAJ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SAAS,KAAKnC,MAAxD,CAAnB;EACA,MAAMoC,IAAI,GAAGxB,OAAO,EAApB;EAEA,oBACE;IACE,SAAS,EAAG,oBAAmBb,QAAS,EAD1C;IAEE,IAAI,EAAC,QAFP;IAGE,OAAO,EAAE+B,YAHX;IAIE,YAAY,EAAE,MAAMxB,UAAU,CAAC,IAAD,CAJhC;IAKE,YAAY,EAAE,MAAMA,UAAU,CAAC,KAAD;EALhC,gBAME,4CACE,oBAAC,IAAD,OADF,CANF,CADF;AAYD,CA/ED;;AAiFAV,cAAc,CAACyC,SAAf,GAA2B;EACzBvC,MAAM,EAAEf,SAAS,CAACuD,MADO;EAEzBzC,QAAQ,EAAEd,SAAS,CAACwD,MAFK;EAGzBxC,QAAQ,EAAEhB,SAAS,CAACwD;AAHK,CAA3B;AAMA3C,cAAc,CAAC4C,YAAf,GAA8B;EAC5B1C,MAAM,EAAE,EADoB;EAE5BD,QAAQ,EAAE,EAFkB;EAG5BE,QAAQ,EAAE;AAHkB,CAA9B;AAMA,eAAeH,cAAf"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["ItemListButton"],"sources":["../../../src/components/ItemListButton/index.js"],"sourcesContent":["import ItemListButton from './ItemListButton';\n\nexport default ItemListButton;\n"],"mappings":"AAAA,OAAOA,cAAP,MAA2B,kBAA3B;AAEA,eAAeA,cAAf"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ItemListCounter.js","names":["React","useState","useEffect","PropTypes","useRouter","useQuery","BsBookmarkStarFill","BsBookmarkStar","getItemList","getItemListData","getItemListId","ItemListCounter","listName","modifier","url","router","idFromStorage","listId","setListId","storageEventHandler","newId","window","addEventListener","removeEventListener","data","error","loading","variables","id","skip","message","listItems","listLength","length","CounterIcon","handleClick","push","propTypes","string","defaultProps"],"sources":["../../../src/components/ItemListCounter/ItemListCounter.js"],"sourcesContent":["import React, { useState, useEffect } from 'react';\nimport PropTypes from 'prop-types';\nimport { useRouter } from 'next/router';\nimport { useQuery } from '@apollo/client';\nimport { BsBookmarkStarFill, BsBookmarkStar } from 'react-icons/bs';\nimport { getItemList } from '../../application/query';\nimport { getItemListData, getItemListId } from '../../helpers';\n\nconst ItemListCounter = ({ listName, modifier, url }) => {\n const router = useRouter();\n const idFromStorage = getItemListId(listName);\n const [listId, setListId] = useState(idFromStorage);\n\n useEffect(\n () => {\n const storageEventHandler = () => {\n const newId = getItemListId(listName);\n setListId(newId);\n };\n\n window.addEventListener('storage', storageEventHandler);\n\n return () => {\n window.removeEventListener('storage', storageEventHandler);\n };\n },\n [listName]\n );\n\n const { data, error, loading } = useQuery(getItemList, {\n variables: { id: listId },\n skip: !listId\n });\n\n if (loading) return '';\n if (error) return error.message;\n\n const listItems = getItemListData(data);\n const listLength = listItems.length;\n const CounterIcon = listLength ? BsBookmarkStarFill : BsBookmarkStar;\n\n const handleClick = () => router.push('/Resolver', `${url}?itemListId=${listId}`);\n\n return (\n <div\n role=\"button\"\n type=\"button\"\n className={`item-list-counter ${modifier}`}\n onClick={handleClick}>\n <CounterIcon />\n <span className=\"item-list-counter__badge\">{listLength}</span>\n </div>\n );\n};\n\nItemListCounter.propTypes = {\n url: PropTypes.string,\n listName: PropTypes.string,\n modifier: PropTypes.string\n};\n\nItemListCounter.defaultProps = {\n url: '',\n listName: '',\n modifier: ''\n};\n\nexport default ItemListCounter;\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,SAA1B,QAA2C,OAA3C;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,SAASC,SAAT,QAA0B,aAA1B;AACA,SAASC,QAAT,QAAyB,gBAAzB;AACA,SAASC,kBAAT,EAA6BC,cAA7B,QAAmD,gBAAnD;AACA,SAASC,WAAT,QAA4B,yBAA5B;AACA,SAASC,eAAT,EAA0BC,aAA1B,QAA+C,eAA/C;;AAEA,MAAMC,eAAe,GAAG,CAAC;EAAEC,QAAF;EAAYC,QAAZ;EAAsBC;AAAtB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SAAS,EAAC;EAAhB,GAA4CH,UAA5C,CANF,CADF;AAUD,CA7CD;;AA+CArB,eAAe,CAAC0B,SAAhB,GAA4B;EAC1BvB,GAAG,EAAEX,SAAS,CAACmC,MADW;EAE1B1B,QAAQ,EAAET,SAAS,CAACmC,MAFM;EAG1BzB,QAAQ,EAAEV,SAAS,CAACmC;AAHM,CAA5B;AAMA3B,eAAe,CAAC4B,YAAhB,GAA+B;EAC7BzB,GAAG,EAAE,EADwB;EAE7BF,QAAQ,EAAE,EAFmB;EAG7BC,QAAQ,EAAE;AAHmB,CAA/B;AAMA,eAAeF,eAAf"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["ItemListCounter"],"sources":["../../../src/components/ItemListCounter/index.js"],"sourcesContent":["import ItemListCounter from './ItemListCounter';\n\nexport default ItemListCounter;\n"],"mappings":"AAAA,OAAOA,eAAP,MAA4B,mBAA5B;AAEA,eAAeA,eAAf"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-item-list-data.js","names":["getItemListData","data","getItemList","listItems"],"sources":["../../src/helpers/get-item-list-data.js"],"sourcesContent":["const getItemListData = data => {\n if (data && data.getItemList && data.getItemList.listItems) return data.getItemList.listItems;\n return [];\n};\n\nexport default getItemListData;\n"],"mappings":"AAAA,MAAMA,eAAe,GAAGC,IAAI,IAAI;EAC9B,IAAIA,IAAI,IAAIA,IAAI,CAACC,WAAb,IAA4BD,IAAI,CAACC,WAAL,CAAiBC,SAAjD,EAA4D,OAAOF,IAAI,CAACC,WAAL,CAAiBC,SAAxB;EAC5D,OAAO,EAAP;AACD,CAHD;;AAKA,eAAeH,eAAf"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-item-list-id.js","names":["LIST_ITEM_LOCAL_KEY","getItemListId","listName","queryId","localStorage","localListName","getItem"],"sources":["../../src/helpers/get-item-list-id.js"],"sourcesContent":["import { LIST_ITEM_LOCAL_KEY } from '../constants';\n\nconst getItemListId = (listName, queryId) => {\n if (queryId) return queryId;\n if (!listName || typeof localStorage === 'undefined') return '';\n\n const localListName = `${LIST_ITEM_LOCAL_KEY}${listName}`;\n return localStorage.getItem(localListName) || '';\n};\n\nexport default getItemListId;\n"],"mappings":"AAAA,SAASA,mBAAT,QAAoC,cAApC;;AAEA,MAAMC,aAAa,GAAG,CAACC,QAAD,EAAWC,OAAX,KAAuB;EAC3C,IAAIA,OAAJ,EAAa,OAAOA,OAAP;EACb,IAAI,CAACD,QAAD,IAAa,OAAOE,YAAP,KAAwB,WAAzC,EAAsD,OAAO,EAAP;EAEtD,MAAMC,aAAa,GAAI,GAAEL,mBAAoB,GAAEE,QAAS,EAAxD;EACA,OAAOE,YAAY,CAACE,OAAb,CAAqBD,aAArB,KAAuC,EAA9C;AACD,CAND;;AAQA,eAAeJ,aAAf"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-item-list-ids.js","names":["getItemListData","getItemListIds","data","itemListElements","length","map","itemId","displayItems"],"sources":["../../src/helpers/get-item-list-ids.js"],"sourcesContent":["import getItemListData from './get-item-list-data';\n\nconst getItemListIds = data => {\n const itemListElements = getItemListData(data);\n return itemListElements.length\n ? itemListElements.map(({ itemId }) => ({ displayItems: [itemId] }))\n : null;\n};\n\nexport default getItemListIds;\n"],"mappings":"AAAA,OAAOA,eAAP,MAA4B,sBAA5B;;AAEA,MAAMC,cAAc,GAAGC,IAAI,IAAI;EAC7B,MAAMC,gBAAgB,GAAGH,eAAe,CAACE,IAAD,CAAxC;EACA,OAAOC,gBAAgB,CAACC,MAAjB,GACHD,gBAAgB,CAACE,GAAjB,CAAqB,CAAC;IAAEC;EAAF,CAAD,MAAiB;IAAEC,YAAY,EAAE,CAACD,MAAD;EAAhB,CAAjB,CAArB,CADG,GAEH,IAFJ;AAGD,CALD;;AAOA,eAAeL,cAAf"}
|