@mikezimm/npmfunctions
Version:
Functions used in my SPFx webparts
244 lines (240 loc) • 12.4 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getExpandColumns = exports.getFuncColumns = exports.getLinkColumns = exports.getSelectColumns = exports.getKeysLike = void 0;
var React = __importStar(require("react"));
var getInterfaceV2_1 = require("./getInterfaceV2");
/**
* 2020-09-28: getFunctions.ts intro
*
* The first 3 functions in this file were pulled from PivotTiles.tsx.
* They are used for fetching items, finding select and expand columns.
*
* Here's how they are used in PivotTiles.tsx
*
let selectCols: string = "*";
let expandThese = "";
let allColumns = this.getKeysLike(this.props,"col","Begins");
let expColumns = this.getExpandColumns(allColumns);
let selColumns = this.getSelectColumns(allColumns);
selColumns.length > 0 ? selectCols += "," + selColumns.join(",") : selectCols = selectCols;
if (expColumns.length > 0) { expandThese = expColumns.join(","); }
web.lists.getByTitle(useTileList).items
.select(selectCols).expand(expandThese).filter(restFilter).orderBy(restSort,true).getAll()
*/
/**
* getKeysLike function takes an object like "props"
* looks for specific keys that begin with a string like 'col'
* and returns those keys back in an array.
* Use case: Look for props that begin with 'col' which will then return all the known or mapped static column names
* @param thisProps
* @param findMe
* @param findOp
*/
function getKeysLike(thisProps, findMe, findOp) {
//Sample call: getKeysLike(this.props,"col","begins")
//console.log('FoundProps that ' + findOp + ' with ' + findMe);
//console.log(thisProps);
var allKeys = Object.keys(thisProps);
var foundKeys = [];
var lFind = findMe.length;
findMe = findMe.toLowerCase();
findOp = findOp.toLowerCase();
if (findOp === "begins") {
foundKeys = allKeys.filter(function (k) { return k.toLowerCase().indexOf(findMe) === 0; });
}
else if (findOp === "ends") {
foundKeys = allKeys.filter(function (k) { return k.toLowerCase().indexOf(findMe) === (k.length - lFind); });
}
else {
foundKeys = allKeys.filter(function (k) { return k.toLowerCase().indexOf(findMe) > -1; });
}
var foundProps = [];
for (var _i = 0, foundKeys_1 = foundKeys; _i < foundKeys_1.length; _i++) {
var thisProp = foundKeys_1[_i];
if (thisProp && thisProp !== "") {
foundProps.push(thisProps[thisProp]);
}
}
return foundProps;
}
exports.getKeysLike = getKeysLike;
/**
* getSelectColumns function will take an array of column names (string format)
* and return an array of the columns that need to be added to the select variable in getItems
* It pushes the entire expanded name like: Created/ID
* @param lookupColumns
*/
/**
* NOTE All this should be gotten from npmFunctions!!!!
* Lists/getFunctions.ts
*
*/
function getSelectColumns(lookupColumns, DoNotExpandColumnsIn) {
if (DoNotExpandColumnsIn === void 0) { DoNotExpandColumnsIn = getInterfaceV2_1.DoNotExpandColumns; }
var baseSelectColumns = [];
var DoNotExpandColumnsLC = DoNotExpandColumnsIn.map(function (item) { return item.toLowerCase(); });
var DoNotExpandFuncColumnsLC = DoNotExpandColumnsIn.map(function (item) { return item.toLowerCase(); });
for (var _i = 0, lookupColumns_1 = lookupColumns; _i < lookupColumns_1.length; _i++) {
var thisColumn = lookupColumns_1[_i];
// Only look at columns with / in the name
if (thisColumn && thisColumn.indexOf("/") > -1) {
var isLookup = thisColumn.indexOf("/");
if (isLookup) {
var splitCol = thisColumn.split("/");
var baseColumn = splitCol[0]; //This is always the zero index splitCol period
var nextPart = splitCol[1];
var rightSide = splitCol[splitCol.length - 1];
var hasFunctionError = false;
if (rightSide.toLowerCase().indexOf('before') > -1 && DoNotExpandFuncColumnsLC.indexOf(rightSide.toLowerCase().replace('before', 'b4')) > -1) {
hasFunctionError = true;
}
if (nextPart && DoNotExpandColumnsLC.indexOf(nextPart.toLowerCase()) > -1) {
//Then do nothing since this column is a 'faux expanded column' used in Drilldown for Link Columns
}
else if (splitCol && splitCol.length === 2 && hasFunctionError === true) {
//Then do nothing since this column is a 'faux expanded column' used in Drilldown for Link Columns
baseSelectColumns.push(splitCol[0]);
}
else if (splitCol && splitCol.length === 3) {
//Then check since this is likely an expanded column with special function
if (nextPart && DoNotExpandColumnsLC.indexOf(nextPart.toLowerCase()) < 0) {
var temp = hasFunctionError !== true ? '/' + splitCol[1] : '';
baseSelectColumns.push(splitCol[0] + temp);
}
}
else {
baseSelectColumns.push(thisColumn);
}
}
}
}
return baseSelectColumns;
}
exports.getSelectColumns = getSelectColumns;
function getLinkColumns(lookupColumns, DoNotExpandColumnsIn) {
if (DoNotExpandColumnsIn === void 0) { DoNotExpandColumnsIn = getInterfaceV2_1.DoNotExpandLinkColumns; }
var baseLinkColumns = [];
var DoNotExpandLinkColumnsLC = DoNotExpandColumnsIn.map(function (item) { return item.toLowerCase(); });
for (var _i = 0, lookupColumns_2 = lookupColumns; _i < lookupColumns_2.length; _i++) {
var thisColumn = lookupColumns_2[_i];
// Only look at columns with / in the name
var splitCol = thisColumn.split("/");
var leftSide = splitCol[0];
var rightSide = splitCol[splitCol.length - 1];
if (rightSide && DoNotExpandLinkColumnsLC.indexOf(rightSide.toLowerCase()) > -1) {
//Then do nothing since this column is a 'faux expanded column' used in Drilldown for Link Columns
if (baseLinkColumns.indexOf(thisColumn) < 0) {
baseLinkColumns.push(thisColumn);
}
}
}
return baseLinkColumns;
}
exports.getLinkColumns = getLinkColumns;
function getFuncColumns(lookupColumns, DoNotExpandColumnsIn) {
if (DoNotExpandColumnsIn === void 0) { DoNotExpandColumnsIn = getInterfaceV2_1.DoNotExpandFuncColumns; }
var allFuncColumns = [];
var funcErrors = [];
var actualFuncColumns = [];
var DoNotExpandFuncColumnsLC = DoNotExpandColumnsIn.map(function (item) { return item.toLowerCase(); });
for (var _i = 0, lookupColumns_3 = lookupColumns; _i < lookupColumns_3.length; _i++) {
var thisColumn = lookupColumns_3[_i];
// Only look at columns with / in the name
var splitCol = thisColumn.split("/");
var leftSide = splitCol.length === 3 ? splitCol[0] + '/' + splitCol[1] : splitCol[0];
var rightSide = splitCol[splitCol.length - 1];
if (rightSide && DoNotExpandFuncColumnsLC.indexOf(rightSide.toLowerCase()) > -1) {
//Then do nothing since this column is a 'faux expanded column' used in Drilldown for Func Columns
if (allFuncColumns.indexOf(thisColumn) < 0) {
allFuncColumns.push(thisColumn);
//This extra if-then is required because there could be 2 functions pointing to the same actual column
if (actualFuncColumns.indexOf(leftSide) < 0) {
actualFuncColumns.push(leftSide);
}
}
}
var funcIdx = DoNotExpandFuncColumnsLC.indexOf(rightSide.toLowerCase());
if (rightSide.toLowerCase().indexOf('before') > -1 && DoNotExpandFuncColumnsLC.indexOf(rightSide.toLowerCase().replace('before', 'b4')) > -1) {
// funcErrors.push ( `For: ${thisColumn}, function ${rightSide} is Not Valid :)`);
funcErrors.push(React.createElement("span", null,
"For: ",
React.createElement("b", null,
leftSide,
"/"),
React.createElement("b", { style: { color: 'red' } }, rightSide),
", replace ",
React.createElement("b", { style: { color: 'red' } }, "'before'"),
" with ",
React.createElement("b", { style: { color: 'green' } }, "'b4'"),
" :)"));
}
else if (splitCol.length === 3 && funcIdx < 0) {
// funcErrors.push ( `For: ${thisColumn}, function ${rightSide} is Not Valid :)`);
funcErrors.push(React.createElement("span", null,
"For: ",
React.createElement("b", null, thisColumn),
", function ",
React.createElement("b", { style: { color: 'red' } }, rightSide),
" is Not Valid :)"));
}
}
return { all: allFuncColumns, actual: actualFuncColumns, funcErrors: funcErrors };
}
exports.getFuncColumns = getFuncColumns;
/**
* getExpandColumns function will take an array of column names (string format)
* and return an array of the columns that need to be added to the expand variable in getItems
* It pushes the just the column name: It finds: Created/ID and returns just Created
* @param lookupColumns
*/
//column 'names' that are special and do not get expanded:
function getExpandColumns(lookupColumns, DoNotExpandColumnsIn) {
if (DoNotExpandColumnsIn === void 0) { DoNotExpandColumnsIn = getInterfaceV2_1.DoNotExpandColumns; }
var baseExpandColumns = [];
var DoNotExpandColumnsLC = DoNotExpandColumnsIn.map(function (item) { return item.toLowerCase(); });
for (var _i = 0, lookupColumns_4 = lookupColumns; _i < lookupColumns_4.length; _i++) {
var thisColumn = lookupColumns_4[_i];
// Only look at columns with / in the name
if (thisColumn && thisColumn.indexOf("/") > -1) {
var splitCol = thisColumn.split("/");
// let leftSide = splitCol.length === 3 ? splitCol[0] + '/' + splitCol[1]: splitCol[0] ;
var baseColumn = splitCol[0]; //This is always the zero index splitCol period
var nextPart = splitCol[1];
// Need to check 2 special cases:
// #1 is splitCol[1] = link column? If so, do not expand
// #2 is if splitCol[1] = any other special column, do not expand
if (nextPart && DoNotExpandColumnsLC.indexOf(nextPart.toLowerCase()) > -1) {
//Then do nothing since this column is a 'faux expanded column' used in Drilldown for Link Columns
}
else if (baseExpandColumns.indexOf(baseColumn) < 0) {
baseExpandColumns.push(baseColumn);
}
}
}
return baseExpandColumns;
}
exports.getExpandColumns = getExpandColumns;
//# sourceMappingURL=getFunctionsV2.js.map