@pnp/spfx-controls-react
Version:
Reusable React controls for SharePoint Framework solutions
59 lines • 2.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useGroups = void 0;
var tslib_1 = require("tslib");
var sp_http_1 = require("@microsoft/sp-http");
var sp_page_context_1 = require("@microsoft/sp-page-context");
var react_1 = tslib_1.__importDefault(require("react"));
var escapeFilterValue = function (value) {
return value.replace(/'/g, "''");
};
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
var useGroups = function (serviceScope) {
var _pageContext = react_1.default.useRef();
var _msgGraphClient = react_1.default.useRef();
var init = react_1.default.useCallback(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var _a;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
_pageContext.current = serviceScope.consume(sp_page_context_1.PageContext.serviceKey);
_a = _msgGraphClient;
return [4 /*yield*/, serviceScope
.consume(sp_http_1.MSGraphClientFactory.serviceKey)
.getClient("3")];
case 1:
_a.current = _b.sent();
return [2 /*return*/];
}
});
}); }, [serviceScope]);
var getGroups = react_1.default.useCallback(function (filter) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var api, groupResults;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, init()];
case 1:
_a.sent();
if (!_msgGraphClient.current)
return [2 /*return*/, []];
api = _msgGraphClient.current
.api("/groups")
.select("id,displayName,description,groupTypes,mailEnabled,mail,securityEnabled,visibility,resourceProvisioningOptions");
if (filter) {
api.filter("startswith(toupper(displayName),toupper('".concat(escapeFilterValue(filter), "'))"));
}
return [4 /*yield*/, api.get()];
case 2:
groupResults = _a.sent();
return [2 /*return*/, groupResults.value];
}
});
}); }, [init]);
return {
init: init,
getGroups: getGroups,
};
};
exports.useGroups = useGroups;
//# sourceMappingURL=useGroups.js.map