@blaze-cms/react-page-builder 0.124.0-alpha.13 → 0.124.0-alpha.14
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/lib/application/query/index.js +8 -2
- package/lib/application/query/index.js.map +1 -1
- package/lib/components/Card/CardFactory.js +37 -5
- package/lib/components/Card/CardFactory.js.map +1 -1
- package/lib/components/ItemListButton/ItemListButton.js +168 -0
- package/lib/components/ItemListButton/ItemListButton.js.map +1 -0
- package/lib/components/ItemListButton/index.js +16 -0
- package/lib/components/ItemListButton/index.js.map +1 -0
- package/lib/components/ItemListCounter/ItemListCounter.js +96 -0
- package/lib/components/ItemListCounter/ItemListCounter.js.map +1 -0
- package/lib/components/ItemListCounter/index.js +16 -0
- package/lib/components/ItemListCounter/index.js.map +1 -0
- package/lib/components/List/ListBuilder.js +12 -6
- package/lib/components/List/ListBuilder.js.map +1 -1
- package/lib/components/List/ListFactory.js +26 -7
- package/lib/components/List/ListFactory.js.map +1 -1
- package/lib/components/index.js +10 -0
- package/lib/components/index.js.map +1 -1
- package/lib/constants/index.js +8 -2
- package/lib/constants/index.js.map +1 -1
- package/lib/helpers/build-raw-query.js.map +1 -1
- package/lib/helpers/get-item-list-data.js +17 -0
- package/lib/helpers/get-item-list-data.js.map +1 -0
- package/lib/helpers/get-item-list-id.js +20 -0
- package/lib/helpers/get-item-list-id.js.map +1 -0
- package/lib/helpers/get-item-list-ids.js +28 -0
- package/lib/helpers/get-item-list-ids.js.map +1 -0
- package/lib/helpers/index.js +24 -0
- package/lib/helpers/index.js.map +1 -1
- package/lib-es/application/query/index.js +44 -1
- package/lib-es/application/query/index.js.map +1 -1
- package/lib-es/components/Card/CardFactory.js +34 -8
- package/lib-es/components/Card/CardFactory.js.map +1 -1
- package/lib-es/components/ItemListButton/ItemListButton.js +117 -0
- package/lib-es/components/ItemListButton/ItemListButton.js.map +1 -0
- package/lib-es/components/ItemListButton/index.js +3 -0
- package/lib-es/components/ItemListButton/index.js.map +1 -0
- package/lib-es/components/ItemListCounter/ItemListCounter.js +67 -0
- package/lib-es/components/ItemListCounter/ItemListCounter.js.map +1 -0
- package/lib-es/components/ItemListCounter/index.js +3 -0
- package/lib-es/components/ItemListCounter/index.js.map +1 -0
- package/lib-es/components/List/ListBuilder.js +12 -6
- package/lib-es/components/List/ListBuilder.js.map +1 -1
- package/lib-es/components/List/ListFactory.js +26 -9
- package/lib-es/components/List/ListFactory.js.map +1 -1
- package/lib-es/components/index.js +6 -0
- package/lib-es/components/index.js.map +1 -1
- package/lib-es/constants/index.js +3 -1
- package/lib-es/constants/index.js.map +1 -1
- package/lib-es/helpers/build-raw-query.js.map +1 -1
- package/lib-es/helpers/get-item-list-data.js +7 -0
- package/lib-es/helpers/get-item-list-data.js.map +1 -0
- package/lib-es/helpers/get-item-list-id.js +10 -0
- package/lib-es/helpers/get-item-list-id.js.map +1 -0
- package/lib-es/helpers/get-item-list-ids.js +13 -0
- package/lib-es/helpers/get-item-list-ids.js.map +1 -0
- package/lib-es/helpers/index.js +3 -0
- package/lib-es/helpers/index.js.map +1 -1
- package/package.json +2 -2
- package/src/application/query/index.js +50 -1
- package/src/components/Card/CardFactory.js +27 -7
- package/src/components/ItemListButton/ItemListButton.js +107 -0
- package/src/components/ItemListButton/index.js +3 -0
- package/src/components/ItemListCounter/ItemListCounter.js +67 -0
- package/src/components/ItemListCounter/index.js +3 -0
- package/src/components/List/ListBuilder.js +10 -5
- package/src/components/List/ListFactory.js +47 -12
- package/src/components/index.js +6 -0
- package/src/constants/index.js +4 -1
- package/src/helpers/build-raw-query.js +1 -0
- package/src/helpers/get-item-list-data.js +6 -0
- package/src/helpers/get-item-list-id.js +10 -0
- package/src/helpers/get-item-list-ids.js +10 -0
- package/src/helpers/index.js +3 -0
- package/tests/unit/src/components/__snapshots__/index.test.js.snap +8 -0
- package/tests/unit/src/helpers/get-item-list-data.test.js +28 -0
- package/tests/unit/src/helpers/get-item-list-id.test.js +20 -0
- package/tests/unit/src/helpers/get-item-list-ids.test.js +19 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import {
|
|
4
|
+
BsBookmarkStarFill,
|
|
5
|
+
BsBookmarkCheckFill,
|
|
6
|
+
BsBookmarkStar,
|
|
7
|
+
BsBookmarkXFill
|
|
8
|
+
} from 'react-icons/bs';
|
|
9
|
+
import { useQuery, useMutation } from '@apollo/client';
|
|
10
|
+
import { getItemList, addItemsToList, removeItemsFromList } from '../../application/query';
|
|
11
|
+
import { getItemListData, getItemListId } from '../../helpers';
|
|
12
|
+
import { LIST_ITEM_LOCAL_KEY } from '../../constants';
|
|
13
|
+
|
|
14
|
+
const ItemListButton = ({ listName, parent, modifier }) => {
|
|
15
|
+
const { itemId, itemEntity } = parent;
|
|
16
|
+
const idFromStorage = getItemListId(listName);
|
|
17
|
+
const [listId, setListId] = useState(idFromStorage);
|
|
18
|
+
const [isHover, setIsHover] = useState(false);
|
|
19
|
+
|
|
20
|
+
useEffect(
|
|
21
|
+
() => {
|
|
22
|
+
const storageEventHandler = () => {
|
|
23
|
+
const newId = getItemListId(listName);
|
|
24
|
+
setListId(newId);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
window.addEventListener('storage', storageEventHandler);
|
|
28
|
+
|
|
29
|
+
return () => {
|
|
30
|
+
window.removeEventListener('storage', storageEventHandler);
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
[listName]
|
|
34
|
+
);
|
|
35
|
+
const getIcon = () => {
|
|
36
|
+
if (isInList) return isHover ? BsBookmarkXFill : BsBookmarkCheckFill;
|
|
37
|
+
return isHover ? BsBookmarkStarFill : BsBookmarkStar;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const { data, error, loading } = useQuery(getItemList, {
|
|
41
|
+
variables: { id: listId },
|
|
42
|
+
skip: !listId
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const [addListItem] = useMutation(addItemsToList, {
|
|
46
|
+
onCompleted: ({ addItemsToList: listAddResult }) => {
|
|
47
|
+
const {
|
|
48
|
+
result: { id }
|
|
49
|
+
} = listAddResult;
|
|
50
|
+
|
|
51
|
+
if (!listId) {
|
|
52
|
+
localStorage.setItem(LIST_ITEM_LOCAL_KEY(listName), id);
|
|
53
|
+
window.dispatchEvent(new Event('storage'));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const [removeListItem] = useMutation(removeItemsFromList);
|
|
59
|
+
|
|
60
|
+
const clickHandler = () => {
|
|
61
|
+
setIsHover(false);
|
|
62
|
+
isInList
|
|
63
|
+
? removeListItem({
|
|
64
|
+
variables: { listId, listItems: [{ itemId, itemEntity }] },
|
|
65
|
+
skip: !listId
|
|
66
|
+
})
|
|
67
|
+
: addListItem({
|
|
68
|
+
variables: { name: listName, id: listId, listItems: [{ itemId, itemEntity }] },
|
|
69
|
+
skip: !listId
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
if (loading) return '';
|
|
74
|
+
if (error) return error.message;
|
|
75
|
+
|
|
76
|
+
const listItems = getItemListData(data);
|
|
77
|
+
const isInList = !!listItems.find(({ itemId: idToCheck }) => idToCheck === itemId);
|
|
78
|
+
|
|
79
|
+
const Icon = getIcon();
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<div
|
|
83
|
+
className={`item-list-button ${modifier}`}
|
|
84
|
+
role="button"
|
|
85
|
+
onClick={clickHandler}
|
|
86
|
+
onMouseEnter={() => setIsHover(true)}
|
|
87
|
+
onMouseLeave={() => setIsHover(false)}>
|
|
88
|
+
<i>
|
|
89
|
+
<Icon />
|
|
90
|
+
</i>
|
|
91
|
+
</div>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
ItemListButton.propTypes = {
|
|
96
|
+
parent: PropTypes.object,
|
|
97
|
+
listName: PropTypes.string,
|
|
98
|
+
modifier: PropTypes.string
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
ItemListButton.defaultProps = {
|
|
102
|
+
parent: {},
|
|
103
|
+
listName: '',
|
|
104
|
+
modifier: ''
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export default ItemListButton;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { useRouter } from 'next/router';
|
|
4
|
+
import { useQuery } from '@apollo/client';
|
|
5
|
+
import { BsBookmarkStarFill, BsBookmarkStar } from 'react-icons/bs';
|
|
6
|
+
import { getItemList } from '../../application/query';
|
|
7
|
+
import { getItemListData, getItemListId } from '../../helpers';
|
|
8
|
+
|
|
9
|
+
const ItemListCounter = ({ listName, modifier, url }) => {
|
|
10
|
+
const router = useRouter();
|
|
11
|
+
const idFromStorage = getItemListId(listName);
|
|
12
|
+
const [listId, setListId] = useState(idFromStorage);
|
|
13
|
+
|
|
14
|
+
useEffect(
|
|
15
|
+
() => {
|
|
16
|
+
const storageEventHandler = () => {
|
|
17
|
+
const newId = getItemListId(listName);
|
|
18
|
+
setListId(newId);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
window.addEventListener('storage', storageEventHandler);
|
|
22
|
+
|
|
23
|
+
return () => {
|
|
24
|
+
window.removeEventListener('storage', storageEventHandler);
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
[listName]
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const { data, error, loading } = useQuery(getItemList, {
|
|
31
|
+
variables: { id: listId },
|
|
32
|
+
skip: !listId
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (loading) return '';
|
|
36
|
+
if (error) return error.message;
|
|
37
|
+
const listItems = getItemListData(data);
|
|
38
|
+
const listLength = listItems.length;
|
|
39
|
+
const CounterIcon = listLength ? BsBookmarkStarFill : BsBookmarkStar;
|
|
40
|
+
|
|
41
|
+
const handleClick = () => router.push('/Resolver', `${url}?itemListId=${listId}`);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div
|
|
45
|
+
role="button"
|
|
46
|
+
type="button"
|
|
47
|
+
className={`icon-button item-list-counter ${modifier}`}
|
|
48
|
+
onClick={handleClick}>
|
|
49
|
+
<CounterIcon />
|
|
50
|
+
<span className="icon-button__badge">{listLength}</span>
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
ItemListCounter.propTypes = {
|
|
56
|
+
url: PropTypes.string,
|
|
57
|
+
listName: PropTypes.string,
|
|
58
|
+
modifier: PropTypes.string
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
ItemListCounter.defaultProps = {
|
|
62
|
+
url: '',
|
|
63
|
+
listName: '',
|
|
64
|
+
modifier: ''
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export default ItemListCounter;
|
|
@@ -52,13 +52,15 @@ const ListBuilder = props => {
|
|
|
52
52
|
requiredSchema,
|
|
53
53
|
searchValues,
|
|
54
54
|
azFilter,
|
|
55
|
-
sortProperties
|
|
55
|
+
sortProperties,
|
|
56
|
+
itemListIds
|
|
56
57
|
} = props;
|
|
57
58
|
const isInfinite = paginationType === INFINITE;
|
|
58
59
|
const listComponent = getListComponent(isCard, paginationType);
|
|
59
60
|
const propsToDisplayValues = checkPropsToUse(propsToDisplay);
|
|
60
61
|
const entityFields = buildPropsQuery(entitySchema, propsToDisplayValues, props) || '';
|
|
61
|
-
const
|
|
62
|
+
const itemsToDisplayToUse = itemListIds || itemsToDisplay;
|
|
63
|
+
const limitToUse = limit || itemsToDisplayToUse.length;
|
|
62
64
|
const shouldApplyDefaultSort = !sortProperties || !sortProperties.length;
|
|
63
65
|
const itemsPerPageToUse = getItemsPerPageToUse(itemsPerPage, limitToUse);
|
|
64
66
|
const initialOffset = getCurrentOffset(offset, itemsPerPageToUse, paginationIndex, limitToUse);
|
|
@@ -94,7 +96,7 @@ const ListBuilder = props => {
|
|
|
94
96
|
stringProps
|
|
95
97
|
},
|
|
96
98
|
itemId,
|
|
97
|
-
|
|
99
|
+
itemsToDisplayToUse,
|
|
98
100
|
shouldApplyDefaultSort,
|
|
99
101
|
{ shouldReturnAggs: true, isAZ }
|
|
100
102
|
);
|
|
@@ -137,7 +139,7 @@ const ListBuilder = props => {
|
|
|
137
139
|
azFilter
|
|
138
140
|
},
|
|
139
141
|
itemId,
|
|
140
|
-
|
|
142
|
+
itemsToDisplayToUse,
|
|
141
143
|
shouldApplyDefaultSort,
|
|
142
144
|
{ shouldReturnAggs: false, isAZ }
|
|
143
145
|
);
|
|
@@ -172,6 +174,7 @@ const ListBuilder = props => {
|
|
|
172
174
|
isAZ={isAZ}
|
|
173
175
|
azFilter={azFilter}
|
|
174
176
|
{...props}
|
|
177
|
+
itemsToDisplay={itemsToDisplayToUse}
|
|
175
178
|
/>
|
|
176
179
|
);
|
|
177
180
|
};
|
|
@@ -202,12 +205,14 @@ ListBuilder.propTypes = {
|
|
|
202
205
|
filterOperator: PropTypes.string.isRequired,
|
|
203
206
|
paginationType: PropTypes.string,
|
|
204
207
|
azFilter: PropTypes.string,
|
|
205
|
-
sortProperties: PropTypes.array
|
|
208
|
+
sortProperties: PropTypes.array,
|
|
209
|
+
itemListIds: PropTypes.array
|
|
206
210
|
};
|
|
207
211
|
|
|
208
212
|
ListBuilder.defaultProps = {
|
|
209
213
|
entityData: {},
|
|
210
214
|
itemsToDisplay: [],
|
|
215
|
+
itemListIds: null,
|
|
211
216
|
limit: 0,
|
|
212
217
|
omitWrappers: false,
|
|
213
218
|
offset: 0,
|
|
@@ -4,7 +4,11 @@ import { parseUrl } from 'query-string';
|
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import { useRouter } from 'next/router';
|
|
6
6
|
import { MainContext } from '@blaze-cms/nextjs-components';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
getSingleEntitySchema,
|
|
9
|
+
generateSingleItemQuery,
|
|
10
|
+
getItemList
|
|
11
|
+
} from '../../application/query';
|
|
8
12
|
import ListBuilder from './ListBuilder';
|
|
9
13
|
import { AZ_LIST_TYPE } from './constants';
|
|
10
14
|
import { getAzQueryFilter, getSortProps } from './helpers';
|
|
@@ -19,7 +23,9 @@ import {
|
|
|
19
23
|
buildSearchValuesText,
|
|
20
24
|
getQueryFilters,
|
|
21
25
|
getInheritedFilters,
|
|
22
|
-
getQueryProps
|
|
26
|
+
getQueryProps,
|
|
27
|
+
getItemListId,
|
|
28
|
+
getItemListIds
|
|
23
29
|
} from '../../helpers';
|
|
24
30
|
import { useGetEntitySchemasAsObj } from '../../hooks';
|
|
25
31
|
import { AND_OPERATOR, TEXT_SEARCH, ID, AND, FULL } from '../../constants';
|
|
@@ -37,16 +43,18 @@ const ListFactory = props => {
|
|
|
37
43
|
sort: defaultSort,
|
|
38
44
|
searchFilter,
|
|
39
45
|
operator: filterOperator,
|
|
40
|
-
sortProperties
|
|
46
|
+
sortProperties,
|
|
47
|
+
itemListName
|
|
41
48
|
} = props;
|
|
42
|
-
|
|
43
49
|
const { isPreview } = useContext(MainContext);
|
|
44
50
|
const router = useRouter();
|
|
45
51
|
const { asPath } = router;
|
|
46
52
|
const parsedQuery = asPath.replace(/%5D/g, ']').replace(/%5B/g, '[');
|
|
47
|
-
const {
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
const {
|
|
54
|
+
query,
|
|
55
|
+
url,
|
|
56
|
+
query: { sort: querySort, sortby: querySortBy, itemListId: queryItemListId } = {}
|
|
57
|
+
} = parseUrl(parsedQuery);
|
|
50
58
|
const { sortbyFilters, updatedSortProperties } = getSortProps({
|
|
51
59
|
querySort,
|
|
52
60
|
sortProperties,
|
|
@@ -55,6 +63,7 @@ const ListFactory = props => {
|
|
|
55
63
|
defaultSortBy
|
|
56
64
|
});
|
|
57
65
|
|
|
66
|
+
const itemListId = getItemListId(itemListName, queryItemListId);
|
|
58
67
|
const { itemEntity, itemId } = parent;
|
|
59
68
|
const itemEntityUpdated = getUnpublishedEntityName(itemEntity);
|
|
60
69
|
const paginationIndex = getPaginationIndex(query, name);
|
|
@@ -98,13 +107,36 @@ const ListFactory = props => {
|
|
|
98
107
|
variables: { id: itemId },
|
|
99
108
|
skip: schemasLoading || (!inheritedFilters.length && queryProps === ID)
|
|
100
109
|
});
|
|
101
|
-
|
|
110
|
+
|
|
111
|
+
const { data: itemListData = {}, error: itemListError, loading: itemListLoading } = useQuery(
|
|
112
|
+
getItemList,
|
|
113
|
+
{
|
|
114
|
+
variables: { id: itemListId },
|
|
115
|
+
skip: !itemListId
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const errorsToCheck = [
|
|
120
|
+
schemaError,
|
|
121
|
+
schemasError,
|
|
122
|
+
requiredSchemaError,
|
|
123
|
+
itemQueryError,
|
|
124
|
+
itemListError
|
|
125
|
+
];
|
|
102
126
|
const { hasErr, errMsg } = checkForError(errorsToCheck);
|
|
103
127
|
|
|
104
|
-
if (
|
|
128
|
+
if (
|
|
129
|
+
requiredSchemaLoading ||
|
|
130
|
+
schemasLoading ||
|
|
131
|
+
schemaLoading ||
|
|
132
|
+
itemQueryLoading ||
|
|
133
|
+
itemListLoading
|
|
134
|
+
)
|
|
135
|
+
return '';
|
|
105
136
|
if (hasErr) return errMsg;
|
|
106
137
|
if (!entitySchema) return null;
|
|
107
138
|
|
|
139
|
+
const itemListIds = getItemListIds(itemListData);
|
|
108
140
|
const isCard = type !== FULL;
|
|
109
141
|
const isAZ = type === AZ_LIST_TYPE;
|
|
110
142
|
const genericProps = getGenericProps(props);
|
|
@@ -147,7 +179,8 @@ const ListFactory = props => {
|
|
|
147
179
|
paginationIndex,
|
|
148
180
|
entityData,
|
|
149
181
|
inheritedFilters,
|
|
150
|
-
filterOperator
|
|
182
|
+
filterOperator,
|
|
183
|
+
itemListIds
|
|
151
184
|
};
|
|
152
185
|
|
|
153
186
|
return <ListBuilder {...listProps} />;
|
|
@@ -165,7 +198,8 @@ ListFactory.propTypes = {
|
|
|
165
198
|
sortby: PropTypes.array,
|
|
166
199
|
sort: PropTypes.string,
|
|
167
200
|
searchFilter: PropTypes.object,
|
|
168
|
-
sortProperties: PropTypes.array
|
|
201
|
+
sortProperties: PropTypes.array,
|
|
202
|
+
itemListName: PropTypes.string
|
|
169
203
|
};
|
|
170
204
|
|
|
171
205
|
ListFactory.defaultProps = {
|
|
@@ -177,7 +211,8 @@ ListFactory.defaultProps = {
|
|
|
177
211
|
sortProperties: [],
|
|
178
212
|
sort: '',
|
|
179
213
|
operator: AND,
|
|
180
|
-
searchFilter: {}
|
|
214
|
+
searchFilter: {},
|
|
215
|
+
itemListName: ''
|
|
181
216
|
};
|
|
182
217
|
|
|
183
218
|
export default ListFactory;
|
package/src/components/index.js
CHANGED
|
@@ -42,5 +42,11 @@ export default {
|
|
|
42
42
|
import(/* webpackChunkName: "blazePbPasswordResetRequest" */ './PasswordResetRequest')
|
|
43
43
|
),
|
|
44
44
|
breadcrumb: dynamic(() => import(/* webpackChunkName: "blazePbBreadcrumb" */ './Breadcrumb')),
|
|
45
|
+
itemlistbutton: dynamic(() =>
|
|
46
|
+
import(/* webpackChunkName: "blazePbItemListButton" */ './ItemListButton')
|
|
47
|
+
),
|
|
48
|
+
itemlistcounter: dynamic(() =>
|
|
49
|
+
import(/* webpackChunkName: "blazePbItemListCounter" */ './ItemListCounter')
|
|
50
|
+
),
|
|
45
51
|
backtotop: dynamic(() => import(/* webpackChunkName: "blazePbBackToTop" */ './BackToTop'))
|
|
46
52
|
};
|
package/src/constants/index.js
CHANGED
|
@@ -209,6 +209,8 @@ const DATA_SUMMARY_EMAIL_REGEX = /^([a-z0-9_\.\+-]+)@([\da-z\.-]+)\.([a-z\.]{2,6
|
|
|
209
209
|
const DATA_SUMMARY_URL_REGEX = /(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/;
|
|
210
210
|
const DATA_SUMMARY_TEL_REGEX = /^\+{0,1}[0-9\(\)\.\- \/]{7,}$/; // note: very loose phone number match not for validation
|
|
211
211
|
|
|
212
|
+
const LIST_ITEM_LOCAL_KEY = name => `blaze_item_list_${name}`;
|
|
213
|
+
|
|
212
214
|
export {
|
|
213
215
|
BANNER_LOADING,
|
|
214
216
|
BANNER_EMPTY,
|
|
@@ -320,5 +322,6 @@ export {
|
|
|
320
322
|
TARGET_BLANK,
|
|
321
323
|
DATA_SUMMARY_EMAIL_REGEX,
|
|
322
324
|
DATA_SUMMARY_URL_REGEX,
|
|
323
|
-
DATA_SUMMARY_TEL_REGEX
|
|
325
|
+
DATA_SUMMARY_TEL_REGEX,
|
|
326
|
+
LIST_ITEM_LOCAL_KEY
|
|
324
327
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LIST_ITEM_LOCAL_KEY } from '../constants';
|
|
2
|
+
|
|
3
|
+
const getItemListId = (listName, queryId) => {
|
|
4
|
+
if (queryId) return queryId;
|
|
5
|
+
if (!listName || typeof localStorage === 'undefined') return '';
|
|
6
|
+
|
|
7
|
+
return localStorage.getItem(LIST_ITEM_LOCAL_KEY(listName)) || '';
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default getItemListId;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import getItemListData from './get-item-list-data';
|
|
2
|
+
|
|
3
|
+
const getItemListIds = data => {
|
|
4
|
+
const itemListElements = getItemListData(data);
|
|
5
|
+
return itemListElements.length
|
|
6
|
+
? itemListElements.map(({ itemId }) => ({ displayItems: [itemId] }))
|
|
7
|
+
: null;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default getItemListIds;
|
package/src/helpers/index.js
CHANGED
|
@@ -51,3 +51,6 @@ export { default as getParsedPropValues } from './get-parsed-prop-values';
|
|
|
51
51
|
export { default as getSanitizedPropValues } from './get-sanitized-prop-values';
|
|
52
52
|
export { default as appendImages } from './append-images';
|
|
53
53
|
export { default as parseTextBlock } from './parse-TextBlock';
|
|
54
|
+
export { default as getItemListId } from './get-item-list-id';
|
|
55
|
+
export { default as getItemListIds } from './get-item-list-ids';
|
|
56
|
+
export { default as getItemListData } from './get-item-list-data';
|
|
@@ -46,6 +46,14 @@ Object {
|
|
|
46
46
|
"$$typeof": Symbol(react.forward_ref),
|
|
47
47
|
"render": [Function],
|
|
48
48
|
},
|
|
49
|
+
"itemlistbutton": Object {
|
|
50
|
+
"$$typeof": Symbol(react.forward_ref),
|
|
51
|
+
"render": [Function],
|
|
52
|
+
},
|
|
53
|
+
"itemlistcounter": Object {
|
|
54
|
+
"$$typeof": Symbol(react.forward_ref),
|
|
55
|
+
"render": [Function],
|
|
56
|
+
},
|
|
49
57
|
"list": Object {
|
|
50
58
|
"$$typeof": Symbol(react.forward_ref),
|
|
51
59
|
"render": [Function],
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
2
|
+
import getItemListData from '../../../../src/helpers/get-item-list-data';
|
|
3
|
+
|
|
4
|
+
describe('getItemListData helper', () => {
|
|
5
|
+
const noData = getItemListData();
|
|
6
|
+
const noGetItemList = getItemListData({});
|
|
7
|
+
const noListItems = getItemListData({ getItemList: {} });
|
|
8
|
+
const withCorrectData = getItemListData({
|
|
9
|
+
getItemList: { listItems: ['one item', 'two items'] }
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should always return an array', () => {
|
|
13
|
+
expect(Array.isArray(noData)).toBeTruthy();
|
|
14
|
+
expect(Array.isArray(noGetItemList)).toBeTruthy();
|
|
15
|
+
expect(Array.isArray(noListItems)).toBeTruthy();
|
|
16
|
+
expect(Array.isArray(withCorrectData)).toBeTruthy();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should return an empty array if data passed doesnt have expected props', () => {
|
|
20
|
+
expect(noData).toEqual([]);
|
|
21
|
+
expect(noGetItemList).toEqual([]);
|
|
22
|
+
expect(noListItems).toEqual([]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should return listData otherwise', () => {
|
|
26
|
+
expect(withCorrectData).toEqual(['one item', 'two items']);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
2
|
+
import getitemListId from '../../../../src/helpers/get-item-list-id';
|
|
3
|
+
|
|
4
|
+
describe('getitemListId helper', () => {
|
|
5
|
+
const noValues = getitemListId();
|
|
6
|
+
const noListId = getitemListId('listName');
|
|
7
|
+
const noListName = getitemListId(null, '123asd');
|
|
8
|
+
|
|
9
|
+
it('should return empty string if no values are passed', () => {
|
|
10
|
+
expect(noValues).toEqual('');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should return listId if passed', () => {
|
|
14
|
+
expect(noListName).toEqual('123asd');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should return local value if no id is passed but name is', () => {
|
|
18
|
+
expect(noListId).toEqual('');
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
2
|
+
import getitemListIds from '../../../../src/helpers/get-item-list-ids';
|
|
3
|
+
|
|
4
|
+
describe('getitemListIds helper', () => {
|
|
5
|
+
const noData = getitemListIds();
|
|
6
|
+
const emptyData = getitemListIds({});
|
|
7
|
+
const withData = getitemListIds({
|
|
8
|
+
getItemList: { listItems: [{ itemId: '123' }, { itemId: '456' }] }
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should return null if no valid data is passed', () => {
|
|
12
|
+
expect(noData).toEqual(null);
|
|
13
|
+
expect(emptyData).toEqual(null);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return itemsToDisplay formatted ids', () => {
|
|
17
|
+
expect(withData).toEqual([{ displayItems: ['123'] }, { displayItems: ['456'] }]);
|
|
18
|
+
});
|
|
19
|
+
});
|