@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
77 lines • 3.01 kB
JavaScript
/**
* 2024-12-07: MOVE THIS TO fps-core-v7 ???
* MIGRATION CANDIDATE
*/
import { CurrentOrigin } from "../../../components/molecules/source-props/WindowLocationConstants";
import { getSourceItemsAPI } from "./getSourceItemsAPI";
const PreConfigSiteUrl = `${CurrentOrigin}/sites/PreConfigProps`;
/**
* This is standard fetch to get preConfigItems, initially in Drilldown.
* These provide the user with a list of property mappings they can pick from to quickly and easily set up the web part.
* The return result is an array of key - value objects like so:
*
* result: [
* { webUrl: "https:tenant.sharepoint.com/sites/collection" }
* { listTitle: "Documents" }
* ];
*
* usage: returns newMap and you need to set this.propserties.newMap = newMap;
* @param listTitle
* @param thisProps
* @param restFilter --- matches webPartScenario eq 'thisWPProps.webPartScenario' where webPartScenario might be Dev or Teams or Corp
* @param webUrl
* @returns
*/
export async function getPreConfigItems(fpsSpService, thisWPProps, listTitle, webUrl = PreConfigSiteUrl) {
let returnProps = [];
if (!thisWPProps.webPartScenario) {
return returnProps;
}
let thisProps = Object.keys(thisWPProps);
let selectProps = ['Id', 'Title', 'Template'].concat(thisProps);
const sourceProps = {
fpsSpService: fpsSpService,
webUrl: webUrl,
listTitle: listTitle,
restFilter: thisWPProps.webPartScenario ? `webPartScenario eq '${thisWPProps.webPartScenario}'` : '',
selectThese: ['*'],
expandThese: [],
fetchCount: 300,
consoleLog: true,
orderByBoolean: {
prop: 'Title',
asc: false,
}
};
const result = await getSourceItemsAPI(sourceProps, true, true, true, []);
if (result.status === 'Success') {
if (result.items && result.items.length === 0) {
alert(`Did not find any preconfigured items at ${webUrl.replace(CurrentOrigin, '')} List: ${listTitle}`);
}
else if (result.items) {
result.items.map(i => {
// i = preConfigProps list item.
let iProps = {};
let currentItemProps = Object.keys(i); //All the props in the pre-configured list
selectProps.map(p => {
if (currentItemProps.indexOf(p) < 0) {
//console.log('Skipping this prop... not in the PreConfigProps list: ', p );
}
else {
if (i[p]) {
iProps[p] = i[p];
}
else {
iProps[p] = i[p];
}
}
});
returnProps.push(iProps);
});
}
}
else {
}
return returnProps;
}
//# sourceMappingURL=getPreConfig.js.map