UNPKG

@mikezimm/fps-library-v2

Version:

Library of reusable typescript/javascript functions, interfaces and constants

179 lines (177 loc) 8.47 kB
/** * CodeAnalizerComment: Updated 2 imports on 2024-09-22 14:49:52 * Update:: import { IAnySourceItem } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IAnyContent;' * Update:: import { IAnySourceItemAny } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IAnyContent;' */ /** * CodeAnalizerComment: Updated 4 imports on 2024-09-21 23:07:24 * Update:: import { IAnySourceItem } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IAnyContent;' * Update:: import { IAnySourceItemAny } 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 { check4This } to '@mikezimm/fps-core-v7/lib/logic/Links/CheckSearch;' */ import * as React from 'react'; import { Icon } from '@fluentui/react/lib/Icon'; import { getHighlightedText } from '../../../atoms/Elements/HighlightedText'; import { check4This, Check4 } from '@mikezimm/fps-core-v7/lib/logic/Links/CheckSearch'; require('@mikezimm/fps-styles/dist/itemPaneProps.css'); export function getItemProperties(props) { const { primarySource, item, columns, searchText } = props; if (!primarySource || !item || !columns) return undefined; const shown = []; const keys = []; const headings = []; const propElements = []; if (primarySource.editProps && primarySource.editProps.length > 0 && columns.indexOf('Edit') < 0) { keys.push('editProps'); headings.push('Edit'); } ; if (primarySource.viewProps && primarySource.viewProps.length > 0 && columns.indexOf('View') < 0) { keys.push('viewProps'); headings.push('View'); } ; columns.map(cols => { if (cols === 'Selected') { keys.push('selectThese'); headings.push(cols); } else if (cols === 'Searched') { keys.push('searchProps'); headings.push(cols); } else if (cols === 'Columns') { keys.push('columns'); headings.push(cols); } else if (cols === 'Expanded') { keys.push('expandThese'); headings.push(cols); } else if (cols === 'View') { keys.push('viewProps'); headings.push(cols); } else if (cols === 'Edit') { keys.push('editProps'); headings.push(cols); } else if (cols === 'SearchText') { keys.push('searchText'); headings.push(cols); } }); // Always add searchText prop to end if searchText has been passed in but the columns were not if (searchText && keys.indexOf('searchText') < 0) keys.push('searchText'); headings.push('SearchText'); keys.map((key, index) => { // Declaring as any so it passes linting when mapping through possible keys const primarySourceAny = primarySource; const showProps = key === 'searchText' ? ['searchText'] : primarySourceAny[key]; let thesePropsList = undefined; //Was doing this in original code, possibly to avoid a mutation so just doing it here to be safe. const doProps = showProps ? JSON.parse(JSON.stringify(showProps)) : []; if (doProps && doProps.length > 0) { // Loop through the item's props that match the doProps array of columns thesePropsList = React.createElement("ul", null, doProps.map((field, idx) => { // https://github.com/mikezimm/ALVFinMan/issues/167 // Only show prop once in first grouping if (shown.indexOf(field) < 0) { shown.push(field); return getValidPropLI(item, field, idx, searchText); } })); } else { thesePropsList = React.createElement("div", null, `There are no ${headings[index]} properties.`); } // Create the property list element const thesePropsElement = React.createElement("div", { key: key, className: 'source-itemPane-properties' }, React.createElement("h3", null, `${headings[index]} Properties`), thesePropsList); // Only show element if there are actually properties to show in the array if (doProps && doProps.length > 0) propElements.push(thesePropsElement); }); // const searchProps: string[] = JSON.parse(JSON.stringify( primarySource.searchProps )); // console.log( 'selectThese - searchProps', searchProps ); // const searchPropsList = primarySource && searchProps && searchProps.length > 0 ? // <ul> // { searchProps.map( ( field: string, idx: number ) => { // // https://github.com/mikezimm/ALVFinMan/issues/167 // return this.getValidPropLI( item, field, idx ); // })} // </ul> : <div>There are no Searched properties.</div>; // //Created this ling hand instead of filter after the LinkColumn issue. // //Filter may work but I've had it on this one trying to figure it out. // const selectThese: string[] = []; // primarySource.selectThese.map( (selectProp) => { // if ( primarySource.searchProps.indexOf( selectProp ) < 0 ) selectThese.push( selectProp ); // }); // console.log( 'selectThese - selectThese', selectThese ); // const selectTheseList: JSX.Element = primarySource && selectThese && selectThese.length > 0 ? // <ul> // { selectThese.map(( field: string, idx: number ) => { // // https://github.com/mikezimm/ALVFinMan/issues/167 // return this.getValidPropLI( item, field, idx ); // })} // </ul>: <div>There are no Selected properties.</div>; const itemContent = React.createElement("div", null, propElements); return itemContent; } /** * function: getValidPropLI * * Created this function to resolve issue: https://github.com/mikezimm/ALVFinMan/issues/167 * @param showThisItem * @param field * @param idx * @returns */ export function getValidPropLI(showThisItem, field, idx, searchText) { var _a; if (check4This(Check4.itemPaneProps_Eq_true) === true) console.log('field', field, typeof showThisItem[field], JSON.stringify(showThisItem[field])); const isLink = ((_a = showThisItem[field]) === null || _a === void 0 ? void 0 : _a.Url) ? true : false; const isObject = typeof showThisItem[field] === 'object' ? true : false; const isRich = typeof showThisItem[field] === 'string' && showThisItem[field].indexOf(`<div class="ExternalClass`) === 0 ? true : false; if (isRich === true) { return React.createElement("li", { key: idx }, React.createElement("div", null, field, ":"), " ", React.createElement("div", { dangerouslySetInnerHTML: { __html: showThisItem[field] } })); } else if (isLink === true) { return React.createElement("li", { key: idx }, React.createElement("div", null, field, ":"), " ", React.createElement("div", { style: { cursor: 'pointer', fontSize: 'larger' }, onClick: () => window.open(showThisItem[field].Url, '_blank') }, React.createElement("span", { style: { display: 'inline-block', width: '80%' } }, getHighlightedText(showThisItem[field].Description, searchText)), React.createElement(Icon, { style: { marginLeft: '15px' }, iconName: 'OpenInNewTab' }))); } else if (isObject === true) { const obj = JSON.stringify(showThisItem[field]); return React.createElement("li", { key: idx }, React.createElement("div", null, field, ":"), " ", React.createElement("div", null, getHighlightedText(obj, searchText))); } else { return React.createElement("li", { key: idx }, React.createElement("div", null, getHighlightedText(field, searchText), ":"), " ", React.createElement("div", null, getHighlightedText(showThisItem[field], searchText))); } } //# sourceMappingURL=itemProperties.js.map