@mikezimm/fps-library-v2
Version:
Library of reusable typescript/javascript functions, interfaces and constants
83 lines (82 loc) • 4.29 kB
JavaScript
/**
* CodeAnalizerComment: Updated 3 imports on 2024-09-21 23:07:24
* Update:: import { IHelpTable } to '@mikezimm/fps-core-v7/lib/banner/components/SingleHelpPage/interfaces/ISinglePageProps;'
* Update:: import { check4This } to '@mikezimm/fps-core-v7/lib/logic/Links/CheckSearch;'
* Update:: import { ITrickRow } to '@mikezimm/fps-core-v7/lib/banner/components/SingleHelpPage/interfaces/ITrickRow;'
*/
import * as React from 'react';
import { check4This } from '@mikezimm/fps-core-v7/lib/logic/Links/CheckSearch';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function makeCenteredSpan(info) {
return { info: info, style: { textAlign: 'center' } };
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function makeCenteredBoldSpan(info) {
return { info: info, style: { textAlign: 'center', fontWeight: 'bolder' } };
}
/**
* THIS IS SIMILAR to tricksTable but that creates the rows by hand. due to added complexity
* @param tricks
* @param heading
* @returns
*/
export function createTricksTable(tricks, heading) {
const table = {
heading: heading ? heading : 'Undocumented console.log url parameters',
headers: ['Param', 'Value', 'Active?', 'Notes'],
rows: [],
};
const hasSearch = window.location.search && window.location.search.length > 0 ? true : false;
let searchParams = hasSearch === true ? window.location.search : '';
const hasSearchParams = searchParams.length > 0 ? '&' : '?';
let hasClear = false;
searchParams = searchParams.split('%3a').join(':');
tricks.map(trick => {
const trickParam = `${trick.param}${trick.op ? trick.op : '='}${trick.value}`;
if (trick.param === 'clearParams')
hasClear = true;
if (trick.op === 'heading') { // https://github.com/mikezimm/pivottiles7/issues/269
table.rows.push([React.createElement("span", { style: { fontWeight: 'bold', paddingTop: '20px' } }, trick.param), undefined, undefined, undefined]);
}
else {
const activeLink = check4This(trickParam) === true ?
makeCenteredBoldSpan('true') :
makeCenteredBoldSpan(React.createElement("a", { href: window.location + hasSearchParams + trickParam }, "Activate!"));
table.rows.push([makeCenteredSpan(trick.param), makeCenteredSpan(trick.value), activeLink, { info: trick.description }]);
}
});
if (hasClear === false) {
const bareLink = hasSearch ?
makeCenteredBoldSpan(React.createElement("a", { href: window.location.pathname }, "Activate!")) :
makeCenteredBoldSpan('true');
table.rows.push([
makeCenteredSpan('clearParams'),
makeCenteredSpan(`${hasSearch}`),
bareLink,
{ info: `Reload without any parameters (wwwthing after the ? in the url )` }
]);
}
return table;
}
export function createTricksTableElement(tricks, heading, tableWidth) {
const tblInfo = createTricksTable(tricks, heading);
const rows = tblInfo.rows.map((row, idx) => {
return React.createElement("tr", { key: idx, style: { padding: `0 ${'5px'}` } }, row.map((cell, idx) => {
// Had to add the cell.info ternary because sometimes cell === JSX.Element
return !cell ? undefined : React.createElement("td", { style: cell.style },
cell.info ? cell.info : cell,
" ");
}));
});
const headerStyles = { textAlign: 'center', };
if (tblInfo.headers && tblInfo.headers.length > 0) {
rows.unshift(React.createElement("tr", null, tblInfo.headers.map(hdr => {
return React.createElement("th", { style: headerStyles }, hdr);
})));
}
const result = React.createElement("div", null,
heading ? React.createElement("div", { style: { fontWeight: 600, fontSize: 'larger', paddingTop: '15px' } }, heading) : undefined,
React.createElement("table", { className: 'fps-gen-table', style: { width: tableWidth ? tableWidth : '1asdf', maxWidth: '1200px', margin: '10px 0px 10px 15px' } }, rows));
return result;
}
//# sourceMappingURL=makeTricksTable.js.map