@constructor-io/constructorio-ui-plp 1.6.0 → 1.6.1
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/constructorio-ui-plp-bundled.js +12 -12
- package/lib/cjs/components/CioPlp/CioPlp.js +2 -2
- package/lib/cjs/hooks/useGroups.js +7 -1
- package/lib/cjs/hooks/useOptionsList.js +7 -5
- package/lib/cjs/utils/itemFieldGetters.js +6 -1
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/CioPlp/CioPlp.js +2 -2
- package/lib/mjs/hooks/useGroups.js +8 -2
- package/lib/mjs/hooks/useOptionsList.js +8 -6
- package/lib/mjs/utils/itemFieldGetters.js +3 -0
- package/lib/mjs/version.js +1 -1
- package/lib/types/hooks/useGroups.d.ts +6 -1
- package/lib/types/hooks/useOptionsList.d.ts +5 -0
- package/lib/types/hooks/usePagination.d.ts +10 -0
- package/lib/types/types.d.ts +2 -1
- package/lib/types/utils/itemFieldGetters.d.ts +2 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -6,8 +6,8 @@ const CioPlpProvider_1 = tslib_1.__importDefault(require("./CioPlpProvider"));
|
|
|
6
6
|
const CioPlpGrid_1 = tslib_1.__importDefault(require("../CioPlpGrid"));
|
|
7
7
|
// Wrapper component for CioPlpProvider with default Markup
|
|
8
8
|
function CioPlp(props) {
|
|
9
|
-
const { children, initialSearchResponse, initialBrowseResponse, sortConfigs, paginationConfigs, filterConfigs } = props, rest = tslib_1.__rest(props, ["children", "initialSearchResponse", "initialBrowseResponse", "sortConfigs", "paginationConfigs", "filterConfigs"]);
|
|
10
|
-
const defaultMarkup = (react_1.default.createElement(CioPlpGrid_1.default, { initialSearchResponse: initialSearchResponse, initialBrowseResponse: initialBrowseResponse, sortConfigs: sortConfigs, paginationConfigs: paginationConfigs, filterConfigs: filterConfigs }));
|
|
9
|
+
const { children, initialSearchResponse, initialBrowseResponse, sortConfigs, paginationConfigs, filterConfigs, groupsConfigs } = props, rest = tslib_1.__rest(props, ["children", "initialSearchResponse", "initialBrowseResponse", "sortConfigs", "paginationConfigs", "filterConfigs", "groupsConfigs"]);
|
|
10
|
+
const defaultMarkup = (react_1.default.createElement(CioPlpGrid_1.default, { initialSearchResponse: initialSearchResponse, initialBrowseResponse: initialBrowseResponse, sortConfigs: sortConfigs, paginationConfigs: paginationConfigs, filterConfigs: filterConfigs, groupsConfigs: groupsConfigs }));
|
|
11
11
|
return (react_1.default.createElement("div", { className: 'cio-plp' },
|
|
12
12
|
react_1.default.createElement(CioPlpProvider_1.default, Object.assign({}, rest), children || defaultMarkup)));
|
|
13
13
|
}
|
|
@@ -9,11 +9,12 @@ const useOptionsList_1 = tslib_1.__importDefault(require("./useOptionsList"));
|
|
|
9
9
|
const useCioBreadcrumb_1 = tslib_1.__importDefault(require("./useCioBreadcrumb"));
|
|
10
10
|
function useGroups(props) {
|
|
11
11
|
var _a, _b;
|
|
12
|
-
const { groups, initialNumOptions: numOptionsProps } = props;
|
|
12
|
+
const { groups, initialNumOptions: numOptionsProps, isHiddenGroupFn } = props;
|
|
13
13
|
const contextValue = (0, useCioPlpContext_1.useCioPlpContext)();
|
|
14
14
|
if (!contextValue) {
|
|
15
15
|
throw new Error('useGroups must be used within a component that is a child of <CioPlp />');
|
|
16
16
|
}
|
|
17
|
+
const { getIsHiddenGroupField } = contextValue.itemFieldGetters;
|
|
17
18
|
const { setFilter } = (0, useFilter_1.default)({ facets: [] });
|
|
18
19
|
const { getRequestConfigs } = (0, useRequestConfigs_1.default)();
|
|
19
20
|
const requestConfigs = getRequestConfigs();
|
|
@@ -26,10 +27,15 @@ function useGroups(props) {
|
|
|
26
27
|
const setGroup = (groupId) => {
|
|
27
28
|
setFilter('group_id', groupId);
|
|
28
29
|
};
|
|
30
|
+
const isHiddenOptionFn = (0, react_1.useCallback)((group) => (typeof isHiddenGroupFn === 'function' && isHiddenGroupFn(group)) ||
|
|
31
|
+
(typeof getIsHiddenGroupField === 'function' && getIsHiddenGroupField(group)) ||
|
|
32
|
+
false, // Ensure that isHiddenOptionFn never returns undefined
|
|
33
|
+
[isHiddenGroupFn, getIsHiddenGroupField]);
|
|
29
34
|
const { breadcrumbs, currentPage } = (0, useCioBreadcrumb_1.default)({ groups, filterValue: currentGroupId || 'all' }) || [];
|
|
30
35
|
const { initialNumOptions, isShowAll, setIsShowAll, optionsToRender, setOptionsToRender } = (0, useOptionsList_1.default)({
|
|
31
36
|
options: groupOptions,
|
|
32
37
|
initialNumOptions: numOptionsProps,
|
|
38
|
+
isHiddenOptionFn,
|
|
33
39
|
});
|
|
34
40
|
const [selectedGroupId, setSelectedGroupId] = (0, react_1.useState)();
|
|
35
41
|
const onOptionSelect = (groupId) => {
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
|
+
const defaultIsHiddenOptionFn = () => false;
|
|
4
5
|
function useOptionsList(props) {
|
|
5
|
-
const { options, initialNumOptions = 5 } = props;
|
|
6
|
+
const { options, initialNumOptions = 5, isHiddenOptionFn = defaultIsHiddenOptionFn } = props;
|
|
7
|
+
const filteredOptions = (0, react_1.useMemo)(() => options.filter((option) => !isHiddenOptionFn(option)), [isHiddenOptionFn, options]);
|
|
6
8
|
const [isShowAll, setIsShowAll] = (0, react_1.useState)(false);
|
|
7
|
-
const [optionsToRender, setOptionsToRender] = (0, react_1.useState)(
|
|
9
|
+
const [optionsToRender, setOptionsToRender] = (0, react_1.useState)(filteredOptions);
|
|
8
10
|
(0, react_1.useEffect)(() => {
|
|
9
11
|
if (isShowAll) {
|
|
10
|
-
setOptionsToRender(
|
|
12
|
+
setOptionsToRender(filteredOptions);
|
|
11
13
|
}
|
|
12
14
|
else {
|
|
13
|
-
setOptionsToRender(
|
|
15
|
+
setOptionsToRender(filteredOptions.slice(0, initialNumOptions));
|
|
14
16
|
}
|
|
15
|
-
}, [isShowAll,
|
|
17
|
+
}, [isShowAll, filteredOptions, initialNumOptions]);
|
|
16
18
|
return {
|
|
17
19
|
// props
|
|
18
20
|
initialNumOptions,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSwatchPreview = exports.getSwatches = exports.getRolloverImage = exports.getSalePrice = exports.getPrice = void 0;
|
|
3
|
+
exports.getIsHiddenGroupField = exports.getSwatchPreview = exports.getSwatches = exports.getRolloverImage = exports.getSalePrice = exports.getPrice = void 0;
|
|
4
4
|
// eslint-disable-next-line import/prefer-default-export
|
|
5
5
|
function getPrice(item) {
|
|
6
6
|
return item.data.price;
|
|
@@ -40,3 +40,8 @@ function getSwatchPreview(variation) {
|
|
|
40
40
|
return (_a = variation === null || variation === void 0 ? void 0 : variation.data) === null || _a === void 0 ? void 0 : _a.swatchPreview;
|
|
41
41
|
}
|
|
42
42
|
exports.getSwatchPreview = getSwatchPreview;
|
|
43
|
+
function getIsHiddenGroupField(group) {
|
|
44
|
+
var _a;
|
|
45
|
+
return (_a = group === null || group === void 0 ? void 0 : group.data) === null || _a === void 0 ? void 0 : _a.cio_plp_hidden;
|
|
46
|
+
}
|
|
47
|
+
exports.getIsHiddenGroupField = getIsHiddenGroupField;
|
package/lib/cjs/version.js
CHANGED
|
@@ -3,8 +3,8 @@ import CioPlpProvider from './CioPlpProvider';
|
|
|
3
3
|
import CioPlpGrid from '../CioPlpGrid';
|
|
4
4
|
// Wrapper component for CioPlpProvider with default Markup
|
|
5
5
|
export default function CioPlp(props) {
|
|
6
|
-
const { children, initialSearchResponse, initialBrowseResponse, sortConfigs, paginationConfigs, filterConfigs, ...rest } = props;
|
|
7
|
-
const defaultMarkup = (React.createElement(CioPlpGrid, { initialSearchResponse: initialSearchResponse, initialBrowseResponse: initialBrowseResponse, sortConfigs: sortConfigs, paginationConfigs: paginationConfigs, filterConfigs: filterConfigs }));
|
|
6
|
+
const { children, initialSearchResponse, initialBrowseResponse, sortConfigs, paginationConfigs, filterConfigs, groupsConfigs, ...rest } = props;
|
|
7
|
+
const defaultMarkup = (React.createElement(CioPlpGrid, { initialSearchResponse: initialSearchResponse, initialBrowseResponse: initialBrowseResponse, sortConfigs: sortConfigs, paginationConfigs: paginationConfigs, filterConfigs: filterConfigs, groupsConfigs: groupsConfigs }));
|
|
8
8
|
return (React.createElement("div", { className: 'cio-plp' },
|
|
9
9
|
React.createElement(CioPlpProvider, { ...rest }, children || defaultMarkup)));
|
|
10
10
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
2
|
import { useCioPlpContext } from './useCioPlpContext';
|
|
3
3
|
import useFilter from './useFilter';
|
|
4
4
|
import useRequestConfigs from './useRequestConfigs';
|
|
5
5
|
import useOptionsList from './useOptionsList';
|
|
6
6
|
import useCioBreadcrumb from './useCioBreadcrumb';
|
|
7
7
|
export default function useGroups(props) {
|
|
8
|
-
const { groups, initialNumOptions: numOptionsProps } = props;
|
|
8
|
+
const { groups, initialNumOptions: numOptionsProps, isHiddenGroupFn } = props;
|
|
9
9
|
const contextValue = useCioPlpContext();
|
|
10
10
|
if (!contextValue) {
|
|
11
11
|
throw new Error('useGroups must be used within a component that is a child of <CioPlp />');
|
|
12
12
|
}
|
|
13
|
+
const { getIsHiddenGroupField } = contextValue.itemFieldGetters;
|
|
13
14
|
const { setFilter } = useFilter({ facets: [] });
|
|
14
15
|
const { getRequestConfigs } = useRequestConfigs();
|
|
15
16
|
const requestConfigs = getRequestConfigs();
|
|
@@ -22,10 +23,15 @@ export default function useGroups(props) {
|
|
|
22
23
|
const setGroup = (groupId) => {
|
|
23
24
|
setFilter('group_id', groupId);
|
|
24
25
|
};
|
|
26
|
+
const isHiddenOptionFn = useCallback((group) => (typeof isHiddenGroupFn === 'function' && isHiddenGroupFn(group)) ||
|
|
27
|
+
(typeof getIsHiddenGroupField === 'function' && getIsHiddenGroupField(group)) ||
|
|
28
|
+
false, // Ensure that isHiddenOptionFn never returns undefined
|
|
29
|
+
[isHiddenGroupFn, getIsHiddenGroupField]);
|
|
25
30
|
const { breadcrumbs, currentPage } = useCioBreadcrumb({ groups, filterValue: currentGroupId || 'all' }) || [];
|
|
26
31
|
const { initialNumOptions, isShowAll, setIsShowAll, optionsToRender, setOptionsToRender } = useOptionsList({
|
|
27
32
|
options: groupOptions,
|
|
28
33
|
initialNumOptions: numOptionsProps,
|
|
34
|
+
isHiddenOptionFn,
|
|
29
35
|
});
|
|
30
36
|
const [selectedGroupId, setSelectedGroupId] = useState();
|
|
31
37
|
const onOptionSelect = (groupId) => {
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
const defaultIsHiddenOptionFn = () => false;
|
|
2
3
|
export default function useOptionsList(props) {
|
|
3
|
-
const { options, initialNumOptions = 5 } = props;
|
|
4
|
+
const { options, initialNumOptions = 5, isHiddenOptionFn = defaultIsHiddenOptionFn } = props;
|
|
5
|
+
const filteredOptions = useMemo(() => options.filter((option) => !isHiddenOptionFn(option)), [isHiddenOptionFn, options]);
|
|
4
6
|
const [isShowAll, setIsShowAll] = useState(false);
|
|
5
|
-
const [optionsToRender, setOptionsToRender] = useState(
|
|
7
|
+
const [optionsToRender, setOptionsToRender] = useState(filteredOptions);
|
|
6
8
|
useEffect(() => {
|
|
7
9
|
if (isShowAll) {
|
|
8
|
-
setOptionsToRender(
|
|
10
|
+
setOptionsToRender(filteredOptions);
|
|
9
11
|
}
|
|
10
12
|
else {
|
|
11
|
-
setOptionsToRender(
|
|
13
|
+
setOptionsToRender(filteredOptions.slice(0, initialNumOptions));
|
|
12
14
|
}
|
|
13
|
-
}, [isShowAll,
|
|
15
|
+
}, [isShowAll, filteredOptions, initialNumOptions]);
|
|
14
16
|
return {
|
|
15
17
|
// props
|
|
16
18
|
initialNumOptions,
|
|
@@ -30,3 +30,6 @@ export function getSwatches(item, retrievePrice, retrieveSwatchPreview, retrieve
|
|
|
30
30
|
export function getSwatchPreview(variation) {
|
|
31
31
|
return variation?.data?.swatchPreview;
|
|
32
32
|
}
|
|
33
|
+
export function getIsHiddenGroupField(group) {
|
|
34
|
+
return group?.data?.cio_plp_hidden;
|
|
35
|
+
}
|
package/lib/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.6.
|
|
1
|
+
export default '1.6.1';
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { PlpItemGroup } from '../types';
|
|
2
2
|
import { UseOptionsListProps } from './useOptionsList';
|
|
3
3
|
import { Breadcrumb } from './useCioBreadcrumb';
|
|
4
|
-
export interface UseGroupProps extends Omit<UseOptionsListProps<PlpItemGroup>, 'options'> {
|
|
4
|
+
export interface UseGroupProps extends Omit<UseOptionsListProps<PlpItemGroup>, 'options' | 'isHiddenOptionFn'> {
|
|
5
5
|
/**
|
|
6
6
|
* Used to build and render the groups filter dynamically
|
|
7
7
|
*/
|
|
8
8
|
groups: Array<PlpItemGroup>;
|
|
9
|
+
/**
|
|
10
|
+
* Function that takes in a PlpItemGroup and returns `true` if the group should be hidden from the final render
|
|
11
|
+
* @returns boolean
|
|
12
|
+
*/
|
|
13
|
+
isHiddenGroupFn?: (group: PlpItemGroup) => boolean;
|
|
9
14
|
}
|
|
10
15
|
export default function useGroups(props: UseGroupProps): {
|
|
11
16
|
groupOptions: PlpItemGroup[];
|
|
@@ -8,6 +8,11 @@ export interface UseOptionsListProps<T> {
|
|
|
8
8
|
* The remaining options will be hidden under a "Show All" button
|
|
9
9
|
*/
|
|
10
10
|
initialNumOptions?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Function that takes in an option object T and returns `true` if it should NOT be rendered as an option
|
|
13
|
+
* @returns boolean
|
|
14
|
+
*/
|
|
15
|
+
isHiddenOptionFn?: (option: T) => boolean;
|
|
11
16
|
}
|
|
12
17
|
export default function useOptionsList<T>(props: UseOptionsListProps<T>): {
|
|
13
18
|
initialNumOptions: number;
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
export interface UsePaginationProps {
|
|
2
2
|
/**
|
|
3
|
+
* **⚠️ Deprecation Notice ⚠️**
|
|
4
|
+
*
|
|
5
|
+
* _This field will be deprecated in v2._
|
|
6
|
+
* _If you're looking to change the number of items requested please use `staticRequestConfigs` instead._
|
|
7
|
+
*
|
|
3
8
|
* Total number of results returned by the API response
|
|
4
9
|
*/
|
|
5
10
|
totalNumResults: number;
|
|
6
11
|
/**
|
|
12
|
+
* **⚠️ Deprecation Notice ⚠️**
|
|
13
|
+
*
|
|
14
|
+
* _This field will be deprecated in v2._
|
|
15
|
+
* _If you're looking to change the number of items requested please use `staticRequestConfigs` instead._
|
|
16
|
+
*
|
|
7
17
|
* Number of results returned per page
|
|
8
18
|
*/
|
|
9
19
|
resultsPerPage?: number;
|
package/lib/types/types.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export interface ItemFieldGetters {
|
|
|
16
16
|
getRolloverImage: (item: Item | Variation) => string | undefined;
|
|
17
17
|
getSwatchPreview: (variation: Variation) => string;
|
|
18
18
|
getSwatches: (item: Item, retrievePrice: ItemFieldGetters['getPrice'], retrieveSwatchPreview: ItemFieldGetters['getSwatchPreview'], retrieveSalePrice: ItemFieldGetters['getSalePrice'], retrieveRolloverImage: ItemFieldGetters['getRolloverImage']) => SwatchItem[] | undefined;
|
|
19
|
+
getIsHiddenGroupField: (group: PlpItemGroup) => boolean | undefined;
|
|
19
20
|
}
|
|
20
21
|
export interface Formatters {
|
|
21
22
|
formatPrice: (price?: number) => string;
|
|
@@ -290,7 +291,7 @@ export interface PlpItemGroup {
|
|
|
290
291
|
groupId: string;
|
|
291
292
|
displayName: string;
|
|
292
293
|
count: number;
|
|
293
|
-
data:
|
|
294
|
+
data: Record<string, any> | null;
|
|
294
295
|
children: Array<PlpItemGroup>;
|
|
295
296
|
parents: Pick<PlpItemGroup, 'groupId' | 'displayName'>[];
|
|
296
297
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ItemFieldGetters, Item, SwatchItem, Variation } from '../types';
|
|
1
|
+
import { ItemFieldGetters, Item, SwatchItem, Variation, PlpItemGroup } from '../types';
|
|
2
2
|
export declare function getPrice(item: Item | Variation): number;
|
|
3
3
|
export declare function getSalePrice(item: Item | Variation): number | undefined;
|
|
4
4
|
export declare function getRolloverImage(item: Item | Variation): string | undefined;
|
|
5
5
|
export declare function getSwatches(item: Item, retrievePrice: ItemFieldGetters['getPrice'], retrieveSwatchPreview: ItemFieldGetters['getSwatchPreview'], retrieveSalePrice: ItemFieldGetters['getSalePrice'], retrieveRolloverImage: ItemFieldGetters['getRolloverImage']): SwatchItem[] | undefined;
|
|
6
6
|
export declare function getSwatchPreview(variation: Variation): string;
|
|
7
|
+
export declare function getIsHiddenGroupField(group: PlpItemGroup): any;
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.6.
|
|
1
|
+
declare const _default: "1.6.1";
|
|
2
2
|
export default _default;
|