@mikezimm/fps-library-v2
Version:
Library of reusable typescript/javascript functions, interfaces and constants
178 lines (176 loc) • 11.1 kB
JavaScript
/**
* CodeAnalizerComment: Updated 5 imports on 2024-09-22 14:49:52
* Update:: import { EmptyStateSource } to '@mikezimm/fps-core-v7/lib/components/molecules/state-source/IStateSource;'
* Update:: import { IAnySourceItem } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IAnyContent;'
* Update:: import { IFPSItem } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IAnyContent;'
* Update:: import { IStateSource } to '@mikezimm/fps-core-v7/lib/components/molecules/state-source/IStateSource;'
* Update:: import { addSearchMeta1 } to '@mikezimm/fps-core-v7/lib/components/molecules/SearchPage/functions/addSearchMeta1;'
*/
/**
* CodeAnalizerComment: Updated 10 imports on 2024-09-21 23:07:24
* Update:: import { EmptyStateSource } to '@mikezimm/fps-core-v7/lib/components/molecules/state-source/IStateSource;'
* Update:: import { IAnySourceItem } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IAnyContent;'
* Update:: import { IFPSItem } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IAnyContent;'
* 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 { IStateSource } to '@mikezimm/fps-core-v7/lib/components/molecules/state-source/IStateSource;'
* Update:: import { addSearchMeta1 } to '@mikezimm/fps-core-v7/lib/components/molecules/SearchPage/functions/addSearchMeta1;'
* Update:: import { startPerformOpV2 } to '@mikezimm/fps-core-v7/lib/components/molecules/Performance/functions;'
* Update:: import { unifiedPerformanceEnd } to '@mikezimm/fps-core-v7/lib/components/molecules/Performance/functions;'
* Update:: import { IPerformanceSettings } to '@mikezimm/fps-core-v7/lib/components/molecules/Performance/IPerformanceSettings;'
*/
import { buildFPSAnyTileItems } from './Any/buildFPSAnyTileItems';
import { getSourceItemsAPI } from "@mikezimm/fps-core-v7/lib/restAPIs/lists/items/getSourceItemsAPI";
import { EmptyStateSource } from '@mikezimm/fps-core-v7/lib/components/molecules/state-source/IStateSource';
import { createErrorFPSTileItem } from './Any/createErrorFPSTileItem';
import { addSearchMeta1 } from '@mikezimm/fps-core-v7/lib/components/molecules/SearchPage/functions/addSearchMeta1';
import { startPerformOpV2, unifiedPerformanceEnd } from '@mikezimm/fps-core-v7/lib/components/molecules/Performance/functions';
import { createContentViewsRecent } from '../../../atoms/Highlights/createContentViewsRecent';
import { createItemHighlights } from '../../../atoms/Highlights/createItemHighlights';
import { CommonSuppressKeys } from '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IsA/IFPSItemIsA';
import { addSearchFileDataV2 } from '@mikezimm/fps-core-v7/lib/components/molecules/SearchPage/functions/addSearchFileV2';
import { MAXSearchTypes } from '@mikezimm/fps-core-v7/lib/components/molecules/SearchPage/Interfaces/ProgrammingFileKeys';
import { createContentPubDate } from '../../../atoms/Highlights/createContentPubDate';
/**
* Similar to getFPSItemTiles which adds Popularity and such... but this is derived for basic FPSItem links from LinkUp
* @param list
* @param FPSItem
* @returns
*/
export async function getFPSLinkList(list, FPSItem, idx, bannerProps) {
if (!list || list.show !== true)
return null;
if (!list.sourceProps)
return null;
const { webUrl, listTitle, webRelativeLink, } = list.sourceProps;
const loadThisData = webUrl && webUrl && listTitle ? true : false;
if (loadThisData === true) {
// https://github.com/fps-solutions/LinkUp/issues/13
// Copied performance model from src\pnpjs\Navigation\addWebNav.ts
let performanceSettings = { label: `getLinkList ${idx}: ${listTitle}`, updateMiliseconds: true, includeMsStr: true, op: 'fetch' };
const fetchOp = performanceSettings ? startPerformOpV2(performanceSettings) : null;
const FPSItemCopy = JSON.parse(JSON.stringify(FPSItem));
let getItems = await getSourceItemsAPI(list.sourceProps, true, false, true);
getItems.itemsY = addSearchMeta1(getItems.items, list.sourceProps, null);
// https://github.com/fps-solutions/LinkUp/issues/32
const webRelativeLinkLC = webRelativeLink ? `${webRelativeLink.toLocaleLowerCase()}` : '';
const listTitleLC = listTitle ? `${listTitle.toLocaleLowerCase().replace(' ', '')}` : '';
const isSitePages = webRelativeLinkLC === 'sitepages' || webRelativeLinkLC === '/sitepages/' ||
listTitleLC.indexOf('sitepages') > -1 ? true : false;
if (isSitePages !== true) {
const ListDispForm = webRelativeLink.indexOf('sitepages') === -1 ? `${webUrl}/${webRelativeLink}/DispForm.aspx?ID={{ID}}` : '';
if (!FPSItemCopy.Link) {
FPSItemCopy.Link = { href: '', altUrl: ListDispForm };
}
else if (FPSItemCopy.Link)
FPSItemCopy.Link.altUrl = ListDispForm;
}
getItems = buildFPSAnyTileItems(getItems, bannerProps, FPSItemCopy);
// Only do this for NON-Site Pages since processTileList really only updates the imageUrl
// ... which should already be taken care of with buildFPSAnyTileItem
if (isSitePages === true) {
getItems.itemsY.map((item) => {
item = addSearchFileDataV2(item, list.sourceProps, MAXSearchTypes);
item.FPSItem.Elements = {
// 2024-09-07: cast all these functions ''as any' to pass build errors with fps-core-v7 interface
content1: createContentPubDate(item),
content2: undefined,
content3: createContentViewsRecent(item),
content4: createItemHighlights(item, { position: 'absolute', top: '10px', right: '10px', zIndex: 1 }, ['Page', ...CommonSuppressKeys]),
};
});
}
else {
getItems.itemsY = processTileList(getItems, list, null, FPSItemCopy);
}
// https://github.com/fps-solutions/LinkUp/issues/13
getItems = unifiedPerformanceEnd(getItems, performanceSettings, fetchOp, 'fetch', 'value');
return getItems;
}
else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return { ...EmptyStateSource, ...{ status: 'Unknown' } };
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
/**
* This may be over done in multiple places but being cautious to protect for future use
* https://github.com/fps-solutions/LinkUp/issues/32
* https://github.com/fps-solutions/LinkUp/issues/34
* @param item
* @returns
*/
export function checkIsAFile(item) {
const isAFile = item.FileLeafRef || item.File || item.FileRef || (item.ServerRelativeUrl && item.ServerRelativeUrl.indexOf('sitepages') > -1) ? true : false;
return isAFile;
}
export function processTileList(itemsReturn, list, search, FPSItem) {
if (itemsReturn.status !== 'Success') {
itemsReturn.itemsY = [createErrorFPSTileItem(itemsReturn, FPSItem)];
return itemsReturn.itemsY;
}
else {
const columns = list.columns;
itemsReturn.itemsY.map((item) => {
item = addSearchFileDataV2(item, list.sourceProps, MAXSearchTypes);
// https://github.com/mikezimm/pivottiles7/issues/399
// Need to add this to avoid error on FPSTileElement here: const { content1, content2, content3, content4 } = item.FPSItem.Elements;
// Adding these from Pages in case there are files to get CheckedOut etc
item.FPSItem.Elements = {
// 2024-09-07: cast all these functions ''as any' to pass build errors with fps-core-v7 interface
content1: createContentPubDate(item),
content2: undefined,
content3: createContentViewsRecent(item),
content4: createItemHighlights(item, { position: 'absolute', top: '10px', right: '10px', zIndex: 1 }, ['Page', ...CommonSuppressKeys]),
};
const title = columns.colTitleText ? item[columns.colTitleText] : '';
const desc = columns.colDescription ? item[columns.colDescription] : '';
item.FPSItem.Link.title = title;
item.FPSItem.Link.description = desc;
/**
* UPDATE The Image src if neccessary
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let src = columns.colImageLink ? item[columns.colImageLink] : '';
// https://github.com/mikezimm/pivottiles7/issues/400
// 2024-11-26: Add this for Pivot Tiles case where colUmageLink === 'BannerImageUrl.Url'
if (!src && columns.colImageLink && columns.colImageLink.indexOf('.Url'))
src = item[columns.colImageLink.split('.')[0]];
// flatten Urls in case it's a Url field... else if Text Field, just use it
src = !src ? '' : typeof src === 'string' ? src : typeof src === 'object' ? src.Url : '';
if (!src && list.defaultImg)
src = list.defaultImg;
/**
* Update Icon.name if neccessary
*/
const icon = src.indexOf('/') < 0 ? src : '';
if (icon)
src = ''; // disable image url if it's not a url... then assume it's an icon
item.FPSItem.Image.src = src;
// https://github.com/fps-solutions/LinkUp/issues/57
if (!item.FPSItem.Icon || !item.FPSItem.Icon.name)
item.FPSItem.Icon.name = icon;
/**
* Only update the Link.href if neccessary
*/
// Only update href if it was not found with buildFPSAnyTileItems first
if (!item.FPSItem.Link.href || item.FPSItem.Link.href.indexOf('Unknown') === 0) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let href = columns.colGotoLink ? item[columns.colGotoLink] : '';
// flatten Urls in case it's a Url field... else if Text Field, just use it
href = !href ? '' : typeof href === 'string' ? href : typeof href === 'object' ? href.Url : '';
item.FPSItem.Link.href = href;
const isAFile = checkIsAFile(item);
if (!isAFile && (!item.FPSItem.Link.altUrl || item.FPSItem.Link.altUrl.indexOf('Unknown') === 0)) {
item.FPSItem.Link.altUrl = href;
}
item.FPSItem.Link.ctrlUrl = href;
item.FPSItem.Link.shiftUrl = href;
item.FPSItem.Link.metaUrl = href;
item.FPSItem.Link.key3Url = href;
}
});
return itemsReturn.itemsY;
}
}
//# sourceMappingURL=getFPSLinkList.js.map