@constructor-io/constructorio-ui-autocomplete 1.23.17 → 1.23.19
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-autocomplete-bundled.js +11 -11
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/hooks/useCioAutocomplete.js +3 -3
- package/lib/cjs/hooks/useDownShift.js +2 -1
- package/lib/cjs/hooks/useSections/index.js +38 -0
- package/lib/cjs/hooks/useSections/useActiveSections.js +25 -0
- package/lib/cjs/hooks/useSections/useActiveSectionsWithData.js +16 -0
- package/lib/cjs/hooks/useSections/useRemoveSections.js +24 -0
- package/lib/cjs/hooks/useSections/useSectionsResults.js +28 -0
- package/lib/cjs/utils.js +8 -4
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/constants.js +1 -0
- package/lib/mjs/hooks/useCioAutocomplete.js +3 -3
- package/lib/mjs/hooks/useDownShift.js +2 -1
- package/lib/mjs/hooks/useSections/index.js +34 -0
- package/lib/mjs/hooks/useSections/useActiveSections.js +22 -0
- package/lib/mjs/hooks/useSections/useActiveSectionsWithData.js +13 -0
- package/lib/mjs/hooks/useSections/useRemoveSections.js +20 -0
- package/lib/mjs/hooks/useSections/useSectionsResults.js +24 -0
- package/lib/mjs/utils.js +8 -4
- package/lib/mjs/version.js +1 -1
- package/lib/types/constants.d.ts +1 -0
- package/lib/types/hooks/useDownShift.d.ts +2 -1
- package/lib/types/hooks/{useSections.d.ts → useSections/index.d.ts} +3 -3
- package/lib/types/hooks/useSections/useActiveSections.d.ts +6 -0
- package/lib/types/hooks/useSections/useActiveSectionsWithData.d.ts +3 -0
- package/lib/types/hooks/useSections/useRemoveSections.d.ts +2 -0
- package/lib/types/hooks/useSections/useSectionsResults.d.ts +15 -0
- package/lib/types/types.d.ts +2 -1
- package/lib/types/utils.d.ts +1 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/lib/cjs/hooks/useSections.js +0 -63
- package/lib/mjs/hooks/useSections.js +0 -58
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
/* eslint-disable max-params */
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const utils_1 = require("../utils");
|
|
7
|
-
const useDebouncedFetchSections_1 = tslib_1.__importDefault(require("./useDebouncedFetchSections"));
|
|
8
|
-
const useFetchRecommendationPod_1 = tslib_1.__importDefault(require("./useFetchRecommendationPod"));
|
|
9
|
-
const typeGuards_1 = require("../typeGuards");
|
|
10
|
-
function useSections(query, cioClient, sections, zeroStateSections, advancedParameters) {
|
|
11
|
-
const zeroStateActiveSections = !query.length && (zeroStateSections === null || zeroStateSections === void 0 ? void 0 : zeroStateSections.length);
|
|
12
|
-
// Define All Sections
|
|
13
|
-
const [activeSections, setActiveSections] = (0, react_1.useState)(zeroStateActiveSections ? zeroStateSections : sections);
|
|
14
|
-
const sectionsRefs = (0, react_1.useRef)(activeSections.map(() => (0, react_1.createRef)()));
|
|
15
|
-
const [activeSectionsWithData, setActiveSectionsWithData] = (0, react_1.useState)([]);
|
|
16
|
-
const autocompleteSections = (0, react_1.useMemo)(() => activeSections === null || activeSections === void 0 ? void 0 : activeSections.filter((config) => (0, typeGuards_1.isAutocompleteSection)(config)), [activeSections]);
|
|
17
|
-
const recommendationsSections = (0, react_1.useMemo)(() => activeSections === null || activeSections === void 0 ? void 0 : activeSections.filter((config) => (0, typeGuards_1.isRecommendationsSection)(config)), [activeSections]);
|
|
18
|
-
// Fetch Autocomplete Results
|
|
19
|
-
const { sectionsData: autocompleteResults, request, totalNumResultsPerSection, } = (0, useDebouncedFetchSections_1.default)(query, cioClient, autocompleteSections, advancedParameters);
|
|
20
|
-
// Fetch Recommendations Results
|
|
21
|
-
const { fetchRecommendationResults, recommendationsResults, podsData } = (0, useFetchRecommendationPod_1.default)(cioClient, recommendationsSections, advancedParameters === null || advancedParameters === void 0 ? void 0 : advancedParameters.fetchZeroStateOnFocus);
|
|
22
|
-
// Remove sections if necessary
|
|
23
|
-
(0, react_1.useEffect)(() => {
|
|
24
|
-
var _a, _b;
|
|
25
|
-
const features = (0, utils_1.getFeatures)((_b = (_a = Object.values(podsData || {})) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.request);
|
|
26
|
-
if (zeroStateActiveSections) {
|
|
27
|
-
if (!features.featureDisplayZeroStateRecommendations) {
|
|
28
|
-
setActiveSections([]);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
setActiveSections(zeroStateSections);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
setActiveSections(sections);
|
|
36
|
-
}
|
|
37
|
-
}, [zeroStateSections, zeroStateActiveSections, sections, podsData]);
|
|
38
|
-
// Merge Recommendation Pods Display Name from Dashboard
|
|
39
|
-
const activeSectionConfigs = (0, react_1.useMemo)(() => activeSections.map((config) => {
|
|
40
|
-
const mergedConfig = config;
|
|
41
|
-
if ((0, typeGuards_1.isRecommendationsSection)(config)) {
|
|
42
|
-
const podData = podsData[config.podId];
|
|
43
|
-
const libraryDisplayName = config.displayName;
|
|
44
|
-
const dashboardDisplayName = podData === null || podData === void 0 ? void 0 : podData.displayName;
|
|
45
|
-
mergedConfig.displayName = libraryDisplayName || dashboardDisplayName;
|
|
46
|
-
}
|
|
47
|
-
return mergedConfig;
|
|
48
|
-
}), [activeSections, podsData]);
|
|
49
|
-
// Add to active sections the results data and refs when autocomplete results or recommendation results fetched
|
|
50
|
-
(0, react_1.useEffect)(() => {
|
|
51
|
-
const sectionsResults = Object.assign(Object.assign({}, autocompleteResults), recommendationsResults);
|
|
52
|
-
setActiveSectionsWithData((0, utils_1.getActiveSectionsWithData)(activeSectionConfigs, sectionsResults, sectionsRefs));
|
|
53
|
-
}, [autocompleteResults, recommendationsResults, activeSectionConfigs]);
|
|
54
|
-
return {
|
|
55
|
-
fetchRecommendationResults,
|
|
56
|
-
activeSections,
|
|
57
|
-
activeSectionsWithData,
|
|
58
|
-
zeroStateActiveSections,
|
|
59
|
-
request,
|
|
60
|
-
totalNumResultsPerSection,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
exports.default = useSections;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-params */
|
|
2
|
-
import { createRef, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
-
import { getActiveSectionsWithData, getFeatures } from '../utils';
|
|
4
|
-
import useDebouncedFetchSection from './useDebouncedFetchSections';
|
|
5
|
-
import useFetchRecommendationPod from './useFetchRecommendationPod';
|
|
6
|
-
import { isAutocompleteSection, isRecommendationsSection } from '../typeGuards';
|
|
7
|
-
export default function useSections(query, cioClient, sections, zeroStateSections, advancedParameters) {
|
|
8
|
-
const zeroStateActiveSections = !query.length && zeroStateSections?.length;
|
|
9
|
-
// Define All Sections
|
|
10
|
-
const [activeSections, setActiveSections] = useState(zeroStateActiveSections ? zeroStateSections : sections);
|
|
11
|
-
const sectionsRefs = useRef(activeSections.map(() => createRef()));
|
|
12
|
-
const [activeSectionsWithData, setActiveSectionsWithData] = useState([]);
|
|
13
|
-
const autocompleteSections = useMemo(() => activeSections?.filter((config) => isAutocompleteSection(config)), [activeSections]);
|
|
14
|
-
const recommendationsSections = useMemo(() => activeSections?.filter((config) => isRecommendationsSection(config)), [activeSections]);
|
|
15
|
-
// Fetch Autocomplete Results
|
|
16
|
-
const { sectionsData: autocompleteResults, request, totalNumResultsPerSection, } = useDebouncedFetchSection(query, cioClient, autocompleteSections, advancedParameters);
|
|
17
|
-
// Fetch Recommendations Results
|
|
18
|
-
const { fetchRecommendationResults, recommendationsResults, podsData } = useFetchRecommendationPod(cioClient, recommendationsSections, advancedParameters?.fetchZeroStateOnFocus);
|
|
19
|
-
// Remove sections if necessary
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
const features = getFeatures(Object.values(podsData || {})?.[0]?.request);
|
|
22
|
-
if (zeroStateActiveSections) {
|
|
23
|
-
if (!features.featureDisplayZeroStateRecommendations) {
|
|
24
|
-
setActiveSections([]);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
setActiveSections(zeroStateSections);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
setActiveSections(sections);
|
|
32
|
-
}
|
|
33
|
-
}, [zeroStateSections, zeroStateActiveSections, sections, podsData]);
|
|
34
|
-
// Merge Recommendation Pods Display Name from Dashboard
|
|
35
|
-
const activeSectionConfigs = useMemo(() => activeSections.map((config) => {
|
|
36
|
-
const mergedConfig = config;
|
|
37
|
-
if (isRecommendationsSection(config)) {
|
|
38
|
-
const podData = podsData[config.podId];
|
|
39
|
-
const libraryDisplayName = config.displayName;
|
|
40
|
-
const dashboardDisplayName = podData?.displayName;
|
|
41
|
-
mergedConfig.displayName = libraryDisplayName || dashboardDisplayName;
|
|
42
|
-
}
|
|
43
|
-
return mergedConfig;
|
|
44
|
-
}), [activeSections, podsData]);
|
|
45
|
-
// Add to active sections the results data and refs when autocomplete results or recommendation results fetched
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
const sectionsResults = { ...autocompleteResults, ...recommendationsResults };
|
|
48
|
-
setActiveSectionsWithData(getActiveSectionsWithData(activeSectionConfigs, sectionsResults, sectionsRefs));
|
|
49
|
-
}, [autocompleteResults, recommendationsResults, activeSectionConfigs]);
|
|
50
|
-
return {
|
|
51
|
-
fetchRecommendationResults,
|
|
52
|
-
activeSections,
|
|
53
|
-
activeSectionsWithData,
|
|
54
|
-
zeroStateActiveSections,
|
|
55
|
-
request,
|
|
56
|
-
totalNumResultsPerSection,
|
|
57
|
-
};
|
|
58
|
-
}
|