@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
117 lines (115 loc) • 7.3 kB
JavaScript
/**
* CodeAnalizerComment: Updated 3 imports on 2024-09-22 14:49:52
* Update:: import { addPopularityToItems } to '@mikezimm/fps-core-v7/lib/components/molecules/SearchPage/functions/markPopular;'
* Update:: import { addSearchMeta1 } to '@mikezimm/fps-core-v7/lib/components/molecules/SearchPage/functions/addSearchMeta1;'
* Update:: import { addItemIsA } to '@mikezimm/fps-core-v7/lib/components/molecules/SearchPage/functions/addItemIsA;'
*/
/**
* CodeAnalizerComment: Updated 12 imports on 2024-09-21 23:07:24
* Update:: import { check4This } to '@mikezimm/fps-core-v7/lib/logic/Links/CheckSearch;'
* Update:: import { addPopularityToItems } to '@mikezimm/fps-core-v7/lib/components/molecules/SearchPage/functions/markPopular;'
* Update:: import { ISourceProps } to '@mikezimm/fps-core-v7/lib/components/molecules/source-props/ISourceProps;'
* Update:: import { ISourceSearch } to '@mikezimm/fps-core-v7/lib/components/molecules/SearchPage/Interfaces/ISourceSearch;'
* Update:: import { addSearchMeta1 } to '@mikezimm/fps-core-v7/lib/components/molecules/SearchPage/functions/addSearchMeta1;'
* Update:: import { filterObjArrayByUniqueKey } to '@mikezimm/fps-core-v7/lib/logic/Arrays/searching/filterObjArrayByUniqueKey;'
* Update:: import { addItemIsA } to '@mikezimm/fps-core-v7/lib/components/molecules/SearchPage/functions/addItemIsA;'
* Update:: import { IItemIsAKeys } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IsA/IFPSItemIsA;'
* Update:: import { ItemHasMinimalDownload } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IsA/IFPSItemIsA;'
* Update:: import { ItemIsASite } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IsA/IFPSItemIsA;'
* Update:: import { ItemIsATeam } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IsA/IFPSItemIsA;'
* Update:: import { ItemIsAWeb } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IsA/IFPSItemIsA;'
*/
import { check4This, Check4 } from '../../../../logic/Links/CheckSearch';
import { addPopularityToItems } from '../../../../components/molecules/SearchPage/functions/markPopular';
import { addSearchMeta1 } from '../../../../components/molecules/SearchPage/functions/addSearchMeta1';
import { filterObjArrayByUniqueKey } from '../../../../logic/Arrays/searching/filterObjArrayByUniqueKey';
import { addItemIsA } from '../../../../components/molecules/SearchPage/functions/addItemIsA';
import { ItemHasMinimalDownload, ItemIsASite, ItemIsATeam, ItemIsAWeb } from '../../../../components/molecules/AnyContent/IsA/IFPSItemIsA';
import { CurrentOrigin } from '../../../../components/molecules/source-props/WindowLocationConstants';
// import { createErrorFPSTileItem } from '../../../FPSTiles/functions/ErrorMessages';
export const NonGroupGroupID = `00000000-0000-0000-0000-000000000000`;
/**
* processHubSubResults adds addSearchMeta1, Popularity and IsA keys to sub, hubs
* @param results
* @param sourceProps - used in addSearchMeta1
* @param search - used in addSearchMeta1
* @param departmentId
* @param siteIsAKeys
* @returns
*/
export function processHubSubResults(results, sourceProps, search, departmentId, siteIsAKeys = []) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// let finalItems: any[] = results.items as any[];
if (results.status !== 'Success') {
results.itemsY = results.items;
// finalItems.push( createErrorTile(props.fetchInfo.hubs.hubsCategory, 'HubSiteFunctions: DID NOT FIND ANY ASSOCIATED SITES!', results.errorInfo.friendly, props ));
}
else {
/**
* 2025-01-21: Added this logic for https://github.com/mikezimm/pivottiles7/issues/441
* ServerRelativeUrl is not a part of the actual search results so I have to add it back here.
* May also be other missing things I had manually added in the past.
*
*/
// const itemsY = [];
results.items.map((item) => {
if (!item.ServerRelativeUrl && item.Path)
item.ServerRelativeUrl = item.Path.replace(CurrentOrigin, '');
// itemsY.push( item );
});
// 2025-01-21: Changed to Path based upon https://github.com/mikezimm/pivottiles7/issues/441
results.itemsY = filterObjArrayByUniqueKey(results.items, 'ServerRelativeUrl');
results.itemsY = addSearchMeta1(results.itemsY, sourceProps, search);
results.itemsY = addPopularityToItems(results.itemsY, 0.2);
const doIsASite = siteIsAKeys.indexOf('STSSite') > -1 ? true : false;
const doIsAWeb = siteIsAKeys.indexOf('STSWeb') > -1 ? true : false;
const doIsAGroup = siteIsAKeys.indexOf('MSTeam') > -1 ? true : false;
results.itemsY = results.itemsY.map(item => {
// Add Group/Teams icon https://github.com/fps-solutions/HubCon/issues/13
const url = item.ServerRelativeUrl;
const IsASite = url && url.replace('/sites/', '').indexOf('/') > 0 ? false : true;
if (doIsASite === true && IsASite === true)
item = addItemIsA(item, ItemIsASite);
// Opting to NOT id IsASite or IsAWeb because in most cases, this may be obvious.
if (doIsAWeb === true && IsASite === false)
item = addItemIsA(item, ItemIsAWeb);
// Added from PivotTiles processWebsResults
if (item.EnableMinimalDownload === true) {
item = addItemIsA(item, ItemHasMinimalDownload);
}
// Adds only for Top Level Sites, Not Subs and if it is a group
if (doIsAGroup === true && IsASite === true && item[`GroupId`] && item[`GroupId`] !== NonGroupGroupID)
item = addItemIsA(item, ItemIsATeam);
return item;
});
/**
* 2024-12-31: Had this line before but was giving warning: "'a.Title' is possibly 'undefined'.ts(18048)" in this line?
* results.itemsY.sort((a, b) => a.Title.localeCompare(b.Title));
*/
results.itemsY.sort((a, b) => a.Title.localeCompare(b.Title));
// Move current hub to top of the list: https://github.com/fps-solutions/HubCon/issues/9
if (departmentId) {
const originalSites = results.itemsY;
const CurrentHubSite = [];
const AssocHubSites = [];
originalSites.map(item => {
// Must add the { } because it comes with it in the object
if (item[`SiteId`] === `${departmentId}`) {
CurrentHubSite.push(item);
}
else {
AssocHubSites.push(item);
}
});
results.itemsY = [...CurrentHubSite, ...AssocHubSites];
}
// results.itemsY = addSearchMeta1(results.items, sourceProps, search);
// results.itemsY = addPopularityToItems(results.items, 0.2);
// results.itemsY.sort((a, b) => a.Title.localeCompare(b.Title));
}
if (check4This(Check4.fpsShowFetchResults_Eq_true) === true) {
console.log(`processHubResults: ~ 54`, results);
}
return results;
}
//# sourceMappingURL=processHubSubResults.js.map