@apvee/spfx-react-toolkit 1.2.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/atoms.internal.js +1 -1
- package/lib/core/atoms.internal.js.map +1 -1
- package/lib/core/context.internal.js +2 -2
- package/lib/core/context.internal.js.map +1 -1
- package/lib/core/provider-base.internal.js +29 -29
- package/lib/core/provider-base.internal.js.map +1 -1
- package/lib/extensions/spFxReactToolkitTest/SpFxReactToolkitTestApplicationCustomizer.d.ts +14 -0
- package/lib/extensions/spFxReactToolkitTest/SpFxReactToolkitTestApplicationCustomizer.d.ts.map +1 -0
- package/lib/extensions/spFxReactToolkitTest/SpFxReactToolkitTestApplicationCustomizer.js +20 -0
- package/lib/extensions/spFxReactToolkitTest/SpFxReactToolkitTestApplicationCustomizer.js.map +1 -0
- package/lib/extensions/spFxReactToolkitTest/SpFxReactToolkitTestApplicationCustomizer.manifest.json +17 -0
- package/lib/extensions/spFxReactToolkitTest/loc/en-us.js +5 -0
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.d.ts.map +1 -1
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useAppCatalogUrl.internal.d.ts +26 -0
- package/lib/hooks/useAppCatalogUrl.internal.d.ts.map +1 -0
- package/lib/hooks/useAppCatalogUrl.internal.js +72 -0
- package/lib/hooks/useAppCatalogUrl.internal.js.map +1 -0
- package/lib/hooks/useAsyncInvoke.internal.js +27 -75
- package/lib/hooks/useAsyncInvoke.internal.js.map +1 -1
- package/lib/hooks/useSPFxAadHttpClient.d.ts +46 -0
- package/lib/hooks/useSPFxAadHttpClient.d.ts.map +1 -1
- package/lib/hooks/useSPFxAadHttpClient.js +65 -20
- package/lib/hooks/useSPFxAadHttpClient.js.map +1 -1
- package/lib/hooks/useSPFxContainerInfo.js +5 -5
- package/lib/hooks/useSPFxContainerInfo.js.map +1 -1
- package/lib/hooks/useSPFxContainerSize.js +9 -10
- package/lib/hooks/useSPFxContainerSize.js.map +1 -1
- package/lib/hooks/useSPFxCorrelationInfo.js +6 -7
- package/lib/hooks/useSPFxCorrelationInfo.js.map +1 -1
- package/lib/hooks/useSPFxCrossSitePermissions.js +48 -58
- package/lib/hooks/useSPFxCrossSitePermissions.js.map +1 -1
- package/lib/hooks/useSPFxDisplayMode.js +8 -8
- package/lib/hooks/useSPFxDisplayMode.js.map +1 -1
- package/lib/hooks/useSPFxEnvironmentInfo.js +17 -18
- package/lib/hooks/useSPFxEnvironmentInfo.js.map +1 -1
- package/lib/hooks/useSPFxFluent9ThemeInfo.js +4 -4
- package/lib/hooks/useSPFxFluent9ThemeInfo.js.map +1 -1
- package/lib/hooks/useSPFxHttpClient.d.ts +18 -2
- package/lib/hooks/useSPFxHttpClient.d.ts.map +1 -1
- package/lib/hooks/useSPFxHttpClient.js +19 -9
- package/lib/hooks/useSPFxHttpClient.js.map +1 -1
- package/lib/hooks/useSPFxHubSiteInfo.js +21 -24
- package/lib/hooks/useSPFxHubSiteInfo.js.map +1 -1
- package/lib/hooks/useSPFxInstanceInfo.js +2 -2
- package/lib/hooks/useSPFxInstanceInfo.js.map +1 -1
- package/lib/hooks/useSPFxListInfo.js +8 -9
- package/lib/hooks/useSPFxListInfo.js.map +1 -1
- package/lib/hooks/useSPFxLocaleInfo.js +10 -10
- package/lib/hooks/useSPFxLocaleInfo.js.map +1 -1
- package/lib/hooks/useSPFxLogger.js +26 -26
- package/lib/hooks/useSPFxLogger.js.map +1 -1
- package/lib/hooks/useSPFxMSGraphClient.d.ts +50 -3
- package/lib/hooks/useSPFxMSGraphClient.d.ts.map +1 -1
- package/lib/hooks/useSPFxMSGraphClient.js +68 -15
- package/lib/hooks/useSPFxMSGraphClient.js.map +1 -1
- package/lib/hooks/useSPFxOneDriveAppData.d.ts +0 -1
- package/lib/hooks/useSPFxOneDriveAppData.d.ts.map +1 -1
- package/lib/hooks/useSPFxOneDriveAppData.js +420 -230
- package/lib/hooks/useSPFxOneDriveAppData.js.map +1 -1
- package/lib/hooks/useSPFxPageContext.js +2 -2
- package/lib/hooks/useSPFxPageContext.js.map +1 -1
- package/lib/hooks/useSPFxPageType.js +19 -20
- package/lib/hooks/useSPFxPageType.js.map +1 -1
- package/lib/hooks/useSPFxPerformance.js +33 -87
- package/lib/hooks/useSPFxPerformance.js.map +1 -1
- package/lib/hooks/useSPFxPermissions.js +14 -15
- package/lib/hooks/useSPFxPermissions.js.map +1 -1
- package/lib/hooks/useSPFxPnP.js +62 -119
- package/lib/hooks/useSPFxPnP.js.map +1 -1
- package/lib/hooks/useSPFxPnPContext.js +22 -25
- package/lib/hooks/useSPFxPnPContext.js.map +1 -1
- package/lib/hooks/useSPFxPnPList.js +307 -451
- package/lib/hooks/useSPFxPnPList.js.map +1 -1
- package/lib/hooks/useSPFxPnPSearch.js +262 -353
- package/lib/hooks/useSPFxPnPSearch.js.map +1 -1
- package/lib/hooks/useSPFxProperties.js +12 -20
- package/lib/hooks/useSPFxProperties.js.map +1 -1
- package/lib/hooks/useSPFxSPHttpClient.d.ts +18 -2
- package/lib/hooks/useSPFxSPHttpClient.d.ts.map +1 -1
- package/lib/hooks/useSPFxSPHttpClient.js +28 -18
- package/lib/hooks/useSPFxSPHttpClient.js.map +1 -1
- package/lib/hooks/useSPFxServiceScope.js +6 -6
- package/lib/hooks/useSPFxServiceScope.js.map +1 -1
- package/lib/hooks/useSPFxSiteInfo.js +7 -8
- package/lib/hooks/useSPFxSiteInfo.js.map +1 -1
- package/lib/hooks/useSPFxStorage.js +22 -22
- package/lib/hooks/useSPFxStorage.js.map +1 -1
- package/lib/hooks/useSPFxTeams.js +37 -92
- package/lib/hooks/useSPFxTeams.js.map +1 -1
- package/lib/hooks/useSPFxTenantKeyValueStore.d.ts +252 -0
- package/lib/hooks/useSPFxTenantKeyValueStore.d.ts.map +1 -0
- package/lib/hooks/useSPFxTenantKeyValueStore.js +572 -0
- package/lib/hooks/useSPFxTenantKeyValueStore.js.map +1 -0
- package/lib/hooks/useSPFxTenantProperty.d.ts +23 -244
- package/lib/hooks/useSPFxTenantProperty.d.ts.map +1 -1
- package/lib/hooks/useSPFxTenantProperty.js +85 -559
- package/lib/hooks/useSPFxTenantProperty.js.map +1 -1
- package/lib/hooks/useSPFxUserInfo.js +3 -4
- package/lib/hooks/useSPFxUserInfo.js.map +1 -1
- package/lib/hooks/useSPFxUserPhoto.js +76 -123
- package/lib/hooks/useSPFxUserPhoto.js.map +1 -1
- package/lib/utils/resize-observer.internal.js +6 -7
- package/lib/utils/resize-observer.internal.js.map +1 -1
- package/lib/utils/theme-subscription.internal.js +8 -8
- package/lib/utils/theme-subscription.internal.js.map +1 -1
- package/lib/utils/type-guards.internal.js +6 -6
- package/lib/utils/type-guards.internal.js.map +1 -1
- package/lib/webparts/spFxReactToolkitTest/SpFxReactToolkitTestWebPart.js +12 -37
- package/lib/webparts/spFxReactToolkitTest/SpFxReactToolkitTestWebPart.js.map +1 -1
- package/lib/webparts/spFxReactToolkitTest/components/SpFxReactToolkitTest.d.ts.map +1 -1
- package/lib/webparts/spFxReactToolkitTest/components/SpFxReactToolkitTest.js +279 -342
- package/lib/webparts/spFxReactToolkitTest/components/SpFxReactToolkitTest.js.map +1 -1
- package/lib/webparts/spFxReactToolkitTest/components/SpFxReactToolkitTest.module.scss.js +1 -1
- package/lib/webparts/spFxReactToolkitTest/components/SpFxReactToolkitTest.module.scss.js.map +1 -1
- package/lib/webparts/spFxReactToolkitTest/components/demos/HttpClientDemo.js +26 -86
- package/lib/webparts/spFxReactToolkitTest/components/demos/HttpClientDemo.js.map +1 -1
- package/lib/webparts/spFxReactToolkitTest/components/demos/PnPContextDemo.js +53 -113
- package/lib/webparts/spFxReactToolkitTest/components/demos/PnPContextDemo.js.map +1 -1
- package/lib/webparts/spFxReactToolkitTest/components/demos/PnPListDemo.js +49 -121
- package/lib/webparts/spFxReactToolkitTest/components/demos/PnPListDemo.js.map +1 -1
- package/lib/webparts/spFxReactToolkitTest/components/demos/PnPOperationsDemo.js +44 -103
- package/lib/webparts/spFxReactToolkitTest/components/demos/PnPOperationsDemo.js.map +1 -1
- package/lib/webparts/spFxReactToolkitTest/components/demos/PnPSearchAdvancedDemo.js +15 -15
- package/lib/webparts/spFxReactToolkitTest/components/demos/PnPSearchAdvancedDemo.js.map +1 -1
- package/lib/webparts/spFxReactToolkitTest/components/demos/PnPSearchBasicDemo.js +18 -66
- package/lib/webparts/spFxReactToolkitTest/components/demos/PnPSearchBasicDemo.js.map +1 -1
- package/lib/webparts/spFxReactToolkitTest/components/demos/PnPSearchRefinersDemo.js +9 -9
- package/lib/webparts/spFxReactToolkitTest/components/demos/PnPSearchRefinersDemo.js.map +1 -1
- package/lib/webparts/spFxReactToolkitTest/components/demos/PnPSearchSuggestionsDemo.js +37 -86
- package/lib/webparts/spFxReactToolkitTest/components/demos/PnPSearchSuggestionsDemo.js.map +1 -1
- package/lib/webparts/spFxReactToolkitTest/components/shared/InfoRow.js +6 -9
- package/lib/webparts/spFxReactToolkitTest/components/shared/InfoRow.js.map +1 -1
- package/lib/webparts/spFxReactToolkitTest/components/shared/StatusBadge.js +3 -6
- package/lib/webparts/spFxReactToolkitTest/components/shared/StatusBadge.js.map +1 -1
- package/package.json +8 -6
|
@@ -1,39 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
1
|
import { useState, useEffect, useCallback, useRef } from 'react';
|
|
38
2
|
import { useSPFxPnPContext } from './useSPFxPnPContext';
|
|
39
3
|
/**
|
|
@@ -390,54 +354,49 @@ import { useSPFxPnPContext } from './useSPFxPnPContext';
|
|
|
390
354
|
* @see {@link PNPContextInfo} for context information
|
|
391
355
|
*/
|
|
392
356
|
export function useSPFxPnPList(listTitle, options, pnpContext) {
|
|
393
|
-
var _this = this;
|
|
394
357
|
// Get PnP context (use provided context or create default)
|
|
395
|
-
|
|
396
|
-
|
|
358
|
+
const defaultContext = useSPFxPnPContext();
|
|
359
|
+
const context = pnpContext || defaultContext;
|
|
397
360
|
// Use the native SPFI instance from context
|
|
398
|
-
|
|
361
|
+
const sp = context?.sp;
|
|
399
362
|
// Default pageSize from hook options
|
|
400
|
-
|
|
363
|
+
const defaultPageSize = options?.pageSize;
|
|
401
364
|
// Local state management
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
365
|
+
const [items, setItems] = useState([]);
|
|
366
|
+
const [loading, setLoading] = useState(false);
|
|
367
|
+
const [loadingMore, setLoadingMore] = useState(false);
|
|
368
|
+
const [error, setError] = useState();
|
|
369
|
+
const [hasMore, setHasMore] = useState(false);
|
|
407
370
|
// State for tracking last query (needed for refetch and loadMore)
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
371
|
+
const [lastQueryBuilder, setLastQueryBuilder] = useState(undefined);
|
|
372
|
+
const [lastEffectivePageSize, setLastEffectivePageSize] = useState(undefined);
|
|
373
|
+
const [currentSkip, setCurrentSkip] = useState(0);
|
|
411
374
|
// Refs
|
|
412
|
-
|
|
413
|
-
|
|
375
|
+
const refetchTimeoutRef = useRef(undefined);
|
|
376
|
+
const mountedRef = useRef(true);
|
|
414
377
|
// Clear error handler
|
|
415
|
-
|
|
378
|
+
const clearError = useCallback(() => {
|
|
416
379
|
setError(undefined);
|
|
417
380
|
}, []);
|
|
418
381
|
/**
|
|
419
382
|
* Helper: Creates a recursive Proxy to track .top() calls in queryBuilder.
|
|
420
383
|
* This allows automatic detection of user-specified page size.
|
|
421
384
|
*/
|
|
422
|
-
|
|
385
|
+
const createMonitoredQuery = useCallback((target, tracker) => {
|
|
423
386
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
424
387
|
return new Proxy(target, {
|
|
425
388
|
get: function (t, prop) {
|
|
426
389
|
if (prop === 'top') {
|
|
427
390
|
return function (n) {
|
|
428
391
|
tracker.top = n;
|
|
429
|
-
|
|
392
|
+
const result = t.top.call(t, n);
|
|
430
393
|
return createMonitoredQuery(result, tracker);
|
|
431
394
|
};
|
|
432
395
|
}
|
|
433
|
-
|
|
396
|
+
const value = t[prop];
|
|
434
397
|
if (typeof value === 'function') {
|
|
435
|
-
return function () {
|
|
436
|
-
|
|
437
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
438
|
-
args[_i] = arguments[_i];
|
|
439
|
-
}
|
|
440
|
-
var result = value.apply(t, args);
|
|
398
|
+
return function (...args) {
|
|
399
|
+
const result = value.apply(t, args);
|
|
441
400
|
if (result && typeof result === 'object' && typeof result.select === 'function') {
|
|
442
401
|
return createMonitoredQuery(result, tracker);
|
|
443
402
|
}
|
|
@@ -452,107 +411,91 @@ export function useSPFxPnPList(listTitle, options, pnpContext) {
|
|
|
452
411
|
/**
|
|
453
412
|
* Executes a query with automatic .top() detection.
|
|
454
413
|
*/
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
// Warning if both specified
|
|
479
|
-
if (tracker.top !== undefined && pageSize !== undefined) {
|
|
480
|
-
console.warn("[useSPFxPnPList] Both .top(".concat(tracker.top, ") and pageSize(").concat(pageSize, ") specified. ") +
|
|
481
|
-
"Using .top(".concat(tracker.top, ")."));
|
|
482
|
-
}
|
|
483
|
-
if (tracker.top !== undefined) {
|
|
484
|
-
// User specified .top() explicitly
|
|
485
|
-
finalQuery = userQuery;
|
|
486
|
-
effectivePageSize = tracker.top;
|
|
487
|
-
}
|
|
488
|
-
else if (pageSize !== undefined) {
|
|
489
|
-
// Use pageSize option
|
|
490
|
-
finalQuery = userQuery.top(pageSize);
|
|
491
|
-
effectivePageSize = pageSize;
|
|
492
|
-
}
|
|
493
|
-
else {
|
|
494
|
-
// No pagination
|
|
495
|
-
finalQuery = userQuery;
|
|
496
|
-
effectivePageSize = undefined;
|
|
497
|
-
}
|
|
498
|
-
return [4 /*yield*/, finalQuery()];
|
|
499
|
-
case 2:
|
|
500
|
-
result = _b.sent();
|
|
501
|
-
if (!mountedRef.current)
|
|
502
|
-
return [2 /*return*/, result];
|
|
503
|
-
// Update state
|
|
504
|
-
setItems(result);
|
|
505
|
-
setLastQueryBuilder(function () { return queryBuilder; });
|
|
506
|
-
setLastEffectivePageSize(effectivePageSize);
|
|
507
|
-
setCurrentSkip(result.length);
|
|
508
|
-
// hasMore only meaningful with pagination
|
|
509
|
-
if (effectivePageSize !== undefined) {
|
|
510
|
-
setHasMore(result.length === effectivePageSize);
|
|
511
|
-
}
|
|
512
|
-
else {
|
|
513
|
-
setHasMore(false);
|
|
514
|
-
}
|
|
515
|
-
setLoading(false);
|
|
516
|
-
return [2 /*return*/, result];
|
|
517
|
-
case 3:
|
|
518
|
-
err_1 = _b.sent();
|
|
519
|
-
if (mountedRef.current) {
|
|
520
|
-
setError(err_1);
|
|
521
|
-
setLoading(false);
|
|
522
|
-
}
|
|
523
|
-
throw err_1;
|
|
524
|
-
case 4: return [2 /*return*/];
|
|
414
|
+
const query = useCallback(async (queryBuilder, queryOptions) => {
|
|
415
|
+
if (!sp || !context?.isInitialized) {
|
|
416
|
+
const err = new Error('[useSPFxPnPList] PnP context not initialized. Ensure @pnp/sp is installed.');
|
|
417
|
+
setError(err);
|
|
418
|
+
throw err;
|
|
419
|
+
}
|
|
420
|
+
setLoading(true);
|
|
421
|
+
setError(undefined);
|
|
422
|
+
try {
|
|
423
|
+
const pageSize = queryOptions?.pageSize ?? defaultPageSize;
|
|
424
|
+
const baseQuery = sp.web.lists.getByTitle(listTitle).items;
|
|
425
|
+
// Track .top() calls with Proxy
|
|
426
|
+
const tracker = { top: undefined };
|
|
427
|
+
const monitored = createMonitoredQuery(baseQuery, tracker);
|
|
428
|
+
// Build user query
|
|
429
|
+
const userQuery = queryBuilder ? queryBuilder(monitored) : monitored;
|
|
430
|
+
// Smart decision: user .top() > pageSize option > no limit
|
|
431
|
+
let finalQuery;
|
|
432
|
+
let effectivePageSize;
|
|
433
|
+
// Warning if both specified
|
|
434
|
+
if (tracker.top !== undefined && pageSize !== undefined) {
|
|
435
|
+
console.warn(`[useSPFxPnPList] Both .top(${tracker.top}) and pageSize(${pageSize}) specified. ` +
|
|
436
|
+
`Using .top(${tracker.top}).`);
|
|
525
437
|
}
|
|
526
|
-
|
|
527
|
-
|
|
438
|
+
if (tracker.top !== undefined) {
|
|
439
|
+
// User specified .top() explicitly
|
|
440
|
+
finalQuery = userQuery;
|
|
441
|
+
effectivePageSize = tracker.top;
|
|
442
|
+
}
|
|
443
|
+
else if (pageSize !== undefined) {
|
|
444
|
+
// Use pageSize option
|
|
445
|
+
finalQuery = userQuery.top(pageSize);
|
|
446
|
+
effectivePageSize = pageSize;
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
// No pagination
|
|
450
|
+
finalQuery = userQuery;
|
|
451
|
+
effectivePageSize = undefined;
|
|
452
|
+
}
|
|
453
|
+
const result = await finalQuery();
|
|
454
|
+
if (!mountedRef.current)
|
|
455
|
+
return result;
|
|
456
|
+
// Update state
|
|
457
|
+
setItems(result);
|
|
458
|
+
setLastQueryBuilder(() => queryBuilder);
|
|
459
|
+
setLastEffectivePageSize(effectivePageSize);
|
|
460
|
+
setCurrentSkip(result.length);
|
|
461
|
+
// hasMore only meaningful with pagination
|
|
462
|
+
if (effectivePageSize !== undefined) {
|
|
463
|
+
setHasMore(result.length === effectivePageSize);
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
setHasMore(false);
|
|
467
|
+
}
|
|
468
|
+
setLoading(false);
|
|
469
|
+
return result;
|
|
470
|
+
}
|
|
471
|
+
catch (err) {
|
|
472
|
+
if (mountedRef.current) {
|
|
473
|
+
setError(err);
|
|
474
|
+
setLoading(false);
|
|
475
|
+
}
|
|
476
|
+
throw err;
|
|
477
|
+
}
|
|
478
|
+
}, [sp, context?.isInitialized, listTitle, defaultPageSize, createMonitoredQuery]);
|
|
528
479
|
/**
|
|
529
480
|
* Re-executes the last query (resets pagination).
|
|
530
481
|
*/
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
setCurrentSkip(0);
|
|
539
|
-
return [4 /*yield*/, query(lastQueryBuilder, { pageSize: lastEffectivePageSize })];
|
|
540
|
-
case 1:
|
|
541
|
-
_a.sent();
|
|
542
|
-
return [2 /*return*/];
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
}); }, [lastQueryBuilder, lastEffectivePageSize, query]);
|
|
482
|
+
const refetch = useCallback(async () => {
|
|
483
|
+
if (!lastQueryBuilder) {
|
|
484
|
+
throw new Error('[useSPFxPnPList] No previous query to refetch. Call query() first.');
|
|
485
|
+
}
|
|
486
|
+
setCurrentSkip(0);
|
|
487
|
+
await query(lastQueryBuilder, { pageSize: lastEffectivePageSize });
|
|
488
|
+
}, [lastQueryBuilder, lastEffectivePageSize, query]);
|
|
546
489
|
/**
|
|
547
490
|
* Debounced refetch to prevent race conditions during rapid CRUD operations.
|
|
548
491
|
*/
|
|
549
|
-
|
|
492
|
+
const debouncedRefetch = useCallback(() => {
|
|
550
493
|
if (refetchTimeoutRef.current) {
|
|
551
494
|
clearTimeout(refetchTimeoutRef.current);
|
|
552
495
|
}
|
|
553
496
|
refetchTimeoutRef.current = setTimeout(function () {
|
|
554
497
|
refetch().catch(function (err) {
|
|
555
|
-
|
|
498
|
+
const error = err;
|
|
556
499
|
console.error('[useSPFxPnPList] Debounced refetch error:', error);
|
|
557
500
|
setError(error);
|
|
558
501
|
});
|
|
@@ -561,318 +504,231 @@ export function useSPFxPnPList(listTitle, options, pnpContext) {
|
|
|
561
504
|
/**
|
|
562
505
|
* Loads more items (pagination with last query).
|
|
563
506
|
*/
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
setLoadingMore(true);
|
|
579
|
-
_a.label = 1;
|
|
580
|
-
case 1:
|
|
581
|
-
_a.trys.push([1, 3, , 4]);
|
|
582
|
-
if (!sp || !(context === null || context === void 0 ? void 0 : context.isInitialized)) {
|
|
583
|
-
throw new Error('[useSPFxPnPList] PnP context not initialized');
|
|
584
|
-
}
|
|
585
|
-
baseQuery = sp.web.lists.getByTitle(listTitle).items;
|
|
586
|
-
tracker = { top: undefined };
|
|
587
|
-
monitored = createMonitoredQuery(baseQuery, tracker);
|
|
588
|
-
userQuery = lastQueryBuilder(monitored);
|
|
589
|
-
finalQuery = userQuery.skip(currentSkip).top(lastEffectivePageSize);
|
|
590
|
-
return [4 /*yield*/, finalQuery()];
|
|
591
|
-
case 2:
|
|
592
|
-
result_1 = _a.sent();
|
|
593
|
-
if (!mountedRef.current)
|
|
594
|
-
return [2 /*return*/, result_1];
|
|
595
|
-
setItems(function (prevItems) {
|
|
596
|
-
return prevItems.concat(result_1);
|
|
597
|
-
});
|
|
598
|
-
setCurrentSkip(function (prev) {
|
|
599
|
-
return prev + result_1.length;
|
|
600
|
-
});
|
|
601
|
-
setHasMore(result_1.length === lastEffectivePageSize);
|
|
602
|
-
setLoadingMore(false);
|
|
603
|
-
return [2 /*return*/, result_1];
|
|
604
|
-
case 3:
|
|
605
|
-
err_2 = _a.sent();
|
|
606
|
-
if (mountedRef.current) {
|
|
607
|
-
setError(err_2);
|
|
608
|
-
setLoadingMore(false);
|
|
609
|
-
}
|
|
610
|
-
throw err_2;
|
|
611
|
-
case 4: return [2 /*return*/];
|
|
507
|
+
const loadMore = useCallback(async () => {
|
|
508
|
+
if (!lastQueryBuilder) {
|
|
509
|
+
throw new Error('[useSPFxPnPList] No previous query. Call query() first.');
|
|
510
|
+
}
|
|
511
|
+
if (lastEffectivePageSize === undefined) {
|
|
512
|
+
throw new Error('[useSPFxPnPList] Cannot loadMore without pageSize. Specify .top() or pageSize option in query().');
|
|
513
|
+
}
|
|
514
|
+
if (loadingMore || loading) {
|
|
515
|
+
return [];
|
|
516
|
+
}
|
|
517
|
+
setLoadingMore(true);
|
|
518
|
+
try {
|
|
519
|
+
if (!sp || !context?.isInitialized) {
|
|
520
|
+
throw new Error('[useSPFxPnPList] PnP context not initialized');
|
|
612
521
|
}
|
|
613
|
-
|
|
614
|
-
|
|
522
|
+
const baseQuery = sp.web.lists.getByTitle(listTitle).items;
|
|
523
|
+
const tracker = { top: undefined };
|
|
524
|
+
const monitored = createMonitoredQuery(baseQuery, tracker);
|
|
525
|
+
const userQuery = lastQueryBuilder(monitored);
|
|
526
|
+
const finalQuery = userQuery.skip(currentSkip).top(lastEffectivePageSize);
|
|
527
|
+
const result = await finalQuery();
|
|
528
|
+
if (!mountedRef.current)
|
|
529
|
+
return result;
|
|
530
|
+
setItems(function (prevItems) {
|
|
531
|
+
return prevItems.concat(result);
|
|
532
|
+
});
|
|
533
|
+
setCurrentSkip(function (prev) {
|
|
534
|
+
return prev + result.length;
|
|
535
|
+
});
|
|
536
|
+
setHasMore(result.length === lastEffectivePageSize);
|
|
537
|
+
setLoadingMore(false);
|
|
538
|
+
return result;
|
|
539
|
+
}
|
|
540
|
+
catch (err) {
|
|
541
|
+
if (mountedRef.current) {
|
|
542
|
+
setError(err);
|
|
543
|
+
setLoadingMore(false);
|
|
544
|
+
}
|
|
545
|
+
throw err;
|
|
546
|
+
}
|
|
547
|
+
}, [lastQueryBuilder, lastEffectivePageSize, loadingMore, loading, sp, context?.isInitialized, listTitle, currentSkip, createMonitoredQuery]);
|
|
615
548
|
/**
|
|
616
549
|
* Gets a single item by ID.
|
|
617
550
|
*/
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
case 3:
|
|
634
|
-
err_3 = _a.sent();
|
|
635
|
-
error_1 = err_3;
|
|
636
|
-
console.error('[useSPFxPnPList] getById error:', error_1);
|
|
637
|
-
setError(error_1);
|
|
638
|
-
return [2 /*return*/, undefined];
|
|
639
|
-
case 4: return [2 /*return*/];
|
|
640
|
-
}
|
|
641
|
-
});
|
|
642
|
-
}); }, [sp, context === null || context === void 0 ? void 0 : context.isInitialized, listTitle]);
|
|
551
|
+
const getById = useCallback(async (id) => {
|
|
552
|
+
if (!sp || !context?.isInitialized) {
|
|
553
|
+
throw new Error('[useSPFxPnPList] PnP context not initialized');
|
|
554
|
+
}
|
|
555
|
+
try {
|
|
556
|
+
const item = await sp.web.lists.getByTitle(listTitle).items.getById(id)();
|
|
557
|
+
return item;
|
|
558
|
+
}
|
|
559
|
+
catch (err) {
|
|
560
|
+
const error = err;
|
|
561
|
+
console.error('[useSPFxPnPList] getById error:', error);
|
|
562
|
+
setError(error);
|
|
563
|
+
return undefined;
|
|
564
|
+
}
|
|
565
|
+
}, [sp, context?.isInitialized, listTitle]);
|
|
643
566
|
/**
|
|
644
567
|
* Creates a new list item.
|
|
645
568
|
*/
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
debouncedRefetch();
|
|
661
|
-
return [2 /*return*/, result.data.Id];
|
|
662
|
-
case 3:
|
|
663
|
-
err_4 = _a.sent();
|
|
664
|
-
setError(err_4);
|
|
665
|
-
throw err_4;
|
|
666
|
-
case 4: return [2 /*return*/];
|
|
667
|
-
}
|
|
668
|
-
});
|
|
669
|
-
}); }, [sp, context === null || context === void 0 ? void 0 : context.isInitialized, listTitle, debouncedRefetch]);
|
|
569
|
+
const create = useCallback(async (item) => {
|
|
570
|
+
if (!sp || !context?.isInitialized) {
|
|
571
|
+
throw new Error('PnP context not initialized');
|
|
572
|
+
}
|
|
573
|
+
try {
|
|
574
|
+
const result = await sp.web.lists.getByTitle(listTitle).items.add(item);
|
|
575
|
+
debouncedRefetch();
|
|
576
|
+
return result.data.Id;
|
|
577
|
+
}
|
|
578
|
+
catch (err) {
|
|
579
|
+
setError(err);
|
|
580
|
+
throw err;
|
|
581
|
+
}
|
|
582
|
+
}, [sp, context?.isInitialized, listTitle, debouncedRefetch]);
|
|
670
583
|
/**
|
|
671
584
|
* Updates an existing list item.
|
|
672
585
|
*/
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
_a.sent();
|
|
687
|
-
debouncedRefetch();
|
|
688
|
-
return [3 /*break*/, 4];
|
|
689
|
-
case 3:
|
|
690
|
-
err_5 = _a.sent();
|
|
691
|
-
setError(err_5);
|
|
692
|
-
throw err_5;
|
|
693
|
-
case 4: return [2 /*return*/];
|
|
694
|
-
}
|
|
695
|
-
});
|
|
696
|
-
}); }, [sp, context === null || context === void 0 ? void 0 : context.isInitialized, listTitle, debouncedRefetch]);
|
|
586
|
+
const update = useCallback(async (id, item) => {
|
|
587
|
+
if (!sp || !context?.isInitialized) {
|
|
588
|
+
throw new Error('PnP context not initialized');
|
|
589
|
+
}
|
|
590
|
+
try {
|
|
591
|
+
await sp.web.lists.getByTitle(listTitle).items.getById(id).update(item);
|
|
592
|
+
debouncedRefetch();
|
|
593
|
+
}
|
|
594
|
+
catch (err) {
|
|
595
|
+
setError(err);
|
|
596
|
+
throw err;
|
|
597
|
+
}
|
|
598
|
+
}, [sp, context?.isInitialized, listTitle, debouncedRefetch]);
|
|
697
599
|
/**
|
|
698
600
|
* Deletes a list item.
|
|
699
601
|
*/
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
_a.sent();
|
|
714
|
-
debouncedRefetch();
|
|
715
|
-
return [3 /*break*/, 4];
|
|
716
|
-
case 3:
|
|
717
|
-
err_6 = _a.sent();
|
|
718
|
-
setError(err_6);
|
|
719
|
-
throw err_6;
|
|
720
|
-
case 4: return [2 /*return*/];
|
|
721
|
-
}
|
|
722
|
-
});
|
|
723
|
-
}); }, [sp, context === null || context === void 0 ? void 0 : context.isInitialized, listTitle, debouncedRefetch]);
|
|
602
|
+
const remove = useCallback(async (id) => {
|
|
603
|
+
if (!sp || !context?.isInitialized) {
|
|
604
|
+
throw new Error('PnP context not initialized');
|
|
605
|
+
}
|
|
606
|
+
try {
|
|
607
|
+
await sp.web.lists.getByTitle(listTitle).items.getById(id).delete();
|
|
608
|
+
debouncedRefetch();
|
|
609
|
+
}
|
|
610
|
+
catch (err) {
|
|
611
|
+
setError(err);
|
|
612
|
+
throw err;
|
|
613
|
+
}
|
|
614
|
+
}, [sp, context?.isInitialized, listTitle, debouncedRefetch]);
|
|
724
615
|
/**
|
|
725
616
|
* Creates multiple items in a batch.
|
|
726
617
|
*/
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
list.items.add(itemsToCreate[i]).then(function (result) {
|
|
747
|
-
ids_1.push(result.data.Id);
|
|
748
|
-
}).catch(function (error) {
|
|
749
|
-
console.error('Batch create error:', error);
|
|
750
|
-
errors_1.push(error);
|
|
751
|
-
});
|
|
752
|
-
}
|
|
753
|
-
// Execute batch
|
|
754
|
-
return [4 /*yield*/, execute()];
|
|
755
|
-
case 2:
|
|
756
|
-
// Execute batch
|
|
757
|
-
_a.sent();
|
|
758
|
-
// If there were errors in individual operations, set error state
|
|
759
|
-
if (errors_1.length > 0) {
|
|
760
|
-
batchError = new Error("Batch create failed: ".concat(errors_1.length, " of ").concat(itemsToCreate.length, " items failed"));
|
|
761
|
-
setError(batchError);
|
|
762
|
-
console.error('Batch create summary:', errors_1);
|
|
763
|
-
}
|
|
764
|
-
debouncedRefetch();
|
|
765
|
-
return [2 /*return*/, ids_1];
|
|
766
|
-
case 3:
|
|
767
|
-
err_7 = _a.sent();
|
|
768
|
-
error_2 = err_7;
|
|
769
|
-
setError(error_2);
|
|
770
|
-
throw error_2;
|
|
771
|
-
case 4: return [2 /*return*/];
|
|
618
|
+
const createBatch = useCallback(async (itemsToCreate) => {
|
|
619
|
+
if (!sp || !context?.isInitialized) {
|
|
620
|
+
throw new Error('PnP context not initialized');
|
|
621
|
+
}
|
|
622
|
+
try {
|
|
623
|
+
const ids = [];
|
|
624
|
+
const errors = [];
|
|
625
|
+
const batchResult = sp.batched();
|
|
626
|
+
const batchedSP = batchResult[0];
|
|
627
|
+
const execute = batchResult[1];
|
|
628
|
+
const list = batchedSP.web.lists.getByTitle(listTitle);
|
|
629
|
+
// Queue all creates
|
|
630
|
+
for (let i = 0; i < itemsToCreate.length; i++) {
|
|
631
|
+
list.items.add(itemsToCreate[i]).then(function (result) {
|
|
632
|
+
ids.push(result.data.Id);
|
|
633
|
+
}).catch(function (error) {
|
|
634
|
+
console.error('Batch create error:', error);
|
|
635
|
+
errors.push(error);
|
|
636
|
+
});
|
|
772
637
|
}
|
|
773
|
-
|
|
774
|
-
|
|
638
|
+
// Execute batch
|
|
639
|
+
await execute();
|
|
640
|
+
// If there were errors in individual operations, set error state
|
|
641
|
+
if (errors.length > 0) {
|
|
642
|
+
const batchError = new Error(`Batch create failed: ${errors.length} of ${itemsToCreate.length} items failed`);
|
|
643
|
+
setError(batchError);
|
|
644
|
+
console.error('Batch create summary:', errors);
|
|
645
|
+
}
|
|
646
|
+
debouncedRefetch();
|
|
647
|
+
return ids;
|
|
648
|
+
}
|
|
649
|
+
catch (err) {
|
|
650
|
+
const error = err;
|
|
651
|
+
setError(error);
|
|
652
|
+
throw error;
|
|
653
|
+
}
|
|
654
|
+
}, [sp, context?.isInitialized, listTitle, debouncedRefetch]);
|
|
775
655
|
/**
|
|
776
656
|
* Updates multiple items in a batch.
|
|
777
657
|
*/
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
for (i = 0; i < updates.length; i++) {
|
|
796
|
-
updateItem = updates[i];
|
|
797
|
-
list.items.getById(updateItem.id).update(updateItem.item).catch(function (error) {
|
|
798
|
-
console.error('Batch update error:', error);
|
|
799
|
-
errors_2.push(error);
|
|
800
|
-
});
|
|
801
|
-
}
|
|
802
|
-
// Execute batch
|
|
803
|
-
return [4 /*yield*/, execute()];
|
|
804
|
-
case 2:
|
|
805
|
-
// Execute batch
|
|
806
|
-
_a.sent();
|
|
807
|
-
// If there were errors in individual operations, set error state
|
|
808
|
-
if (errors_2.length > 0) {
|
|
809
|
-
batchError = new Error("Batch update failed: ".concat(errors_2.length, " of ").concat(updates.length, " items failed"));
|
|
810
|
-
setError(batchError);
|
|
811
|
-
console.error('Batch update summary:', errors_2);
|
|
812
|
-
}
|
|
813
|
-
debouncedRefetch();
|
|
814
|
-
return [3 /*break*/, 4];
|
|
815
|
-
case 3:
|
|
816
|
-
err_8 = _a.sent();
|
|
817
|
-
error_3 = err_8;
|
|
818
|
-
setError(error_3);
|
|
819
|
-
throw error_3;
|
|
820
|
-
case 4: return [2 /*return*/];
|
|
658
|
+
const updateBatch = useCallback(async (updates) => {
|
|
659
|
+
if (!sp || !context?.isInitialized) {
|
|
660
|
+
throw new Error('PnP context not initialized');
|
|
661
|
+
}
|
|
662
|
+
try {
|
|
663
|
+
const errors = [];
|
|
664
|
+
const batchResult = sp.batched();
|
|
665
|
+
const batchedSP = batchResult[0];
|
|
666
|
+
const execute = batchResult[1];
|
|
667
|
+
const list = batchedSP.web.lists.getByTitle(listTitle);
|
|
668
|
+
// Queue all updates
|
|
669
|
+
for (let i = 0; i < updates.length; i++) {
|
|
670
|
+
const updateItem = updates[i];
|
|
671
|
+
list.items.getById(updateItem.id).update(updateItem.item).catch(function (error) {
|
|
672
|
+
console.error('Batch update error:', error);
|
|
673
|
+
errors.push(error);
|
|
674
|
+
});
|
|
821
675
|
}
|
|
822
|
-
|
|
823
|
-
|
|
676
|
+
// Execute batch
|
|
677
|
+
await execute();
|
|
678
|
+
// If there were errors in individual operations, set error state
|
|
679
|
+
if (errors.length > 0) {
|
|
680
|
+
const batchError = new Error(`Batch update failed: ${errors.length} of ${updates.length} items failed`);
|
|
681
|
+
setError(batchError);
|
|
682
|
+
console.error('Batch update summary:', errors);
|
|
683
|
+
}
|
|
684
|
+
debouncedRefetch();
|
|
685
|
+
}
|
|
686
|
+
catch (err) {
|
|
687
|
+
const error = err;
|
|
688
|
+
setError(error);
|
|
689
|
+
throw error;
|
|
690
|
+
}
|
|
691
|
+
}, [sp, context?.isInitialized, listTitle, debouncedRefetch]);
|
|
824
692
|
/**
|
|
825
693
|
* Deletes multiple items in a batch.
|
|
826
694
|
*/
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
// Queue all deletes
|
|
844
|
-
for (i = 0; i < ids.length; i++) {
|
|
845
|
-
list.items.getById(ids[i]).delete().catch(function (error) {
|
|
846
|
-
console.error('Batch delete error:', error);
|
|
847
|
-
errors_3.push(error);
|
|
848
|
-
});
|
|
849
|
-
}
|
|
850
|
-
// Execute batch
|
|
851
|
-
return [4 /*yield*/, execute()];
|
|
852
|
-
case 2:
|
|
853
|
-
// Execute batch
|
|
854
|
-
_a.sent();
|
|
855
|
-
// If there were errors in individual operations, set error state
|
|
856
|
-
if (errors_3.length > 0) {
|
|
857
|
-
batchError = new Error("Batch delete failed: ".concat(errors_3.length, " of ").concat(ids.length, " items failed"));
|
|
858
|
-
setError(batchError);
|
|
859
|
-
console.error('Batch delete summary:', errors_3);
|
|
860
|
-
}
|
|
861
|
-
debouncedRefetch();
|
|
862
|
-
return [3 /*break*/, 4];
|
|
863
|
-
case 3:
|
|
864
|
-
err_9 = _a.sent();
|
|
865
|
-
error_4 = err_9;
|
|
866
|
-
setError(error_4);
|
|
867
|
-
throw error_4;
|
|
868
|
-
case 4: return [2 /*return*/];
|
|
695
|
+
const removeBatch = useCallback(async (ids) => {
|
|
696
|
+
if (!sp || !context?.isInitialized) {
|
|
697
|
+
throw new Error('PnP context not initialized');
|
|
698
|
+
}
|
|
699
|
+
try {
|
|
700
|
+
const errors = [];
|
|
701
|
+
const batchResult = sp.batched();
|
|
702
|
+
const batchedSP = batchResult[0];
|
|
703
|
+
const execute = batchResult[1];
|
|
704
|
+
const list = batchedSP.web.lists.getByTitle(listTitle);
|
|
705
|
+
// Queue all deletes
|
|
706
|
+
for (let i = 0; i < ids.length; i++) {
|
|
707
|
+
list.items.getById(ids[i]).delete().catch(function (error) {
|
|
708
|
+
console.error('Batch delete error:', error);
|
|
709
|
+
errors.push(error);
|
|
710
|
+
});
|
|
869
711
|
}
|
|
870
|
-
|
|
871
|
-
|
|
712
|
+
// Execute batch
|
|
713
|
+
await execute();
|
|
714
|
+
// If there were errors in individual operations, set error state
|
|
715
|
+
if (errors.length > 0) {
|
|
716
|
+
const batchError = new Error(`Batch delete failed: ${errors.length} of ${ids.length} items failed`);
|
|
717
|
+
setError(batchError);
|
|
718
|
+
console.error('Batch delete summary:', errors);
|
|
719
|
+
}
|
|
720
|
+
debouncedRefetch();
|
|
721
|
+
}
|
|
722
|
+
catch (err) {
|
|
723
|
+
const error = err;
|
|
724
|
+
setError(error);
|
|
725
|
+
throw error;
|
|
726
|
+
}
|
|
727
|
+
}, [sp, context?.isInitialized, listTitle, debouncedRefetch]);
|
|
872
728
|
/**
|
|
873
729
|
* Cleanup on unmount.
|
|
874
730
|
*/
|
|
875
|
-
useEffect(
|
|
731
|
+
useEffect(() => {
|
|
876
732
|
mountedRef.current = true;
|
|
877
733
|
return function () {
|
|
878
734
|
mountedRef.current = false;
|
|
@@ -882,25 +738,25 @@ export function useSPFxPnPList(listTitle, options, pnpContext) {
|
|
|
882
738
|
};
|
|
883
739
|
}, []);
|
|
884
740
|
// Derived state
|
|
885
|
-
|
|
741
|
+
const isEmpty = items.length === 0 && !loading && !error;
|
|
886
742
|
return {
|
|
887
|
-
query
|
|
743
|
+
query,
|
|
888
744
|
items: items,
|
|
889
|
-
loading
|
|
890
|
-
loadingMore
|
|
891
|
-
error
|
|
892
|
-
isEmpty
|
|
893
|
-
hasMore
|
|
894
|
-
refetch
|
|
895
|
-
loadMore
|
|
896
|
-
clearError
|
|
897
|
-
getById
|
|
898
|
-
create
|
|
899
|
-
update
|
|
900
|
-
remove
|
|
901
|
-
createBatch
|
|
902
|
-
updateBatch
|
|
903
|
-
removeBatch
|
|
745
|
+
loading,
|
|
746
|
+
loadingMore,
|
|
747
|
+
error,
|
|
748
|
+
isEmpty,
|
|
749
|
+
hasMore,
|
|
750
|
+
refetch,
|
|
751
|
+
loadMore,
|
|
752
|
+
clearError,
|
|
753
|
+
getById,
|
|
754
|
+
create,
|
|
755
|
+
update,
|
|
756
|
+
remove,
|
|
757
|
+
createBatch,
|
|
758
|
+
updateBatch,
|
|
759
|
+
removeBatch,
|
|
904
760
|
};
|
|
905
761
|
}
|
|
906
762
|
//# sourceMappingURL=useSPFxPnPList.js.map
|