@mikezimm/fps-library-v2
Version:
Library of reusable typescript/javascript functions, interfaces and constants
50 lines (48 loc) • 2.15 kB
JavaScript
/**
* CodeAnalizerComment: Updated 1 imports on 2024-09-22 14:49:52
* Update:: import { IAnySourceItem } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IAnyContent;'
*/
/**
* CodeAnalizerComment: Updated 2 imports on 2024-09-21 23:07:24
* Update:: import { ISourceProps } to '@mikezimm/fps-core-v7/lib/components/molecules/source-props/ISourceProps;'
* Update:: import { IAnySourceItem } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IAnyContent;'
*/
import * as React from 'react';
import { Icon } from '@fluentui/react/lib/Icon';
// https://github.com/mikezimm/fps-library-v2/issues/190
import { CommonLinkCSS, CommonClasses } from './GetGoToListLink';
require('@mikezimm/fps-styles/dist/fpsGeneralCSS.css');
/**
* https://github.com/mikezimm/fps-library-v2/issues/190
*
* @param props
* @returns
*/
export function GetGoToItemLink(props) {
const { primarySource, showItemLink, item, altText, itemLinkCSS } = props;
const viewItemLink = getGoToItemLinkUrl(item, primarySource);
const linkCSS = itemLinkCSS ? { ...CommonLinkCSS, ...itemLinkCSS } : CommonLinkCSS;
const gotoItemLink = showItemLink === false || !viewItemLink ? undefined : React.createElement("div", { className: CommonClasses.join(' '), onClick: () => { window.open(viewItemLink, '_blank'); }, style: linkCSS },
altText ? altText : `Open item`,
" ",
React.createElement(Icon, { iconName: 'OpenInNewTab' }));
return gotoItemLink;
}
/**
* https://github.com/mikezimm/fps-library-v2/issues/190
*
* @param item
* @param primarySource
* @returns
*/
export function getGoToItemLinkUrl(item, primarySource) {
const { FileRef, ID, } = item;
const searchHref = item.FPSItem && item.FPSItem.Search ? item.FPSItem.Search.searchHref : '';
let viewItemLink = FileRef;
if (!viewItemLink && primarySource.viewItemLink)
viewItemLink = primarySource.viewItemLink.replace('{{item.ID}}', ID);
if (!viewItemLink && searchHref)
viewItemLink = searchHref;
return viewItemLink;
}
//# sourceMappingURL=GoToLinks.js.map