@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
100 lines (99 loc) • 5.63 kB
JavaScript
/**
* CodeAnalizerComment: Updated 2 imports on 2024-09-22 02:56:43
* Update:: import { fetchListList } to '@mikezimm/fps-core-v7/lib/banner/components/ItemPicker/functions/fetchListList;'
* Update:: import { fetchFileList } to '@mikezimm/fps-core-v7/lib/banner/components/ItemPicker/functions/fetchFileList;'
*/
import { fetchListList } from "../../ItemPicker/functions/fetchListList";
import { fetchFileList } from "../../ItemPicker/functions/fetchFileList";
export function testValidWebUrl(approvedWebs, webUrl) {
let isValidWebUrl = true;
let isApprovedWeb = false;
if (!webUrl || webUrl.length === 0) {
isValidWebUrl = false;
}
else if (webUrl.indexOf('/sites/') !== 0 && webUrl.indexOf(window.origin) !== 0) {
isValidWebUrl = false;
}
if (isValidWebUrl === true) {
if (approvedWebs.length === 0) {
isApprovedWeb = true;
}
else {
approvedWebs.map(site => {
if (webUrl.toLowerCase().indexOf(`${site.siteRelativeURL.toLowerCase()}/`) > -1) {
isApprovedWeb = true;
}
});
}
}
return isApprovedWeb;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export async function onListItemPropPaneStart(thisWPClass, approvedWebs, BaseTemplate, includeItem, idx) {
// 2024-10-21: For the sake of reusability and type definition ease, casting as IFPSListItemPickerWPProps but can be used as IFPSListItemPickerWPProps2 with the 'as ...'
const wpProps = thisWPClass.properties;
let webUrlPickerValueX = wpProps[`webUrlPickerValue${idx}`];
if (webUrlPickerValueX && webUrlPickerValueX.toLowerCase().indexOf('currentsite') > -1) {
webUrlPickerValueX = `${thisWPClass.context.pageContext.web.serverRelativeUrl}/`;
wpProps[`webUrlPickerValue${idx}`] = webUrlPickerValueX; // Added this just to be sure the wpProps are also updated
thisWPClass.context.propertyPane.refresh();
}
thisWPClass[`_webUrlPickerValueApproved${idx}`] = false;
thisWPClass[`_itemsDropdownDisabled${idx}`] = true;
thisWPClass[`_listsDropdownDisabled${idx}`] = true;
const webUrlIsApproved = approvedWebs.length === 0 ? true : testValidWebUrl(approvedWebs, webUrlPickerValueX);
let restFilter = `Hidden eq false`; // ADDED 2024-10-15
if (BaseTemplate)
restFilter = `${restFilter} and BaseTemplate eq ${BaseTemplate}`; // ADDED 2024-10-15
//May need to remove this check so you can run in sandbox mode after saving props to invalid CDN
if (webUrlIsApproved === true || thisWPClass._runSandbox === true) {
// 2025-02-13: Fixed: https://github.com/fps-solutions/Core-FPT1.20.X/issues/1Z
// eslint-disable-next-line @typescript-eslint/no-floating-promises, @typescript-eslint/no-explicit-any
fetchListList(thisWPClass._fpsSpService, webUrlPickerValueX, restFilter)
.then((results) => {
if (results.items.length > 0) {
thisWPClass[`_listPickerList${idx}`] = results.items;
thisWPClass[`_approvedLists${idx}`] = thisWPClass[`_listPickerList${idx}`];
thisWPClass[`_listsDropdownDisabled${idx}`] = false;
if (results.items.length > 0) {
if (wpProps[`listPickerValue${idx}`]) {
// 2024-09-22: Added undefined as any to pass type error
let selectedLibrary = undefined;
thisWPClass[`_listPickerList${idx}`].map((lib, idxX) => {
if (lib.key === wpProps[`listPickerValue${idxX}`]) {
selectedLibrary = lib;
}
});
if (!includeItem) { // ADDED 2024-10-15
thisWPClass.refreshPaneReRender();
}
else {
// 2025-02-13: Fixed: https://github.com/fps-solutions/Core-FPT1.20.X/issues/1
// eslint-disable-next-line @typescript-eslint/no-floating-promises, @typescript-eslint/no-explicit-any
fetchFileList(thisWPClass._fpsSpService, selectedLibrary, thisWPClass[`_approvedFilePickerTypes${idx}`])
.then((results) => {
console.log('onPropertyPaneConfigurationStart: files', results);
thisWPClass[`_listItemsPickerList${idx}`] = results.items;
// enable item selector
thisWPClass[`_itemsDropdownDisabled${idx}`] = false;
thisWPClass.refreshPaneReRender();
});
}
}
else {
console.log(`onPropertyPaneConfigurationStart: wpProps.listPickerValue${idx}`, wpProps[`listPickerValue${idx}`]);
thisWPClass[`_listItemsPickerList${idx}`] = [];
thisWPClass.refreshPaneReRender();
}
}
}
});
}
else { //No web selected, clear all sub properties
// 2024-09-22: Added null as any to pass type error
wpProps[`listPickerValue${idx}`] = null;
thisWPClass[`_listItemsPickerList${idx}`] = [];
thisWPClass.refreshPaneReRender();
}
}
//# sourceMappingURL=onListItemPropPaneStart.js.map